-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcd_s.s
90 lines (70 loc) · 1.71 KB
/
lcd_s.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
; ======
; lcd.s
; ======
;
; LCD hardware routines
.include "athena.inc"
.PC02
.export _lcd_init
.export _lcd_cmd
.export _lcd_putc
.define LCD_E %10000000
.define LCD_RW %01000000
.define LCD_RS %00100000
.segment "CODE"
; void lcd_init(void)
.proc _lcd_init: near
lda #$FF ; Set all pins on port B_2 to output
sta VIA2_DDRB
lda #%11100000 ; Set top 3 pins on port A_2 to output
sta VIA2_DDRA
lda #%00111000 ; Set 8-bit mode; 2-line display; 5x8 font
jsr _lcd_cmd
lda #%00001110 ; Display on; cursor on; blink off
jsr _lcd_cmd
lda #%00000110 ; Increment and shift cursor; don't shift display
jsr _lcd_cmd
lda #$00000001 ; Clear display
jsr _lcd_cmd
rts
.endproc
; void lcd_cmd(char)
.proc _lcd_cmd: near
jsr lcd_wait ; Ensure not busy
sta VIA2_PORTB ; Set command on data lines
stz VIA2_PORTA ; RS=RW=E=0
lda #LCD_E ; RS=0 RW=0; E=1 to send instruction
sta VIA2_PORTA
stz VIA2_PORTA ; RS=RW=E=0
rts
.endproc
; void lcd_putc(char)
.proc _lcd_putc: near
jsr lcd_wait
sta VIA2_PORTB
lda #LCD_RS
sta VIA2_PORTA
lda #(LCD_RS | LCD_E)
sta VIA2_PORTA
lda #LCD_RS
sta VIA2_PORTA
rts
.endproc
.proc lcd_wait: near
pha
stz VIA2_DDRB ; Set port B to input
lcdbusy:
lda #LCD_RW ; RW=1 E=0
sta VIA2_PORTA
lda #(LCD_RW | LCD_E) ; RW=1 E=1
sta VIA2_PORTA
lda VIA2_PORTB ; Read D7-D0
and #%10000000 ; Test for busy flag
bne lcdbusy ; Loop if busy flag set
lda #LCD_RW ; RW=1 E=0
sta VIA2_PORTA
lda #$FF ; Restore Port B to output
sta VIA2_DDRB
pla
rts
.endproc