-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcd.fs
116 lines (90 loc) · 1.97 KB
/
lcd.fs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
\ simple LCD HD44780 interface
\ needs the following includes:
\ ./lib/ans94/core-ext/marker.frt
\ lib/bitnames.frt
marker lcd:forth:ifs
PORTD 3 portpin: pin:lcd:enable
PORTD 2 portpin: pin:lcd:rs
: init:lcd:pins
pin:lcd:enable pin_output
pin:lcd:enable low
pin:lcd:rs pin_output
pin:lcd:rs low
DDRD c@ %11110000 OR DDRD c!
;
: nop \ wait a short delay...
;
: lcd:enable \ pulse the Enable pin
pin:lcd:enable high
\ 10 0 do nop loop \ wait a short time...
1ms
pin:lcd:enable low
;
: delay5ms
5 0 ?do 1ms loop
;
: write-hnibble ( n -- )
\ set lower nibble to 0
$F0 AND
PORTD c@ $F AND \ get current PORTD setting and set high nibble to 0
\ combine high and low nibble and write it to port
OR PORTD C!
lcd:enable
;
: write-byte ( n -- )
dup write-hnibble
1ms
4 LSHIFT
write-hnibble
1ms
;
: lcd:command ( n -- )
pin:lcd:rs low
write-byte
;
: lcd:data ( n -- )
pin:lcd:rs high
write-byte
;
: lcd:init
init:lcd:pins
delay5ms
\ write 0011 to the High nible of PORTD 3 times
3 0 ?do
PORTD c@ %00001111 AND \ fetch PORTD and set high nibble to 0000
%00110000 OR PORTD c! \ set high nibble to 0010 and leave low nibble untouched
lcd:enable
delay5ms
loop
\ 4 Bit Mode --> set high nibble to 0010
PORTD c@ %00001111 AND \ fetch PORTD and set high nibble to 0000
%00100000 OR PORTD c! \ set high nibble to 0010 and leave low nibble untouched
lcd:enable
delay5ms
\ 4 Bit, zwei Zeilen, 5x8
%00101000 lcd:command
delay5ms
%00001100 lcd:command \ Display ein / Cursor aus / kein Blinken
delay5ms
%00000100 lcd:command \ kein increment, kein scrollen.
delay5ms
;
: lcd:string ( caddr u -- )
0 ?do
dup I + c@ lcd:data
loop
drop
;
: lcd:home
%10 lcd:command
;
: lcd:clear
1 lcd:command
;
\ display string from flash
: lcd:istring ( caddr u -- )
0 ?do
dup I + @I lcd:data
loop
drop
;