//********************************
//LCD1602+ADC0809制造的数字电压表
//接口方法:总线扩展
//作者:曾宪阳
//网址:http://hi.baidu.com/zxymcu
//********************************
#include
#defineADC0809Addr0x78ff
#defineLCDWriteComAddr0xa7ff
#defineLCDWriteDatAddr0xafff
#defineucharunsignedchar
#defineuintunsignedint
ucharDisp[6];
voiddelay_ms(uintt)
{
ucharx,y;
for(t;t>0;t–)
{
for(x=0;x<114;x++)
for(y=0;y<1;y++);
}
}
voidInit1602(void)
{
delay_ms(15);
*((ucharxdata*)LCDWriteComAddr)=0x38;
delay_ms(5);
*((ucharxdata*)LCDWriteComAddr)=0x38;
delay_ms(5);
*((ucharxdata*)LCDWriteComAddr)=0x38;
delay_ms(2);
*((ucharxdata*)LCDWriteComAddr)=0x08;
delay_ms(2);
*((ucharxdata*)LCDWriteComAddr)=0x01;
delay_ms(2);
*((ucharxdata*)LCDWriteComAddr)=0x0c;
delay_ms(2);
*((ucharxdata*)LCDWriteComAddr)=0x06;
delay_ms(2);
*((ucharxdata*)LCDWriteComAddr)=0x80;
delay_ms(2);
}
voidDisplay(void)
{
*((ucharxdata*)LCDWriteComAddr)=0XC0;
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=I;
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=N;
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=0;
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)==;
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=(0+Disp[0]);
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=(.);
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=(0+Disp[1]);
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=(0+Disp[2]);
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=(0+Disp[3]);
delay_ms(2);
*((ucharxdata*)LCDWriteDatAddr)=(V);
delay_ms(2);
}
voidADC0809(void)
{
unsignedlongi;
*((ucharxdata*)ADC0809Addr)=0;
delay_ms(100);
i=*((ucharxdata*)ADC0809Addr);
P1=i;
i=(i*5000/255);
Disp[0]=(i/1000);
Disp[1]=(i00/100);
Disp[2]=(i000/10);
Disp[3]=(i000);
}
voidmain(void)
{
Init1602();
while(1)
{
ADC0809();
Display();
}
}