资源描述:
《矩阵按钮的显示实验》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、矩阵按钮的显示实验一・静态显不一位数#include#includefloatn=1234;unsignedcharj=0;unsignedcharcodedesg[10]={0x3f/0x06/0x5b/0x4f/0x66/0x6d,0x7d/0x07/0x7f/0x6f};unsignedcharIoc[4]={3,2/1/0};unsignedintled[4];sbitIOCLK=0x93;sbitCS=0x94;sbitDOUT=0x95;voidstart(){TMOD=0x01;TH0=(
2、65536-922)/256;TL0=(65536-922)%256;TR0=l;ETO=1;EA=1;}voidtimer()interrupt1{unsignedcharj;TH0=(65536-922)/256;TL0=(65536・922)%256;P2=loc[j];PO=desg[led[j]];j++;if(j>3)j=0;}voidhexzbcdfunsignedintn){unsignedchari;for(i=0;i<4;i++){led[3-i]=n%10;n=n/10;}}voidDelay_n_us(unsign
3、edchari){while(i-);}unsignedcharTLC549_RD()unsignedchari;unsignedchartemp;unsignedcharrdata;cs=o;Delay_n_us(2);rdata=OxOO;temp=0x80;for(i=0;iv8;i++){if(DOUT==1)rdata=rdata
4、temp;IOCLK=1;Delay_n_us(2);IOCLK=0;Delay_n_us(2);temp=temp»l;}CS=1;return(rdata);}voidmain(void){sta
5、rt();IOCLK=0;Delay_n_us(10);n=TLC549_RD();while(l){Delay_n_us(100);n=TLC549_RD();n=(n/(51.0))*1000;hexzbcd(n);}#include#defineucharunsignedchar/*****************************/unsignedcharcodetable[16]={0x3f/6/0x5b/0x4f/0x66,0x6(1,0x7(1,7,0x7(0x61,0x77,0x7cQx5&0x5e
6、p0x79,0x71};/**********显示选择表***********************/unsignedcharcodedigit[8]={0xf7/0xf6/0xf5/0xf4z0xf3/0xf2/0xfl/0xf0};/**♦*♦定义一个数组用于存放将要显示的值***♦*♦*/unsignedchard[8]={l,234,5Q7,8};**♦*键值变量*******/uchark=0;/料和软件延时DELAYms****/voidSoftware_Delay(constunsignedintDELAY){unsign
7、edintx,y;for(x=0;x<=DELAY;x++){for(y=0;y<=120;y++);}}厂矩阵键盘扫描*/ucharkeyscan(void){ucharX,Z;uchartemp;Pl=0xf0;temp=Pl;temp=temp&0xf0;if(temp!=0xf0){Software_Delay(5);Pl=0xf0;temp=Pl;temp=temp&0xf0;if(temp!=0xf0)X=temp&OxfO;Pl=X
8、OxOf;Z=(P1&OxOf)
9、(temp&OxfO);switch(Z){caseOxe
10、e:k=O;break;caseOxde:k=l;break;caseOxbe:k=2;break;case0x7e:k=3;break;caseOxed:k=4;break;caseOxdd:k=5;break;caseOxbd:k=6;break;case0x7d:k=7;break;caseOxeb:k=8;break;caseOxdb:k=9;break;caseOxbb:k=10;break;case0x7b:k=ll;break;case0xe7:k=12;break;case0xd7:k=13;break;case0xb7:
11、k=14;break;case0x77:k=15;break;return(k);}/*****水**^^函^^************voidmain(void){unsignedcharn