首页 > 学院 > 开发设计 > 正文

单片机时钟实现闹钟功能

2019-11-09 20:39:31
字体:
来源:转载
供稿:网友
void main (void){unsigned int i = 0;LCD_Init(); LCD_Clear();  Init_INT0();while(1)        {  LCD_Write_String(6,1,"clock");if(flag2 == 1){DelayMs(1);    SPK =! SPK;Display();flag2 = 0;}if(flag1 == 1){for(i = 0; i<500; i++)      {      DelayMs(1);    SPK =! SPK;  }flag1 = 0; }if(clockflag == 1&&hour == clock[0]&&minute == clock[1]&&second == 0){for(i = 0; i<3000; i++)      {      DelayMs(1);    SPK =! SPK;  }  clockflag = 0;}time();}}void time(){unsigned char num1;static unsigned char temp = 0;  KeyPort = 0xf0;  if(KeyPRessFlag == 1)  {  KeyPressFlag = 0;  num1 = KeyPro();switch(num1)  {        case 0:hour++;if(hour == 24)hour = 0;                 break;case 1:hour--;if(hour == 255)hour = 23;           break;case 2:minute++;if(minute == 60)minute = 0;            break;case 3:minute--;if(minute == 255)minute = 59;         break;case 4:{Init_Timer0();IRcvStr(0xae,4,store,3);hour = store[0];minute = store[1];second = store[2];  break;  }case 5:{if(temp%2 == 0)ET0 = 1;elseET0 = 0;temp++;break;}case 6: hour = 0;minute = 0;second = 0; break;case 7: { alarm();} default:break;}}}void alarm(){unsigned char num2;unsigned char hour1 = 0;unsigned char minute1 = 0;    LCD_Init(); LCD_Clear();  LCD_Write_String(0,0,"next alarm: ");    while(1){LCD_Write_Char(11,0,clock[0]/10+'0');  LCD_Write_Char(12,0,clock[0]%10+'0');  LCD_Write_Char(13,0,':');  LCD_Write_Char(14,0,clock[1]/10+'0');  LCD_Write_Char(15,0,clock[1]%10+'0');  LCD_Write_String(0,1,"set alarm: ");  LCD_Write_Char(11,1,hour1/10+'0');  LCD_Write_Char(12,1,hour1%10+'0');  LCD_Write_Char(13,1,':');  LCD_Write_Char(14,1,minute1/10+'0');  LCD_Write_Char(15,1,minute1%10+'0');  KeyPort = 0xf0;  if(KeyPressFlag == 1)  {KeyPressFlag = 0;  num2 = KeyPro();switch(num2)    {        case 0:hour1++;if(hour1 == 24)hour1 = 0;                   break;case 1:hour1--;if(hour1 == 255)hour1 = 23;          break;case 2:minute1++;if(minute1 == 60)minute1 = 0;          break;case 3:minute1--;if(minute1 == 255)minute1 = 59;           break;case 4:clock[0] = hour1;clock[1] = minute1;clockflag = 1;break;case 5:LCD_Clear();return;default:break;}}}}void Display(){unsigned char h0,h1, m0,m1 ,s0,s1;h0 = hour/10+48;h1 = hour%10+48;m0 = minute/10+48;m1 = minute%10+48;s0 = second/10+48;s1 = second%10+48;   LCD_Write_Char(4,0,h0);LCD_Write_Char(5,0,h1);LCD_Write_Char(6,0,':');LCD_Write_Char(7,0,m0);LCD_Write_Char(8,0,m1);LCD_Write_Char(9,0,':');LCD_Write_Char(10,0,s0);LCD_Write_Char(11,0,s1);store[0] = hour;store[1] = minute;store[2] = second;    ISendStr(0xae,4,store,3); }
上一篇:PAT 1004 成绩排名

下一篇:TabLayout 解析

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表