-
Notifications
You must be signed in to change notification settings - Fork 0
/
pins.inc
181 lines (121 loc) · 2.1 KB
/
pins.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
NOLIST
IFDEF GPIO
PORTA equ GPIO
ENDIF
_PortTotal = 0
IFDEF PORTA
_PortTotal = 1
ENDIF
IFDEF PORTB
_PortTotal = 2
ENDIF
IFDEF PORTC
_PortTotal = 3
ENDIF
IFDEF PORTD
_PortTotal = 4
ENDIF
IFDEF PORTE
_PortTotal = 5
ENDIF
IFDEF PORTF
_PortTotal = 6
ENDIF
OALLOC PORTABuf,_PortTotal
_PinBufOffset equ ((PORTABuf-PORTA)<<8)
_PortMask = 0
; Pin handling macros
; op is {clrb,setb,cplb,movb,movnotb,xorb,andb,iorb,andnotb,iornotb,xornotb}
WrPinBuf MACRO op,pin,bool
IF ((bool)==(-1))
op pin+_PinBufOffset
ELSE
op pin+_PinBufOffset,bool
ENDIF
_PortMask = _PortMask | ( 1 << ( high(pin) - PORTA ) )
ENDM
ClrPinBuf MACRO pin
WrPinBuf clrb,pin,-1
ENDM
SetPinBuf MACRO pin
WrPinBuf setb,pin,-1
ENDM
CplPinBuf MACRO pin
WrPinBuf movnotb,pin,pin+_PinBufOffset
ENDM
AndPinBuf MACRO pin,bool
WrPinBuf andb,pin,bool
ENDM
AndnotPinBuf MACRO pin,bool
WrPinBuf andnotb,pin,bool
ENDM
IorPinBuf MACRO pin,bool
WrPinBuf iorb,pin,bool
ENDM
IornotPinBuf MACRO pin,bool
WrPinBuf iornotb,pin,bool
ENDM
XorPinBuf MACRO pin,bool
WrPinBuf xorb,pin,bool
ENDM
XornotPinBuf MACRO pin,bool
WrPinBuf xornotb,pin,bool
ENDM
MovPinBuf MACRO pin,bool
WrPinBuf movb,pin,bool
ENDM
MovnotPinBuf MACRO pin,bool
WrPinBuf movnotb,pin,bool
ENDM
WritePinBuffer MACRO pin
mov high(pin),high((pin)+_PinBufOffset)
ENDM
WritePortBuffers MACRO
LOCAL _PortN
_PortN = PORTA
WHILE ( _PortMask )
IF ( _PortMask & 1 )
WritePinBuffer _PortN << BITSPERBYTE
ENDIF
_PortMask = _PortMask >> 1
_PortN = _PortN + 1
ENDW
ENDM
WrPin MACRO op,pin,bool
WrPinBuf op,pin,bool
WritePortBuffers
ENDM
ClrPin MACRO pin
WrPin clrb,pin,-1
ENDM
SetPin MACRO pin
WrPin setb,pin,-1
ENDM
CplPin MACRO pin
WrPin movnotb,pin,pin+_PinBufOffset
ENDM
; Pins direction handling
SelectTRISBank MACRO
bsf STATUS,RP0
ENDM
UnselectTRISBank MACRO
bcf STATUS,RP0
ENDM
_TurnIn MACRO pin
setb pin
ENDM
_TurnOut MACRO pin
clrb pin
ENDM
WrPinTRIS MACRO op,pin
SelectTRISBank
op pin
UnselectTRISBank
ENDM
TurnIn MACRO pin
WrPinTRIS _TurnIn,pin
ENDM
TurnOut MACRO pin
WrPinTRIS _TurnOut,pin
ENDM
LIST