Presentation is loading. Please wait.

Presentation is loading. Please wait.

Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.

Similar presentations


Presentation on theme: "Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing."— Presentation transcript:

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

15 Mike Stacey 200815 Assignment 1a The program only accepts keys zero to nine It displays the value of the key pressed to Port A LEDs The program then waits until the clear key is pressed (S12 –’C’). When it is pressed, the program goes back to the start. See flowchart ZeroToNineZeroToNine

16 Mike Stacey 200816 Assignment 1a [2] ZeroToNine: rcall GetKey cpi keyval, 'A' breq ZeroToNine cpi keyval, 'B' breq ZeroToNine cpi keyval, 'C' breq ZeroToNine cpi keyval, 'D' breq ZeroToNine ; etc - check for other 'not allowed' keys out PortA, keyval Clear:; look for clear key to continue rcall GetKey cpi keyval, 'C' brne Clear rjmp ZeroToNine GetKey is the code which was provided – it includes key debouncing and everything required for correctly returning a key from the keypad. Use it every time you need to scan the keypad but change the last line to RET. Don’t just use KeyScan – it wont work on the hardware.

17 Mike Stacey 200817 Assignment 1b [1] Program accepts a 4 digit pin number Initially, the program displays $AA to Port A LEDs When the correct pin has been entered, the display changes to $55 and then waits for the Clear key (S12) to be pressed. When Clear is pressed, program goes back to start If an incorrect pin is entered, the program displays $66 (error code) and waits for Clear key. See flowchart GetPinGetPin

18 Mike Stacey 200818 Assignment 1b Code Organisation GetPin: rcall DisplayReady; subroutine for displaying $AA rcall GetKey cpi keyval, ‘D’ brne DisplayError ; subroutine for displaying $66 cpi keyval, ‘9’ brne DisplayError cpi keyval, ‘5’ brne DisplayError cpi keyval, ‘1’ brne DisplayError rcall DisplayPinOK ; subroutine for displaying $55 rjmp GetPin Clear:; look for clear key to continue rcall GetKey cpi keyval, ‘C’ brne Clear rjmp GetPin

19 Mike Stacey 200819 Assignment 1b Code Organisation DisplayError: ; DisplayError sub-routine ldi temp, $66 out PortA, temp rjmp Clear ; wait for ‘Clear’ then restart DisplayPinOK: ; DisplayPinOK sub-routine ldi temp, $55 out PortA, temp rjmp Clear ; wait for ‘Clear’ then restart


Download ppt "Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing."

Similar presentations


Ads by Google