100% found this document useful (2 votes)
52 views

Assignment#7

This document contains code and diagrams for an Arduino project that displays temperature readings from an analog-to-digital converter (ADC) on a liquid crystal display (LCD). It includes code to initialize the LCD, print text to it, read the ADC, convert the ADC value to a temperature, and continuously display the updated temperature every 500 milliseconds in a loop. Flowcharts and schematics are also referenced but not shown.

Uploaded by

liquidmoon1973
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
52 views

Assignment#7

This document contains code and diagrams for an Arduino project that displays temperature readings from an analog-to-digital converter (ADC) on a liquid crystal display (LCD). It includes code to initialize the LCD, print text to it, read the ADC, convert the ADC value to a temperature, and continuously display the updated temperature every 500 milliseconds in a loop. Flowcharts and schematics are also referenced but not shown.

Uploaded by

liquidmoon1973
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Design Assignment #7

Code
#define F_CPU 8000000UL

#include <avr/io.h> //standard AVR header
#include <util/delay.h> //delay header

#define LCD_DPRT PORTB //LCD DATA PORT
#define LCD_DDDR DDRB //LCD DATA DDR
#define LCD_DPIN PINB //LCD DATA PIN

#define LCD_CPRT PORTD //LCD COMMANDS PORT
#define LCD_CDDR DDRD //LCD COMMANDS DDR
#define LCD_CPIN PIND //LCD COMMANDS PIN

#define LCD_RS 0 //LCD RS
#define LCD_RW 1 //LCD RW
#define LCD_EN 2 //LCD EN
//****************************************************************
//****************************************************************
void lcdCommanda (unsigned char cmnd)
{
LCD_DPRT = cmnd; //send cmnd to data port
LCD_CPRT &= ~(1<<LCD_RS); //RS = 0 for command
LCD_CPRT &= ~(1<<LCD_RW); //RW = 0 for write
LCD_CPRT |= (1<<LCD_EN); //EN = 1 for H-to-L pulse
_delay_us(1); //wait to make enable wide
LCD_CPRT &= ~(1<<LCD_EN); //EN = 0 for H-to_L pulse
_delay_us(100); //wait to make enable wide
}
void lcdData(unsigned char data)
{
LCD_DPRT = data; //send data to data port
LCD_CPRT |= (1<<LCD_RS); //RS = 1 for data
LCD_CPRT &= ~(1<<LCD_RW); //RW = 0 for write
LCD_CPRT |= (1<<LCD_EN); //EN = 1 for H-to-L pulse
_delay_us(1); //wait to make enable wide
LCD_CPRT &= ~(1<<LCD_EN); //EN = 0 for H-to_L pulse
_delay_us(100); //wait to make enable wide
}
void lcd_init()
{
LCD_DDDR = 0xFF;
LCD_CDDR = 0xFF;
LCD_CPRT &=~(1<<LCD_EN); //LCD_EN = 0
_delay_us(2000); //wait for init
lcdCommanda(0x38); //inti. LCD 2 line, 5x7
lcdCommanda(0x0E); //display on, cursor on
lcdCommanda(0x01); //clear LCD
_delay_us(2000); //wait
lcdCommanda(0x06); //shift cursor right
}

//****************************************************************************
void lcd_gotoxy(unsigned char x, unsigned char y)
{
unsigned char firstCharAdr[] = {0x80, 0xC0, 0x94, 0xD4};
lcdCommanda(firstCharAdr[y-1] + x -1);
_delay_us(100);
}
void lcd_print(char * str)
{
unsigned char i = 0;
while (str[i]!=0)
{
lcdData(str[i]);
i++;
}
}
int main(void)
{
char temp[3];
temp[3] = 0;
float i = 0;
int t;
lcd_init(); //turn on LCD
lcd_gotoxy(1,1); //move cursor to position 1,1
lcd_print("Temp "); //print "Temp on LCD
ADCSRA = 0x86; //turn on ADC select clock 1/64
while(1)
{
ADCSRA |= (1<<ADSC); //start conversion
while((ADCSRA & (1<<ADIF)) == 0); //wait till conversion is done
i = ADC*.48 + 5;//convert ADC value using line with points (0,5) and
(5,295)

t = i;
for(int j=2;j>=0;j--) //convert int to char
{
temp[j] = t%10 + 48;
t /= 10;
}
if(temp[0] == 48)
{
temp[0] = ' ';
}
lcd_gotoxy(6,1); //move cursor to position 96,1)
lcd_print(temp); //display temperature value
_delay_ms(500);
}
return 0;
}









Code Flowchart:













































Schematic
Initialize LCD
Print Temp


Start A2D.
Convert A2D value.
Print temperature value
Wait for 500 ms.

You might also like