本文引用地址:http://butianyuan.cn/article/201611/323327.htm#include#define uint unsigned int #define uchar unsigned charsbit rd=P3^7;sbit wr=P3^6;sbit cs0=P3^5;sbit hc=P3^4;void delay(uint );void format0804();void display(uchar aa );unsigned char code table1[]= //共陽(yáng)段碼控制{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40}; unsigned char code dispbit[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F}; //位選控制 查表的方法控制 uchar aa,adc0804;void main(){ //uint adc0804;cs0=0;P1=0xff;//為P1口讀取數(shù)據(jù)做準(zhǔn)備,與P1口相連的某個(gè)引腳若為低,則P1相應(yīng)位被拉低,hc=1; //以此來(lái)讀取數(shù)據(jù)while(1){ /*wr=1;delay(1);wr=0;rd=1;delay(1);wr=1;rd=0;adc0804=P1;//根據(jù)時(shí)序DAC0804時(shí)序圖,只能在些讀取其輸出值delay(1);rd=1;delay(1); */format0804();adc0804=P1; //在rd=0才能讀取P1口狀態(tài),display(adc0804); } }void delay(uint z){uint j;for(z;z>0;z--)for(j=110;j>0;j--);}void format0804(){wr=1;//delay(1);wr=0;wr=1;//根據(jù)時(shí)序ADC0804時(shí)序圖,只有wr端存在上升沿就可讀取模擬值rd=1;//delay(1);rd=0; //根據(jù)時(shí)序ADC0804時(shí)序圖,只有rd低電平時(shí)才能向外發(fā)送信號(hào)//adc0804=P1;//delay(1);//rd=1;} void display(uchar aa){uchar ledout[10],i;ledout[0]=table1[aa%10000/1000]; //千位ledout[1]=table1[aa%1000/100]; //百位帶小數(shù)點(diǎn)ledout[2]=table1[aa%100/10]; //十位ledout[3]=table1[aa%10]; //個(gè)位for(i=0;i<4;i++){P2=dispbit[i];//位選 先位選再段選P0=ledout[i]; //段碼delay(1);}}
評(píng)論