Components Required
- ATmega32 microcontroller
- AVR Programmer Board
- Crystal
- Capacitors
- 16x2 LCD
- +5V supply
- Breadboard
- Connecting Wires
Circuit Diagram
Description
- PC0 to PC7 are connected to the data pins D0 to D7 of the LCD.
- VDD and VEE are connected to the +5 volts directly.
- VEE can be connected to a potentiometer to adjust the contrast.
- VSS is connected to ground.
- RS, RW and E are connected to PD5, PD6 and PD7 respectively.
- A crystal is connected to XTAL1 and XTAL2 pins to provide the clock pulse.
- Reset is connected to +5V.
DB0-DB7: Data Pins( use DB4-DB7 in 4 bit mode)
RS(Register Select) : 1 - Data is sent , 0 - Command is sent .
R/W(Read/Write) :1 - Read the LCD , 0 - Write to LCD.
E(Enable): to enable an operation . first make low(0) to send data and then set the other two control lines and when they are configured, bring E high (1) and wait for the minimum amount of time required by the LCD and bring it low (0) again.
VEE: Contrast Adjust Pin.
Connections
Source Code
/*
The following code will display the string defined in the main function.
*/
#include <avr/io.h>
#include <util/delay.h>
#ifndef F_CPU
#define F_CPU 1000000UL //Frequency of the external crystal
#endif
/*CWR - Command Word Register*/
#define ENABLE_LCD PORTD |= 0x80 //CWR state to enable LCD
#define DISABLE_LCD PORTD &= ~0x80//CWR state to disable LCD
#define SET_LCD_DATA PORTD |= 0x20 //CWR state to send data
#define SET_LCD_CMD PORTD &= ~0x20 //CWR state to send command
void LCD_WriteCommand (unsigned char CMD);
void LCD_WriteData (unsigned char Data);
void LCD_DisplayString_F(char row, char column,char *string);
void LCD_Cursor(char row, char column);
void init_devices(void)
{
DDRC = 0xFF; //All pins of PORTC declared as Output
PORTC = 0x00;//Initially all pins declared as output low
DDRD = 0xF0;//Pins D4 to D7 declared as input,remaining as o/p
PORTD = 0x00;//All output pins as low
_delay_ms(100); // wait for 100ms
LCD_WriteCommand (0x38); // 8 data lines
LCD_WriteCommand (0x06); // cursor setting
LCD_WriteCommand (0x0f); // display ON
LCD_WriteCommand (0x01); // clear LCD memory
_delay_ms (10); // 10ms delay after clearing LCD
}
int main(void)
{
init_devices();
//Text to be displayed in first row
LCD_DisplayString_F(1,1," ROBOWARES ");
//Text to be displayed in second row
LCD_DisplayString_F(2,1,"rickruling.blogspot.in");
return 0;
}
void LCD_WriteCommand (unsigned char Command)
{
SET_LCD_CMD; // Set LCD in command mode
PORTC = Command; // Load data to port
ENABLE_LCD; // Write data to LCD
_delay_ms(1);
DISABLE_LCD; // Disable LCD
_delay_ms(1); // wait for 1ms
}
void LCD_WriteData (unsigned char Data)
{
SET_LCD_DATA; // Set LCD in data mode
PORTC = Data; // Load data to port
ENABLE_LCD; // Write data to LCD
_delay_ms(1);
DISABLE_LCD; // Disable LCD
_delay_ms(1); // wait for 1ms
}
void LCD_DisplayString_F (char row, char column ,char *string)
{
/*Break the string into characters and send them for the display*/
LCD_Cursor (row, column);
while (*string)//Loop till the string is not null
LCD_WriteData(*string++);
}
void LCD_Cursor (char row, char column)
{
switch (row)
{
case 1: //Set the position in the first row
LCD_WriteCommand (0x80 + column - 1);
break;
case 2: //Set the position in the second row
LCD_WriteCommand (0xC0 + column - 1);
break;
default: break;
}
}
No comments:
Post a Comment