最近通過ADC0808做了一個AD轉換程序,并通過仿真驗證了一下
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png (15.79 KB, 下載次數: 67)
下載附件
2020-11-21 00:18 上傳
具體程序如下(在壓縮包中有工程文件和仿真文件)
#include<reg52.h>
unsigned char s[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char ss[]= {0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};
unsigned char d[]={0xff,0xfe,0xfd,0xfb,0xf7};
unsigned char vol=0;
#define time 10
sbit start=P3^0;
sbit eoc=P3^1;
sbit oe=P3^2;
void delayms(unsigned int xms)//延時函數
{int i,j;
for(i=0;i<xms;i++)
for(j=0;j<120;j++);}
void adc()//啟動AD轉換
{ start=0;
start=1;
delayms(10);
start=0;
while(eoc!=1)
oe=1;
vol=P1;
oe=0;}
void shuo()//將轉換后的數值進行數碼管顯示
{unsigned char t1=0,t2=0,t3=0;
t1=vol/51;
t2=(vol%51)*10/51;
t3=((((vol%51)*10)%51)*10+25)/51;
if(t3>9)
{t2=t2+1;
t3=t3-10;}
P2=d[1];
P0=ss[t1];
delayms(time);
P2=d[2];
P0=s[t2];
delayms(10);
P2=d[3];
P0=s[t3];
delayms(10);
P2=d[4];
P0=0x3e;
delayms(10);}
void main()
{while(1)
{adc();
shuo();}}
51hei.png (8.82 KB, 下載次數: 63)
下載附件
2020-11-21 00:19 上傳
全部資料51hei下載地址(Proteus仿真7.5才能打開):
ADC0808.zip
(39.21 KB, 下載次數: 87)
2020-11-20 23:39 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|