基于单片机的宠物喂食器电路设计
break;
case 2:if(newval>59) newval=0; display(hour1,minute1,second1); minute1=newval; break;
case 3:if(newval>59) newval=0; display(hour1,minute1,second1); second1=newval; break; default:break; } } else {
newval--; switch(slnum) {
case 1:if(newval<0) newval=23; display(hour1,minute1,second1); hour1=newval; break;
case 2:if(newval<0) newval=59; display(hour1,minute1,second1); minute1=newval; break;
case 3:if(newval<0) newval=59; display(hour1,minute1,second1); second1=newval; break;
default:break; }
18
基于单片机的宠物喂食器电路设计
} }
void key_scan1(void) {
uchar slnum=0; if(s1==0) {
delay(5); if(s1==0) {
while(!s1);
display(hour1,minute1,second1); slnum++; TR0=0; while(1) {
display(hour1,minute1,second1); if(s1==0) {
delay(5); if(s1==0) {
while(!s1); slnum++; } } if(slnum==1) {
if(add==0)
19
基于单片机的宠物喂食器电路设计
{
delay(3); if(add==0) {
while(!add);
turn_val1(hour1,1,1); } }
if(dec==0) {
delay(3); if(dec==0) {
while(!dec);
turn_val1(hour1,0,1); } } }
if(slnum==2) {
if(add==0) {
delay(3); if(add==0) {
while(!add);
turn_val1(minute1,1,2); } }
if(dec==0) {
20
基于单片机的宠物喂食器电路设计
delay(3); if(dec==0) {
while(!dec);
turn_val1(minute1,0,2); } } }
if(slnum==3) {
if(add==0) {
delay(3); if(add==0) {
while(!add);
turn_val1(second1,1,3); } }
if(dec==0) {
delay(3); if(dec==0) {
while(!dec);
turn_val1(second1,0,3); // } } }
if(slnum==4) {
写入日寄存器21
基于单片机的宠物喂食器电路设计
slnum=0; break; } } } } }
void turn_val2(char newval,uchar flag,uchar slnum) {
if(flag) //判断是加一还是减一 {
newval++; switch(slnum) {
case 1:if(newval>23) newval=0; display(hour2,minute2,second2); hour2=newval; break;
case 2:if(newval>59) newval=0; display(hour2,minute2,second2); minute2=newval; break;
case 3:if(newval>59) newval=0; display(hour2,minute2,second2); second2=newval; break; default:break; } } else
22