i am trying to display two sets of voltages on a lcd with PIC16f684. i can get one line with voltage displaying using ANSEL and selecting an line as an analogue input.
but when i set more than one input as an analogue and set it to read, all i get is rubbish symbols on the LCD. is this even possible to do?
any help will be appreciated.
here is my code:
// LCD module connections
sbit LCD_RS at RC4_bit;
sbit LCD_EN at RC5_bit;
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_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_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;
// End LCD module connections
char Message1[] = "Voltage:";
unsigned int ADC_Value1, DisplayVolt1;
char *volt = "00.00";
char Message2[] = "Amperage:";
unsigned int ADC_Value2, DisplayVolt2;
char *volt1 = "00.00";
void main() {
ANSEL = 0b00010100;
ADCON0 = 0b00010100;
ADCON1 = 0x00;
CMCON0 = 0x07 ;
TRISC = 0b00000000;
TRISA = 0b00010100;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,Message1);
Lcd_Out(2,1,Message2);
do {
ADC_Value1 = ADC_Read(2);
DisplayVolt1 = ADC_Value1 * 2;
volt[0] = DisplayVolt1/1000 + 48;
volt[1] = (DisplayVolt1/100)%10 + 48;
volt[3] = (DisplayVolt1/10)%10 + 48;
volt[4] = (DisplayVolt1/1)%10 + 48;
Lcd_Out(1,9,volt);
delay_ms(200);
ADC_Value2 = ADC_Read(2);
DisplayVolt2 = ADC_Value2 * 2;
volt[0] = DisplayVolt2/1000 + 48;
volt[1] = (DisplayVolt2/100)%10 + 48;
volt[3] = (DisplayVolt2/10)%10 + 48;
volt[4] = (DisplayVolt2/1)%10 + 48;
Lcd_Out(2,10,volt);
delay_ms(200);
} while(1);
}