版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
版权
C专栏收录该内容
4 篇文章0 订阅
订阅专栏
#includesbit key1=P3^1; sbit key2=P3^0; sbit key3=P3^2; sbit key4=P3^3; sbit a=P2^2; //位选声明 sbit b=P2^3; sbit c=P2^4; void delay(int); void zhongduan(); void display(int,int,int,int,int,int); void keyscan(); //独立按键 char num[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; char num2[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};//带点数据 int shu1,shu2,shu3,shu4;// int ge,shi,fen1,fen2,hour1,hour2; int main(){ TMOD=0x01; TH0=(65536-45872)/256; TL0=(65536-45872)%256; //TH1=(65536-45872)/256; //TL1=(65536-45872)%256; EA=1; ET0=1; //ET1=1; TR0=1; //TR1=1; while(1) { //显示 display(ge,shi,fen1,fen2,hour1,hour2); keyscan(); } return 0; } void delay(int x){//timer int i,j; for(i=x;x>0;x--) for(j=110;j>0;j--); } void zhongduan()interrupt 1 { TH0=(65536-45872)/256; TL0=(65536-45872)%256; shu2++; if(shu2==20){ //1s shu2=0; shu1++; if(shu1==60){ shu3++; shu1=0; } shi=shu1/10; ge=shu1%10; if(shu3==60){ shu4++; shu3=0; } fen1=shu3%10; fen2=shu3/10; if(shu4==24){ shu4=0; } hour1=shu4%10; hour2=shu4/10; }//第一个if }//函数 void display(int ge,int shi,int fen1,int fen2,int hour1,int hour2){ P0=num[ge]; //段选 秒个位 a=0; //位选 b=0; c=0; delay(1); P0=num[shi]; //段选 秒十位 a=1; //位选 b=0; c=0; delay(1); P0=num2[fen1]; //段选 分个位 a=0; //位选 b=1; c=0; delay(1); P0=num[fen2]; //段选 分十位 a=1; //位选 b=1; c=0; delay(1); P0=num2[hour1]; //段选 时个位 a=0; //位选 b=0; c=1; delay(1); P0=num[hour2]; //段选 时十位 a=1; //位选 b=0; c=1; delay(1); }//fd=16*16^1+13*16^0=256+13=269=>11111101 void keyscan(){ if(key1==0){ delay(5); if(key1==0){ shu4++; if(shu4==24) shu4=0; while(!key1);//等待按键释放 } } if(key2==0) { delay(5); if(key2==0) { shu3++; if(shu4>=24) shu3=0; while(!key2);// } } if(key3==0) { delay(5); if(key3==0) { shu1+=10; if(shu1>=60) shu1=0; while(!key3); } } if(key4==0) { delay(5); if(key4==0) { while(!key4) TR0=~TR0; } } //return 0; }
收藏
一键三连
扫一扫,分享海报
专栏目录