1

i'm displaying the temperature on 16x2 LCD using atmega16 microcontroller , in the super loop i'm calling the function to display the temperature on the screen , in case the temperature is 136C ( for example ) and temperature becomes 50C , the screen displayed 50CC , i want it to be 50C , how to modify the function to handle this ?

#include "lcd.h"
#include "adc.h"
#include "stdio.h"
#include "stdlib.h"

uint8 g_flag = 0 ;
uint16 g_adc_value = 0 ;
float32 g_voltage = 0 ;
float32 g_temprature = 0 ;
float32 g_resolution = 0.0048828 ;

void display_temprature(sint16 a_temprature) ;
int main(void)
{
    LCD_init() ;
    ADC_init() ;
    LCD_displayStringRowCol(0 , 1 , "Temprature is") ;
    while(1)
    {
        g_adc_value = ADC_readChannel(1) ;
        g_voltage = g_adc_value*g_resolution ;
        g_temprature = g_voltage / 0.01 ;
        display_temprature((sint16)g_temprature) ;
    }
}


void display_temprature(sint16 a_temprature)
{
    LCD_goToRowCol(1 , 7) ;
    LCD_integerToString(a_temprature) ;
    LCD_displayCharacter(223) ;
    LCD_displayCharacter('C') ;
}
mrMatrix
  • 37
  • 5

1 Answers1

1

There are two simple ways to solve this issue:

  1. Issue a "clear screen" command to the LCD to wipe out previous output.
  2. Write a string of spaces long enough to clear the previous output.

The main problem you're seeing is that the end of the longer string, ending in 'C' is not being erased when you later output the shorter string, also ending in 'C'. So one of the two methods above should solve your problem.

TomServo
  • 7,248
  • 5
  • 30
  • 47