Professional Documents
Culture Documents
2MHz Clock
;LCD Registers addresses LCD_CMD_WR equ LCD_DATA_WR equ LCD_BUSY_RD equ LCD_DATA_RD equ 0 1 2 3
;LCD Commands LCD_CLS LCD_HOME equ equ 2 4 8 16 equ equ equ 32 64 128 1
string1a:db ' !! A M A Z I N G !! ' db 0 string1b:db '!! A M A Z I N G !! ' db 0 string2:db ' A virtual LM032L... ' db 0
start:
loop:
;Clear screen
;Clear screen
djnz R7,loop2
;Clear screen
;Clear screen
jmp loop
;Sub routine to write null terminated string at DPTR in program ram. wrstr: mov R0,#LCD_DATA_WR wrstr1: clr A movc A,@A+DPTR jz wrstr2 movx @R0,A call wtbusy inc DPTR push DPL push DPH pop DPH pop DPL jmp wrstr1 wrstr2: ret
;Sub routine to write null terminated string at DPTR in program ram. Slowly
wrslow: mov R0,#LCD_DATA_WR wrslw1: clr A movc A,@A+DPTR jz wrslw2 movx @R0,A call wtbusy inc DPTR push DPL push DPH mov DPTR,#100 call wtms pop DPH pop DPL jmp wrslw1 wrslw2: ret
;Sub routine to write command: wrcmd: mov R0,#LCD_CMD_WR movx @R0,A jmp wtbusy
movx @R0,A
;Subroutine to wait for busy clear wtbusy: mov R1,#LCD_BUSY_RD movx A,@r1 jb ACC.7,wtbusy ret
;Wait for number of seconds in A wtsec: push ACC call wtms pop ACC dec A jnz wtsec ret
;Wait for number of milliseconds in DPTR wtms: xrl DPL,#0FFh xrl DPH,#0FFh inc DPTR wtms1: mov TL0,#09Ch mov TH0,#0FFh mov TMOD,#1 setb TCON.4 wtms2: jnb TCON.5,wtms2 ;Timer 0 mode 1 ;Timer 0 runs ;100 ticks before overflow = 1ms at 1.2MHz Clock ;Can't do DEC DPTR, so do the loop by forming 2's complement ;and incrementing instead.
clr TCON.4 clr TCON.5 inc DPTR mov A,DPL orl A,DPH jnz wtms1 ret
;Timer 0 stops
END
1. $MOD51 ; instructions for assembler 2. 3. ; variables 4. ARED equ P1.0 5. AYEL equ P1.1 6. AGRE equ P1.2 7. BRED equ P1.3 8. BYEL equ P1.4 9. BGRE equ P1.5 10. 11. ORG 0000H 12. LJMP BEGGIN 13. ORG 0030H 14. 15. BEGGIN: 16. LCALL CLEARALL 17. SJMP MAIN 18. 19. MAIN: 20. LCALL SIT1 21. LCALL SIT3 22. LCALL SIT2 23. LCALL SIT4 24. SJMP MAIN 25. 26. ; the four possible situations 27. SIT1: 28. SETB ARED 29. SETB BGRE 30. MOV R0, #0AH ; 10 seconds 31. LCALL WAIT 32. LCALL CLEARALL 33. RET
lcd_datadisplay: // this is a part of main program call sub routine, the function of
this sub routine is to display //data on lcd. SETB RS //Telling the LCD that the data which is being send is to be displayed MOV P1,A //Character to be displayed is in Acc SETB EN // the enable pin of lcd is set to logic one CLR EN //High to Low pulse on EN to latch the data CALL DELAY //Delay so that LCD finishes its internal operations ret // return from this routine is called
Initialization of LCD
initialization: // in this sub-routine initialization of LCD is described mov A, #38H ; Initialize, 2-lines, 5X7 matrix. lcall Command mov A, #0EH ; LCD on, cursor on lcall Command mov A, #01H ; Clear LCD Screen lcall Command mov A, #06H ; Shift cursor right lcall Command
Display clear
clear: // this is sub-routine to clear the display of LCD setb p3.7 ;enable EN clr 3.6 ;RS=0 for cmd. mov DATA,#01h clr p3.7 ;disable EN lcall ready RET Note- As we need to clear the LCD frequently and not the whole initialisation , it is better to use this routine separately.
mov A,#'F' lcall data mov A,#'r' lcall data lcall data mov A,#'i' lcall data mov A,#'e' lcall data mov A,#'n' lcall data mov A,#'d' lcall data mov A,#'s' ret
Program.
MOV A,#38H // Use 2 lines and 5x7 matrix ACALL CMND MOV A,#0FH // LCD ON, cursor ON, cursor blinking ON ACALL CMND MOV A,#01H //Clear screen ACALL CMND MOV A,#06H //Increment cursor ACALL CMND MOV A,#82H //Cursor line one , position 2 ACALL CMND MOV A,#3CH //Activate second line ACALL CMND MOV A,#49D ACALL DISP MOV A,#54D ACALL DISP MOV A,#88D ACALL DISP MOV A,#50D ACALL DISP MOV A,#32D ACALL DISP MOV A,#76D ACALL DISP MOV A,#67D
MOV A,#0C1H //Jump to second line, position 1 ACALL CMND MOV A,#67D ACALL DISP MOV A,#73D ACALL DISP MOV A,#82D ACALL DISP MOV A,#67D ACALL DISP MOV A,#85D ACALL DISP MOV A,#73D ACALL DISP MOV A,#84D ACALL DISP MOV A,#83D ACALL DISP MOV A,#84D ACALL DISP MOV A,#79D ACALL DISP MOV A,#68D ACALL DISP MOV A,#65D ACALL DISP MOV A,#89D ACALL DISP HERE: SJMP HERE CMND: MOV P1,A CLR P3.5 CLR P3.4 SETB P3.3 CLR P3.3 ACALL DELY RET;
DISP:MOV P1,A SETB P3.5 CLR P3.4 SETB P3.3 CLR P3.3 ACALL DELY RET; DELY: CLR P3.3 CLR P3.5 SETB P3.4 MOV P1,#0FFh SETB P3.3 MOV A,P1 JB ACC.7,DELY CLR P3.3 CLR P3.4 RET;
END
http://www.circuitstoday.com/interfacing-16x2-lcd-with-8051