闹钟实验报告 下载本文

display();

/* if(min==0&&sec==0){sound=0;delay(1);sound=1;delay(1);

sound=0;delay(1);sound=1;delay(1);sound=0;delay(1);sound=1;delay(1); } */

if(min==0&&sec==0||amin1==min&&ahour1==hour&&sec==0||amin2==min&&ahour2==hour&&sec==0||amin3==min&&ahour3==hour&&sec==0||aday==day&&amonth==month&&min==0&&sec==0&&hour==0) {sound=0;}

if(sec>5) { sound=1;} }

/*********************************************************************

时间显示函数

**********************************************************************/

void display() {

unsigned char t;

//wrcom(0x80); //wrdat(0xfb); wrcom(0x84); for(t=8;t>=1;t--) {

wrdat(timebuf[t-1]); }

wrcom(0xc3);

for(t=7;t<=16;t++) {

wrdat(timebuf[t+1]); } if(amin1!=61) { wrcom(0xc1); wrdat(0x41); } }

/*********************************************************************

按键扫描

**********************************************************************/

unsigned char scankey() {

if(P1!=0xff) //判断是否有键按下 {

delay(2); //延时消抖 if(P1!=0xff) {

switch(P1) {

case 0xfe:{P1=0xff; while(P1!=0xff); return(1);}break; //判断所按键值并等

case 0xfd:{P1=0xff; while(P1!=0xff); return(2);}break; // 等待按键松开,再

case 0xfb:{P1=0xff; while(P1!=0xff); return(3);}break; // 返回键值 case return(4);}break;

case 0x7f:{P1=0xff; while(P1!=0xff); return(5);}break;

0xf7:{P1=0xff;

while(P1!=0xff);

}

} } else

return(0); }

/*********************************************************************

按键功能处理函数

**********************************************************************/

void keywork() {

key=scankey(); switch(key) {

case 1: //按下menu键 {