Alphanumeric Liquid-Crystal Display Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 1 Announcements • Lab 3 due at 22:00 – Zip lab2 directory – Submit via WebCT Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 2 Liquid Crystal Display • Purpose – Display information – 8 bit binary numbers are mapped to 256 different characters – Mapping is done using ASCII table • American Standard Code for Information Interchange • Qwikflash board LCD – LCD is an Optrex 8x2 character display – LCD controller is a Hitachi HD44780 LCD controller chip • This is the defacto standard – Controller and display are mounted on a single board Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 3 ASCII Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 4 Extended ASCII Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 5 Notes on ASCII • Characters 0x00 to 0x1F are control characters • The numbers go from 0x30 to 0x39 • Upper case letters run from – 0x41 (A) to 0x5A (Z) • Lower case letters run from – 0x61(a) to 0x7A (z) • To convert from lower case to upper case letters add 0x20 • To convert from decimal numbers to their ASCII equivalent add 0x30 • Characters below 128 are standard and above 128 are not standard characters Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 6 Liquid Crystal Display • Hitachi HD44780 LCD – – – – – – Can interface in either 8 bit (byte) or 4 bit (nibble) mode The Qwikflash board uses the 4 bit (nibble) mode Qwikflash uses 2 control lines (RS & E) Data is clocked in on falling edge of E Read/Write (R/W) is grounded disabling reads RS selects LCD mode • RS=0, indicates following data are control statements • RS=1, indicates following data are characters – Interface has specific timing requirements for data transfer – User can send both ASCII codes and LCD control codes – LCD required specific initialization sequence Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 7 4 bit nibble interface PIC 18F452 HD44780 Not used DB0 DB1 DB2 DB3 RD4 RD5 RD6 RD7 DB4 DB5 DB6 DB7 RE0 RE1 RS E RS & E are control lines Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 8 Optrex pin assignment Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 9 Optrex write timing requirements I R/W line is grounded on Qwikflash board only write enabled Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 10 Optrex write timing requirements II Author indicates this is 40µsec Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 11 Liquid Crystal Display Initialization 1. Wait 0.1 sec after PIC comes out of reset 2. Drive RS low and leave it there because all of the following bytes are configuration bytes 3. Raise E, send 0x3, drop E, wait 4. Raise E, send 0x3, drop E, wait 5. Raise E, send 0x3, drop E, wait ; Sets 4-bit interface 6. Raise E, send 0x2, drop E, wait 7. Raise E, send 0x2, drop E, wait ; Sets 2 line display 8. Raise E, send 0x8, drop E, wait 9. Raise E, send 0x0, drop E, wait ; Clears the display 10. Raise E, send 0x1, drop E, wait 11. Raise E, send 0x0, drop E, wait ; Turns cursor off and 12. Raise E, send 0xC, drop E, wait ; display on 13. Raise E, send 0x0, drop E, wait ; Increments cursor 14. Raise E, send 0x6, drop E, wait ; automatically Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 12 Point Macro and LCD string LCDstr db 0x33,0x32,0x28,0x01,0x0c,0x06,0x00 ;Initialization string for LCD POINT macro stringname MOVLF high stringname, TBLPTRH MOVLF low stringname, TBLPTRL endm Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 13 Liquid Crystal Display Initialization InitLCD MOVLF 10,COUNT REPEAT_ rcall LoopTime decf COUNT,F UNTIL_ .Z. bcf PORTE,0 POINT LCDstr tblrd* REPEAT_ bsf PORTE,1 movff TABLAT,PORTD bcf PORTE,1 rcall LoopTime bsf PORTE,1 swapf TABLAT,W movwf PORTD bcf PORTE,1 rcall LoopTime tblrd+* movf TABLAT,F UNTIL_ .Z. return Copyright University of Colorado, 2005 ;Wait 0.1 second ;Call LoopTime 10 times ;RS=0 for command ;Set up table pointer to initialization string ;Get first byte from string into TABLAT ;Drive E high ;Send upper nibble ;Drive E low so LCD will process input ;Wait ten milliseconds ;Drive E high ;Swap nibbles ;Send lower nibble ;Drive E low so LCD will process input ;Wait ten milliseconds ;Increment pointer and get next byte ;Is it zero? ASEN 4519/5519 Lecture #10 14 LCD positioning codes 0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0xC0 0xC1 0xC2 0xC3 0xC4 0xC5 0xC6 0xC7 Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 15 Displaying a static string First store a static string in memory to put kHz right justified on the top row of the LCD kHz db “\x85kHz\x00” \xhh indicates interpret two characters after x as hex values otherwise values are converted to hex using the ASCII mapping kHz is interpreted as 856B487A00 in hexadecimal. This is the value stored in memory. To display a static string we do the following POINT rcall Copyright University of Colorado, 2005 kHz DISPLAYC ASEN 4519/5519 Lecture #10 16 DisplayC subroutine DisplayC bcf PORTE,0 tblrd* movf TABLAT,F IF_ .Z. tblrd+* ENDIF_ REPEAT_ bsf PORTE,1 movff TABLAT,PORTD bcf PORTE,1 bsf PORTE,1 swapf TABLAT,W movwf PORTD bcf PORTE,1 rcall T40 bsf PORTE,0 tblrd+* movf TABLAT,F UNTIL_ .Z. return Copyright University of Colorado, 2005 ;Drive RS pin low for cursor-positioning code ;Get byte from string into TABLAT ;Check for leading zero byte ;If zero, get next byte ;Drive E pin high ;Send upper nibble ;Drive E pin low so LCD will accept nibble ;Drive E pin high again ;Swap nibbles ;Write lower nibble ;Drive E pin low so LCD will process byte ;Wait 40 usec ;Drive RS pin high for displayable characters ;Increment pointer, then get next byte ;Is it zero? ASEN 4519/5519 Lecture #10 17 T40 subroutine ;;;;;;; T40 subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Pause for 40 microseconds or 40/0.4 = 100 clock cycles. ; Assumes 10/4 = 2.5 MHz internal clock rate. T40 movlw 100/3 movwf COUNT REPEAT_ decf COUNT,F UNTIL_ .Z. return Copyright University of Colorado, 2005 ;Each REPEAT loop takes 3 cycles ASEN 4519/5519 Lecture #10 18 Homework MONDAY 03-OCT-05 (LECTURE) • Read chapter 7 (Alphanumeric LCD) • Lab #3 due at 22:00 (submit via WebCT) WEDNESDAY 05-OCT-05 (LECTURE) • Read and start lab #4 • Look at Hitachi 44780 LCD datasheet (website) FRIDAY 07-OCT-05 (LAB) • Lab #4 - LCD Copyright University of Colorado, 2005 ASEN 4519/5519 Lecture #10 19