Linspire
Full Member level 5
Guys,
Any idea how to write a proper coding for ATD for showing the voltage level of my battery 5V ?
I want to implement this to check whether the battery face low battery scenario.
I'm not used to ATD field.
Hope someone can guide me.
I have tried simple coding for mikroC.
Here's the coding:
However, the result shows 5V = 1203
0V = 0
I have tried used variable resistor result's weird.
Regards
Linspire
Any idea how to write a proper coding for ATD for showing the voltage level of my battery 5V ?
I want to implement this to check whether the battery face low battery scenario.
I'm not used to ATD field.
Hope someone can guide me.
I have tried simple coding for mikroC.
Here's the coding:
Code:
unsigned int temp;
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RA1_bit;
sbit LCD_D5 at RA2_bit;
sbit LCD_D6 at RA3_bit;
sbit LCD_D7 at RA4_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISA1_bit;
sbit LCD_D5_Direction at TRISA2_bit;
sbit LCD_D6_Direction at TRISA3_bit;
sbit LCD_D7_Direction at TRISA4_bit;
// End LCD module connections
void main() {
ADCON0 = 0x13;
ADCON1 = 0x0E;
CMCON = 0x07;
TRISA = 0x10;
ADC_Init();
Lcd_Init();
LCD_CMD(_LCD_CURSOR_OFF);
do{
temp= ADC_Read(0); // Port A0: AN0
InttoStr(temp,output);
Lcd_Out(1,1,output);
delay_ms(500);
Lcd_cmd(_LCD_CLEAR);
}while(1);
}
However, the result shows 5V = 1203
0V = 0
I have tried used variable resistor result's weird.
Regards
Linspire