Professional Documents
Culture Documents
Lab Report 03
Lab Report 03
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:
}
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