Can you post your exact circuit and code?
- Raj
Experiments with PIC16F628A
Hi raj, thanks for your attention. The following is my up to date code:
// LCD module connections
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
// End LCD module connections
void main() {
long scale;
int temp;
char print;
char txt[7];
TRISB = 0; //PORTB as output
TRISA = 0xFF; //PORTA as input
ADCON1 = 0x0E; // Set AN0 channel pin as analog
CMCON |= 7; // Disable comparators
Lcd_Init(); //Initialize LCD
while (1){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
temp = ADC_Read(0);
scale = 5000*temp;
scale=scale/1024;
temp=scale;
print = temp/1000;
Lcd_Chr(1, 1, print+48); //print 1st digit (print=5, 5+48 = 53. in ascii, 53 is character 5
Lcd_Chr_CP('.');
print = (temp/100)%10;
Lcd_Chr_CP(print+48); //print 2nd digit
print= (temp/10)%10;
Lcd_Chr_CP(print+48); //print 3rd digit
print=temp%10;
Lcd_Chr_CP(print+48); //print 4th digit
Lcd_Chr_CP('V');
IntToStr(temp, txt);
Lcd_Out(2,1,txt); //display ADC value
Delay_ms(1000);
}
}
How can I post my circuit here? I don't have any schematics. My circuit has LCD interfaced to port B, and the LCD works fine. For ADC purposes, I directly connect AN0 to VDD using a jumper. There is nuthin else unusual in my simple circuit. Any suggestion what Im doing wrong? Thanks again for your attention.