按键控制数码管显示数字加减

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includereg52.h#defineucharunsignedchar#defineuintunsignedintuintnum=0,num1=0;sbitkey1=P3^0;sbitkey2=P3^1;sbitkey3=P3^2;sbitkey4=P3^3;uchartable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};voiddelayms(uintx){uinti,j;for(i=x;i0;i--)for(j=110;j0;j--);}voiddisplay(uintnum){uintshi,ge;shi=num/10;ge=num%10;P0=table[shi];P1=0xfd;delayms(5);P0=table[ge];P1=0xfe;delayms(5);}voidkeyscan(){if(key1==0){delayms(10);if(key1==0){num1++;if(num1==60)num1=0;while(!key1)display(num1);}}if(key2==0){delayms(10);if(key2==0){if(num1==0)num1=60;num1--;while(!key2)display(num1);}}if(key3==0){delayms(10);if(key3==0){num1=0;while(!key3)display(num1);}}if(key4==0){delayms(10);if(key4==0){TR0=~TR0;while(!key4)display(num1);}}}voidmain(){TMOD=0x01;TH0=(65536-45872)/256;TL0=(65536-45872)%256;EA=1;ET0=1;while(1){keyscan();display(num1);}}voidT()interrupt1{TH0=(65536-45872)/256;TL0=(65536-45872)%256;num++;if(num==20){num1++;num=0;if(num1==60)num1=0;}}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功