vibodha
Newbie level 6
- Joined
- Jun 3, 2013
- Messages
- 11
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,365
I have made a small program to measure voltage(0-5) on AN2. Its works fine but have a little problem. When the voltage less than 1v (ie. 0.99) it shows wrong voltage on LCD.
ie when voltage 0.568V , Lcd shows 5.68v
0.0213v -----> 0.213v
Can anyone correct me..
here is the program (mikroc)
ie when voltage 0.568V , Lcd shows 5.68v
0.0213v -----> 0.213v
Can anyone correct me..
here is the program (mikroc)
Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt1[] = "ADC Example";
char txt[2];
char txt2[5];
unsigned int temp_res;
float data2;
void main() {
ansel=4; // Configure AN2 pin as analog
anselh=0;
c1on_bit=0;
c2on_bit=0;
////////////////////////////////////////////////////////////////
TRISA = 0xFF; // PORTA is input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,txt1);
adc_init();
do {
temp_res = ADC_read(2); // Get 10-bit results of AD conversion
data2 = (temp_res*5)/1023.0;
FloatToStr(data2,txt2);
txt2[5]=0;
Lcd_Out(2,1,txt2);
Delay_ms(1000);
}
while(1) ;
}