内容发布更新时间 : 2024/12/23 10:24:19星期一 下面是文章的全部内容请认真阅读。
基于单片机的宠物喂食器电路设计
{
newval--; switch(slnum) {
case 1:if(newval<0) newval=23; display(hour2,minute2,second2); hour2=newval; break;
case 2:if(newval<0) newval=59; display(hour2,minute2,second2); minute2=newval; break;
case 3:if(newval<0) newval=59; display(hour2,minute2,second2); second2=newval; break;
default:break; } } }
void key_scan2(void) {
uchar slnum=0; if(s2==0) {
delay(5); if(s2==0) {
while(!s2);
23
基于单片机的宠物喂食器电路设计
display(hour2,minute2,second2); slnum++; TR0=0; while(1) {
display(hour2,minute2,second2); if(s2==0) {
delay(5); if(s2==0) {
while(!s2); slnum++; } } if(slnum==1) {
if(add==0) {
delay(3); if(add==0) {
while(!add);
turn_val2(hour2,1,1); } }
if(dec==0) {
delay(3); if(dec==0) {
24
基于单片机的宠物喂食器电路设计
while(!dec);
turn_val2(hour2,0,1); } } }
if(slnum==2) {
if(add==0) {
delay(3); if(add==0) {
while(!add);
turn_val2(minute2,1,2); } }
if(dec==0) {
delay(3); if(dec==0) {
while(!dec);
turn_val2(minute2,0,2); } } }
if(slnum==3) {
if(add==0) {
delay(3);
25
基于单片机的宠物喂食器电路设计
if(add==0) {
while(!add);
turn_val2(second2,1,3); } }
if(dec==0) {
delay(3); if(dec==0) {
while(!dec);
turn_val2(second2,0,3); //写入日寄存器 } } }
if(slnum==4) { slnum=0; break; } } } } }
void turn_val3(char newval,uchar flag,uchar slnum) {
if(flag) //判断是加一还是减一 {
newval++;
26
基于单片机的宠物喂食器电路设计
switch(slnum) {
case 1:if(newval>23) newval=0; display(hour3,minute3,second3); hour3=newval; break;
case 2:if(newval>59) newval=0; display(hour3,minute3,second3); minute3=newval; break;
case 3:if(newval>59) newval=0; display(hour3,minute3,second3); second3=newval; break; default:break; } } else {
newval--; switch(slnum) {
case 1:if(newval<0) newval=23; display(hour3,minute3,second3); hour3=newval; break;
case 2:if(newval<0) newval=59; display(hour3,minute3,second3); minute3=newval; break;
case 3:if(newval<0) newval=59;
27