In proteus when you will select hex file.
You also need to write processor clock frequency.Which is by default 1Mhz.
I simulate its a lcd base dc volt meter with battery charging cut relay.
It displays max dc 30volt.
And relay become off (unenergized) at 13.83v.
And relay become on again at 13.53v.
I think these volts should 12.5v for charging restore.
Thank you....thanks a lot...by the way how can I replace this LCD with a seven segment display???...can we do it easily??
// 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
//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() {
TRISA = 0b00000001;
PORTA = 0b00000000;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISC = 0b00000111;
PORTC = 0b00000000;
TRISD = 0b00000000;
PORTD = 0b00000000;
ADCON1 = 0b10001110;
CMCON = 0b00000111;
LCD_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Voltage is");
while(1) {
volt = ADC_Read(0);
volt = volt * 0.0305498981670061;
volt = volt * 0.9612303748798462;
floattostring(volt);
Lcd_Out(2,1,string);
Lcd_Out(2,7,"V");
if(volt > 13.8) { // Change value here
PORTD.F0 = 0;
}
else if(volt < 13.6) { // Change value here
PORTD.F0 = 1;
}
}
}
Thank you.its really working.......now the only pending requirement is the LCD to 7-segmant conversion..i am trying for that...thanks a lot internetuser2k12
Charging restore means,battery charger circuit resume charging.what is 12.5 v for charging restore?
while(1) {
volt = ADC_Read(0);
volt = volt * 0.0305498981670061;
volt = volt * 0.9612303748798462;
floattostring(volt);
Lcd_Out(2,1,string);
Lcd_Out(2,7,"V");
if(volt > 13.8) { // Change value here
PORTD.F0 = 0;
}
else if(volt < 13.6) { // Change value here
PORTD.F0 = 1;
} // end of while loop
}// end of main
ADC_Init();
ADC_Get_Sample( );
ADC_Read( );
unsigned int ADCR;
void main(void){
ADC_Init();
TRISA = 0xFF;
while (1){
ADCR = ADC_Get_Sample(0); //Number within parentheses is the channel to read from
//............ Rest of the code
//............
}
}
I try to change code like this and build.Change ADCON1 to 0b10001101; and also change volt = ADC_Read(0); to volt = ADC_Read(1);
// 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
//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() {
TRISA = 0b00000001;
PORTA = 0b00000000;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISC = 0b00000111;
PORTC = 0b00000000;
TRISD = 0b00000000;
PORTD = 0b00000000;
ADCON1 = 0b10001110;
CMCON = 0b00000111;
LCD_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Voltage is");
while(1) {
volt = ADC_Read(0);
volt = volt * 0.0305498981670061;
volt = volt * 0.9612303748798462;
floattostring(volt);
Lcd_Out(2,1,string);
Lcd_Out(2,7,"V");
if(volt > 13.8) { // Change value here
PORTD.F0 = 0;
}
else if(volt < 13.6) { // Change value here
PORTD.F0 = 1;
}
ADCON1 = 0b10001101; //next 2nd channel selection
volt = ADC_Read(1); //AN1 will also read an other analog value
if(volt > 15.8) { // Change value here
PORTD.F1 = 0;
}
else if(volt < 14.6) { // Change value here
PORTD.F1 = 1;
}
}
}
// 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
//Function Prototypes
void floattostring(double FP_NUM);
double FP_NUM, volt, volt1;
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() {
TRISA = 0b00000011;
PORTA = 0b00000000;
TRISB = 0b00000000;
PORTB = 0b00000000;
TRISC = 0b00000111;
PORTC = 0b00000000;
TRISD = 0b00000000;
PORTD = 0b00000000;
ADCON1 = 0b10001110;
CMCON = 0b00000111;
LCD_Init();
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Voltage is");
ADC_Init();
while(1) {
volt = ADC_Read(0);
volt = volt * 0.0305498981670061;
volt = volt * 0.9612303748798462;
floattostring(volt);
Lcd_Out(2,1,string);
Lcd_Out(2,7,"V");
if(volt > 13.8) { // Change value here
PORTD.F0 = 0;
}
else if(volt < 13.6) { // Change value here
PORTD.F0 = 1;
}
ADCON1 = 0b10001101; //next 2nd channel selection
volt1 = ADC_Read(1); //AN1 will also read an other analog value
if(volt1 > 15.8) { // Change value here
PORTD.F1 = 0;
}
else if(volt1 < 14.6) { // Change value here
PORTD.F1 = 1;
}
}
}
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?