51單片機(jī)驅(qū)動(dòng)ADC0808電路圖C51及匯編程序
第一個(gè)C程序,值得紀(jì)念,也值得以后參考。
本文引用地址:http://m.butianyuan.cn/article/201611/323982.htm本程序的功能是:
1.ADC0808轉(zhuǎn)換功能;
2.數(shù)據(jù)16進(jìn)制顯示;
3.串行通信數(shù)據(jù)。
C51程序:工程文件下載:http://www.51hei.com/f/0808_c.rar
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit START=P3^6; //啟動(dòng)轉(zhuǎn)換
sbit OE=P3^5; //輸出允許
sbit EOC=P3^7; //轉(zhuǎn)換結(jié)束
sbit WC=P3^4; //通道選擇
sbit WB=P3^3; //通道選擇
sbit WA=P3^2; //通道選擇
uchar data led[12];
signed data data1;
signed data data2;
signed data data3;
signed data data4;
signed data data5;
signed data data6;
signed data data7;
uchar code tv[]={0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb};
uchar code dc[]={0xC0, //"0"
0xF9, //"1"
0xA4, //"2"
0xB0, //"3"
0x99, //"4"
0x92, //"5"
0x82, //"6"
0xF8, //"7"
0x80, //"8"
0x90, //"9"
0x88, //"A"
0x83, //"B"
0xC6, //"C"
0xA1, //"D"
0x86, //"E"
0x8E, };//"F"};/十六進(jìn)制顯示方式
void delay(void) //延時(shí)程序
{
uint i;
for(i=0;i<10;i++);
}
void ledxianshi(void) //顯示模塊
{
uchar k,i;
led[0]=data1%16; //編碼1個(gè)位
led[1]=data1/16%16; //編碼1十位
led[2]=data2%16; //數(shù)據(jù)1個(gè)位
led[3]=data2/16%16; //數(shù)據(jù)1十位
led[4]=data3%16; //編碼2個(gè)位
led[5]=data3/16%16; //編碼2十位
led[6]=data4%16; //數(shù)據(jù)2個(gè)位
led[7]=data4/16%16; //數(shù)據(jù)2十位
led[8]=data5%16; //編碼3個(gè)位
led[9]=data5/16%16; //編碼3十位
led[10]=data6%16; //數(shù)據(jù)3個(gè)位
led[11]=data6/16%16; //數(shù)據(jù)3十位
for(k=0;k<12;k++)
{
P2=tv[k]; //位選用
i=led[k];
P1=dc[i]; //段碼數(shù)顯示
delay();
}
}
void csh(void)
{
SM0=0;
SM1=1;
REN=1;
TI=0;
RI=0;
PCON=0;
TH1=0xF3;
TL1=0XF3;
TMOD=0X20;
EA=1;
ET1=0;
ES=1;
TR1=1;
TI=0;
SBUF=data1;
while(!TI);
TI=0;
SBUF=data2;
while(!TI);
TI=0;
SBUF=data3;
while(!TI);
TI=0;
SBUF=data4;
while(!TI);
TI=0;
SBUF=data5;
while(!TI);
TI=0;
SBUF=data6;
while(!TI);
TI=0;
}
void ad1(void)
{
WA=0; //通道1
WB=0;
WC=0;
START=1;
START=0; //啟動(dòng)轉(zhuǎn)換
while(EOC==0); //轉(zhuǎn)換結(jié)束信號(hào),為0則說明轉(zhuǎn)換結(jié)束
OE=1; //輸出允許信號(hào),為真,可以輸出
data7=P0; //P0口的測(cè)量值送到TVDATE
OE=0; //關(guān)輸出允許
}
void ad2(void)
{
WA=1; //通道1
WB=0;
WC=0;
START=1;
START=0; //啟動(dòng)轉(zhuǎn)換
while(EOC==0); //轉(zhuǎn)換結(jié)束信號(hào),為0則說明轉(zhuǎn)換結(jié)束
OE=1; //輸出允許信號(hào),為真,可以輸出
data4=P0; //P0口的測(cè)量值送到TVDATE
OE=0; //關(guān)輸出允許
}
評(píng)論