最近通过ADC0808做了一个AD转换程序,并通过仿真验证了一下
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
具体程序如下(在压缩包中有工程文件和仿真文件)
#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下载地址(Proteus仿真7.5才能打开):
ADC0808.zip
(39.21 KB, 下载次数: 87)
|