PIYUSH SONI
Newbie level 2
- Joined
- Nov 16, 2013
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 13
Hi,
I am PIYUSH. I am working on a project to control the charger using pic microcontroller. I am using pic 18f4520 MCU and easy pic5 development board. I have taken 2 ADC channel and displaying the equivalent voltage on 4*16 LCD. Actually i want to display the difference of both channel in percentage.Help me so that i can solve my problem. I am also attaching my program code:-
Plz help me to display the difference b/w adc channel .
I am PIYUSH. I am working on a project to control the charger using pic microcontroller. I am using pic 18f4520 MCU and easy pic5 development board. I have taken 2 ADC channel and displaying the equivalent voltage on 4*16 LCD. Actually i want to display the difference of both channel in percentage.Help me so that i can solve my problem. I am also attaching my program code:-
Code:
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB4_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D7 at RB0_bit;
sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB4_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D7_Direction at TRISB0_bit;
char message1[] = "SPG SYSTEMS";
char message2[] = "-----------";
char message3[] = "DEVELOPED BY:-";
char message4[] = "SPG INFOTECH LTD";
char message5[] = "CH1= VOLTS";
char message6[] = "CH2= VOLTS";
char message7[] = "CHARGER OFF";
char message8[] = "CHARGER ON";
sbit Relay at RA5_bit;
sbit Buzzer at RA4_bit;
char *temp = "00000";
char *temps = "00000";
unsigned int adc_value;
unsigned int adc_valueV;
unsigned int adc_values;
unsigned int adc_valueVs;
unsigned char VOLTS;
void main()
{
OSCCON = 0b01111110;
ANSEL = 0b00000011;
ADCON0 = 0b00001000;
ADCON1 = 0b00000000;
CMCON = 7 ;
TRISA = 0b00000011;
TRISB = 0b00000000;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,3,message1);
Lcd_Out(2,3,message2);
Lcd_Out(3,-3,message3);
Lcd_Out(4,-3,message4);
Delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,message5);
Lcd_Out(2,1,message6);
Lcd_Out(4,1,message7);
Lcd_Out(4,1,message8);
do
{
Delay_ms(1);
Lcd_Out(1,1,message5);
Lcd_Out(2,1,message6);
adc_value = ADC_READ(1);
Delay_ms(25);
adc_valueV = adc_value*4.89;
temp[0] = adc_valueV/1000 + 48;
temp[1] = '.';
temp[2] = (adc_valueV/100)%10 + 48;
temp[3] = (adc_valueV/10)%10 + 48;
temp[4] = adc_valueV%10 + 48;
Lcd_Out(1,5,temp);
adc_values = ADC_READ(0);
Delay_ms(25);
adc_valueVs = adc_values*4.89 ;
temps[0] = adc_valueVs/1000 + 48;
temps[1] = '.';
temps[2] = (adc_valueVs/100)%10 + 48;
temps[3] = (adc_valueVs/10)%10 + 48;
temps[4] = adc_valueVs%10 + 48;
Lcd_Out(2,5,temps);
Delay_ms(500);
if((adc_valueV/666 >2.0) || (adc_valueVs/666 >2.0))
{
Relay = 0;
Lcd_Out(4,0,message7);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(4,0,message7);
Buzzer =1 ;
}
else
{
Relay = 1;
Lcd_Out(4,0,message8);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(4,0,message8);
Buzzer =0 ;
}
}while(1);
} /*
Last edited by a moderator: