| ??? 12/18/03 00:07 Read: times |
#60908 - RE: lcd init routine:urgent Responding to: ???'s previous message |
Hello!
Follow this routine. The LCD module is attached to P1 Port. ; ROUTINES FOR DRIVING LCD DISPLAY WITH 8051 ; by CHRIS BURIAN LCD_PORT EQU P1 LCD_E EQU P1.2 R_MASK EQU 00000000b ;register access S_MASK EQU 00001000b ;DD/CG RAM access LOW_MASK EQU 11110000b ;mask out low nybble CLS EQU 00000001b D_SET EQU 00001000b ;display on/off control E_SET EQU 00000100b ;entry mode control F_SET EQU 00100000b ;function set D_D_ON EQU 00000100b ;display on D_D_OFF EQU 00000000b ;display off D_C_ON EQU 00000010b ;cursor on D_C_OFF EQU 00000000b ;cursor off D_B_ON EQU 00000001b ;blink on (blinking solid box) D_B_OFF EQU 00000000b ;blink off (solid underscore) E_S_NO EQU 00000000b ;entry mode--don't shift E_S_YES EQU 00000001b ;entry mode--shift display E_C_INC EQU 00000010b ;cursor move right E_C_DEC EQU 00000000b ;cursor move left F_8BIT EQU 00010000b ;8-bit interface F_4BIT EQU 00000000b ;4-bit interface (D7-D0) F_2LINE EQU 00001000b ;2-line display F_1LINE EQU 00000000b ;1-line display F_8FONT EQU 00000000b ;font for 5x8 matrix F_11FONT EQU 00000100b ;font for 5x11 matrix CG_ADDR EQU 01000000b DD_ADDR EQU 10000000b ;transmit nybble to LCD LCD_OUT: MOV LCD_PORT,A ;set up data and RS lines SETB LCD_E ;toggle Enable pin CLR LCD_E RET ;send character in ACC to LCD CHAR_OUT: push ACC PUSH ACC ;store the byte ANL A,#LOW_MASK ;mask out low nybble ORL A,#S_MASK ;set RS=1 ACALL LCD_OUT ;send high order nybble of char POP ACC ;get low order nybble SWAP A ;move to high nybble ANL A,#LOW_MASK ;mask out low nybble ORL A,#S_MASK ;set RS=1 ACALL LCD_OUT ;send low order nibble of char ACALL WAIT_40U ;pause for 40us POP ACC RET ;send command in ACC to LCD COMD_OUT: PUSH ACC ;store the byte ANL A,#LOW_MASK ;mask out low nybble ORL A,#R_MASK ;set RS=0 ACALL LCD_OUT ;send high order nybble of command POP ACC ;get low order nybble SWAP A ;move to high nybble ANL A,#LOW_MASK ;mask out low nybble ORL A,#R_MASK ;set RS=0 ACALL LCD_OUT ;send low order nybble of command ACALL WAIT_40U ;pause for 40us RET ;initialize the LCD INIT_LCD: MOV A, #150 ;pause for 15ms ACALL WAIT MOV A, #(F_SET OR F_8BIT) ;set 8-bit mode ACALL LCD_OUT ;send to LCD MOV A, #41 ;pause for 4.1ms ACALL WAIT MOV A, #(F_SET OR F_8BIT) ;set 8-bit mode ACALL LCD_OUT ;send to LCD MOV A, #1 ;pause for 100us ACALL WAIT MOV A, #(F_SET OR F_8BIT) ;set 8-bit mode ACALL LCD_OUT ;send to LCD MOV A, #41 ;pause for 4.1ms ACALL WAIT MOV A, #(F_SET OR F_4BIT) ;set 4-bit mode ACALL LCD_OUT ;send to LCD ACALL WAIT_40U ;pause for 40us MOV A, #(F_SET OR F_4BIT OR F_2LINE OR F_8FONT) ACALL COMD_OUT ;set 4-bit, 2-line, 5x8 font MOV A, #(D_SET OR D_D_OFF OR D_C_OFF OR D_B_OFF) ACALL COMD_OUT ;display, cursor, blink off MOV A, #(D_SET OR D_D_ON OR D_C_OFF OR D_B_OFF) ACALL COMD_OUT ;display, underscore cursor on MOV A, #(E_SET OR E_S_NO OR E_C_INC) ACALL COMD_OUT ;cursor moves right, no shift RET ;initialization complete ; send a message string to the LCD, first letter of msg in DPTR PRINT_LCD: MOV A,#0 ;clear ACC MOVC A,@A+DPTR ;fetch letter INC DPTR CJNE A,#16,PR_1 ;strings end with 16, SJMP PR_DONE ;finished PR_1: ACALL CHAR_OUT ;send letter to LCD SJMP PRINT_LCD ;repeat loop PR_DONE: RET ; program character generator RAM PROG_LCD: PUSH 1 ;save register R1 MOV R1,#8 ;8 bytes in a character RL A RL A ;multiply char # by 8 to RL A ;get CG RAM address ORL A, #CG_ADDR ;set addr command ACALL COMD_OUT ;send to LCD PG_1: MOV A, #0 ;clear ACC MOVC A, @A+DPTR ;fetch row INC DPTR ACALL CHAR_OUT ;send row to LCD ACALL WAIT_40U ;pause extra 80us ACALL WAIT_40U DJNZ R1, PG_1 ;send 8 rows total POP 1 ;restore register R1 MOV A, #DD_ADDR ;go back to display RAM ACALL COMD_OUT ;send to LCD RET ;40 microsecond delay, assumes 11MHz clock WAIT_40U: PUSH 1 ;save register R1 MOV R1,#19 ;19 DJNZ instr = 40us DJNZ R1,$ POP1 ;restore register R1 RET WAITB: PUSH 1 ;save register R1 WAITLPB: MOV R1, #241 ;50 DJNZ instr = 100us DJNZ R1, $ DJNZ ACC, WAITLPB WAITLPC: MOV R1, #241 ;50 DJNZ instr = 100us DJNZ R1, $ DJNZ ACC, WAITLPC POP ;restore register R1 RET ; ACC*100us delay, assumes 11MHz clock WAIT: PUSH 1 ;save register R1 WAITLP: MOV R1, #46 DJNZ R1, $ DJNZ ACC, WAITLP POP 1 ;restore register R1 RET WAIT_1S: MOV A,#250 ACALL WAITB MOV A,#250 ACALL WAITB MOV A,#250 ACALL WAITB MOV A,#250 ACALL WAITB RET WAIT_4S: ACALL WAIT_1S ACALL WAIT_1S ACALL WAIT_1S ACALL WAIT_1S RET PRINT_VAL: PUSH B MOV A,B MOV B,#100 DIV AB PUSH B MOV B,A MOV A, #0 ADD A,B MOVC A, @A+DPTR ;fetch letter ACALL CHAR_OUT ;send letter to LCD POP ACC MOV B,#10 DIV AB PUSH B MOV B,A MOV A, #0 ADD A,B MOVC A, @A+DPTR ;fetch letter ACALL CHAR_OUT ;send letter to LCD POP B MOV A, #0 ADD A,B MOVC A, @A+DPTR ;fetch letter ACALL CHAR_OUT ;send letter to LCD POP B RET |
| Topic | Author | Date |
| lcd init routine:urgent | 01/01/70 00:00 | |
| RE: lcd init routine:urgent | 01/01/70 00:00 | |
| RE: lcd init routine:urgent | 01/01/70 00:00 | |
| RE: lcd init routine:urgent | 01/01/70 00:00 | |
| RE: lcd init routine:urgent | 01/01/70 00:00 | |
RE: lcd init routine:urgent | 01/01/70 00:00 |



