Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with LCD implementation on Proteus

Status
Not open for further replies.
Joined
Jan 31, 2023
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
41
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
#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.
 

Attachments

  • 1677951107772.png
    1677951107772.png
    83.7 KB · Views: 94
  • 1677951131525.png
    1677951131525.png
    84.5 KB · Views: 98

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
 

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
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top