Professional Documents
Culture Documents
Exp5 Display Text and Custom Character On LCD 16x2
Exp5 Display Text and Custom Character On LCD 16x2
(ATMEGA32)
Submitted by
Ronit Dutta, MS in IOT and Signal Processing
Department of Electrical Engineering, IIT Kharagpur
Pin
Function Name
No.
Ground (0V)
1 Ground
2
Embedded System on AVR ATMEGA32:Exp5
Selects command register when low, and data register when RS (Register
4
high. Select )
5 Low to write to the register; High to read from the register Read/write
7 D0 (LSB)
8 D1
9 D2
10 D3
8-bit data pins
11 D4
12 D5
13 D6
14 D7 (MSB)
3
Embedded System on AVR ATMEGA32:Exp5
Command Register: The command register stores the command instructions given to
the LCD. A command is an instruction given to an LCD to do a predefined task.
Examples: Initializing 8bit mode or 4bit mode
Clear screen
Setting the cursor position etc.
Data Register: The data register stores the data to be displayed on the LCD. The data
is the ASCII value of the character to be displayed on the LCD. When we send data to
LCD, it goes to the data register and is processed there. When RS=1, the data register
is selected.
4
Embedded System on AVR ATMEGA32:Exp5
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
// LCD Initialization
CBI PORTD,PIND1 // Command Register Enable
LDI R16,0x38 //2 lines and 5x7 matrix
OUT PORTB,R16
CALL ENABLE
LDI R16,0x02 // Return Home
OUT PORTB,R16
CALL ENABLE
LDI R16,0x01 // Clear display screen
OUT PORTB,R16
CALL ENABLE
LDI R16,0x0C //Display on, cursor off
OUT PORTB,R16
CALL ENABLE
5
Embedded System on AVR ATMEGA32:Exp5
// Writing Text on it
SBI PORTD,PIND1 // Data Register Enable
LDI R16,0x49 // Ascii of I
OUT PORTB,R16
CALL ENABLE
LOOP_INF: NOP
JMP LOOP_INF
6
Embedded System on AVR ATMEGA32:Exp5
.INCLUDE "M32DEF.INC"
.ORG 0x0000
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
LDI R16,'I'
ST X+,R16
LDI R16,'I'
ST X+,R16
LDI R16,'T'
ST X+,R16
LDI R16,0
ST X+,R16
LDI R16,'K'
ST X+,R16
LDI R16,'H'
ST X+,R16
LDI R16,'A'
ST X+,R16
LDI R16,'R'
ST X+,R16
LDI R16,'A'
ST X+,R16
LDI R16,'G'
ST X+,R16
LDI R16,'P'
ST X+,R16
LDI R16,'U'
ST X+,R16
LDI R16,'R'
ST X+,R16
LDI R16,0
ST X,R16
// LCD Initialization
CBI PORTD,PIND1 // Command Register Enable
LDI R16,0x38 //2 lines and 5x7 matrix
OUT PORTB,R16
CALL ENABLE
LDI R16,0x02 // Return Home
OUT PORTB,R16
7
Embedded System on AVR ATMEGA32:Exp5
CALL ENABLE
LDI R16,0x01 // Clear display screen
OUT PORTB,R16
CALL ENABLE
LDI R16,0x0C //Display on, cursor off
OUT PORTB,R16
CALL ENABLE
LDI R16,0x06 // Shift Cursor to right automatically after print on LCD
OUT PORTB,R16
CALL ENABLE
LD R16,X
CPI R16,0
BRNE LCD_PRINT1
LD R16,X
CPI R16,0
BRNE LCD_PRINT2
LOOP_INF: NOP
JMP LOOP_INF
8
Embedded System on AVR ATMEGA32:Exp5
Class Assignment 1: Write Assembly Code for LCD 16x2 in 8bit Mode to display your name
with call SRAM and hold your name on the screen 5sec approximately then clear the screen
to display your department & Roll No. on 1st line, 2nd line respectively from SRAM. Hold
these also 5sec approximately then repeat again your name for looping. The Circuit is same
as above to simulate and make the hardware.
Class Assignment 2: Write Assembly Code for LCD 16x2 in 8bit Mode to display “AVR
ATMEGA32“ at 2nd line on 16x2 LCD form SRAM. Scroll entire display right with an interrupt
and to scroll entire display left with another interrupt. The Circuit is same as below to
simulate and make the hardware.
9
Embedded System on AVR ATMEGA32:Exp5
.INCLUDE "M32DEF.INC"
.ORG 0x0000
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
LDI R16,'E'
ST X+,R16
LDI R16,'m'
ST X+,R16
LDI R16,'b'
ST X+,R16
LDI R16,'e'
ST X+,R16
LDI R16,'d'
ST X+,R16
LDI R16,'d'
ST X+,R16
10
Embedded System on AVR ATMEGA32:Exp5
LDI R16,'e'
ST X+,R16
LDI R16,'d'
ST X+,R16
LDI R16,' '
ST X+,R16
LDI R16,'S'
ST X+,R16
LDI R16,'y'
ST X+,R16
LDI R16,'s'
ST X+,R16
LDI R16,'t'
ST X+,R16
LDI R16,'e'
ST X+,R16
LDI R16,'m'
ST X+,R16
LDI R16,'s'
ST X+,R16
LDI R16,0
ST X,R16
LD R16,X
CPI R16,0
BRNE LCD_PRINT1
LOOP_INF: NOP
JMP LOOP_INF
11
Embedded System on AVR ATMEGA32:Exp5
CBI PORTD,PIND0
RET
FourBit_Mode: OUT PORTB,R16
CALL ENABLE
SWAP R16
OUT PORTB,R16
CALL ENABLE
RET
As we know, to print character symbol on LCD, we have to send ASCII code. LCD16x2
also has feature, where we can print our own custom character, which is not included
in ASCII set of character.
12
Embedded System on AVR ATMEGA32:Exp5
LDI R16,HIGH(RAMEND)
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
// LCD Initialization
CBI PORTD,PIND1 // Command Register Enable
LDI R16,0x38 //2 lines and 5x7 matrix
OUT PORTB,R16
CALL ENABLE
LDI R16,0x02 // Return Home
OUT PORTB,R16
CALL ENABLE
LDI R16,0x01 // Clear display screen
OUT PORTB,R16
CALL ENABLE
LDI R16,0x0C //Display on, cursor off
OUT PORTB,R16
CALL ENABLE
SBI PORTD,PIND1
13
Embedded System on AVR ATMEGA32:Exp5
LOOP_INF: NOP
JMP LOOP_INF
14
Embedded System on AVR ATMEGA32:Exp5
Class Assignment 3: Write Assembly Code for LCD 16x2 in 4bit Mode to display any custom
character. Make the below circuit to simulate the code.
15