欢迎来到天天文库
浏览记录
ID:53723120
大小:29.00 KB
页数:3页
时间:2020-04-06
《按键控制数码管显示数字加减.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#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;i>0;i--)for(j=110;j>0;j--);}
2、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(nu
3、m1==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;
4、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;}}
此文档下载收益归作者所有