Download presentation
Presentation is loading. Please wait.
Published byKory Goodman Modified over 9 years ago
1
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing
2
Mike Stacey 20082 Hardware Connections Only 4 bits of data used: DB4 – DB7 DB1 = Register Select, DB2 = R/W, DB3 = Enable Others: BL- = GND and BL+ = optional backlight
3
Mike Stacey 20083 Driving an LCD Initialisation: the LCD must be initialised using the routine supplied in the data sheets. 4 bits only: we are using only 4 bits but ASCII characters are 8 bits so we have to do 2 writes to the LCD for one character. Initialisation allows us to: –set LCD to operate in 4 bit mode –set the number of lines –set the font (5 x 10 dots or 5 x 7 dots) –set cursor move direction –set cursor to 1 st position –clear display See page 4 of LCD datasheet for full list of instructions
4
Mike Stacey 20084 Operation High nibble 1 st then low nibble Parallel data interface RS selects whether data or instruction is being written Enable is active high R/W: write active low
5
Mike Stacey 20085 Code [1].equ RS = pc1; port c bit 1.equ r_w = pc2; port c bit 2.equ E = pc3; port c bit 3
6
Mike Stacey 20086 Code [2] lcd_send_char:; writes a single char to LCD clr temp mov temp, output_data; create a backup copy andi temp, 0b11110000 ; get upper nibble ori temp, 0b00000010; and set RS out portc, temp; send data rcall strobe; pulse enable clr temp mov temp, output_data; create copy swap temp; swap nibbles andi temp, 0b11110000 ; then get upper (lower) nibble ori temp, 0b00000010; set RS bit out portc, temp; and send it rcall strobe; pulse enable ret
7
Mike Stacey 20087 Code [3] strobe: cbi portC,r_w; reset r_w cbi portC,E; reset enable sbi portC,E; set enable nop; keep high for pulse time nop cbi portC,E; reset enable rcall wait1ms; wait ret
8
Mike Stacey 20088 Initialisation [page 4 datasheets] lcdInit: cbi portC,E cbi portC,r_w cbi portC,rs rcall wait10ms ldi temp,0b00110000 out portC,temp rcall strobe rcall wait10ms ldi temp,0b00110000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b00110000 out portC,temp rcall strobe rcall wait1ms write 0x30 (function set) wait > 4.1mS wait > 100uS write 0x30 (function set) clear RS for writing instructions
9
Mike Stacey 20089 Initialisation [2] ldi temp,0b00100000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b00100000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b11000000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b00000000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b10000000 out portC,temp rcall strobe rcall wait1ms write 0x20 (function set-4 bit) No. lines = 2 (bit 7), matrix size (font - bit 6) display off
10
Mike Stacey 200810 Initialisation [3] ldi temp,0b00000000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b00010000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b00000000 out portC,temp rcall strobe rcall wait1ms ldi temp,0b01100000 out portC,temp rcall strobe rcall wait1ms sbi portC, rs ret display clear Enter mode set, cursor move direction (bit 5) set RS for writing data to LCD
11
Mike Stacey 200811 Write String from Memory text1:.db "LCD Test Message",0 ; strores msg string as bytes The Z register comprises R30 & R31 and can be used as a memory pointer. If you execute a load operation (lpm) the location pointed at by Z register will be loaded into destination register. You can also automatically increment the pointer after the load if you wish. ldi ZL,low(text1*2) ; load low byte address of string into Z reg (R30) ldi ZH,high(text1*2); load high byte address of string into Z reg (R31)
12
Mike Stacey 200812 Write String from Memory [2] message: ldi temp,0 mov zero,temp ; just for a zero reference send1: lpm; move the contents of the memory location ; pointed to by the Z register to R0 (R0 = text) cpse text,zero ; check for end of text zero, if zero skip next rjmp send2; instruction sendend: ret send2: rcall lcd_send_char ; output text character inc ZL; get ready for next character rjmp send1
13
Mike Stacey 200813 Samples See –LCD-PrintOneChar.asm –LCD-PrintString.asm
14
Mike Stacey 200814 What to do? Project check 1 is due this week Assignment 1a and 1b are due this week Assignment 2 is due next week
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.