Noobmaster6910
Newbie

Hello everyone. I currently work on a small project to evaluate air quality using MQ135 sensor with Atmega16. The simulation works fine for me, but there is a problem with LCD representation in the Proteus simulator. As I want the LCD to display the air quality based on the PPM, the GOOD one sounds fine, but the AVG and BAD have an extra D at the back, which become BADD and AVGD. Does anyone know how to solve this problem or is this an error from Proteus ?
Below is my code written on IDE CodeVisionAVR :
And the image of 2 cases I mention already been attached.
Below is my code written on IDE CodeVisionAVR :
Code:
#include <mega16.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <delay.h>
// Alphanumeric LCD functions
#include <alcd.h> //chen thu vien lcd
// Declare your global variables here
//------------------------------------------------------------------
// Voltage Reference: AREF pin
#define ADC_VREF_TYPE ((0<<REFS1) | (0<<REFS0) | (0<<ADLAR))
//------------------------------------------------------------------
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)//doc gia tri adc
{
ADMUX=adc_input | ADC_VREF_TYPE;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=(1<<ADSC);
// Wait for the AD conversion to complete
while ((ADCSRA & (1<<ADIF))==0);
ADCSRA|=(1<<ADIF);
return ADCW;
}
//------------------------------------------------------------------
void main(void)
{
unsigned int gas;
char arr[15];
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: Free Running
ADMUX=ADC_VREF_TYPE;
ADCSRA=(1<<ADEN) | (0<<ADSC) | (1<<ADATE) | (0<<ADIF) | (0<<ADIE) | (1<<ADPS2) | (1<<ADPS1) | (0<<ADPS0);
SFIOR=(0<<ADTS2) | (0<<ADTS1) | (0<<ADTS0);
lcd_init(16); //khoi dong lcd
DDRA.0 = 0;
while (1)
{
// Place your code here
gas = read_adc(0);//du lieu gas
sprintf(arr,"Gas:%02d PPM",gas);
PORTD.4=1;
lcd_gotoxy(0,1);
lcd_puts(arr);
if(gas>=0 && gas<=600)
{
// Purple light for good
PORTD.5 = 1;
PORTD.4 = 0;
PORTD.6 = 0;
lcd_gotoxy(0,0);
lcd_puts("GOOD");
}
else if (gas>600 && gas<=800)
{
// Yellow for average
PORTD.6 = 1;
PORTD.5 = 0;
PORTD.4 = 0;
lcd_gotoxy(0,0);
lcd_puts("AVG");
}
else {
// Red for bad
PORTD.4= 1;
PORTD.5 = 0;
PORTD.6 = 0;
lcd_gotoxy(0,0);
lcd_puts("BAD");
}
}
}
And the image of 2 cases I mention already been attached.