You are on page 1of 9

 

           UNITED INTERNATIONAL UNIVERSITY


     
                                                   Lab report-03
                                
         
Course name: Microprocessor and Interfacing Laboratory
Course code: EEE 3404
Section : A
Department: EEE.

Submitted To: Md. Salahuddin Ahmed


                          Assistant Professor, Department of Electrical & Electronic Engineering
           
Submitted By: Shadman Shakib
Student ID: 021 182 033
Example 01: Interfacing of LCD displays with ATmega32 in 8-Bit mode:

Circuit Diagram:

CVAVR Codes:

#include <mega32.h>
#include <delay.h>
void lcdcmd(unsigned char value);
void lcddata(unsigned char value);
void lcdcmd(unsigned char value)
{P
ORTC = value;
PORTA.0 =0; // Selecting command register
PORTA.1 =0; // Selecting the write mode
PORTA.2 =1; // High to low pulse in E pin
delay_ms(20);
PORTA.2 =0;
}
void lcddata(unsigned char value)
{P
ORTC=value;
PORTA.0 =1;
PORTA.1 =0;
PORTA.2 =1;
delay_ms(10);
PORTA.2 =0;
}
void main(void)
{D
DRC=0xFF;
DDRA=0b00000111;
PORTC=0x00;
PORTA=0x00;
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
while (1)
{l
cdcmd(0x83);
lcddata('8');
lcddata('-');
lcddata('B');
lcddata('i');
lcddata('t');
lcddata(' ');
lcddata('M');
lcddata('o');
lcddata('d');
lcddata('e');
lcdcmd(0xC4);
lcddata('E');
lcddata('n');
lcddata('a');
lcddata('b');
lcddata('l');
lcddata('e');
lcddata('d');
}
}
Example 02: Implementation of 4-bit mode LCD interfacing:

Circuit Diagram:

CVAVR Codes:

(Enabled and configured the Alphanumeric LCD Support in chip setting)


#include <mega32.h>
#include <alcd.h>
#include <delay.h>
void main(void)
{l
cd_init(16);
lcd_clear();
while (1)
{l
cd_gotoxy(3,0); // move cursor in col 0 row 0
lcd_puts("We can");
lcd_gotoxy(10,0); // move cursor in col 3 row 1
lcd_puts("do it");
lcd_gotoxy(3,1);
lcd_puts("In 4-Bit");
lcd_putchar(' ');
}

}
Example 04: Interfacing a 4x4 Matrix keypad

Circuit Diagram:
CVAVR Codes:

#include <mega32.h>
#include <delay.h>
#include <alcd.h>
void main(void)
{
DDRB=0b00001111;
PORTB=0b11110000;

lcd_init(16);
lcd_clear();
while (1)
{
PORTB=0b11110000;
if((PINB.4==1)&&(PINB.5==1)&&(PINB.6==1)&&(PINB.7==1))
{
lcd_gotoxy(0,0);
lcd_puts("Nokey is pressed");
}

else
{
PORTB=0b11111110;
if(PINB.4 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("7");
}
else if(PINB.5 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("8");
}
else if(PINB.6 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("9");
}
else if(PINB.7 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("/");
}

delay_ms(10);
PORTB=0b11111101;
if(PINB.4 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("4");
}
else if(PINB.5 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("5");
}
else if(PINB.6 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("6");
}
else if(PINB.7 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("x");
}

delay_ms(10);
PORTB=0b11111011;
if(PINB.4 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("1");
}
else if(PINB.5 == 0)
{

lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("2");
}
else if(PINB.6 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("3");
}
else if(PINB.7 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("-");
}
delay_ms(10);
PORTB=0b11110111;
if(PINB.4 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("On");
}
else if(PINB.5 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("0");
}
else if(PINB.6 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("=");
}
else if(PINB.7 == 0)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_puts("+");
}
}
}
}

END

You might also like