You are on page 1of 5

;=================================== ; *** LCD support routines *** ;=================================== ;#include <sfr51.

inc> ;inisialisasi port LCD ;LCDPort Data P0 ;inisialisasi bit-bit port LCD LCDrs Bit LCDPort.0 LCDrw Bit LCDPort.1 LCDen Bit LCDPort.2 Line1 Line2 equ equ 80h 0C0h

;LCD connection port

;LCD rs pin connected to P0.0 ;LCD r/w pin connected to P0.1 ;LCD e pin connected to P0.2

cseg ;================================================ ;initialize LCD module LCDinit: mov LCDPort, #0 ;Pull all pins low mov rdelay, #15 ;Wait at least 15 mS at power up acall delay ;LCD specs call for 3 repetitions as follows: ;first rep mov LCDPort, #30h ;to 8-bit mode setb LCDen ;Toggle enable line nop nop nop clr LCDen mov rdelay, #5 ;Wait at least 5 mS acall delay ;second rep mov setb nop nop nop clr acall ;third rep mov setb nop nop nop LCDPort, #30h LCDen ;to 8-bit mode ;Toggle enable line LCDPort, #30h LCDen ;to 8-bit mode ;Toggle enable line

LCDen delay1ms

clr

LCDen

;Now change to 4-wire interface mode mov LCDPort, #20h setb LCDen nop nop nop clr LCDen

;Function set, 4 wire databus ;Toggle enable line

;Finally, at this point, ;the normal 4 wire command routine (LCDcmd) can be used mov a, #00101000b ;Function set, 4 wire, 2 line, 5x7 font acall LCDcmd ;tadinya 1 line, skrg dicoba 2 line mov a, #00001100b ;Display on, cursor off, blink off acall LCDcmd mov a, #00000110b ;Address increment, no scrolling acall LCDcmd ret ;================================================ ;Routine meng-On-kan BLINK BlinkOn: push acc mov a, #00001101b acall LCDcmd pop acc ret ;================================================ ;Routine meng-Off-kan BLINK BlinkOff: push acc mov a, #00001100b acall LCDcmd pop acc ret ;================================================ ;Routine menghapus seluruh karakter di LCD LCDclr: push acc mov a, #1 ;Clear LCD command acall LCDcmd mov rdelay, #3 ;Delay 3 mS for clear command acall delay pop acc ret ;============================================ ;Wait for LCD to go unbusy

LCDwait: mov setb clr Waitloop: setb nop nop nop clr nop nop nop LCDen ;Toggle enable line LCDPort, #0 LCDrw ;Set r/w pin to read LCDrs ;Set register select to command

LCDen

;Read, and ignore lower nibble setb LCDen ;Toggle enable lmove nop nop nop clr LCDen jb LCDPort.7, waitloop ;Loop until done ret ;============================================= ;Send command in a to LCD LCDcmd: push acc acall LCDwait push acc anl a, #0F0h ;Strip off upper bits mov LCDPort, a ;Put on port nop ;wait for data setup time setb LCDen ;Toggle enable lmove nop nop nop clr LCDen pop acc swap a ;Get upper nibble anl a, #0F0h ;Strip off upper bits mov LCDPort, a ;Put on port nop setb LCDen ;Toggle enable lmove nop nop nop clr LCDen pop acc ret

;============================================= ;Send character data in a to LCD LCDPutCh: push acc acall LCDwait push acc anl a, #0F0h ;Strip off upper bits mov LCDPort, a ;Put on port nop setb LCDrs ;Register select set for data setb LCDen ;Toggle enable lmove nop nop nop clr LCDen pop acc swap a ;Get upper nibble anl a, #0F0h ;Strip off upper bits mov LCDPort, a ;Put on port nop setb LCDrs ;Register select set for data setb LCDen ;Toggle enable lmove nop nop nop clr LCDen pop acc ret ;================================================ ;Routine pengiriman strings LCDPutStr: push acc StrLoop: clr a movc a, @a+dptr ;Mengirimkan strings yang ada di DPTR cjne a, #0, NextCh sjmp DoneStr NextCh: acall inc sjmp DoneStr: pop ret acc LCDPutCh dptr StrLoop

;================================================ ;Routine pengiriman data Decimal ke LCD Dec2LCD:

push ;mov acall mov acall mov acall mov acall pop ret

acc MathBuffer, a Dec2ASCII a, ASCIIhi LCDPutCh a, ASCIImid LCDPutCh a, ASCIIlo LCDPutCh acc

;================================================ ;Routine pengiriman data BCD ke LCD BCD2LCD: push acc ;mov MathBuffer, a acall BCD2ASCII mov a, ASCIIhi acall LCDPutCh mov a, ASCIIlo acall LCDPutCh pop acc ret ;================================================ ;Routine pengiriman data Hexadecimal ke LCD Hex2LCD: push acc ;mov MathBuffer, a acall Hex2ASCII mov a, ASCIIhi acall LCDPutCh mov a, ASCIIlo acall LCDPutCh pop acc ret ;end ; ---------------- (end of program) ------------------

You might also like