基于51单片机电子闹钟的设计 下载本文

P0=table[table2[i]];

delay(10);

j=_cror_(j,1); } }

void display2()// 显示子函数,用于显示定时2时间 { uchar i,j; if(alm2==0)

{ if(cnt!=4||wss==0)

{ table3[0]=miao2; //以下含义同上

table3[1]=miao2/10;

} else

{ table3[0]=table3[1]=11;} if(cnt!=5||wss==0) { table3[3]=fen2;

table3[4]=fen2/10;

} else

{ table3[3]=table3[4]=11;} if(cnt!=6||wss==0) { table3[6]=shi2;

table3[7]=shi2/10;

} else

{ table3[6]=table3[7]=11;}

} else

table3[0]=table3[1]=table3[3]=table3[4]=table3[6]=table3[7]=10;

table3[2]= table3[5]=10; j=0x7f;

for(i=0;i<=7;i++)

17

{ P3=j;

P0=table[table3[i]];

delay(10);

j=_cror_(j,1); } }

void display3() // 显示子函数,用于显示定时3时间数值 { uchar i,j; if(alm3==0)

{ if(cnt!=7||wss==0)

{ table4[0]=miao3; //分离秒的个位与十位

table4[1]=miao3/10; }

else

{ table4[0]=table4[1]=11;} if(cnt!=8||wss==0)

{ table4[3]=fen3; //分离分的个位与十位

table4[4]=fen3/10;

}

else

{ table4[3]=table4[4]=11;} if(cnt!=9||wss==0)

{ table4[6]=shi3; //分离时的个位与十位

table4[7]=shi3/10;

}

else

{ table4[6]=table4[7]=11;}

} else

table4[0]=table4[1]=table4[3]=table4[4]=table4[6]=table4[7]=10;

table4[2]= table4[5]=10;

j=0x7f; //从秒到时的扫描

18

for(i=0;i<=7;i++) { P3=j;

P0=table[table4[i]]; //显示数值

delay(10);

j=_cror_(j,1); //循环右移 } }

void shijian() // 时间子函数

{ if(flag>=20) //判断是否到一秒 { wss=~wss;

flag=0;

//到了,则标志位清零

if(cnt1!=0)

{ miao4++; //秒加1

if( miao4>59) //判断秒是否到60s { miao4=0; //到了,则清零 fen4++; //分加1 if(fen4>59) //以下含义同上 { fen4=0; shi4++; if(shi4>23) shi4=0;

} } }

else

{ miao++; //秒加1

if( miao>59) //判断秒是否到60s { miao=0; //到了,则清零 fen++; //分加1 if(fen>59) //以下含义同上 { fen=0;

19

shi++; if(shi>23) shi=0; } } } } }

void key_scan()// 键盘扫描子函数 { if(key1==0)

{ while(!key1) //防止掉显 { if(cnt==1||cnt==2||cnt==3) { display1(); }

if(cnt==4||cnt==5||cnt==6)

{ display2(); }

if(cnt==7||cnt==8||cnt==9)

{ display3(); }

if(cnt==0||cnt==10||cnt==11||cnt==12||cnt==13)

{ display(); } }

cnt++; //记下按键key1按下的次数

if(cnt==10&&cnt1==0) { miao4=miao; fen4=fen;

shi4=shi; cnt1++; }

if(cnt==13) { cnt=0; if(cnt1==1)

{ miao=miao4;

fen=fen4;

20