單片機(jī)AT89S51與ADC0809設(shè)計(jì)一個(gè)數(shù)字電壓表
發(fā)布時(shí)間:2008/8/14 0:00:00 訪(fǎng)問(wèn)次數(shù):612
1. 實(shí)驗(yàn)任務(wù)
利用單片機(jī)at89s51與adc0809設(shè)計(jì)一個(gè)數(shù)字電壓表,能夠測(cè)量0-5v之間的直流電壓值,四位數(shù)碼顯示,但要求使用的元器件數(shù)目最少。
2. 電路原理圖
3. 系統(tǒng)板上硬件連線(xiàn)
a) 把“單片機(jī)系統(tǒng)”區(qū)域中的p1.0-p1.7與“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的abcdefgh端口用8芯排線(xiàn)連接。
b) 把“單片機(jī)系統(tǒng)”區(qū)域中的p2.0-p2.7與“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的s1s2s3s4s5s6s7s8端口用8芯排線(xiàn)連接。
c) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.0與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的st端子用導(dǎo)線(xiàn)相連接。
d) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.1與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的oe端子用導(dǎo)線(xiàn)相連接。
e) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.2與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的eoc端子用導(dǎo)線(xiàn)相連接。
f) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.3與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的clk端子用導(dǎo)線(xiàn)相連接。
g) 把“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的a2a1a0端子用導(dǎo)線(xiàn)連接到“電源模塊”區(qū)域中的gnd端子上。
h) 把“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的in0端子用導(dǎo)線(xiàn)連接到“三路可調(diào)電壓模塊”區(qū)域中的vr1端子上。
i) 把“單片機(jī)系統(tǒng)”區(qū)域中的p0.0-p0.7用8芯排線(xiàn)連接到“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的d0d1d2d3d4d5d6d7端子上。
4. 程序設(shè)計(jì)內(nèi)容
由于adc0809在進(jìn)行a/d轉(zhuǎn)換時(shí)需要有clk信號(hào),而此時(shí)的adc0809的clk是接在at89s51單片機(jī)的p3.3端口上,也就是要求從p3.3輸出clk信號(hào)供adc0809使用。因此產(chǎn)生clk信號(hào)的方法就得用軟件來(lái)產(chǎn)生了;由于adc0809的參考電壓vref=vcc,所以轉(zhuǎn)換之后的數(shù)據(jù)要經(jīng)過(guò)數(shù)據(jù)處理,在數(shù)碼管上顯示出電壓值。實(shí)際顯示的電壓值 (d/256*vref)
5. 匯編源程序
6. c語(yǔ)言源程序
#include <at89x52.h>
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
unsigned char dispbuf[8]={10,10,10,10,0,0,0,0};
unsigned char dispcount;
unsigned char getdata;
unsigned int temp;
unsigned char i;
sbit st=p3^0;
sbit oe=p3^1;
sbit eoc=p3^2;
sbit clk=p3^3;
void main(void)
{
st=0;
oe=0;
et0=1;
et1=1;
ea=1;
tmod=0x12;
th0=216;
tl0=216;
th1=(65536-4000)/256;
tl1=(65536-4000)%256;
tr1=1;
tr0=1;
st=1;
st=0;
while(1)
{
if(eoc==1)
{
oe=1;
getdata=p0;
oe=0;
temp=getdata*235;
temp=temp/128;
i=5;
dispbuf[0]=10;
dispbuf[1]=10;
dispbuf[2]=10;
dispbuf[3]=10;
dispbuf[4]=10;
dispbuf[5]=0;
dispbuf[6]=0;
dispbuf[7]=0;
while(temp/10)
{
dispbuf[i]=temp%10;
temp=temp/10;
i++;
}
dispbuf[i]=temp;
st=1;
st=0;
}
}
}
void t0(void) interrupt 1 using 0
{
clk=~clk;
}
void t1(void) interrupt 3 using 0
{
th1=(65536-4000)/256;
tl1=(65536-4000)%256;
p1=dispcode[dispbuf[dispcount]];
p2=dispbitcode[dispcount];
if(dispcount==7)
{
p1=p1 | 0x80;
}
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}
1. 實(shí)驗(yàn)任務(wù)
利用單片機(jī)at89s51與adc0809設(shè)計(jì)一個(gè)數(shù)字電壓表,能夠測(cè)量0-5v之間的直流電壓值,四位數(shù)碼顯示,但要求使用的元器件數(shù)目最少。
2. 電路原理圖
3. 系統(tǒng)板上硬件連線(xiàn)
a) 把“單片機(jī)系統(tǒng)”區(qū)域中的p1.0-p1.7與“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的abcdefgh端口用8芯排線(xiàn)連接。
b) 把“單片機(jī)系統(tǒng)”區(qū)域中的p2.0-p2.7與“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的s1s2s3s4s5s6s7s8端口用8芯排線(xiàn)連接。
c) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.0與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的st端子用導(dǎo)線(xiàn)相連接。
d) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.1與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的oe端子用導(dǎo)線(xiàn)相連接。
e) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.2與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的eoc端子用導(dǎo)線(xiàn)相連接。
f) 把“單片機(jī)系統(tǒng)”區(qū)域中的p3.3與“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的clk端子用導(dǎo)線(xiàn)相連接。
g) 把“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的a2a1a0端子用導(dǎo)線(xiàn)連接到“電源模塊”區(qū)域中的gnd端子上。
h) 把“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的in0端子用導(dǎo)線(xiàn)連接到“三路可調(diào)電壓模塊”區(qū)域中的vr1端子上。
i) 把“單片機(jī)系統(tǒng)”區(qū)域中的p0.0-p0.7用8芯排線(xiàn)連接到“模數(shù)轉(zhuǎn)換模塊”區(qū)域中的d0d1d2d3d4d5d6d7端子上。
4. 程序設(shè)計(jì)內(nèi)容
由于adc0809在進(jìn)行a/d轉(zhuǎn)換時(shí)需要有clk信號(hào),而此時(shí)的adc0809的clk是接在at89s51單片機(jī)的p3.3端口上,也就是要求從p3.3輸出clk信號(hào)供adc0809使用。因此產(chǎn)生clk信號(hào)的方法就得用軟件來(lái)產(chǎn)生了;由于adc0809的參考電壓vref=vcc,所以轉(zhuǎn)換之后的數(shù)據(jù)要經(jīng)過(guò)數(shù)據(jù)處理,在數(shù)碼管上顯示出電壓值。實(shí)際顯示的電壓值 (d/256*vref)
5. 匯編源程序
6. c語(yǔ)言源程序
#include <at89x52.h>
unsigned char code dispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,0x66,
unsigned char dispbuf[8]={10,10,10,10,0,0,0,0};
unsigned char dispcount;
unsigned char getdata;
unsigned int temp;
unsigned char i;
sbit st=p3^0;
sbit oe=p3^1;
sbit eoc=p3^2;
sbit clk=p3^3;
void main(void)
{
st=0;
oe=0;
et0=1;
et1=1;
ea=1;
tmod=0x12;
th0=216;
tl0=216;
th1=(65536-4000)/256;
tl1=(65536-4000)%256;
tr1=1;
tr0=1;
st=1;
st=0;
while(1)
{
if(eoc==1)
{
oe=1;
getdata=p0;
oe=0;
temp=getdata*235;
temp=temp/128;
i=5;
dispbuf[0]=10;
dispbuf[1]=10;
dispbuf[2]=10;
dispbuf[3]=10;
dispbuf[4]=10;
dispbuf[5]=0;
dispbuf[6]=0;
dispbuf[7]=0;
while(temp/10)
{
dispbuf[i]=temp%10;
temp=temp/10;
i++;
}
dispbuf[i]=temp;
st=1;
st=0;
}
}
}
void t0(void) interrupt 1 using 0
{
clk=~clk;
}
void t1(void) interrupt 3 using 0
{
th1=(65536-4000)/256;
tl1=(65536-4000)%256;
p1=dispcode[dispbuf[dispcount]];
p2=dispbitcode[dispcount];
if(dispcount==7)
{
p1=p1 | 0x80;
}
dispcount++;
if(dispcount==8)
{
dispcount=0;
}
}
熱門(mén)點(diǎn)擊
- 51單片機(jī)8*8點(diǎn)陣LED顯示原理及程序
- 用AT89S51單片機(jī)來(lái)制作的手動(dòng)計(jì)數(shù)器
- TEA5767收音機(jī)模塊的C51控制程序
- pic單片機(jī)的模擬I2C通信
- ST推出基于STM8內(nèi)核的STM8S系列8位
- 單片機(jī)相關(guān)常用名詞解釋
- 單片機(jī)C語(yǔ)言編程基礎(chǔ)
- 美國(guó)微芯推出低成本8位PIC單片機(jī)
- HOLTEK新推出HT46RS03/HT46
- 單片機(jī)與MMC卡的接口
推薦技術(shù)資料
- 硬盤(pán)式MP3播放器終級(jí)改
- 一次偶然的機(jī)會(huì)我結(jié)識(shí)了NE0 2511,那是一個(gè)遠(yuǎn)方的... [詳細(xì)]
- 100A全集成電源模塊R
- Teseo-VIC6A GNSS車(chē)用精準(zhǔn)定位
- 高效先進(jìn)封裝工藝
- 模數(shù)轉(zhuǎn)換器 (Analog-to-Digit
- 集成模數(shù)轉(zhuǎn)換器(ADC)
- 128 通道20 位電流數(shù)字轉(zhuǎn)換器̴
- 多媒體協(xié)處理器SM501在嵌入式系統(tǒng)中的應(yīng)用
- 基于IEEE802.11b的EPA溫度變送器
- QUICCEngine新引擎推動(dòng)IP網(wǎng)絡(luò)革新
- SoC面世八年后的產(chǎn)業(yè)機(jī)遇
- MPC8xx系列處理器的嵌入式系統(tǒng)電源設(shè)計(jì)
- dsPIC及其在交流變頻調(diào)速中的應(yīng)用研究