欢迎来到天天文库
浏览记录
ID:34265287
大小:416.45 KB
页数:15页
时间:2019-03-04
《印张计数器的设计与实现源代码实习报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#include#defineLEDLen6charOUTBITat0x8002;//charOUTSEGat0x8004;//charIN_at_0x8001;//xdataunsignedxdataunsignedxdataunsigned位控制口段控制口f盘读入口unsignedcharLEDBuf[LEDLen];//显示缓冲codeunsignedcharLEDMAP[]={//八段管显示码0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,
2、0x5e,0x79,0x71};intnum;//六位数intnum2,numl;sbitLED1=Pro;voidDelay(unsignedcharCNT)unsignedchari;wh订e(CNT—!=0)for(i=100;i!=0;i一-);}voidDisplayLED(){unsignedchari;unsignedcharPos;unsignedcharLED;Pos=0x20;//从左边开始显示for(i=0;i3、BIT=Pos;//显示一位八段管Delay(1);Pos}1»=1:■f//显示下一位codeunsignedcharKeyTable[]={//键码定义0x16,0x15,0x14,Oxff,0x13,0x12,0x11,0x10,OxOd,0x0c,0x0b,0x0a,OxOe,0x03,0x06,0x09,OxOf,0x02,0x05,0x0&0x00,0x01,0x04,0x07};unsignedcharTestKey(){//输出线置为0//读入键状态(高四位不用)OUTBIT=0;return(~IN&0x0f);}unsigne4、dcharGetKey(){unsignedcharPos;unsignedchari;unsignedchark;i=6;Pos=0x20;//找出键所在列do{OUTBIT=~Pos;Pos»=1;k二~IN&OxOf;}while((--i!=0)&&(k==0));//键值二列x4+行if(k!=0){i*=4;if(k&2)i+=1;elseif(k&4)i+二2;elseif(k&8)i+=3;OUTBIT=0;doDelay(10);while(TestKey());//等键释放return(KeyTable[iJ)://取出键码}5、elsereturn(Oxff);}voidExtlntOOinterrupt0{numl++;num2—;}voidzhengzhuan()〃正转计数unsignedchari;TCON=OxOl;//外部中断0下降沿触发IE=0x81;//打开外部中断允许位(EXO)及总中断允许位(EA)do{LEDBuf[5]=LEDMAP[numl%10]:LEDBuf[4]=LEDMAP[numl/10%10];LEDBuf[3]=LEDMAP[numl/100%10];LEDBuf[2]=LEDMAP[numl/1000%10];LEDBuf[1]=6、LEDMAP[numl/10000%10];LEDBuf[0]=LEDMAP[numl/1000000%10];DisplayLEDO;if(numl==num){LED1=1;LEDBuf[5]=LEDMAP[num%10];LEDBuf[4]=LEDMAP[(num/10)%10];LEDBuf[3]=LEDMAP[(num/100)%10];LEDBuf[2]=LEDMAP[(num/1000)%10];LEDBuf[1]=LEDMAP[(num/10000)%10];LEDBuf[0]=LEDMAP[(num/1000000)%10];D7、isplayLEDO;break;}}while(numl<=num);}voidfanzhuan()j〃反转计数iunsignedchari;TCON=0x01;//外部中断o下降沿触发IE=0x81;//打开外部中断允许位(EXO)及总中断允许位(EA)wh订e(num2>=0){LEDBuf[5]=LEDMAP[num2%10];LEDBuf[4]=LEDMAP[(num2/10)%10];LEDBuf[3]=LEDMAP[(num2/100)%10];LEDBuf[2]=LEDMAP[(num2/1000)%10];LEDBuf[l]=L8、EDMAP[(num2/10000)%10];LEDBuf[0]=LEDMAP[(num2/1000000)%10];DisplayLE
3、BIT=Pos;//显示一位八段管Delay(1);Pos}1»=1:■f//显示下一位codeunsignedcharKeyTable[]={//键码定义0x16,0x15,0x14,Oxff,0x13,0x12,0x11,0x10,OxOd,0x0c,0x0b,0x0a,OxOe,0x03,0x06,0x09,OxOf,0x02,0x05,0x0&0x00,0x01,0x04,0x07};unsignedcharTestKey(){//输出线置为0//读入键状态(高四位不用)OUTBIT=0;return(~IN&0x0f);}unsigne
4、dcharGetKey(){unsignedcharPos;unsignedchari;unsignedchark;i=6;Pos=0x20;//找出键所在列do{OUTBIT=~Pos;Pos»=1;k二~IN&OxOf;}while((--i!=0)&&(k==0));//键值二列x4+行if(k!=0){i*=4;if(k&2)i+=1;elseif(k&4)i+二2;elseif(k&8)i+=3;OUTBIT=0;doDelay(10);while(TestKey());//等键释放return(KeyTable[iJ)://取出键码}
5、elsereturn(Oxff);}voidExtlntOOinterrupt0{numl++;num2—;}voidzhengzhuan()〃正转计数unsignedchari;TCON=OxOl;//外部中断0下降沿触发IE=0x81;//打开外部中断允许位(EXO)及总中断允许位(EA)do{LEDBuf[5]=LEDMAP[numl%10]:LEDBuf[4]=LEDMAP[numl/10%10];LEDBuf[3]=LEDMAP[numl/100%10];LEDBuf[2]=LEDMAP[numl/1000%10];LEDBuf[1]=
6、LEDMAP[numl/10000%10];LEDBuf[0]=LEDMAP[numl/1000000%10];DisplayLEDO;if(numl==num){LED1=1;LEDBuf[5]=LEDMAP[num%10];LEDBuf[4]=LEDMAP[(num/10)%10];LEDBuf[3]=LEDMAP[(num/100)%10];LEDBuf[2]=LEDMAP[(num/1000)%10];LEDBuf[1]=LEDMAP[(num/10000)%10];LEDBuf[0]=LEDMAP[(num/1000000)%10];D
7、isplayLEDO;break;}}while(numl<=num);}voidfanzhuan()j〃反转计数iunsignedchari;TCON=0x01;//外部中断o下降沿触发IE=0x81;//打开外部中断允许位(EXO)及总中断允许位(EA)wh订e(num2>=0){LEDBuf[5]=LEDMAP[num2%10];LEDBuf[4]=LEDMAP[(num2/10)%10];LEDBuf[3]=LEDMAP[(num2/100)%10];LEDBuf[2]=LEDMAP[(num2/1000)%10];LEDBuf[l]=L
8、EDMAP[(num2/10000)%10];LEDBuf[0]=LEDMAP[(num2/1000000)%10];DisplayLE
此文档下载收益归作者所有