pradeep_k_b
Full Member level 3
- Joined
- Dec 21, 2011
- Messages
- 160
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,306
- Location
- Nilambur, India
- Activity points
- 2,509
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 txt2[] = {4,4,4,4,31,14,4,0};
const char character[] = {0,0,4,2,31,2,4,0};
void CustomChar(char pos_row, char pos_char) {
char i;
Lcd_Cmd(64);
for (i = 0; i<=7; i++) Lcd_Chr_CP(character[i]);
Lcd_Cmd(_LCD_RETURN_HOME);
Lcd_Chr(pos_row, pos_char, 0);
}
char txt1[] = " CHR OFF ";
char txt3[] = " CHR ON ";
char txt4[] = "BAD LIGHT";
//Function Prototypes
void floattostring(double FP_NUM);
double FP_NUM, volt;
char string[6];
//Sub Function
void floattostring(double FP_NUM) {
double fpnumber;
long int befdec, aftdec;
fpnumber = FP_NUM;
befdec = fpnumber; // Fractional part is truncated
// 12.163456 becomes 12
aftdec = fpnumber * 100; // 12.163456 becomes 1216
aftdec = aftdec - (befdec * 100); // 1216 - 1200 = 16
if (fpnumber < 1) {
string[0] = '0';
string[1] = '.';
string[2] = (aftdec/10) + 48;
string[3] = (befdec/1)%10 + 48;
string[4] = ' ';
string[5] = '\0';
}
else if ((fpnumber >= 1) && (fpnumber < 10)) {
string[0] = (befdec/1)%10 + 48;
string[1] = '.';
string[2] = (aftdec/10) + 48;
string[3] = (befdec/1)%10 + 48;
string[4] = ' ';
string[5] = '\0';
}
else if ((fpnumber >= 10) && (fpnumber < 100)) {
string[0] = (befdec/10) + 48;
string[1] = (befdec/1)%10 + 48;
string[2] = '.';
string[3] = (aftdec/10) + 48;
string[4] = (befdec/1)%10 + 48;
string[5] = '\0';
}
}
void main(){ANSEL = 0b00000100; // RA2/AN2 is analog input
ADCON0 = 0b00001000; // Analog channel select @ AN2
ADCON1 = 0x00;
//CMCON0 = 0x07 ; // Disbale comparators
TRISC = 0b00000000; // PORTC All Outputs
//TRISA = 0b00001100; // PORTA All Outputs, Except RA3 and RA2
TRISA = 0b00000011; // PORTA All Outputs, Except RA3 and RA2
//TRISA = 0b00001111; // PORTA All Outputs, Except RA3 and RA2
LCD_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2,1,"Hello...!");
Delay_ms(1000); // Waits 2 sec. for splash screen to be shown :)
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Welcom To");
Lcd_Out(2,8,"SOLAR CHARGER");
Delay_ms(1000); // Waits 2 sec. for splash screen to be shown :)
LCD_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"SOLAR");
Lcd_Out(2,1,"BATTERY");
while(1) {
volt = ADC_Read(0);
volt = volt * 0.0305498981670061;
volt = volt * 0.9612303748798462;
floattostring(volt);
Lcd_Out(2,11,string);
Lcd_Out(2,16,"V");
if(PORTA.RA1 = 0) {
Lcd_Out(1,8,txt4);
PORTA.RA2 = 0;
//PORTA.RA4 = 1;
}
else if(volt < 13.8) { // Change value here
PORTA.RA2 = 1;
Lcd_Out(1,8,txt3);
}
if(volt > 14.8) { // Change value here
PORTA.RA2 = 0;
Lcd_Out(1,8,txt1);
}
if(volt>10.8)
{
PORTA.RA4 = 1; }
}
}
if(volt>10.8)
{
PORTA.RA4 = 1; }
it working fine with simulator,but that part is very important and I can't remove that from the program .Please help me to solve this