如何将单片机代码中的闹钟部分删掉?
2019-07-15 07:33发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
#include<reg52.h>#define uchar unsigned char#define uint unsigned intuchar table[]="tiME";sbit lcden=P3^4;sbit lcdrs=P3^5;sbit beep=P3^6;extern void key1();extern void key2();extern void key3();uchar num,hour=12,minite,second,ahour,aminite,asecond,a,F_k1,F_k2,F_k3;void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void write_com(uchar com){lcdrs=0;P0=com;delay(5);lcden=1;delay(5);lcden=0;}void write_data(uchar date){lcdrs=1;P0=date;delay(5);lcden=1;delay(5);lcden=0;}void write_add(uchar add,uchardate){uchar aa,bb;aa=date/10;bb=date%10;write_com(0x80+add);write_data(0x30+aa);write_data(0x30+bb);}void init(){lcden=0;write_com(0x38);write_com(0x0c);write_com(0x06);write_com(0x01);write_com(0x80);}void display(uchar h,uchar m,uchars){ write_com(0x80+0x04); write_data(':'); write_data(0x30+(h/10));write_data(0x30+(h%10));write_data(':'); write_data(0x30+(m/10));write_data(0x30+(m%10));write_data(':');write_data(0x30+(s/10));write_data(0x30+(s%10));write_data(' ');write_data(' ');write_data(' ');write_data(' ');}void main(){init();TMOD=0X01;TH0=(65535-50000)/256;TL0=(65535-50000)%256;EA=1;TR0=1;ET0=1;for(num=0;num<4;num++){write_data(table[num]);}while(1){key1();key2();key3();if(ahour==hour&&aminite==minite&&second<10){beep=~beep;}if(F_k1==0&F_k3==0)display(hour,minite,second);}}void timer0() interrupt 1{ TH0=(65535-50000)/256; TL0=(65535-50000)%256; a++; if(a==20){a=0;second++;if(second==60){second=0;minite++;if(minite==60){minite=0;hour++;if(hour==24){hour=0;}}}}}#include "reg52.h"#define uchar unsigned char#define uint unsigned intsbit k1=P1^0;sbit k2=P1^1;sbit k3=P1^2;extern uchar F_k1,F_k3,second,minite,hour,ahour,aminite,asecond;extern void write_com(uchar com);extern void write_add(ucharadd,uchar date);extern void display(uchar h,uchARM,uchar s);void delay_key(int i){while(i--);}void key1(){ if(k1==0){delay_key(100);if(k1==0){TR0=0;while(!k1);F_k1++;if(F_k1==4){F_k1=0;write_com(0x0c);TR0=1;}}}if(F_k1==1|F_k3==1){write_com(0x80+0x0c);write_com(0x0f);}if(F_k1==2|F_k3==2)write_com(0x80+0x09);if(F_k1==3|F_k3==3)write_com(0x80+0x06);}void key2(){if(k2==0){delay_key(100);{while(!k2);if(F_k1==1){second++;if(second==60)second=0;write_add(0x0b,second);}if(F_k1==2){minite++;if(minite==60)minite=0;write_add(0x08,minite);}if(F_k1==3){hour++;if(hour==24)hour=0;write_add(0x05,hour);}if(F_k3==1){asecond++;if(asecond==60)asecond=0;write_add(0x0b,asecond);}if(F_k3==2){aminite++;if(aminite==60)aminite=0;write_add(0x08,aminite);}if(F_k3==3){ahour++;if(ahour==24)ahour=0;write_add(0x05,ahour);}}}}void key3(){if(k3==0){delay_key(100);if(k3==0){while(!k3);F_k3++;if(F_k3==4){F_k3=0;write_com(0x0c);}if(F_k3==1)display(ahour,aminite,asecond);}}}
一周热门 更多>