forked from TG9541/stm8ef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboardcore.inc
143 lines (119 loc) · 3.4 KB
/
boardcore.inc
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
; W1209-CA-V2 STM8S device dependent HW routines
; BOARDINIT ( -- )
; Init board GPIO (except COM ports)
BOARDINIT:
; Board I/O initialization
; W1209 STM8S003F3 init GPIO
MOV PA_DDR,#0b00001110 ; d3,d2,d1
MOV PA_CR1,#0b00001110
MOV PB_DDR,#0b00110000 ; A,F
MOV PB_CR1,#0b00110000
MOV PC_DDR,#0b11111000 ; D,DP,C,G,B
MOV PC_CR1,#0b11111000 ;
MOV PD_DDR,#0b00000110 ; set,+,-, adc,E,relay
MOV PD_CR1,#0b11110111
.ifne HAS_OUTPUTS
CLR A
JRA AOUTSTOR
.else
RET
.endif
;===============================================================
.ifne HAS_LED7SEG
; LED_MPX driver ( -- )
; Output bit pattern in A to 7S-LED digit hardware
; Common Anode display:
; Digits - active high
; Segments - active low
LED_MPX:
BRES PA_ODR,#3 ; Digit .3..
BRES PA_ODR,#2 ; Digit ..2.
BRES PA_ODR,#1 ; Digit ...1
LD A,TICKCNT+1
AND A,#0x03 ; 3 digits MPX
JRNE 1$
BSET PA_ODR,#1 ; digit .3..
JRA 3$
1$: CP A,#1
JRNE 2$
BSET PA_ODR,#2 ; digit ..2.
JRA 3$
2$: CP A,#2
JRNE 4$
BSET PA_ODR,#3 ; digit ...1
; fall through
3$: CLRW X
LD XL,A
LD A,(LED7LAST-2,X)
CPL A ; invert bits for active low
; W1209 7S LED display row
; bit 76543210 input (parameter A)
; PB ..BF....
; PC CG......
; PD ..A.DPE.
RRC A
BCCM PB_ODR,#5 ; A
RRC A
BCCM PC_ODR,#3 ; B
RRC A
BCCM PC_ODR,#5 ; C
RRC A
BCCM PC_ODR,#7 ; D
RRC A
BCCM PD_ODR,#2 ; E
RRC A
BCCM PB_ODR,#4 ; F
RRC A
BCCM PC_ODR,#4 ; G
RRC A
BCCM PC_ODR,#6 ; P
4$: RET
.endif
;===============================================================
.ifne HAS_OUTPUTS
RamWord OUTPUTS ; "OUT", e.g. relays, LEDs, etc. (16 bit)
; OUT! ( c -- )
; Put c to board outputs, storing a copy in OUTPUTS
.dw LINK
LINK = .
.db (4)
.ascii "OUT!"
OUTSTOR:
INCW X
LD A,(X)
INCW X
AOUTSTOR:
LD OUTPUTS+1,A
RRC A
BCCM PD_ODR,#1 ; W1209 relay
RET
.endif
;===============================================================
.ifne HAS_KEYS
; BKEY ( -- c ) ( TOS STM8: -- A,Z,N )
; Read board key state as a bitfield
.dw LINK
LINK = .
.db (4)
.ascii "BKEY"
BKEY:
; Keys "set" (1), "+" (2), and "-" (4) on PC.3:5 (PD 6,5,4)
LD A,PD_IDR
; SLA A
SWAP A
CPL A
AND A,#0x07
JP ASTOR
; BKEYC ( -- c ) ( TOS STM8: -- A,Z,N )
; Read and translate board dependent key bitmap into char
.dw LINK
LINK = .
.db (5)
.ascii "BKEYC"
BKEYCHAR:
CALLR BKEY
JREQ 1$
ADD A,#'@'
LD (1,X),A
1$: RET
.endif