发布时间:2018-03-26 浏览量:
51单片机驱动 adc0804模数转换 ,下面是电路图
#include
#include "lcd.h"
#include
#define uint unsigned int
#define uchar unsigned char
uchar lcd[]="0123456789";
sbit rd=P3^6; //IO口定义
sbit wr=P3^5;
sbit cs=P3^7;
read_adc0804()//控制并读取adc0804转换好的数据
{
uchar a; //写入控制命令,启动转换
cs=1;
wr=1;
cs=0;
wr=0;
_nop_();
wr=1;
P1=0xff; //读取已转换好的数据
rd=1;
rd=0;
_nop_();
a=P1;
rd=1;
cs=1;
return a;
}
void main()
{
uchar a,A1,A2,A3;
lcd_init();
while(1)
{
a=read_adc0804();
A1=a/100; //分出百,十,和个位
A2=a0/10;
A3=a;
lcd_busy();
lcd_xy(3,0);
lcd_write_dat(lcd[A1]);
lcd_busy();
lcd_xy(4,0);
lcd_write_dat(lcd[A2]);
lcd_busy();
lcd_xy(5,0);
lcd_write_dat(lcd[A3]);
}
}