| ??? 11/25/07 22:42 Read: times |
#147386 - Some code shortening: Responding to: ???'s previous message |
LCD_DAT equ 0A0H ;P2 RS equ 0A3H ;P2.3 EN equ 0A0H ;P2.0 Delay50us: ;1+1+R7*2+2 MC =1+1+23*2+2 = 50 MC = 50 us MOV R7, #023 ;1 MC NOP ;1 MC DJNZ R7, $ ;R7*2 MC RET ;2 MC INIT_LCD: ;-------15 ms Startup Delay--------------- MOV R5, #0150 INIT1: ACALL Delay50us ACALL Delay50us DJNZ R5, INIT1 ;-------FUnction Set 8bit----------------- CLR RS MOV A, #030h ; set to 8 bit interface, only D4-D7 connected acall wr_nibble ;-------4.1 ms Delay----------- MOV R5, #082 INIT2: ACALL Delay50us DJNZ R5, INIT2 ;-------FUnction Set 8bit----------------- MOV A, #030h ; set to 8 bit interface, only D4-D7 connected acall wr_nibble ;-------100us Delay------------ ACALL Delay50us ACALL Delay50us ;-------FUnction Set 8bit----------------- ; MOV A, #030h ; set to 8 bit interface, only D4-D7 connected acall wr_nibble ACALL Delay50us ;-------FUnction Set 4bit----------------- MOV A, #020h ; set to 4 bit interface, only D4-D7 connected acall wr_nibble ACALL Delay50us ;-------Normal settings------------------- MOV A, #028h ; function set: 4bits, 2 lines, 5x8 dots ACALL WRITE_CMD MOV A, #0Eh ; display on/off control: Display on, cursor on, blinking off ACALL WRITE_CMD MOV A, #06h ; entry mode set: increcement ACALL WRITE_CMD MOV A, #01h ; clear display ACALL WRITE_CMD RET WRITE_CMD: clr rs ;rs = 0 sjmp wr_byte WRITE_TEXT: setb rs ;rs = 1 wr_byte: acall wr_nibble ;d7..d4 swap a ;reverse nibbles acall wr_nibble ;d3..d0 ajmp delay50us wr_nibble: push acc anl LCD_DAT, #0Fh ;clear D7..D4 anl a, #0F0h ;mask LCD bits orl LCD_DAT, a ;set LCD setb en pop acc ;restore ACC clr en ret end I must remove "." from equ and append ":" to labels and rename DATA (reserved word), to assemble it with Keil A51. Maybe you must reverse these changes. Peter |
| Topic | Author | Date |
| 4 bit LCD trouble | 01/01/70 00:00 | |
| Possible Error | 01/01/70 00:00 | |
| DATA is port EN is pin | 01/01/70 00:00 | |
| Initialization | 01/01/70 00:00 | |
| I think I did initialize correct | 01/01/70 00:00 | |
| Logical operations | 01/01/70 00:00 | |
| Oops, should have been ANL BA | 01/01/70 00:00 | |
| Clobbering your data | 01/01/70 00:00 | |
| topic gone?? | 01/01/70 00:00 | |
| code library | 01/01/70 00:00 | |
| Try LCD Tutorial in tutorials section | 01/01/70 00:00 | |
| Tutorial uses 2 ports | 01/01/70 00:00 | |
| previous comments... | 01/01/70 00:00 | |
| All tested an nailed the problem | 01/01/70 00:00 | |
| yes, timing | 01/01/70 00:00 | |
Some code shortening: | 01/01/70 00:00 |



