// 16F873A
// 20MHz
#define ON 1;
#define OFF 0;
//
sbit LCD_D4 at RC0_bit;
sbit LCD_D5 at RC1_bit;
sbit LCD_D6 at RC2_bit;
sbit LCD_D7 at RC3_bit;
sbit LCD_EN at RC4_bit;
sbit LCD_RS at RC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
sbit LCD_EN_Direction at TRISC4_bit;
sbit LCD_RS_Direction at TRISC5_bit;
//
unsigned int voltage;
unsigned int tens;
unsigned int ones;
unsigned int tenths;
unsigned int hundths;
unsigned char ch;
unsigned int temp1;
unsigned int temp2;
void check ()
{
CCP1CON = 0x00;
CCP2CON = 0x00;
ADCON0 = 0x80;
ADCON1 = 0xCE;
ADON_bit = ON;
GO_DONE_bit = ON;
do
{
}
while (GO_DONE_bit == 1);
voltage = ADRESH;
voltage = voltage << 8;
voltage = voltage + ADRESL;
tens = voltage / 1000;
temp1 = voltage % 1000;
ones = temp1 /100;
temp2 = temp1 % 100;
tenths = temp2 / 10;
hundths = temp2 % 10;
ch = tens + 48;
Lcd_Chr(2,1,ch);
ch = ones + 48;
Lcd_Chr_CP(ch);
ch = tenths + 48;
Lcd_Chr_CP(ch);
ch = hundths + 48;
Lcd_Chr_CP(ch);
delay_ms(100);
temp1 = 0;
temp2 = 0;
}
void main ()
{
TRISA = 0xFF;
Lcd_Init ();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
do
{
check ();
}
while (1);
}