Interfacing To An LCD Module
Interfacing To An LCD Module
Interfacing To An LCD Module
AN587
Interfacing to an LCD Module
3-49
Interfacing to an LCD Module
Figure 1A through Figure 1C show the block diagrams assignment. This is accomplished with EQUate state-
for the three different data interfaces. The LCD_CNTL ments in the source code. See Appendices B - D.
and LCD_DATA lines are user definable to their port
LM032L
Vcc (2)
PIC16CXX R1 (10KΩ)
RS (4) Vo (3)
LCD_CNTL
Port R_W (5) R2 (330Ω)
E (6) Vss (1)
Port LCD_DATA
<7:0> DB (14)-DB0 (7)
FIGURE 1B: 4-BIT MODE. DATA TRANSFERRED ON THE HIGH NIBBLE OF THE PORT
LM032L
Vcc (2)
PIC16CXX R1 (10KΩ)
RS (4) Vo (3)
LCD_CNTL
Port R_W (5) R2 (330Ω)
E (6) Vss (1)
Port LCD_DATA
<7:4> DB7 (14)-DB4 (11)
DB3 (10)-DB0 (7)
FIGURE 1C: 4-BIT MODE. DATA TRANSFERRED ON THE LOW NIBBLE OF THE PORT
LM032L
Vcc (2)
PIC16CXX R1 (10KΩ)
RS (4) Vo (3)
LCD_CNTL
Port R_W (5) R2 (330Ω)
E (6) Vss (1)
Port LCD_DATA
<3:0> DB7 (14)-DB4 (11)
DB3 (10)-DB0 (7)
3-50
Interfacing to an LCD Module
LCD ‘s (drivers) are slow devices when compared to 4.6 ms must be executed before the LCD module can be
microcontrollers. Care must be taken from having com- initialized. Some of the LCD module commands are:
munication occur to quickly. The timing requirements of
• 1 or 2 lines of characters
the LM032L are shown in Appendix A. It is recom-
mended that the complete specifications of the LM032L • Display on /off
be acquired from Hitachi or an Hitachi distributor. The • Clear display
literature number is CE-E613Q and M24T013 for the
display driver. • Increment / do not increment character address
pointer after each character
When the module powers up, the default data transfer
mode is 8-bit. The initialization sequence only requires • Load character address pointer
commands that are 4-bit in length. The last initialization The initialization flow for the module is shown in
command then needs to be sent to the display to specify Figure 2.
the data transfer width (4- or 8-bit). Then a delay of
3
FIGURE 2: INITIALIZATION FLOW FOR LCD MODULE
3
1) When interface is 8 bits long: 2) When interface is 4 bits long:
Power ON Power ON
[ ]
0 0 0 0 0 0 Interface is 8 / 4 bits long. The number of display lines
0 0 0 0 0 0 1 0 0 0 Display OFF Specify the number of
0 0 1 0 0 0 and character font cannot
display lines and character be changed afterwards.
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 font.
0 0 0 1 0 1 Display ON
3-51
Interfacing to an LCD Module
After initialization, each character address is individually Figure 4 shows the display data positions supported by
addressable. Figure 3 shows the structure of the com- the display driver as well as the characters actually
mand to specify the character address. displayed by the module (the shaded addresses).
The program example implemented here uses the auto
character increment feature. This automatically incre-
FIGURE 3: CHARACTER ADDRESS ments the character address pointer after each charac-
COMMAND FORMAT ter is written to the display.
Program Data
Mode Memory Memory Verified On
8-bit 32 3 PICDEM-2 *
4-bit, Data transferred on the high nibble 53 3 PICDEM-2 *
of the port
4-bit, Data transferred on the high nibble 53 3 Low Power Real Time
of the port Clock Board (AN582)
3-52
Interfacing to an LCD Module
4 7
2.2V 2.2V
E 0.6V 0.6V
0.6V
3 6
2.2V 2.2V
RS 0.6V 0.6V
4 7
2.2V 2.2V
3 0.6V
E 0.6V 0.6V
3
5
2.2V 2.2V
DB0 DB7 Valid Data
0.4V 0.4V
3-53
Interfacing to an LCD Module
Notes:
In the HD44780, the data can be sent in either a 4-bit 2-operation or a 8-bit 1-operation, so that it can interface to both
4- and 8-bit MPUs.
(1) When interface data is 4-bits long, data is transferred using only 4 buses of DB~ DB7 and DB0~ DB3 are not used.
Data transfer between the HD44780 and the MPU completes when 4-bit data is tranferred twice. Data of the higher
order 4 bits (contents of DB4 ~ DB7 when interface data is 8-bits long) is tranferred first and then lower order 4 bits
(contents of DB4 ~DB7 when interface data is 8-bits long).
(2) When interface data is 8-bits long, data is transferred using 8 data buses of DB0 ~DB7.
3-54
APPENDIX B: 8-BIT DATA INTERFACE LISTING
3-55
0233
0013
0014 include <lm032l.h>
0014
0015 ;
0000 0016 Four_bit EQU FALSE ; Selects 4- or 8-bit data transfers
0001 0017 Data_HI EQU TRUE ; If 4-bit transfers, Hi or Low nibble of PORT
0018 ;
0019 ;
0020 if ( Four_bit && !Data_HI )
0021 ;
0022 LCD_DATA EQU PORTB
0023 LCD_DATA_TRIS EQU TRISB
0024 ;
0025 else
0026 ;
0008 0027 LCD_DATA EQU PORTD
0088 0028 LCD_DATA_TRIS EQU TRISD
0029 ;
0030 endif
0031 ;
DS00587A-page 7
Interfacing to an LCD Module
3
0005 0032 LCD_CNTL EQU PORTA
0033 ;
0034 ;
0035 ;
DS00587A-page 8
0036 ; LCD Display Commands and Control Signal names.
0037 ;
0038 if ( Four_bit && !Data_HI )
0039 ;
0040 E EQU 0 ; LCD Enable control line
0041 R_W EQU 1 ; LCD Read/Write control line
0042 RS EQU 2 ; LCD Register Select control line
0043 ;
0044 else
0045 ;
0003 0046 E EQU 3 ; LCD Enable control line
0002 0047 R_W EQU 2 ; LCD Read/Write control line
0001 0048 RS EQU 1 ; LCD Register Select control line
0049 ;
0050 endif
0051 ;
0052 ;
0030 0053 TEMP1 EQU 0x030
0054 ;
3-56
0055 org RESET_V ; RESET vector location
Interfacing to an LCD Module
3-57
0101 ;
0103 ;
0104 ; Initilize the LCD Display Module
0105 ;
0023 0185 0106 CLRF LCD_CNTL ; ALL PORT output should output Low.
0107
0108 DISPLAY_INIT
0109 if ( Four_bit && !Data_HI )
0110 MOVLW 0x02 ; Command for 4-bit interface low nibble
0111 endif
0112 ;
0113 if ( Four_bit && Data_HI )
0114 MOVLW 0x020 ; Command for 4-bit interface high nibble
0115 endif
0116 ;
0117 if ( !Four_bit )
0024 3038 0118 MOVLW 0x038 ; Command for 8-bit interface
0119 endif
0120 ;
0025 0088 0121 MOVWF LCD_DATA ;
0026 1585 0122 BSF LCD_CNTL, E ;
DS00587A-page 9
Interfacing to an LCD Module
3
0027 1185 0123 BCF LCD_CNTL, E ;
0124 ;
0125 ; This routine takes the calculated times that the delay loop needs to
0126 ; be executed, based on the LCD_INIT_DELAY EQUate that includes the
DS00587A-page 10
0127 ; frequency of operation. These uses registers before they are needed to
0128 ; store the time.
0129 ;
0028 3006 0130 LCD_DELAY MOVLW LCD_INIT_DELAY ;
0029 00B3 0131 MOVWF MSD ; Use MSD and LSD Registers to Initilize LCD
002A 01B4 0132 CLRF LSD ;
002B 0BB4 0133 LOOP2 DECFSZ LSD ; Delay time = MSD * ((3 * 256) + 3) * Tcy
002C 282B 0134 GOTO LOOP2 ;
002D 0BB3 0135 DECFSZ MSD ;
0136 END_LCD_DELAY
002E 282B 0137 GOTO LOOP2 ;
0138 ;
0139 ; Command sequence for 2 lines of 5x7 characters
0140 ;
0141 CMD_SEQ
0142 ;
0143 if ( Four_bit )
0144 if ( !Data_HI )
3-58
0145 MOVLW 0X02 ; 4-bit low nibble xfer
Interfacing to an LCD Module
0146 else
0147 MOVLW 0X020 ; 4-bit high nibble xfer
0148 endif
0149 ;
0150 else ; 8-bit mode
002F 3038 0151 MOVLW 0X038
0152 endif
0153 ;
0030 0088 0154 MOVWF LCD_DATA ; This code for both 4-bit and 8-bit modes
0031 1585 0155 BSF LCD_CNTL, E ;
0032 1185 0156 BCF LCD_CNTL, E ;
0157 ;
0158 if ( Four_bit ) ; This code for only 4-bit mode (2nd xfer)
0159 if ( !Data_HI )
0160 MOVLW 0x08 ; 4-bit low nibble xfer
0161 else
0162 MOVLW 0x080 ; 4-bit high nibble xfer
0163 endif
0164 MOVWF LCD_DATA ;
0165 BSF LCD_CNTL, E ;
0166 BCF LCD_CNTL, E ;
3-59
0044 2061 0192 call SEND_CHAR
0045 3063 0193 movlw ‘c’
0046 2061 0194 call SEND_CHAR
0047 3068 0195 movlw ‘h’
0048 2061 0196 call SEND_CHAR
0049 3069 0197 movlw ‘i’
004A 2061 0198 call SEND_CHAR
004B 3070 0199 movlw ‘p’
004C 2061 0200 call SEND_CHAR
0201
004D 30C0 0202 movlw B’11000000' ;Address DDRam first character, second line
004E 206A 0203 call SEND_CMD
0204
0205 ;Demonstration of the use of a table to output a message
004F 3000 0206 movlw 0 ;Table address of start of message
0207 dispmsg
0050 00B0 0208 movwf TEMP1 ;TEMP1 holds start of message address
0051 2085 0209 call Table
0052 39FF 0210 andlw 0FFh ;Check if at end of message (zero
0053 1903 0211 btfsc STATUS,Z ;returned at end)
0054 2859 0212 goto out
0055 2061 0213 call SEND_CHAR ;Display character
0056 0830 0214 movf TEMP1,w ;Point to next character
DS00587A-page 11
Interfacing to an LCD Module
3
0057 3E01 0215 addlw 1
0058 2850 0216 goto dispmsg
0217 out
0218 loop
0059 2859 0219 goto loop ;Stay here forever
0220 ;
DS00587A-page 12
0221 ;
0222 INIT_DISPLAY
005A 300C 0223 MOVLW DISP_ON ; Display On, Cursor On
005B 206A 0224 CALL SEND_CMD ; Send This command to the Display Module
005C 3001 0225 MOVLW CLR_DISP ; Clear the Display
005D 206A 0226 CALL SEND_CMD ; Send This command to the Display Module
005E 3006 0227 MOVLW ENTRY_INC ; Set Entry Mode Inc., No shift
005F 206A 0228 CALL SEND_CMD ; Send This command to the Display Module
0060 0008 0229 RETURN
0230 ;
0232 ;
0233 ;*******************************************************************
0234 ;* The LCD Module Subroutines *
0235 ;*******************************************************************
0236 ;
0237 if ( Four_bit ) ; 4-bit Data transfers?
0238 ;
0239 if ( Data_HI ) ; 4-bit transfers on the high nibble of the PORT
3-60
0240 ;
Interfacing to an LCD Module
0241 ;*******************************************************************
0242 ;*SendChar - Sends character to LCD *
0243 ;*This routine splits the character into the upper and lower *
0244 ;*nibbles and sends them to the LCD, upper nibble first. *
0245 ;*******************************************************************
0246 ;
0247 SEND_CHAR
0248 MOVWF CHAR ;Character to be sent is in W
0249 CALL BUSY_CHECK ;Wait for LCD to be ready
0250 MOVF CHAR, w
0251 ANDLW 0xF0 ;Get upper nibble
0252 MOVWF LCD_DATA ;Send data to LCD
0253 BCF LCD_CNTL, R_W ;Set LCD to read
0254 BSF LCD_CNTL, RS ;Set LCD to data mode
0255 BSF LCD_CNTL, E ;toggle E for LCD
0256 BCF LCD_CNTL, E
0257 SWAPF CHAR, w
0258 ANDLW 0xF0 ;Get lower nibble
0259 MOVWF LCD_DATA ;Send data to LCD
0260 BSF LCD_CNTL, E ;toggle E for LCD
0261 BCF LCD_CNTL, E
3-61
0286 BSF LCD_CNTL, E ; toggle E for LCD
0287 BCF LCD_CNTL, E
0288 RETURN
0289 ;
0290 endif
0291 else
0292 ;
0293 ;*****************************************************************
0294 ;* SEND_CHAR - Sends character contained in register W to LCD *
0295 ;* This routine sends the entire character to the PORT *
0296 ;* The data is transmitted on the PORT<7:0> pins *
0297 ;*****************************************************************
0298 ;
0299 SEND_CHAR
0061 00B6 0300 MOVWF CHAR ; Character to be sent is in W
0062 2073 0301 CALL BUSY_CHECK ; Wait for LCD to be ready
0063 0836 0302 MOVF CHAR, w
0064 0088 0303 MOVWF LCD_DATA ; Send data to LCD
0065 1105 0304 BCF LCD_CNTL, R_W ; Set LCD in read mode
0066 1485 0305 BSF LCD_CNTL, RS ; Set LCD in data mode
0067 1585 0306 BSF LCD_CNTL, E ; toggle E for LCD
0068 1185 0307 BCF LCD_CNTL, E
0069 0008 0308 RETURN
DS00587A-page 13
Interfacing to an LCD Module
3
0309 ;
0310 endif
0311 ;
0313 ;
0314 ;*******************************************************************
0315 ;* SendCmd - Sends command to LCD *
DS00587A-page 14
0316 ;* This routine splits the command into the upper and lower *
0317 ;* nibbles and sends them to the LCD, upper nibble first. *
0318 ;* The data is transmitted on the PORT<3:0> pins *
0319 ;*******************************************************************
0320 ;
0321 if ( Four_bit ) ; 4-bit Data transfers?
0322 ;
0323 if ( Data_HI ) ; 4-bit transfers on the high nibble of the PORT
0324 ;
0325 ;*******************************************************************
0326 ;* SEND_CMD - Sends command to LCD *
0327 ;* This routine splits the command into the upper and lower *
0328 ;* nibbles and sends them to the LCD, upper nibble first. *
0329 ;*******************************************************************
0330
0331 SEND_CMD
0332 MOVWF CHAR ; Character to be sent is in W
0333 CALL BUSY_CHECK ; Wait for LCD to be ready
3-62
0334 MOVF CHAR,w
Interfacing to an LCD Module
3-63
006E 1105 0381 BCF LCD_CNTL, R_W ; Set LCD in read mode
006F 1085 0382 BCF LCD_CNTL, RS ; Set LCD in command mode
0070 1585 0383 BSF LCD_CNTL, E ; toggle E for LCD
0071 1185 0384 BCF LCD_CNTL, E
0072 0008 0385 RETURN
0386 ;
0387 endif
0388 ;
0390 ;
0391 if ( Four_bit ) ; 4-bit Data transfers?
0392 ;
0393 if ( Data_HI ) ; 4-bit transfers on the high nibble of the PORT
0394 ;
0395 ;*******************************************************************
0396 ;* This routine checks the busy flag, returns when not busy *
0397 ;* Affects: *
0398 ;* TEMP - Returned with busy/address *
0399 ;*******************************************************************
0400 ;
0401 BUSY_CHECK
0402 BSF STATUS, RP0 ; Select Register page 1
0403 MOVLW 0xFF ; Set Port_D for input
0404 MOVWF LCD_DATA_TRIS
DS00587A-page 15
Interfacing to an LCD Module
3
0405 BCF STATUS, RP0 ; Select Register page 0
0406 BCF LCD_CNTL, RS ; Set LCD for Command mode
0407 BSF LCD_CNTL, R_W ; Setup to read busy flag
0408 BSF LCD_CNTL, E ; Set E high
0409 BCF LCD_CNTL, E ; Set E low
0410 MOVF LCD_DATA, W ; Read upper nibble busy flag, DDRam address
DS00587A-page 16
0411 ANDLW 0xF0 ; Mask out lower nibble
0412 MOVWF TEMP
0413 BSF LCD_CNTL, E ; Toggle E to get lower nibble
0414 BCF LCD_CNTL, E
0415 SWAPF LCD_DATA, w ; Read lower nibble busy flag, DDRam address
0416 ANDLW 0x0F ; Mask out upper nibble
0417 IORWF TEMP ; Combine nibbles
0418 BTFSC TEMP, 7 ; Check busy flag, high = busy
0419 GOTO BUSY_CHECK ; If busy, check again
0420 BCF LCD_CNTL, R_W
0421 BSF STATUS, RP0 ; Select Register page 1
0422 MOVLW 0x0F
0423 MOVWF LCD_DATA_TRIS ; Set Port_D for output
0424 BCF STATUS, RP0 ; Select Register page 0
0425 RETURN
0426 ;
0427 else ; 4-bit transfers on the low nibble of the PORT
0428 ;
0429 ;*******************************************************************
3-64
Interfacing to an LCD Module
0430 ;* This routine checks the busy flag, returns when not busy *
0431 ;* Affects: *
0432 ;* TEMP - Returned with busy/address *
0433 ;*******************************************************************
0434 ;
0435 BUSY_CHECK
0436 BSF STATUS, RP0 ; Bank 1
0437 MOVLW 0xFF ; Set PortB for input
0438 MOVWF LCD_DATA_TRIS
0439 BCF STATUS, RP0 ; Bank 0
0440 BCF LCD_CNTL, RS ; Set LCD for Command mode
0441 BSF LCD_CNTL, R_W ; Setup to read busy flag
0442 BSF LCD_CNTL, E ; Set E high
0443 BCF LCD_CNTL, E ; Set E low
0444 SWAPF LCD_DATA, W ; Read upper nibble busy flag, DDRam address
0445 ANDLW 0xF0 ; Mask out lower nibble
0446 MOVWF TEMP ;
0447 BSF LCD_CNTL, E ; Toggle E to get lower nibble
0448 BCF LCD_CNTL, E
0449 MOVF LCD_DATA, W ; Read lower nibble busy flag, DDRam address
0450 ANDLW 0x0F ; Mask out upper nibble
0451 IORWF TEMP, F ; Combine nibbles
3-65
0079 1585 0477 BSF LCD_CNTL, E ; Set E high
007A 1185 0478 BCF LCD_CNTL, E ; Set E low
007B 0808 0479 MOVF LCD_DATA, w ; Read busy flag, DDram address
007C 00B5 0480 MOVWF TEMP
007D 1BB5 0481 BTFSC TEMP, 7 ; Check busy flag, high=busy
007E 2873 0482 GOTO BUSY_CHECK
007F 1105 0483 BCF LCD_CNTL, R_W
0080 1683 0484 BSF STATUS, RP0 ; Select Register page 1
0081 3000 0485 MOVLW 0x00
0082 0088 0486 MOVWF LCD_DATA_TRIS ; Set port_D for output
0083 1283 0487 BCF STATUS, RP0 ; Select Register page 0
0084 0008 0488 RETURN
0489 ;
0490 endif
0492 ;
0493 Table
0085 0782 0494 addwf PCL ;Jump to char pointed to in W reg
0086 344D 0495 retlw ‘M’
0087 3469 0496 retlw ‘i’
0088 3463 0497 retlw ‘c’
0089 3472 0498 retlw ‘r’
008A 346F 0499 retlw ‘o’
008B 3463 0500 retlw ‘c’
DS00587A-page 17
Interfacing to an LCD Module
3
008C 3468 0501 retlw ‘h’
008D 3469 0502 retlw ‘i’
008E 3470 0503 retlw ‘p’
008F 3420 0504 retlw ‘ ‘
0090 3454 0505 retlw ‘T’
0091 3465 0506 retlw ‘e’
DS00587A-page 18
0092 3463 0507 retlw ‘c’
0093 3468 0508 retlw ‘h’
0094 346E 0509 retlw ‘n’
0095 346F 0510 retlw ‘o’
0096 346C 0511 retlw ‘l’
0097 346F 0512 retlw ‘o’
0098 3467 0513 retlw ‘g’
0099 3479 0514 retlw ‘y’
0515 Table_End
009A 3400 0516 retlw 0
0517 ;
0518 if ( (Table & 0x0FF) >= (Table_End & 0x0FF) )
0519 MESSG “Warning - User Definded: Table Table crosses page boundry in computed jump”
0520 endif
0521 ;
0522
0523
0524
0525 end
3-66
Interfacing to an LCD Module
0526
0527
0528
0529
0530
Errors : 0
Warnings : 13
3-67
DS00587A-page 19
Interfacing to an LCD Module
3
APPENDIX C: 4-BIT DATA INTERFACE, HIGH NIBBLE LISTING
DS00587A-page 20
LOC OBJECT CODE LINE SOURCE TEXT
3-68
0013
Interfacing to an LCD Module
3-69
0058 ; This is the Periperal Interrupt routine. Should NOT get here
0059 ;
0061 org ISR_V ; Interrupt vector location
0062 PER_INT_V
0004 1283 0063 ERROR1 BCF STATUS, RP0 ; Bank 0
0005 1407 0064 BSF PORTC, 0
0006 1007 0065 BCF PORTC, 0
0007 2804 0066 GOTO ERROR1
0067 ;
0068 ;
0069 ;
0070 START ; POWER_ON Reset (Beginning of program)
0008 0183 0071 CLRF STATUS ; Do initialization (Bank 0)
0009 018B 0072 CLRF INTCON
000A 018C 0073 CLRF PIR1
000B 1683 0074 BSF STATUS, RP0 ; Bank 1
000C 3000 0075 MOVLW 0x00 ; The LCD module does not like to work w/ weak pull-ups
000D 0081 0076 MOVWF OPTION_R ;
000E 018C 0077 CLRF PIE1 ; Disable all peripheral interrupts
000F 30FF 0078 MOVLW 0xFF ;
0010 009F 0079 MOVWF ADCON1 ; Port A is Digital.
0080 ;
0081 ;
DS00587A-page 21
Interfacing to an LCD Module
3
0011 1283 0082 BCF STATUS, RP0 ; Bank 0
0012 0185 0083 CLRF PORTA ; ALL PORT output should output Low.
0013 0186 0084 CLRF PORTB
0014 0187 0085 CLRF PORTC
0015 0188 0086 CLRF PORTD
0016 0189 0087 CLRF PORTE
0017 1010 0088 BCF T1CON, TMR1ON ; Timer 1 is NOT incrementing
DS00587A-page 22
0089 ;
0018 1683 0090 BSF STATUS, RP0 ; Select Bank 1
0019 0185 0091 CLRF TRISA ; RA5 - 0 outputs
001A 30F0 0092 MOVLW 0xF0 ;
001B 0086 0093 MOVWF TRISB ; RB7 - 4 inputs, RB3 - 0 outputs
001C 0187 0094 CLRF TRISC ; RC Port are outputs
001D 1407 0095 BSF TRISC, T1OSO ; RC0 needs to be input for the oscillator to function
001E 0188 0096 CLRF TRISD ; RD Port are outputs
001F 0189 0097 CLRF TRISE ; RE Port are outputs
0020 140C 0098 BSF PIE1, TMR1IE ; Enable TMR1 Interrupt
0021 1781 0099 BSF OPTION_R, RBPU ; Disable PORTB pull-ups
0022 1283 0100 BCF STATUS, RP0 ; Select Bank 0
0101 ;
0103 ;
0104 ; Initilize the LCD Display Module
0105 ;
0023 0185 0106 CLRF LCD_CNTL ; ALL PORT output should output Low.
0107
3-70
0108 DISPLAY_INIT
Interfacing to an LCD Module
3-71
0032 1185 0156 BCF LCD_CNTL, E ;
0157 ;
0158 if ( Four_bit ) ; This code for only 4-bit mode (2nd xfer)
0159 if ( !Data_HI )
0160 MOVLW 0x08 ; 4-bit low nibble xfer
0161 else
0033 3080 0162 MOVLW 0x080 ; 4-bit high nibble xfer
0163 endif
0034 0088 0164 MOVWF LCD_DATA ;
0035 1585 0165 BSF LCD_CNTL, E ;
0036 1185 0166 BCF LCD_CNTL, E ;
0167 endif
0168 ;
0169 ; Busy Flag should be valid after this point
0170 ;
0037 300C 0171 MOVLW DISP_ON ;
0038 2074 0172 CALL SEND_CMD ;
0039 3001 0173 MOVLW CLR_DISP ;
003A 2074 0174 CALL SEND_CMD ;
003B 3006 0175 MOVLW ENTRY_INC ;
003C 2074 0176 CALL SEND_CMD ;
003D 3080 0177 MOVLW DD_RAM_ADDR ;
003E 2074 0178 CALL SEND_CMD ;
DS00587A-page 23
Interfacing to an LCD Module
3
0179 ;
0181 ;
0182 ;Send a message the hard way
003F 304D 0183 movlw ‘M’
0040 2065 0184 call SEND_CHAR
0041 3069 0185 movlw ‘i’
0042 2065 0186 call SEND_CHAR
DS00587A-page 24
0043 3063 0187 movlw ‘c’
0044 2065 0188 call SEND_CHAR
0045 3072 0189 movlw ‘r’
0046 2065 0190 call SEND_CHAR
0047 306F 0191 movlw ‘o’
0048 2065 0192 call SEND_CHAR
0049 3063 0193 movlw ‘c’
004A 2065 0194 call SEND_CHAR
004B 3068 0195 movlw ‘h’
004C 2065 0196 call SEND_CHAR
004D 3069 0197 movlw ‘i’
004E 2065 0198 call SEND_CHAR
004F 3070 0199 movlw ‘p’
0050 2065 0200 call SEND_CHAR
0201
0051 30C0 0202 movlw B’11000000' ;Address DDRam first character, second line
0052 2074 0203 call SEND_CMD
0204
3-72
0205 ;Demonstration of the use of a table to output a message
Interfacing to an LCD Module
3-73
006B 1485 0254 BSF LCD_CNTL, RS ;Set LCD to data mode
006C 1585 0255 BSF LCD_CNTL, E ;toggle E for LCD
006D 1185 0256 BCF LCD_CNTL, E
006E 0E36 0257 SWAPF CHAR, w
006F 39F0 0258 ANDLW 0xF0 ;Get lower nibble
0070 0088 0259 MOVWF LCD_DATA ;Send data to LCD
0071 1585 0260 BSF LCD_CNTL, E ;toggle E for LCD
0072 1185 0261 BCF LCD_CNTL, E
0073 0008 0262 RETURN
0263 ;
0264 else ; 4-bit transfers on the low nibble of the PORT
0265 ;
0266 ;*******************************************************************
0267 ;* SEND_CHAR - Sends character to LCD *
0268 ;* This routine splits the character into the upper and lower *
0269 ;* nibbles and sends them to the LCD, upper nibble first. *
0270 ;* The data is transmitted on the PORT<3:0> pins *
0271 ;*******************************************************************
0272 ;
0273 SEND_CHAR
0274 MOVWF CHAR ; Character to be sent is in W
0275 CALL BUSY_CHECK ; Wait for LCD to be ready
0276 SWAPF CHAR, W
DS00587A-page 25
Interfacing to an LCD Module
3
0277 ANDLW 0x0F ; Get upper nibble
0278 MOVWF LCD_DATA ; Send data to LCD
0279 BCF LCD_CNTL, R_W ; Set LCD to read
0280 BSF LCD_CNTL, RS ; Set LCD to data mode
0281 BSF LCD_CNTL, E ; toggle E for LCD
0282 BCF LCD_CNTL, E
0283 MOVF CHAR, W
DS00587A-page 26
0284 ANDLW 0x0F ; Get lower nibble
0285 MOVWF LCD_DATA ; Send data to LCD
0286 BSF LCD_CNTL, E ; toggle E for LCD
0287 BCF LCD_CNTL, E
0288 RETURN
0289 ;
0290 endif
0291 else
0292 ;
0293 ;*****************************************************************
0294 ;* SEND_CHAR - Sends character contained in register W to LCD *
0295 ;* This routine sends the entire character to the PORT *
0296 ;* The data is transmitted on the PORT<7:0> pins *
0297 ;*****************************************************************
0298 ;
0299 SEND_CHAR
0300 MOVWF CHAR ; Character to be sent is in W
0301 CALL BUSY_CHECK ; Wait for LCD to be ready
3-74
0302 MOVF CHAR, w
Interfacing to an LCD Module
3-75
0351 MOVWF CHAR ; Character to be sent is in W
0352 CALL BUSY_CHECK ; Wait for LCD to be ready
0353 SWAPF CHAR, W
0354 ANDLW 0x0F ; Get upper nibble
0355 MOVWF LCD_DATA ; Send data to LCD
0356 BCF LCD_CNTL, R_W ; Set LCD to read
0357 BCF LCD_CNTL, RS ; Set LCD to command mode
0358 BSF LCD_CNTL, E ; toggle E for LCD
0359 BCF LCD_CNTL, E
0360 MOVF CHAR, W
0361 ANDLW 0x0F ; Get lower nibble
0362 MOVWF LCD_DATA ; Send data to LCD
0363 BSF LCD_CNTL, E ; toggle E for LCD
0364 BCF LCD_CNTL, E
0365 RETURN
0366 ;
0367 endif
0368 else
0369 ;
0370 ;**************************************************************
0371 ;* SEND_CND - Sends command contained in register W to LCD *
0372 ;* This routine sends the entire character to the PORT *
0373 ;* The data is transmitted on the PORT<7:0> pins *
DS00587A-page 27
Interfacing to an LCD Module
3
0374 ;**************************************************************
0375
0376 SEND_CMD
0377 MOVWF CHAR ; Command to be sent is in W
0378 CALL BUSY_CHECK ; Wait for LCD to be ready
0379 MOVF CHAR, w
0380 MOVWF LCD_DATA ; Send data to LCD
DS00587A-page 28
0381 BCF LCD_CNTL, R_W ; Set LCD in read mode
0382 BCF LCD_CNTL, RS ; Set LCD in command mode
0383 BSF LCD_CNTL, E ; toggle E for LCD
0384 BCF LCD_CNTL, E
0385 RETURN
0386 ;
0387 endif
0388 ;
0390 ;
0391 if ( Four_bit ) ; 4-bit Data transfers?
0392 ;
0393 if ( Data_HI ) ; 4-bit transfers on the high nibble of the PORT
0394 ;
0395 ;*******************************************************************
0396 ;* This routine checks the busy flag, returns when not busy *
0397 ;* Affects: *
0398 ;* TEMP - Returned with busy/address *
0399 ;*******************************************************************
3-76
0400 ;
Interfacing to an LCD Module
0401 BUSY_CHECK
0083 1683 0402 BSF STATUS, RP0 ; Select Register page 1
0084 30FF 0403 MOVLW 0xFF ; Set Port_D for input
0085 0088 0404 MOVWF LCD_DATA_TRIS
0086 1283 0405 BCF STATUS, RP0 ; Select Register page 0
0087 1085 0406 BCF LCD_CNTL, RS ; Set LCD for Command mode
0088 1505 0407 BSF LCD_CNTL, R_W ; Setup to read busy flag
0089 1585 0408 BSF LCD_CNTL, E ; Set E high
008A 1185 0409 BCF LCD_CNTL, E ; Set E low
008B 0808 0410 MOVF LCD_DATA, W ; Read upper nibble busy flag, DDRam address
008C 39F0 0411 ANDLW 0xF0 ; Mask out lower nibble
008D 00B5 0412 MOVWF TEMP
008E 1585 0413 BSF LCD_CNTL, E ; Toggle E to get lower nibble
008F 1185 0414 BCF LCD_CNTL, E
0090 0E08 0415 SWAPF LCD_DATA, w ; Read lower nibble busy flag, DDRam address
0091 390F 0416 ANDLW 0x0F ; Mask out upper nibble
0092 04B5 0417 IORWF TEMP ; Combine nibbles
0093 1BB5 0418 BTFSC TEMP, 7 ; Check busy flag, high = busy
0094 2883 0419 GOTO BUSY_CHECK ; If busy, check again
0095 1105 0420 BCF LCD_CNTL, R_W
0096 1683 0421 BSF STATUS, RP0 ; Select Register page 1
0097 300F 0422 MOVLW 0x0F
3-77
0448 BCF LCD_CNTL, E
0449 MOVF LCD_DATA, W ; Read lower nibble busy flag, DDRam address
0450 ANDLW 0x0F ; Mask out upper nibble
0451 IORWF TEMP, F ; Combine nibbles
0452 BTFSC TEMP, 7 ; Check busy flag, high = busy
0453 GOTO BUSY_CHECK ; If busy, check again
0454 BCF LCD_CNTL, R_W
0455 BSF STATUS, RP0 ; Bank 1
0456 MOVLW 0xF0 ;
0457 MOVWF LCD_DATA_TRIS ; RB7 - 4 = inputs, RB3 - 0 = output
0458 BCF STATUS, RP0 ; Bank 0
0459 RETURN
0460 ;
0461 endif
0462 else
0463 ;
0464 ;**************************************************************
0465 ;* This routine checks the busy flag, returns when not busy *
0466 ;* Affects: *
0467 ;* TEMP - Returned with busy/address *
0468 ;**************************************************************
0469 ;
0470 BUSY_CHECK
DS00587A-page 29
Interfacing to an LCD Module
3
0471 BSF STATUS,RP0 ; Select Register page 1
0472 MOVLW 0xFF ; Set port_D for input
0473 MOVWF LCD_DATA_TRIS
0474 BCF STATUS, RP0 ; Select Register page 0
0475 BCF LCD_CNTL, RS ; Set LCD for command mode
0476 BSF LCD_CNTL, R_W ; Setup to read busy flag
0477 BSF LCD_CNTL, E ; Set E high
DS00587A-page 30
0478 BCF LCD_CNTL, E ; Set E low
0479 MOVF LCD_DATA, w ; Read busy flag, DDram address
0480 MOVWF TEMP
0481 BTFSC TEMP, 7 ; Check busy flag, high=busy
0482 GOTO BUSY_CHECK
0483 BCF LCD_CNTL, R_W
0484 BSF STATUS, RP0 ; Select Register page 1
0485 MOVLW 0x00
0486 MOVWF LCD_DATA_TRIS ; Set port_D for output
0487 BCF STATUS, RP0 ; Select Register page 0
0488 RETURN
0489 ;
0490 endif
0492 ;
0493 Table
009B 0782 0494 addwf PCL ;Jump to char pointed to in W reg
009C 344D 0495 retlw ‘M’
009D 3469 0496 retlw ‘i’
3-78
009E 3463 0497 retlw ‘c’
Interfacing to an LCD Module
3-79
00C0 : ———————— ———————— ———————— ————————
Errors : 0
Warnings : 13
DS00587A-page 31
Interfacing to an LCD Module
3
APPENDIX D: 4-BIT DATA INTERFACE, LOW NIBBLE LISTING
DS00587A-page 32
LOC OBJECT CODE LINE SOURCE TEXT
3-80
0014 include <lm032l.h>
Interfacing to an LCD Module
0014
0015 ;
0001 0016 Four_bit EQU TRUE ; Selects 4- or 8-bit data transfers
0000 0017 Data_HI EQU FALSE ; If 4-bit transfers, Hi or Low nibble of PORT
0018 ;
0019 ;
0020 if ( Four_bit && !Data_HI )
0021 ;
0006 0022 LCD_DATA EQU PORTB
0086 0023 LCD_DATA_TRIS EQU TRISB
0024 ;
0025 else
0026 ;
0027 LCD_DATA EQU PORTD
0028 LCD_DATA_TRIS EQU TRISD
0029 ;
0030 endif
0031 ;
0005 0032 LCD_CNTL EQU PORTA
0033 ;
0034 ;
0035 ;
3-81
0059 ;
0061 org ISR_V ; Interrupt vector location
0062 PER_INT_V
0004 1283 0063 ERROR1 BCF STATUS, RP0 ; Bank 0
0005 1407 0064 BSF PORTC, 0
0006 1007 0065 BCF PORTC, 0
0007 2804 0066 GOTO ERROR1
0067 ;
0068 ;
0069 ;
0070 START ; POWER_ON Reset (Beginning of program)
0008 0183 0071 CLRF STATUS ; Do initialization (Bank 0)
0009 018B 0072 CLRF INTCON
000A 018C 0073 CLRF PIR1
000B 1683 0074 BSF STATUS, RP0 ; Bank 1
000C 3000 0075 MOVLW 0x00 ; The LCD module does not like to work w/ weak pull-ups
000D 0081 0076 MOVWF OPTION_R ;
000E 018C 0077 CLRF PIE1 ; Disable all peripheral interrupts
000F 30FF 0078 MOVLW 0xFF ;
0010 009F 0079 MOVWF ADCON1 ; Port A is Digital.
0080 ;
0081 ;
0011 1283 0082 BCF STATUS, RP0 ; Bank 0
DS00587A-page 33
Interfacing to an LCD Module
3
0012 0185 0083 CLRF PORTA ; ALL PORT output should output Low.
0013 0186 0084 CLRF PORTB
0014 0187 0085 CLRF PORTC
0015 0188 0086 CLRF PORTD
0016 0189 0087 CLRF PORTE
0017 1010 0088 BCF T1CON, TMR1ON ; Timer 1 is NOT incrementing
0089 ;
DS00587A-page 34
0018 1683 0090 BSF STATUS, RP0 ; Select Bank 1
0019 0185 0091 CLRF TRISA ; RA5 - 0 outputs
001A 30F0 0092 MOVLW 0xF0 ;
001B 0086 0093 MOVWF TRISB ; RB7 - 4 inputs, RB3 - 0 outputs
001C 0187 0094 CLRF TRISC ; RC Port are outputs
001D 1407 0095 BSF TRISC, T1OSO ; RC0 needs to be input for the oscillator to function
001E 0188 0096 CLRF TRISD ; RD Port are outputs
001F 0189 0097 CLRF TRISE ; RE Port are outputs
0020 140C 0098 BSF PIE1, TMR1IE ; Enable TMR1 Interrupt
0021 1781 0099 BSF OPTION_R, RBPU ; Disable PORTB pull-ups
0022 1283 0100 BCF STATUS, RP0 ; Select Bank 0
0101 ;
0103 ;
0104 ; Initilize the LCD Display Module
0105 ;
0023 0185 0106 CLRF LCD_CNTL ; ALL PORT output should output Low.
0107
0108 DISPLAY_INIT
3-82
0109 if ( Four_bit && !Data_HI )
Interfacing to an LCD Module
0024 3002 0110 MOVLW 0x02 ; Command for 4-bit interface low nibble
0111 endif
0112 ;
0113 if ( Four_bit && Data_HI )
0114 MOVLW 0x020 ; Command for 4-bit interface high nibble
0115 endif
0116 ;
0117 if ( !Four_bit )
0118 MOVLW 0x038 ; Command for 8-bit interface
0119 endif
0120 ;
0025 0086 0121 MOVWF LCD_DATA ;
0026 1405 0122 BSF LCD_CNTL, E ;
0027 1005 0123 BCF LCD_CNTL, E ;
0124 ;
0125 ; This routine takes the calculated times that the delay loop needs to
0126 ; be executed, based on the LCD_INIT_DELAY EQUate that includes the
0127 ; frequency of operation. These uses registers before they are needed to
0128 ; store the time.
0129 ;
0028 3006 0130 LCD_DELAY MOVLW LCD_INIT_DELAY ;
0029 00B3 0131 MOVWF MSD ; Use MSD and LSD Registers to Initilize LCD
3-83
0157 ;
0158 if ( Four_bit ) ; This code for only 4-bit mode (2nd xfer)
0159 if ( !Data_HI )
0033 3008 0160 MOVLW 0x08 ; 4-bit low nibble xfer
0161 else
0162 MOVLW 0x080 ; 4-bit high nibble xfer
0163 endif
0034 0086 0164 MOVWF LCD_DATA ;
0035 1405 0165 BSF LCD_CNTL, E ;
0036 1005 0166 BCF LCD_CNTL, E ;
0167 endif
0168 ;
0169 ; Busy Flag should be valid after this point
0170 ;
0037 300C 0171 MOVLW DISP_ON ;
0038 2074 0172 CALL SEND_CMD ;
0039 3001 0173 MOVLW CLR_DISP ;
003A 2074 0174 CALL SEND_CMD ;
003B 3006 0175 MOVLW ENTRY_INC ;
003C 2074 0176 CALL SEND_CMD ;
003D 3080 0177 MOVLW DD_RAM_ADDR ;
003E 2074 0178 CALL SEND_CMD ;
0179 ;
DS00587A-page 35
Interfacing to an LCD Module
3
0181 ;
0182 ;Send a message the hard way
003F 304D 0183 movlw ‘M’
0040 2065 0184 call SEND_CHAR
0041 3069 0185 movlw ‘i’
0042 2065 0186 call SEND_CHAR
0043 3063 0187 movlw ‘c’
DS00587A-page 36
0044 2065 0188 call SEND_CHAR
0045 3072 0189 movlw ‘r’
0046 2065 0190 call SEND_CHAR
0047 306F 0191 movlw ‘o’
0048 2065 0192 call SEND_CHAR
0049 3063 0193 movlw ‘c’
004A 2065 0194 call SEND_CHAR
004B 3068 0195 movlw ‘h’
004C 2065 0196 call SEND_CHAR
004D 3069 0197 movlw ‘i’
004E 2065 0198 call SEND_CHAR
004F 3070 0199 movlw ‘p’
0050 2065 0200 call SEND_CHAR
0201
0051 30C0 0202 movlw B’11000000' ;Address DDRam first character, second line
0052 2074 0203 call SEND_CMD
0204
0205 ;Demonstration of the use of a table to output a message
3-84
0053 3000 0206 movlw 0 ;Table address of start of message
Interfacing to an LCD Module
0207 dispmsg
0054 00B0 0208 movwf TEMP1 ;TEMP1 holds start of message address
0055 209B 0209 call Table
0056 39FF 0210 andlw 0FFh ;Check if at end of message (zero
0057 1903 0211 btfsc STATUS,Z ;returned at end)
0058 285D 0212 goto out
0059 2065 0213 call SEND_CHAR ;Display character
005A 0830 0214 movf TEMP1,w ;Point to next character
005B 3E01 0215 addlw 1
005C 2854 0216 goto dispmsg
0217 out
0218 loop
005D 285D 0219 goto loop ;Stay here forever
0220 ;
0221 ;
0222 INIT_DISPLAY
005E 300C 0223 MOVLW DISP_ON ; Display On, Cursor On
005F 2074 0224 CALL SEND_CMD ; Send This command to the Display Module
0060 3001 0225 MOVLW CLR_DISP ; Clear the Display
0061 2074 0226 CALL SEND_CMD ; Send This command to the Display Module
0062 3006 0227 MOVLW ENTRY_INC ; Set Entry Mode Inc., No shift
0063 2074 0228 CALL SEND_CMD ; Send This command to the Display Module
3-85
0255 BSF LCD_CNTL, E ;toggle E for LCD
0256 BCF LCD_CNTL, E
0257 SWAPF CHAR, w
0258 ANDLW 0xF0 ;Get lower nibble
0259 MOVWF LCD_DATA ;Send data to LCD
0260 BSF LCD_CNTL, E ;toggle E for LCD
0261 BCF LCD_CNTL, E
0262 RETURN
0263 ;
0264 else ; 4-bit transfers on the low nibble of the PORT
0265 ;
0266 ;*******************************************************************
0267 ;* SEND_CHAR - Sends character to LCD *
0268 ;* This routine splits the character into the upper and lower *
0269 ;* nibbles and sends them to the LCD, upper nibble first. *
0270 ;* The data is transmitted on the PORT<3:0> pins *
0271 ;*******************************************************************
0272 ;
0273 SEND_CHAR
0065 00B6 0274 MOVWF CHAR ; Character to be sent is in W
0066 2083 0275 CALL BUSY_CHECK ; Wait for LCD to be ready
0067 0E36 0276 SWAPF CHAR, W
0068 390F 0277 ANDLW 0x0F ; Get upper nibble
DS00587A-page 37
Interfacing to an LCD Module
3
0069 0086 0278 MOVWF LCD_DATA ; Send data to LCD
006A 1085 0279 BCF LCD_CNTL, R_W ; Set LCD to read
006B 1505 0280 BSF LCD_CNTL, RS ; Set LCD to data mode
006C 1405 0281 BSF LCD_CNTL, E ; toggle E for LCD
006D 1005 0282 BCF LCD_CNTL, E
006E 0836 0283 MOVF CHAR, W
006F 390F 0284 ANDLW 0x0F ; Get lower nibble
DS00587A-page 38
0070 0086 0285 MOVWF LCD_DATA ; Send data to LCD
0071 1405 0286 BSF LCD_CNTL, E ; toggle E for LCD
0072 1005 0287 BCF LCD_CNTL, E
0073 0008 0288 RETURN
0289 ;
0290 endif
0291 else
0292 ;
0293 ;*****************************************************************
0294 ;* SEND_CHAR - Sends character contained in register W to LCD *
0295 ;* This routine sends the entire character to the PORT *
0296 ;* The data is transmitted on the PORT<7:0> pins *
0297 ;*****************************************************************
0298 ;
0299 SEND_CHAR
0300 MOVWF CHAR ; Character to be sent is in W
0301 CALL BUSY_CHECK ; Wait for LCD to be ready
0302 MOVF CHAR, w
3-86
0303 MOVWF LCD_DATA ; Send data to LCD
Interfacing to an LCD Module
3-87
0074 00B6 0351 MOVWF CHAR ; Character to be sent is in W
0075 2083 0352 CALL BUSY_CHECK ; Wait for LCD to be ready
0076 0E36 0353 SWAPF CHAR, W
0077 390F 0354 ANDLW 0x0F ; Get upper nibble
0078 0086 0355 MOVWF LCD_DATA ; Send data to LCD
0079 1085 0356 BCF LCD_CNTL, R_W ; Set LCD to read
007A 1105 0357 BCF LCD_CNTL, RS ; Set LCD to command mode
007B 1405 0358 BSF LCD_CNTL, E ; toggle E for LCD
007C 1005 0359 BCF LCD_CNTL, E
007D 0836 0360 MOVF CHAR, W
007E 390F 0361 ANDLW 0x0F ; Get lower nibble
007F 0086 0362 MOVWF LCD_DATA ; Send data to LCD
0080 1405 0363 BSF LCD_CNTL, E ; toggle E for LCD
0081 1005 0364 BCF LCD_CNTL, E
0082 0008 0365 RETURN
0366 ;
0367 endif
0368 else
0369 ;
0370 ;**************************************************************
0371 ;* SEND_CND - Sends command contained in register W to LCD *
0372 ;* This routine sends the entire character to the PORT *
0373 ;* The data is transmitted on the PORT<7:0> pins *
DS00587A-page 39
Interfacing to an LCD Module
3
0374 ;**************************************************************
0375
0376 SEND_CMD
0377 MOVWF CHAR ; Command to be sent is in W
0378 CALL BUSY_CHECK ; Wait for LCD to be ready
0379 MOVF CHAR, w
0380 MOVWF LCD_DATA ; Send data to LCD
DS00587A-page 40
0381 BCF LCD_CNTL, R_W ; Set LCD in read mode
0382 BCF LCD_CNTL, RS ; Set LCD in command mode
0383 BSF LCD_CNTL, E ; toggle E for LCD
0384 BCF LCD_CNTL, E
0385 RETURN
0386 ;
0387 endif
0388 ;
0390 ;
0391 if ( Four_bit ) ; 4-bit Data transfers?
0392 ;
0393 if ( Data_HI ) ; 4-bit transfers on the high nibble of the PORT
0394 ;
0395 ;*******************************************************************
0396 ;* This routine checks the busy flag, returns when not busy *
0397 ;* Affects: *
0398 ;* TEMP - Returned with busy/address *
0399 ;*******************************************************************
3-88
0400 ;
Interfacing to an LCD Module
0401 BUSY_CHECK
0402 BSF STATUS, RP0 ; Select Register page 1
0403 MOVLW 0xFF ; Set Port_D for input
0404 MOVWF LCD_DATA_TRIS
0405 BCF STATUS, RP0 ; Select Register page 0
0406 BCF LCD_CNTL, RS ; Set LCD for Command mode
0407 BSF LCD_CNTL, R_W ; Setup to read busy flag
0408 BSF LCD_CNTL, E ; Set E high
0409 BCF LCD_CNTL, E ; Set E low
0410 MOVF LCD_DATA, W ; Read upper nibble busy flag, DDRam address
0411 ANDLW 0xF0 ; Mask out lower nibble
0412 MOVWF TEMP
0413 BSF LCD_CNTL, E ; Toggle E to get lower nibble
0414 BCF LCD_CNTL, E
0415 SWAPF LCD_DATA, w ; Read lower nibble busy flag, DDRam address
0416 ANDLW 0x0F ; Mask out upper nibble
0417 IORWF TEMP ; Combine nibbles
0418 BTFSC TEMP, 7 ; Check busy flag, high = busy
0419 GOTO BUSY_CHECK ; If busy, check again
0420 BCF LCD_CNTL, R_W
0421 BSF STATUS, RP0 ; Select Register page 1
0422 MOVLW 0x0F
3-89
008F 1005 0448 BCF LCD_CNTL, E
0090 0806 0449 MOVF LCD_DATA, W ; Read lower nibble busy flag, DDRam address
0091 390F 0450 ANDLW 0x0F ; Mask out upper nibble
0092 04B5 0451 IORWF TEMP, F ; Combine nibbles
0093 1BB5 0452 BTFSC TEMP, 7 ; Check busy flag, high = busy
0094 2883 0453 GOTO BUSY_CHECK ; If busy, check again
0095 1085 0454 BCF LCD_CNTL, R_W
0096 1683 0455 BSF STATUS, RP0 ; Bank 1
0097 30F0 0456 MOVLW 0xF0 ;
0098 0086 0457 MOVWF LCD_DATA_TRIS ; RB7 - 4 = inputs, RB3 - 0 = output
0099 1283 0458 BCF STATUS, RP0 ; Bank 0
009A 0008 0459 RETURN
0460 ;
0461 endif
0462 else
0463 ;
0464 ;**************************************************************
0465 ;* This routine checks the busy flag, returns when not busy *
0466 ;* Affects: *
0467 ;* TEMP - Returned with busy/address *
0468 ;**************************************************************
0469 ;
0470 BUSY_CHECK
DS00587A-page 41
Interfacing to an LCD Module
3
0471 BSF STATUS,RP0 ; Select Register page 1
0472 MOVLW 0xFF ; Set port_D for input
0473 MOVWF LCD_DATA_TRIS
0474 BCF STATUS, RP0 ; Select Register page 0
0475 BCF LCD_CNTL, RS ; Set LCD for command mode
0476 BSF LCD_CNTL, R_W ; Setup to read busy flag
0477 BSF LCD_CNTL, E ; Set E high
DS00587A-page 42
0478 BCF LCD_CNTL, E ; Set E low
0479 MOVF LCD_DATA, w ; Read busy flag, DDram address
0480 MOVWF TEMP
0481 BTFSC TEMP, 7 ; Check busy flag, high=busy
0482 GOTO BUSY_CHECK
0483 BCF LCD_CNTL, R_W
0484 BSF STATUS, RP0 ; Select Register page 1
0485 MOVLW 0x00
0486 MOVWF LCD_DATA_TRIS ; Set port_D for output
0487 BCF STATUS, RP0 ; Select Register page 0
0488 RETURN
0489 ;
0490 endif
0492 ;
0493 Table
009B 0782 0494 addwf PCL ;Jump to char pointed to in W reg
009C 344D 0495 retlw ‘M’
009D 3469 0496 retlw ‘i’
3-90
009E 3463 0497 retlw ‘c’
Interfacing to an LCD Module
3-91
0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX X———————
00C0 : ———————— ———————— ———————— ————————
Errors : 0
Warnings : 13
DS00587A-page 43
Interfacing to an LCD Module
3
APPENDIX E: LM032L.H
nolist
;******************************************************************************
;
; This is the custom Header File for the real time clock application note
DS00587A-page 44
; PROGRAM: CLOCK.H
; Revision: 5-10-94
;
;******************************************************************************
; This is used for the ASSEMBLER to recalculate certain frequency
; dependant variables. The value of Dev_Freq must be changed to
; reflect the frequency that the device actually operates at.
;
Dev_Freq EQU D’4000000' ; Device Frequency is 4 MHz
DB_HI_BYTE EQU (HIGH ((( Dev_Freq / 4 ) * 1 / D’1000' ) / 3 ) ) + 1
LCD_INIT_DELAY EQU (HIGH ((( Dev_Freq / 4 ) * D’46' / D’10000' ) / 3 ) ) + 1
INNER_CNTR EQU 40 ; RAM Location
OUTER_CNTR EQU 41 ; RAM Location
3-92
Interfacing to an LCD Module
list
3-93
DS00587A-page 45
Interfacing to an LCD Module
3
Interfacing to an LCD Module
NOTES:
3-94
WORLDWIDE SALES & SERVICE
AMERICAS AMERICAS (continued) EUROPE
Corporate Office San Jose United Kingdom
Microchip Technology Inc. Microchip Technology Inc. Arizona Microchip Technology Ltd.
2355 West Chandler Blvd. 2107 North First Street, Suite 590 Unit 6, The Courtyard
Chandler, AZ 85224-6199 San Jose, CA 95131 Meadow Bank, Furlong Road
Tel: 602 786-7200 Fax: 602 786-7277 Tel: 408 436-7950 Fax: 408 436-7955 Bourne End, Buckinghamshire SL8 5AJ
Technical Support: 602 786-7627 ASIA/PACIFIC Tel: 44 0 1628 851077 Fax: 44 0 1628 850259
Web: http://www.mchip.com/microhip France
Hong Kong
Atlanta Arizona Microchip Technology SARL
Microchip Technology 2 Rue du Buisson aux Fraises
Microchip Technology Inc. Unit No. 3002-3004, Tower 1
500 Sugar Mill Road, Suite 200B 91300 Massy - France
Metroplaza Tel: 33 1 69 53 63 20 Fax: 33 1 69 30 90 79
Atlanta, GA 30350 223 Hing Fong Road
Tel: 770 640-0034 Fax: 770 640-0307 Germany
Kwai Fong, N.T. Hong Kong
Boston Tel: 852 2 401 1200 Fax: 852 2 401 3431 Arizona Microchip Technology GmbH
Microchip Technology Inc. Gustav-Heinemann-Ring 125
Korea
5 Mount Royal Avenue D-81739 Muenchen, Germany
Microchip Technology Tel: 49 89 627 144 0 Fax: 49 89 627 144 44
Marlborough, MA 01752 168-1, Youngbo Bldg. 3 Floor
Tel: 508 480-9990 Fax: 508 480-8575 Italy
Samsung-Dong, Kangnam-Ku,
Chicago Seoul, Korea Arizona Microchip Technology SRL
Microchip Technology Inc. Tel: 82 2 554 7200 Fax: 82 2 558 5934 Centro Direzionale Colleoni
333 Pierce Road, Suite 180 Palazzo Pegaso Ingresso No. 2
Singapore
Itasca, IL 60143 Via Paracelso 23, 20041
Microchip Technology Agrate Brianza (MI) Italy
Tel: 708 285-0071 Fax: 708 285-0075 200 Middle Road
Dallas Tel: 39 039 689 9939 Fax: 39 039 689 9883
#10-03 Prime Centre
Microchip Technology Inc. Singapore 188980 JAPAN
14651 Dallas Parkway, Suite 816 Tel: 65 334 8870 Fax: 65 334 8850 Microchip Technology Intl. Inc.
Dallas, TX 75240-8809 Taiwan Benex S-1 6F
Tel: 214 991-7177 Fax: 214 991-8588 Microchip Technology 3-18-20, Shin Yokohama
Dayton 10F-1C 207 Kohoku-Ku, Yokohama
Microchip Technology Inc. Tung Hua North Road Kanagawa 222 Japan
35 Rockridge Road Taipei, Taiwan, ROC Tel: 81 45 471 6166 Fax: 81 45 471 6122
Englewood, OH 45322 Tel: 886 2 717 7175 Fax: 886 2 545 0139
Tel: 513 832-2543 Fax: 513 832-2841 9/22/95
Los Angeles
Microchip Technology Inc.
18201 Von Karman, Suite 455
Irvine, CA 92715
Tel: 714 263-1888 Fax: 714 263-1338
New York
Microchip Technology Inc.
150 Motor Parkway, Suite 416
Hauppauge, NY 11788
Tel: 516 273-5305 Fax: 516 273-5335