EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
You are here: Home / Replies / Try this code for displaying

Try this code for displaying

|

Microcontroller › AVR › Temperature display on LCD › Try this code for displaying

March 17, 2012 at 2:22 pm #7310
Dhruwank Vankawala
Participant

Try this code for displaying temperature on LCD

 

#include <avr/io.h>
#include<util/delay.h>
#include<math.h>
#include<stdlib.h>
#define LCD_PRT PORTC
#define LCD_PIN PINC
#define LCD_DDR DDRC
#define LCD_RS 0
#define LCD_RW 1
#define LCD_EN 2

void delay_us(int d)
{
_delay_us(d);
}

void delay_ms(int d)
{
_delay_ms(d);
}

void lcdcommand(unsigned char cmnd)
{
LCD_PRT = (LCD_PRT & 0x0F)| (cmnd & 0xF0);
LCD_PRT &=~(1<<LCD_RS);
LCD_PRT &=~(1<<LCD_RW);
LCD_PRT |=(1<<LCD_EN);
delay_us(1);
LCD_PRT &=~(1<<LCD_EN);
delay_us(20);
LCD_PRT = (LCD_PRT & 0x0F) | (cmnd<<4);
LCD_PRT |= (1<<LCD_EN);
delay_us(1);
LCD_PRT &=~ (1<<LCD_EN);
}

void lcddata(unsigned char data)
{
LCD_PRT = (LCD_PRT & 0x0F) | (data & 0xF0);
LCD_PRT |= (1<<LCD_RS);
LCD_PRT &=~ (1<<LCD_RW);
LCD_PRT |= (1<<LCD_EN);
delay_us(1);
LCD_PRT &=~ (1<<LCD_EN);
delay_us(20);
LCD_PRT = (LCD_PRT & 0x0F) | (data << 4);
LCD_PRT |= (1<<LCD_EN);
delay_us(1);
LCD_PRT &=~ (1<<LCD_EN);
}

void LCD_init()
{
LCD_DDR = 0xFF;
LCD_PRT &=~(1<<LCD_EN);
delay_us(2000);
lcdcommand(0x33);
delay_us(100);
lcdcommand(0x32);
delay_us(100);
lcdcommand(0x28);
delay_us(100);
lcdcommand(0x0E);
delay_us(100);
lcdcommand(0x01);
delay_us(2000);
lcdcommand(0x06);
delay_us(100);
}

unsigned int adc_conv(void)
{
DDRA=0;
ADCSRA=0x87;
ADMUX=0xE0;
ADCSRA|=(1<<ADSC);
while((ADCSRA&(1<<ADIF))==0);
return ADCH;
}

void LCD_gotoxy(unsigned char x, unsigned char y)
{
unsigned char firstcharadr[]={0x80, 0x85};
lcdcommand(firstcharadr[y-1] + x – 1);
delay_us(100);
}

void LCD_print(char * str)
{
unsigned char i=0;
while(str!=0)
{
lcddata(str
);
i++;
}
}

int main(void)
{
    unsigned int val;
    LCD_init();
    while(1)
    {
    LCD_gotoxy(1,1);
    LCD_print(“Temp “);
    LCD_gotoxy(1,2);
    val=adc_conv();
    char buffer[10];
    itoa(val,buffer,10);
    LCD_print(buffer);
    delay_ms(1000);
}
return 0;
}

RSS Recent Posts

  • Washing Machine motor August 14, 2022
  • arduino help needed August 14, 2022
  • Looking for amplifier ic August 14, 2022
  • Light Automation via mqtt August 14, 2022
  • Right channel distortion on vintage fisher rs-2010 August 14, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools