Continue to Site

# Problem with LCD implementation on Proteus

#### 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 :
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
//------------------------------------------------------------------
{
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Wait for the AD conversion to complete
}
//------------------------------------------------------------------
void main(void)
{
unsigned int gas;
char arr[15];
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: AREF pin
// ADC Auto Trigger Source: Free Running

lcd_init(16); //khoi dong lcd
DDRA.0 = 0;
while (1)
{
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 {
PORTD.4= 1;
PORTD.5 = 0;
PORTD.6 = 0;
lcd_gotoxy(0,0);
}
}

}

And the image of 2 cases I mention already been attached.

#### Attachments

• 1677951107772.png
83.7 KB · Views: 17
• 1677951131525.png
84.5 KB · Views: 17

#### KlausST

##### Super Moderator
Staff member
Hi,

"GOOD" has 4 characters.
"BAD" has only 3. Thus if you don't delete the 4th character of "GOOD" = "D" in the display it will remain there.
Why not simply defining "BAD " = also as 4 character text?

Klaus

#### Noobmaster6910

##### Newbie
Thank you for your solution. In fact I just put a space by the end of the character statement for "BAD" and "AVG" and it works perfectly