//********************************
//LCD1602+ADC0809制作的数字电压表
//接口方式:总线扩展
//作者:曾宪阳
//网址:http://hi.baidu.com/zxymcu
//********************************
#include
#define ADC0809Addr 0x78ff
#define LCDWriteComAddr 0xa7ff
#define LCDWriteDatAddr 0xafff
#define uchar unsigned char
#define uint unsigned int
uchar Disp[6];
void delay_ms(uint t)
{
uchar x,y;
for(t;t>0;t--)
{
for(x=0;x<114;x++)
for(y=0;y<1;y++);
}
}
void Init1602(void)
{
delay_ms(15);
*((uchar xdata*)LCDWriteComAddr)=0x38;
delay_ms(5);
*((uchar xdata*)LCDWriteComAddr)=0x38;
delay_ms(5);
*((uchar xdata*)LCDWriteComAddr)=0x38;
delay_ms(2);
*((uchar xdata*)LCDWriteComAddr)=0x08;
delay_ms(2);
*((uchar xdata*)LCDWriteComAddr)=0x01;
delay_ms(2);
*((uchar xdata*)LCDWriteComAddr)=0x0c;
delay_ms(2);
*((uchar xdata*)LCDWriteComAddr)=0x06;
delay_ms(2);
*((uchar xdata*)LCDWriteComAddr)=0x80;
delay_ms(2);
}
void Display(void)
{
*((uchar xdata*)LCDWriteComAddr)=0XC0;
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)='I';
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)='N';
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)='0';
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)='=';
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)=('0'+Disp[0]);
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)=('.');
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)=('0'+Disp[1]);
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)=('0'+Disp[2]);
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)=('0'+Disp[3]);
delay_ms(2);
*((uchar xdata*)LCDWriteDatAddr)=('V');
delay_ms(2);
}
void ADC0809(void)
{
unsigned long i;
*((uchar xdata*)ADC0809Addr)=0;
delay_ms(100);
i=*((uchar xdata*)ADC0809Addr);
P1=i;
i=(i*5000/255);
Disp[0]=(i/1000);
Disp[1]=(i00/100);
Disp[2]=(i000/10);
Disp[3]=(i000);
}
void main(void)
{
Init1602();
while(1)
{
ADC0809();
Display();
}
}
上一篇:单片机实现的温度显示系统
下一篇:定时器计数并将计数值实时显示在数码管
推荐阅读最新更新时间:2024-03-16 14:35