LCD1602+ADC0809制作的數(shù)字電壓表
//********************************
//LCD1602+ADC0809制作的數(shù)字電壓表
//接口方式:總線擴(kuò)展
//作者:曾憲陽(yáng)
//網(wǎng)址: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();
}
}
評(píng)論