Fa20-Bee-150 MP Lab Report - 04
Fa20-Bee-150 MP Lab Report - 04
Fa20-Bee-150 MP Lab Report - 04
MICROPROCESSORS
EEE-342
Pre Lab-Tasks:
2 Lab Report 4
Table 1
In Lab Tasks:
Consider the basic wiring shown between an ATmega328P chip and an LCD in
figure 4.2.
Write and execute a C-program on Proteus that is able print Hello World on the
first row of the LCD.
Code:
#include <util/delay.h>
#define RS PB0
#define RW PB1
#define EN PB2
int LCD_init(void);
void LCD_Send_Command(unsigned char);
void LCD_Send_Data(unsigned char);
int LCD_Send_Array(char * ptr);
int main(void)
{
3 Lab Report 4
LCD_init();
LCD_Send_Array("Hello World");
while (1)
{
}
return(0);
}
int LCD_init()
{
DDRD = 0b11111111;
DDRB = 0b00000111;
UCSR0B &= ~(1<<TXEN0);
UCSR0B &= ~(1<<RXEN0);
_delay_ms(100);
PORTB |=(1<<EN);
LCD_Send_Command(0x38);//lcd mode 8bit, 2 line, character size 5*7
_delay_ms(2);
LCD_Send_Command(0x0E);//display on, turn on cursor, no blinking
_delay_ms(2);
LCD_Send_Command(0x01);//clear display
_delay_ms(2);
LCD_Send_Command(0x06);//increament cursor, no display shift
_delay_ms(2);
return(0);
}
void LCD_Send_Command(unsigned char comm)
{
PORTB &= ~(1<<RS);//RS low command
PORTB &= ~(1<<RW);//RW low writing
PORTD = comm;//comm on port
PORTB &= ~(1<<EN);//short pulse on EN
_delay_ms(1);
PORTB |= (1<<EN);
}
void LCD_Send_Data(unsigned char data)
{
PORTB |= (1<<RS);//RS High command
PORTB &= ~(1<<RW);//RW low writing
4 Lab Report 4
Proteus Simulation:
Figure 1
In Lab Task 2: Consider the basic wiring shown between an ATmega328P chip
and an LCD in figure 4.2.
5 Lab Report 4
Write and execute a C-program on Proteus that is able print your name on the
first row of the LCD and your roll-number on the second row of the LCD.
Code:
#include <util/delay.h>
#define RS PB0
#define RW PB1
#define EN PB2
int LCD_init(void);
void LCD_Send_Command(unsigned char);
void LCD_Send_Data(unsigned char);
int LCD_Send_Array(char * ptr);
int main(void)
{
LCD_init();
LCD_Send_Array("Muhammad Umar ");
LCD_Send_Command(0xC0);
LCD_Send_Array("FA20-BEE-150");
Output:
7 Lab Report 4
Figure 2
Hardware Implementation:
Figure 3
8 Lab Report 4
The main objective of this lab was to interface LM016 16x2 LCD with ATmega328P
controller. I analyzed the basic configuration, data pins, register pins of the LCD. Made
the table for different instructions used for communication with LCD as shown in table1.
Wrote a C code to display some text on LCD my task was to display my name and
registration no on two different lines of LCD. Simulated it on proteus as shown in fig2
and then implemented it on hardware using Arduino nano as shown in fig3. After
interfacing LM016 with ATmega328P the outcome of this lab is that now I can use
LM016 LCD with ATmega328P according to my needs.