欢迎来到天天文库
浏览记录
ID:59346184
大小:1.18 MB
页数:6页
时间:2020-09-04
《独立键盘控制数码管c语言程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#defineucharunsignedchar#defineuintunsignedintsbitkey1=P2^0;sbitkey2=P2^1;sbitkey3=P2^2;sbitkey4=P2^3;sbitduanxuan=P1^2;sbitweixuan=P1^3;ucharcodeshuma[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};voiddelay(uint);ucharnum1,n
2、um2;voiddisplay(ucharnum){ucharshi,ge;shi=num/10;ge=num%10;duanxuan=1;P0=shuma[shi];duanxuan=0;P0=0xff;weixuan=1;P0=0xfe;weixuan=0;delay(1);duanxuan=1;P0=shuma[ge];duanxuan=0;P0=0xff;weixuan=1;P0=0xfd;weixuan=0;delay(1);}voidkeyscan(){if(key1==0){delay(10);if(key1==0){num1++;if(num
3、1==60)num1=0;while(!key1);}}if(key2==0){delay(10);if(key2==0){if(num1==0)num1=60;num1--;while(!key2);}}if(key3==0){delay(10);if(key3==0){num1=0;//清0while(!key3);}}if(key4==0){delay(10);if(key4==0){while(!key4);TR0=~TR0;}}}voidmain(){TMOD=0x01;//设置定时器0为工作方式1EA=1;//开启总中断允许ET0=1;//开启定
4、时器0中断允许TH0=(65536-45872)/256;TL0=(65536-45872)%256;//装入初值while(1){keyscan();display(num1);}}voidtimer0()interrupt1{TH0=(65536-45872)/256;TL0=(65536-45872)%256;num2++;if(num2==20){num2=0;num1++;if(num1==60)num1=0;}}voiddelay(uintxms){uinti,j;for(i=xms;i>0;i--)for(j=110;j>0;j--);}
此文档下载收益归作者所有