Lab 7 - MNM Comp

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Lab 7

LCD Interfacing using AVR Atmega3


Objective

● To have a basic understanding of Liquid crystal display.

● To learn how to interface LCD with AVR using built in functions in MikroC.
Software Requirement
1. MikroC Pro for AVR
2. Proteus Professional

Overview
The microcontroller is a wonderful piece of engineering and it can do many things (with the
help of some great programming), but it is still an opaque black box. If you want it to share
information, or show you what it is trying to do, you need to hook-up (interface) an output
device. An output device is a thing that provides you a way to show information from the
microcontroller.
The LCD is a much more informative output device than a single LED. The LCD is a display that
can easily show characters on its screen. LCDs range in size, price and configuration, from
having a couple of lines to large displays. Some are even very specifically designed for a single
application, having only that ability to display set graphics. We will be using an LCD that has 2
lines and 16 characters per line.

Figure 1: Liquid Crystal Display (LCD)

Example 1:
// LCD module connections
sbit LCD_RS at PORTD5_bit;
sbit LCD_EN at PORTD7_bit;
sbit LCD_D0 at PORTB0_bit;
sbit LCD_D1 at PORTB1_bit;
sbit LCD_D2 at PORTB2_bit;
sbit LCD_D3 at PORTB3_bit;
sbit LCD_D4 at PORTB4_bit;
sbit LCD_D5 at PORTB5_bit;
sbit LCD_D6 at PORTB6_bit;
sbit LCD_D7 at PORTB7_bit;
sbit LCD_RS_Direction at DDD5_bit;
sbit LCD_EN_Direction at DDD7_bit;
sbit LCD_D0_Direction at DDB0_bit;
sbit LCD_D1_Direction at DDB1_bit;
sbit LCD_D2_Direction at DDB2_bit;
sbit LCD_D3_Direction at DDB3_bit;
sbit LCD_D4_Direction at DDB4_bit;
sbit LCD_D5_Direction at DDB5_bit;
sbit LCD_D6_Direction at DDB6_bit;
sbit LCD_D7_Direction at DDB7_bit;
// End LCD module connections
char txt1[] = "AVR";
char txt2[] = "ATMEGA32";
void main(){
DDD7_bit=1; //this pin sets bit1 to the
output
PORTD7_bit=0; //bit0 is reset to enable LCD.
Must be declared.
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row
Lcd_Out(2,2,txt2); // Write text in second row
while(1) { // Endless loop}}

This example demonstrates the usage of basic LCD library.


C CODE
// LCD module connections
sbit LCD_RS at PORTA0_bit;
sbit LCD_EN at PORTA2_bit;
sbit LCD_D4 at PORTA4_bit;
sbit LCD_D5 at PORTA5_bit;
sbit LCD_D6 at PORTA6_bit;
sbit LCD_D7 at PORTA7_bit;
sbit LCD_RS_Direction at DDA0_bit;
sbit LCD_EN_Direction at DDA2_bit;
sbit LCD_D4_Direction at DDA4_bit;
sbit LCD_D5_Direction at DDA5_bit;
sbit LCD_D6_Direction at DDA6_bit;
sbit LCD_D7_Direction at DDA7_bit;
// End LCD module connections
char txt1[] = "Lab DEMO";
char txt2[] = "CHARACTER LCD";
void main(){
DDA1_bit=1; //this pin sets bit1 to the output
PORTA1_bit=0; //bit0 is reset to enable LCD. Must be declared.
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row
Lcd_Out(2,2,txt2); // Write text in second row
while(1) { // Endless loop } }

Lab Tasks
1- Interface LCD with AVR and display “Electronic Engineering.”
sbit LCD_RS at PORTD5_bit;
sbit LCD_EN at PORTD7_bit;
sbit LCD_D0 at PORTB0_bit;
sbit LCD_D1 at PORTB1_bit;
sbit LCD_D2 at PORTB2_bit;
sbit LCD_D3 at PORTB3_bit;
sbit LCD_D4 at PORTB4_bit;
sbit LCD_D5 at PORTB5_bit;
sbit LCD_D6 at PORTB6_bit;
sbit LCD_D7 at PORTB7_bit;
sbit LCD_RS_Direction at DDD5_bit;
sbit LCD_EN_Direction at DDD7_bit;
sbit LCD_D0_Direction at DDB0_bit;
sbit LCD_D1_Direction at DDB1_bit;
sbit LCD_D2_Direction at DDB2_bit;
sbit LCD_D3_Direction at DDB3_bit;
sbit LCD_D4_Direction at DDB4_bit;
sbit LCD_D5_Direction at DDB5_bit;
sbit LCD_D6_Direction at DDB6_bit;
sbit LCD_D7_Direction at DDB7_bit;
// End LCD module connections
char txt1[] = "ELECTRONIC ";
char txt2[] = "Enginnering";
void main(){
DDD7_bit=1; //this pin sets bit1 to the output
PORTD7_bit=0; //bit0 is reset to enable LCD. Must be declared.
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row
Lcd_Out(2,2,txt2); // Write text in second row
while(1) { // Endless loop}}

2. Interface LCD with AVR and display your name and roll number
Sbit LCD_RS at PORTD5_bit;
sbit LCD_EN at PORTD7_bit;
sbit LCD_D0 at PORTB0_bit;
sbit LCD_D1 at PORTB1_bit;
sbit LCD_D2 at PORTB2_bit;
sbit LCD_D3 at PORTB3_bit;
sbit LCD_D4 at PORTB4_bit;
sbit LCD_D5 at PORTB5_bit;
sbit LCD_D6 at PORTB6_bit;
sbit LCD_D7 at PORTB7_bit;
sbit LCD_RS_Direction at DDD5_bit;
sbit LCD_EN_Direction at DDD7_bit;
sbit LCD_D0_Direction at DDB0_bit;
sbit LCD_D1_Direction at DDB1_bit;
sbit LCD_D2_Direction at DDB2_bit;
sbit LCD_D3_Direction at DDB3_bit;
sbit LCD_D4_Direction at DDB4_bit;
sbit LCD_D5_Direction at DDB5_bit;
sbit LCD_D6_Direction at DDB6_bit;
sbit LCD_D7_Direction at DDB7_bit;
char txt1[] = "LAIBA ";
char txt2[] = "2021-BEE-008";
void main(){ DDD7_bit=1; //this pin sets bit1 to the output
PORTD7_bit=0; //bit0 is reset to enable LCD. Must be declared.
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,2,txt1); // Write text in first row
Lcd_Out(2,2,txt2); // Write text in second row
while(1) { // Endless loop }}

You might also like