thorwynn
Newbie level 1
Good Day
I have to troubleshoot this PIC programming in line with my thesis panel's recommendations
i purposely used the PIC16F877A just to convert the Analog Output of the gas sensors into Digital...
i supposedly will use the ADC value and plug it into my equations in the GUI.
the original code drive an output to my zigbee tranciever and LCD output however, when i revised my code, i don't seem to have an output anymore
Original Code
Revised Code that i made
Thanks, your help is muchly appreciated
I have to troubleshoot this PIC programming in line with my thesis panel's recommendations
i purposely used the PIC16F877A just to convert the Analog Output of the gas sensors into Digital...
i supposedly will use the ADC value and plug it into my equations in the GUI.
the original code drive an output to my zigbee tranciever and LCD output however, when i revised my code, i don't seem to have an output anymore
Original Code
Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
int ctr = 0;
char valueStr[7];
float mq135Reading;
float mq131Reading;
float mg811Reading;
float tgs203Reading;
void main(){
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"NO2 :"); // MQ-135
Lcd_Out(2,1,"O3 :"); // MQ-131
Lcd_Out(3,1,"CO2 :"); // MG-811
Lcd_Out(4,1,"CO :"); // MQ7
Delay_ms(5000);
while(1){
mq135Reading = ((ADC_Read(1)/1024.0) * 100.0);
mq131Reading = ((ADC_Read(2)/1024.0) * 100.0);
mg811Reading = ((ADC_Read(3)/1024.0) * 100.0);
tgs203Reading = ((ADC_Read(4)/1024.0) * 100.0);
//if(mg811Reading < 0){ mg811Reading = 0;}
//Vrl = val * ( 5.00 / 1024.0 ); // Volt
//Rs = 20000 * ( 5.00 - Vrl) / Vrl ; // Ohm
//ratio = Rs/Ro;
//mg811Reading =
if(ctr > 10){
IntToStr(mq135Reading, valueStr);
Lcd_Out(1,13, valueStr);
Lcd_Out(1,19, "%");
IntToStr(mq131Reading, valueStr);
Lcd_Out(2,13, valueStr);
Lcd_Out(2,19, "%");
IntToStr(mg811Reading, valueStr);
Lcd_Out(3,13, valueStr);
Lcd_Out(3,19, "%");
IntToStr(tgs203Reading, valueStr);
Lcd_Out(4,13, valueStr);
Lcd_Out(4,19, "%");
Lcd_Out(1,13,":");
Lcd_Out(2,13,":");
Lcd_Out(3,13,":");
Lcd_Out(4,13,":");
IntToStr(mq135Reading, valueStr);
UART1_Write_Text(valueStr); // MQ 135 value
UART1_Write(0x2C); // Separator ","
IntToStr(mq131Reading, valueStr);
UART1_Write_Text(valueStr); // MQ 131 value
UART1_Write(0x2C); // Separator ","
IntToStr(mg811Reading, valueStr);
UART1_Write_Text(valueStr); // MG 811 value
UART1_Write(0x2C); // Separator ","
IntToStr(tgs203Reading, valueStr);
UART1_Write_Text(valueStr); // TGS 203 value
UART1_Write(0x0D); // Return
UART1_Write(0x0A); // Line Feed
ctr = 0;
}
ctr = ctr + 1;
Delay_ms(100);
}
}
Revised Code that i made
Code:
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
int ctr = 0;
char valueStr[7];
float mq135Reading;
float mq131Reading;
float mg811Reading;
float tgs203Reading;
float mq135;
float mq131;
float mg811;
float tgs203;
float rs1;
float rs2;
float rs3;
float rs4;
void main(){
UART1_Init(9600); // initialize UART1 module
Delay_ms(100);
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"NO2 :"); // MQ-135
Lcd_Out(2,1,"O3 :"); // MQ-131
Lcd_Out(3,1,"CO2 :"); // MG-811
Lcd_Out(4,1,"CO :"); // TGS-203
Delay_ms(200);
while(1){
//mq135Reading = ((5*(ADC_Read(1))/1024.0) * 5);
//mq131Reading = ((5*(ADC_Read(2))/1024.0) * 5);
//mg811Reading = ((5*(ADC_Read(3))/1024.0) * 5);
//if(mg811Reading < 0){ mg811Reading = 0; }
//tgs203Reading = ((5*(ADC_Read(4))/1024.0) * 5);
rs1 = (12000.0/(((5 - ((5*(ADC_Read(1))/1024.0) * 1.0))/((5*(ADC_Read(1))/1024.0) * 1.0))*10000.0));
rs2 = (12000.0/(((5 - ((5*(ADC_Read(2))/1024.0) * 1.0))/((5*(ADC_Read(2))/1024.0) * 1.0))*10000.0));
rs3 = (12000.0/(((5 - ((5*(ADC_Read(3))/1024.0) * 1.0))/((5*(ADC_Read(3))/1024.0) * 1.0))*10000.0));
rs4 = (12000.0/(((5 - ((5*(ADC_Read(4))/1024.0) * 1.0))/((5*(ADC_Read(4))/1024.0) * 1.0))*20000.0));
//exp1 = 8000/rs1;
//exp2 = 8000/rs2;
//exp3 = 8000/rs2;
//exp4 = 8000/rs2;
mq135 = 73.15* pow (rs1 , 3.75);
mq131 = 73.15* pow (rs2 , 3.75);
mg811 = 73.15* pow (rs3 , 3.75);
tgs203 = 73.15* pow (rs4 , 3.75);
//Vrl = val * ( 5.00 / 1024.0 ); // Volt
//Rs = 20000 * ( 5.00 - Vrl) / Vrl ; // Ohm
//ratio = Rs/Ro;
//mg811Reading =
if(ctr > 10){
IntToStr(mq135, valueStr);
Lcd_Out(1,13, valueStr);
Lcd_Out(1,19, "%");
IntToStr(mq131, valueStr);
Lcd_Out(2,13, valueStr);
Lcd_Out(2,19, "%");
IntToStr(mg811, valueStr);
Lcd_Out(3,13, valueStr);
Lcd_Out(3,19, "%");
IntToStr(tgs203, valueStr);
Lcd_Out(4,13, valueStr);
Lcd_Out(4,19, "%");
Lcd_Out(1,13,":");
Lcd_Out(2,13,":");
Lcd_Out(3,13,":");
Lcd_Out(4,13,":");
IntToStr(mq135, valueStr);
UART1_Write_Text(valueStr); // MQ 135 value
UART1_Write(0x2C); // Separator ","
IntToStr(mq131, valueStr);
UART1_Write_Text(valueStr); // MQ 131 value
UART1_Write(0x2C); // Separator ","
IntToStr(mg811, valueStr);
UART1_Write_Text(valueStr); // MG 811 value
UART1_Write(0x2C); // Separator ","
IntToStr(tgs203, valueStr);
UART1_Write_Text(valueStr); // TGS 203 value
UART1_Write(0x0D); // Return
UART1_Write(0x0A); // Line Feed
ctr = 0;
{
ctr = ctr + 1;
Delay_ms(100);
}
}
}}
Thanks, your help is muchly appreciated