*本例程采用AD0804芯片,硬件電路:cs片選端接P2.3,WR寫數(shù)據(jù)端寫P3.6,RD讀數(shù)據(jù)端接P3.7,鎖存端接P2.6腳,數(shù)碼管位選端分別接P3.2 ,P3.3,P3.4,段選端接P1口*/#includereg52.h>//頭文件#define uint unsigned int//宏文件#define uchar unsigned char//宏文件uchar num;//變量void delay3(uint z);//延時定義void dissy();//延時函數(shù)定義sbit ge=P3^2;//個位定義sbit shi=P3^3;//十位定義sbit bai=P3^4;//百位定義sbit ad_cs=P2^3;//片選端sbit ad_wr=P3^6;//寫數(shù)據(jù)端sbit ad_rd=P3^7;//讀數(shù)據(jù)端sbit pian=P2^6;//鎖存器片選void add();//ad轉(zhuǎn)換子函數(shù)void delay(uint i);//延時子函數(shù)申明uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//數(shù)組/************主函數(shù)**********/void main(){while(1){add();//調(diào)用AD轉(zhuǎn)換子函數(shù)dissy();//數(shù)碼管顯示子函數(shù) } }/************AD轉(zhuǎn)換子函數(shù)**********/void add()//AD轉(zhuǎn)換子函數(shù){uchar i;ad_cs=1;//將片選關(guān)閉ad_cs=0;//將片選打開ad_wr=1;//寫數(shù)上升沿ad_wr=0;//寫數(shù)下降沿ad_wr=1;//寫數(shù)上升沿P1=0xff;//送數(shù)到P0口ad_rd=1;//讀數(shù)上升沿delay(25);//延時一會兒ad_rd=0;//讀數(shù)下降沿//////**************因為AD轉(zhuǎn)換時間周期長,
我現(xiàn)在的數(shù)碼管沒有采用鎖存器,AD轉(zhuǎn)換時間大于顯示時間,
所以顯示時會閃爍,解決此問題方法是,連續(xù)調(diào)用了顯示子程序七次,
這樣顯示時就和AD轉(zhuǎn)換時一至,顯示出來的數(shù)就不閃了********************//////for(i=0;i7;i++) //調(diào)用7次,相當于delay(255)void dissy();//////**********************************//////num=P1;//將數(shù)給計數(shù)器num}/************顯示子函數(shù)**********/void dissy()//顯示子函數(shù){ P0=table[num/100];//百位顯示數(shù)據(jù)bai=0;//百位打開delay(14);//延時一會bai=1;//關(guān)閉百位P0=table[num%100/10];//十位顯示數(shù)據(jù)shi=0;//十位打開delay(14);//延時一會shi=1;//關(guān)閉十位P0=table[num%10];//百位顯示數(shù)據(jù)ge=0;//關(guān)閉十位delay(14);//延時一會ge=1;//關(guān)閉十位}/**************延時子函數(shù)*************/void delay(uint i)//延時函數(shù) {uint j,k;//定義變量for(j=i;j>0;j--)//外循環(huán)for(k=30;k>0;k--);//內(nèi)循環(huán)}
評論