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
// 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; }
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 // 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 #define lower_limit 13.8 #define upper_limit 14.8 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); } const char lcdMsg1[] = "Charger OFF "; const char lcdMsg2[] = "Charger ON "; const char lcdMsg3[] = "Bad Light "; const char lcdMsg4[] = "Hello!... "; const char lcdMsg5[] = "Welcome to "; const char lcdMsg6[] = "Solar Charger "; const char lcdMsg7[] = "Solar "; const char lcdMsg8[] = "Battery "; char lcdData[23]; double volt = 0.0, voltBackup = 0.0; void Delay2Sec() { Delay_ms(2000); } char *CopyConst2Ram(char *dest, const char *src) { char *d ; d = dest; for(;*dest++ = *src++;); return d; } void main() { ANSEL = 0x04; // RA2/AN2 is analog input ACON0 = 0x88; ADCON1 = 0x00; TRISA = 0x06; // PORTA All Outputs, Except RA3 and RA2 TRISC = 0x00; // PORTC All Outputs PORTA = 0x00; PORTC = 0x00; LCD_Init(); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdMsg4)); Delay2Sec()(); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg5)); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdMsg6)); Delay2Sec()(); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg7)); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdMsg8)); while(1) { volt = ADC_Read(2); if(voltBackup != volt) { volt /= 34.0536; FloatToStr(volt, lcdData); lcdData[7] = '\0'; strcat(lcdData, " V"); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdData)); if(volt < lower_limit) { PORTA.F2 = 1; Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg2)); } else if(volt > 10.8) { PORTA.RA4 = 1; if(volt > upper_limit) { PORTA.F2 = 0; Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg1)); } } voltBackup = volt; } if(PORTA.F1 == 0) { Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg3)); PORTA.F2 = 0; } } }
PORTA = 0; // initialise all outputs to low
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 // 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 #define lower_limit 13.8 #define upper_limit 14.8 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); } const char lcdMsg1[] = "Charger OFF "; const char lcdMsg2[] = "Charger ON "; const char lcdMsg3[] = "Bad Light "; const char lcdMsg4[] = "Hello!... "; const char lcdMsg5[] = "Welcome to "; const char lcdMsg6[] = "Solar Charger "; const char lcdMsg7[] = "Solar "; const char lcdMsg8[] = "Battery "; char lcdData[23]; double volt = 0.0, voltBackup = 0.0; void Delay2Sec() { Delay_ms(2000); } char *CopyConst2Ram(char *dest, const char *src) { char *d ; d = dest; for(;*dest++ = *src++;); return d; } void main() { ANSEL = 0x04; // RA2/AN2 is analog input ADCON0 = 0x88; ADCON1 = 0x00; TRISA = 0x06; // PORTA All Outputs, Except RA3 and RA2 TRISC = 0x00; // PORTC All Outputs PORTA = 0x00; PORTC = 0x00; LCD_Init(); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdMsg4)); Delay2Sec()(); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg5)); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdMsg6)); Delay2Sec()(); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg7)); Lcd_Out(2,1,CopyConst2Ram(lcdData, lcdMsg8)); while(1) { volt = ADC_Read(2); if(voltBackup != volt) { volt /= 34.0536; FloatToStr(volt, lcdData); lcdData[7] = '\0'; strcat(lcdData, " V"); Lcd_Out(2,1,lcdData); if(volt < lower_limit) { PORTA.F2 = 1; Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg2)); } else if(volt > 10.8) { PORTA.RA4 = 1; if(volt > upper_limit) { PORTA.F2 = 0; Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg1)); } } voltBackup = volt; } if(PORTA.F1 == 0) { Lcd_Out(1,1,CopyConst2Ram(lcdData, lcdMsg3)); PORTA.F2 = 0; } } }
11.2V-14.2-"solar charger on&Load ON" -if the voltage is between 11.6-14.2&"solar charger On and load OFF"
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?