C51单片机学习(实验)
AD(模数)转换——ADC0809
硬件测试仿真图
使用通道0进行模数转换
C程序
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit ADDA=P2^0;
sbit ADDB=P2^1;
sbit ADDC=P2^2;
sbit ALE=P2^3;
sbit START=P2^4;
sbit EOC=P2^5;
sbit OE=P2^6;
uchar ad(uchar channel)
{
uchar i;
ALE=0;START=0;
if(channel==0){ADDC=0;ADDB=0;ADDA=0;}//选中通道0
if(channel==1){ADDC=0;ADDB=0;ADDA=1;}//选中通道1
if(channel==2){ADDC=0;ADDB=1;ADDA=0;}//选中通道2
ALE=1;//通道锁存
START=1;//启动转换
for(i=0;i<10;i++);
ALE=0;START=0;
while(EOC==0);//EOC为高电平,转换结束,获取结果
OE=1;//允许输出
P1=P0;
OE=0;//禁止输出
}
void main()
{
uchar i;
while(1)
{
for(i=0;i<3;i++){
ad(i);
}
}
}