Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Phil Cranmer
- ; 16 July 2019
- ; 1602 LCD
- ; RS - Register select : 0 = Instruction, 1 = Data ( PA3 )
- ; Data - D4, D5, D6 & D7 : 4 bit data ( PA4, PA5, PA6 & PA7 )
- ; to set up 2 line 4-bit : 0x00 | 0x08 | 0x00
- ; LED1|LED2|Enable|RS|D4|D5|D6|D7
- INIT: jp START
- push af
- pop af
- DLY: ld b,10
- DLP: nop
- djnz DLP
- ret
- DLYBG: ld B,100 ; Load in 10
- BLP: nop
- djnz BLP
- ret
- LCMD: ; send command in a
- push af ; save a copy
- push af ; and another
- and 0xF0 ; remove lower nibble and send it
- out (0x01),a
- xor %00000101
- out (0x01),a
- xor %00000101
- out (0x01),a
- pop af ; fetch original value back
- sla a ; scoot it over 4 places
- sla a
- sla a
- sla a
- and 0xF0 ; remove lower nibble and send it
- out (0x01),a
- xor %00000101
- out (0x01),a
- xor %00000101
- out (0x01),a
- pop af ; fetch back initial value before returning
- nop
- nop
- nop
- nop
- nop
- ret
- LDAT: ; send data in a
- push af ; save a copy
- push af ; and another
- and 0xF0 ; remove lower nibble and send it
- xor %00001000 ; set LCD to data mode (RS)
- out (0x01),a
- xor %00000101
- out (0x01),a
- xor %00000101
- out (0x01),a
- pop af ; fetch original value back
- sla a ; scoot it over 4 places
- sla a
- sla a
- sla a
- and 0xF0 ; remove lower nibble and send it
- out (0x01),a
- xor %00001101
- out (0x01),a
- xor %00001101
- out (0x01),a
- pop af ; fetch back initial value before returning
- nop
- nop
- nop
- nop
- nop
- ret
- START: ld a,0xFF ; Load 255 into acc
- out (0x02),a ; Port B all outputs
- out (0x03),a ; Port A all outputs
- BLNK: ld a,0x01 ; Load 1 into acc
- out (0x01),a ; Turn on 1 output on port A
- call DLY
- ld a,0x00 ; Load 0 into acc
- out (0x01),a ; Turn off all output on port A
- call DLY
- ; setup 4-bit mode
- ld a,0x02
- call LCMD
- call LCMD
- call LCMD
- call LCMD
- ;ld a,%00100000
- ;call LCMD
- ;0x08 | 0x02 - send lines, font etc.
- ld a,0x28
- call LCMD
- ; 0x04 | 0x02 | 0x0 - Display on, cursor off, blink off
- ld a,0x0E
- call LCMD
- ;; 0x00 | 0x02 | 0x04 - default text direction
- ;ld a,%01100000
- ; Clear
- ld a,0x01
- call LCMD
- ; Move cursor to start
- ld a,0x80
- call LCMD
- ; Send some text
- ld a,'H'
- call LDAT
- ld a,'e'
- call LDAT
- ld a,'l'
- call LDAT
- ld a,'l'
- call LDAT
- ld a,'o'
- call LDAT
- LOOP: nop
- jp LOOP
- ; Call - go to sub routine
- ; RET - return
- ; DJNZ - Dec, jump not zero
- ; 10 = Dec, 0xA = Hex & %1010 = binary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement