標題: 單片機ADC0808轉換 [打印本頁]

作者: 嘻嘻哈哈哦    時間: 2020-4-1 16:37
標題: 單片機ADC0808轉換
分析:
程序啟動前可將滑動電阻調至最大值,4位8段共陽極數(shù)碼管初始值顯示為0。拖動滑動電阻器向上,電壓表電壓增大,數(shù)碼管顯示的數(shù)值也變大。
當滑動電阻器滑至中央,電壓表顯示2.5V是數(shù)碼管顯示127;
當滑動電阻器滑至最小時,電壓表顯示5V數(shù)碼管顯示255。
工作方式2
16位
TH0=(65536-250)/256;
TL0=(65536-250)%256;
C語言源碼
#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int

unsigned char code tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
sbit clock=P1^4;
sbit start=P1^5;
sbit eoc=P1^6;
sbit oe=P1^7;

void DelayMS(unsigned int ms)
{
        unsigned char i;
        while(ms--)
        for(i=0;i<200;i++);
}
display(unsigned char d){
P1=0xe1;
P0=tab[d/1000];
DelayMS(2);
P1=0xe2;
P0=tab[d/100%10];
DelayMS(2);
P1=0xe4;
P0=tab[d%100/10];
DelayMS(2);
P1=0xe8;
P0=tab[d%10];
DelayMS(2);
}

init(){
TMOD=2;
TL0=0x6;
TH0=0x6;
IE=0x82;
TR0=1;
}
t0_int() interrupt 1
{
clock=!clock;

}
main()
{
//0111
//4
init();
while(1)
{
start=0;
start=1;//清零
start=0;//啟動
while(eoc==0); //等待轉換結果
oe=1; //允許輸出
display(P2);//顯示A/D轉換結果
oe=0; //關閉輸出
}
}

圖片1.png (116.84 KB, 下載次數(shù): 32)

圖片1.png





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1