salim alfarsi
New Member
Hi,
i have this code to convert the ADC value to PPM value and display it on LCD. now the problem is LCD is on but doesn't show any value!! any suggestion?
/*
* Project name:
LPG Project
* Copyright:
(c) 2012.
* Revision History:
Feb 2012 - V 1.2
* Description:
This program tests for the presence of combustible gas
using an LPG gas sensor.
* Test configuration:
MCU: PIC16F877A
Oscillator: 8.0000 MHz Crystal
Ext. Modules: None.
SW: mikroC PRO for PIC
https://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/
*/
// Lcd pinout settings
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;
// Pin direction
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;
char lcd_text[17];
char tmp_text[17];
// The ADC conversion value is 1023 ADC Levels/5V = 204.6 ADC Levels / Volt
#define ADC_CONVERSION_FACTOR 204.6
//The PPM conversion factor is10000PPM/5V = 2000 PPM per Volt
#define PPM_CONVERSION_FACTOR 2000
//The ADC LEVEL to PPM conversion factor is 10000PPM/1023ADC LEVELS = 9.775171
#define ADC_TO_PPM_CONVERSION_FACTOR 9.775171
//If the adc reads 512 the real voltage is 2.5 VDC and the PPM level is 5000PPM.
void main(){
unsigned int adc_value;
float ppm_value;
TRISE.B0=1; // RE5 as input
Lcd_Init();
ADC_Init();
while(1)
{
//--------------------------------
//Get the current ADC value
//--------------------------------
//Read the ADC for the latest value
adc_value = ADC_Read(5);
//Convert the ADC value to the PPM concentration
ppm_value = ADC_TO_PPM_CONVERSION_FACTOR*adc_value;
//--------------------------------
//Display the ADC value on the LCD
//--------------------------------
Lcd_Out(1,1,adc_value);
delay_ms(500);
//Convert the adc value to text
WordToStr(adc_value,tmp_text);
//Build the LCD display text
strcpy("Raw ADC:",lcd_text);
strcat(tmp_text,lcd_text);
//Display the RAW ADC Value
Lcd_Out(1,1,lcd_text);
delay_ms(500);
//--------------------------------
//Display the PPM value on the LCD
//--------------------------------
//Convert the ppm value to text
FloatToStr(ppm_value,tmp_text);
//Build the LCD display text
strcpy("PPM:", lcd_text);
strcat(tmp_text, lcd_text);
//Display the PPM Value
Lcd_Out(2,1,lcd_text);
Delay_ms(1000);
}
}
i have this code to convert the ADC value to PPM value and display it on LCD. now the problem is LCD is on but doesn't show any value!! any suggestion?
/*
* Project name:
LPG Project
* Copyright:
(c) 2012.
* Revision History:
Feb 2012 - V 1.2
* Description:
This program tests for the presence of combustible gas
using an LPG gas sensor.
* Test configuration:
MCU: PIC16F877A
Oscillator: 8.0000 MHz Crystal
Ext. Modules: None.
SW: mikroC PRO for PIC
https://www.mikroe.com/eng/products/view/7/mikroc-pro-for-pic/
*/
// Lcd pinout settings
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;
// Pin direction
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;
char lcd_text[17];
char tmp_text[17];
// The ADC conversion value is 1023 ADC Levels/5V = 204.6 ADC Levels / Volt
#define ADC_CONVERSION_FACTOR 204.6
//The PPM conversion factor is10000PPM/5V = 2000 PPM per Volt
#define PPM_CONVERSION_FACTOR 2000
//The ADC LEVEL to PPM conversion factor is 10000PPM/1023ADC LEVELS = 9.775171
#define ADC_TO_PPM_CONVERSION_FACTOR 9.775171
//If the adc reads 512 the real voltage is 2.5 VDC and the PPM level is 5000PPM.
void main(){
unsigned int adc_value;
float ppm_value;
TRISE.B0=1; // RE5 as input
Lcd_Init();
ADC_Init();
while(1)
{
//--------------------------------
//Get the current ADC value
//--------------------------------
//Read the ADC for the latest value
adc_value = ADC_Read(5);
//Convert the ADC value to the PPM concentration
ppm_value = ADC_TO_PPM_CONVERSION_FACTOR*adc_value;
//--------------------------------
//Display the ADC value on the LCD
//--------------------------------
Lcd_Out(1,1,adc_value);
delay_ms(500);
//Convert the adc value to text
WordToStr(adc_value,tmp_text);
//Build the LCD display text
strcpy("Raw ADC:",lcd_text);
strcat(tmp_text,lcd_text);
//Display the RAW ADC Value
Lcd_Out(1,1,lcd_text);
delay_ms(500);
//--------------------------------
//Display the PPM value on the LCD
//--------------------------------
//Convert the ppm value to text
FloatToStr(ppm_value,tmp_text);
//Build the LCD display text
strcpy("PPM:", lcd_text);
strcat(tmp_text, lcd_text);
//Display the PPM Value
Lcd_Out(2,1,lcd_text);
Delay_ms(1000);
}
}