Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Phil Cranmer
  2. ; 16 July 2019
  3.  
  4. ; 1602 LCD
  5. ; RS - Register select : 0 = Instruction, 1 = Data ( PA3 )
  6. ; Data - D4, D5, D6 & D7 : 4 bit data ( PA4, PA5, PA6 & PA7 )
  7.  
  8. ; to set up 2 line 4-bit : 0x00 | 0x08 | 0x00
  9. ; LED1|LED2|Enable|RS|D4|D5|D6|D7
  10.  
  11.  
  12. INIT:       jp START
  13.             push af
  14.             pop af
  15.  
  16. DLY:        ld b,10
  17. DLP:        nop
  18.             djnz DLP
  19.             ret
  20.          
  21. DLYBG:      ld B,100 ; Load in 10
  22. BLP:        nop
  23.             djnz BLP
  24.             ret
  25.  
  26. LCMD:       ; send command in a
  27.             push af ; save a copy
  28.             push af ; and another
  29.             and 0xF0 ; remove lower nibble and send it
  30.             out (0x01),a
  31.             xor %00000101
  32.             out (0x01),a
  33.             xor %00000101
  34.             out (0x01),a
  35.             pop af ; fetch original value back
  36.             sla a ; scoot it over 4 places
  37.             sla a
  38.             sla a
  39.             sla a
  40.             and 0xF0 ; remove lower nibble and send it
  41.             out (0x01),a
  42.             xor %00000101
  43.             out (0x01),a
  44.             xor %00000101
  45.             out (0x01),a
  46.             pop af ; fetch back initial value before returning
  47.             nop
  48.             nop
  49.             nop
  50.             nop
  51.             nop
  52.             ret
  53.  
  54. LDAT:       ; send data in a
  55.             push af ; save a copy
  56.             push af ; and another
  57.             and 0xF0 ; remove lower nibble and send it
  58.             xor %00001000 ; set LCD to data mode (RS)
  59.             out (0x01),a
  60.             xor %00000101
  61.             out (0x01),a
  62.             xor %00000101
  63.             out (0x01),a
  64.             pop af ; fetch original value back
  65.             sla a ; scoot it over 4 places
  66.             sla a
  67.             sla a
  68.             sla a
  69.             and 0xF0 ; remove lower nibble and send it
  70.             out (0x01),a
  71.             xor %00001101
  72.             out (0x01),a
  73.             xor %00001101
  74.             out (0x01),a
  75.             pop af ; fetch back initial value before returning
  76.             nop
  77.             nop
  78.             nop
  79.             nop
  80.             nop
  81.             ret
  82.  
  83. START:      ld a,0xFF ; Load 255 into acc
  84.             out (0x02),a ; Port B all outputs
  85.             out (0x03),a ; Port A all outputs
  86. BLNK:       ld a,0x01 ; Load 1 into acc
  87.             out (0x01),a ; Turn on 1 output on port A
  88.             call DLY
  89.             ld a,0x00 ; Load 0 into acc
  90.             out (0x01),a ; Turn off all output on port A
  91.             call DLY
  92.             ; setup 4-bit mode
  93.             ld a,0x02
  94.             call LCMD
  95.             call LCMD
  96.             call LCMD
  97.             call LCMD
  98.             ;ld a,%00100000
  99.             ;call LCMD
  100.             ;0x08 | 0x02  - send lines, font etc.
  101.             ld a,0x28
  102.             call LCMD
  103.             ; 0x04 | 0x02 | 0x0 - Display on, cursor off, blink off
  104.             ld a,0x0E
  105.             call LCMD
  106.             ;; 0x00 | 0x02 | 0x04 - default text direction
  107.             ;ld a,%01100000
  108.             ; Clear
  109.             ld a,0x01
  110.             call LCMD
  111.             ; Move cursor to start
  112.             ld a,0x80
  113.             call LCMD
  114.             ; Send some text
  115.             ld a,'H'
  116.             call LDAT
  117.             ld a,'e'
  118.             call LDAT
  119.             ld a,'l'
  120.             call LDAT
  121.             ld a,'l'
  122.             call LDAT
  123.             ld a,'o'
  124.             call LDAT
  125. LOOP:       nop
  126.             jp LOOP
  127.        
  128.        
  129.        
  130.  
  131.        
  132. ; Call - go to sub routine
  133. ; RET - return
  134. ; DJNZ - Dec, jump not zero
  135. ; 10 = Dec, 0xA = Hex & %1010 = binary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement