annotate src/mcp.asm @ 2:ab8a7c3f1db0

battery warning levels, max. brightnes setting
author heinrichsweikamp
date Sun, 05 May 2013 15:37:24 +0200
parents 11d4fc797f74
children fcaf94b913db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File mcp.asm
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Basic routines for RX circuity
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2012-08-12 : [mH] Creation
heinrichsweikamp
parents:
diff changeset
11
heinrichsweikamp
parents:
diff changeset
12
heinrichsweikamp
parents:
diff changeset
13 #include "ostc3.inc"
heinrichsweikamp
parents:
diff changeset
14 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
15
heinrichsweikamp
parents:
diff changeset
16 mcp_writebyte_1st macro char
heinrichsweikamp
parents:
diff changeset
17 movlw char
heinrichsweikamp
parents:
diff changeset
18 rcall mcp_write_one_byte
heinrichsweikamp
parents:
diff changeset
19 endm
heinrichsweikamp
parents:
diff changeset
20
heinrichsweikamp
parents:
diff changeset
21 mcp_writebyte_2nd macro char
heinrichsweikamp
parents:
diff changeset
22 movlw char
heinrichsweikamp
parents:
diff changeset
23 rcall mcp_write_one_byte2
heinrichsweikamp
parents:
diff changeset
24 endm
heinrichsweikamp
parents:
diff changeset
25
heinrichsweikamp
parents:
diff changeset
26 ; Writes mcp_temp+0 to config reg
heinrichsweikamp
parents:
diff changeset
27 mcp_write_config macro char
heinrichsweikamp
parents:
diff changeset
28 movlw char
heinrichsweikamp
parents:
diff changeset
29 rcall mcp_write_config_reg
heinrichsweikamp
parents:
diff changeset
30 endm
heinrichsweikamp
parents:
diff changeset
31
heinrichsweikamp
parents:
diff changeset
32 mcp code
heinrichsweikamp
parents:
diff changeset
33
heinrichsweikamp
parents:
diff changeset
34 mcp_write_one_byte:
heinrichsweikamp
parents:
diff changeset
35 movwf mcp_temp+0 ; save one byte
heinrichsweikamp
parents:
diff changeset
36 bcf TRISG,0 ; CLK output
heinrichsweikamp
parents:
diff changeset
37 nop
heinrichsweikamp
parents:
diff changeset
38 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
39 bsf mcp_ncs ; cs=1
heinrichsweikamp
parents:
diff changeset
40 nop
heinrichsweikamp
parents:
diff changeset
41 bcf mcp_ncs ; cs=0
heinrichsweikamp
parents:
diff changeset
42 bcf TRISB,3 ; mcp_lf_data output
heinrichsweikamp
parents:
diff changeset
43 movlw .8
heinrichsweikamp
parents:
diff changeset
44 movwf mcp_temp+1 ; Bit counter
heinrichsweikamp
parents:
diff changeset
45 mcp_write_one_byte_loop:
heinrichsweikamp
parents:
diff changeset
46 btfss mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
47 bcf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
48 btfsc mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
49 bsf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
50 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
51 rlncf mcp_temp+0,F ; shift byte left no carry
heinrichsweikamp
parents:
diff changeset
52 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
53 decfsz mcp_temp+1,F ; 8Bit done?
heinrichsweikamp
parents:
diff changeset
54 bra mcp_write_one_byte_loop ; Not yet...
heinrichsweikamp
parents:
diff changeset
55 return
heinrichsweikamp
parents:
diff changeset
56
heinrichsweikamp
parents:
diff changeset
57 mcp_write_one_byte2:
heinrichsweikamp
parents:
diff changeset
58 movwf mcp_temp+0 ; save one byte
heinrichsweikamp
parents:
diff changeset
59 movlw .8
heinrichsweikamp
parents:
diff changeset
60 movwf mcp_temp+1 ; Bit counter
heinrichsweikamp
parents:
diff changeset
61 mcp_write_one_byte_loop2:
heinrichsweikamp
parents:
diff changeset
62 btfss mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
63 bcf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
64 btfsc mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
65 bsf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
66 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
67 rlncf mcp_temp+0,F ; shift byte left no carry
heinrichsweikamp
parents:
diff changeset
68 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
69 decfsz mcp_temp+1,F ; 8Bit done?
heinrichsweikamp
parents:
diff changeset
70 bra mcp_write_one_byte_loop2; Not yet...
heinrichsweikamp
parents:
diff changeset
71 bsf TRISB,3 ; mcp_lf_data input again
heinrichsweikamp
parents:
diff changeset
72 bsf mcp_ncs ; cs=1
heinrichsweikamp
parents:
diff changeset
73 bsf TRISG,0 ; CLK input
heinrichsweikamp
parents:
diff changeset
74 return
heinrichsweikamp
parents:
diff changeset
75
heinrichsweikamp
parents:
diff changeset
76 mcp_readbyte:
heinrichsweikamp
parents:
diff changeset
77 bcf TRISG,0 ; CLK output
heinrichsweikamp
parents:
diff changeset
78 nop
heinrichsweikamp
parents:
diff changeset
79 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
80 bcf mcp_ncs ; cs=0
heinrichsweikamp
parents:
diff changeset
81 movlw .7
heinrichsweikamp
parents:
diff changeset
82 movwf mcp_temp+1 ; Bit counter
heinrichsweikamp
parents:
diff changeset
83 nop
heinrichsweikamp
parents:
diff changeset
84 nop
heinrichsweikamp
parents:
diff changeset
85 mcp_readloop:
heinrichsweikamp
parents:
diff changeset
86 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
87 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
88 decfsz mcp_temp+1,F ; 7 Bit done?
heinrichsweikamp
parents:
diff changeset
89 bra mcp_readloop ; Not yet...
heinrichsweikamp
parents:
diff changeset
90
heinrichsweikamp
parents:
diff changeset
91 movlw .8
heinrichsweikamp
parents:
diff changeset
92 movwf mcp_temp+1 ; Bit counter
heinrichsweikamp
parents:
diff changeset
93 mcp_readloop2:
heinrichsweikamp
parents:
diff changeset
94 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
95 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
96 btfss mcp_lf_data
heinrichsweikamp
parents:
diff changeset
97 bcf mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
98 btfsc mcp_lf_data
heinrichsweikamp
parents:
diff changeset
99 bsf mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
100 rlncf mcp_temp+0 ; MSB first
heinrichsweikamp
parents:
diff changeset
101 decfsz mcp_temp+1,F ; 8 Bit done?
heinrichsweikamp
parents:
diff changeset
102 bra mcp_readloop2 ; Not yet...
heinrichsweikamp
parents:
diff changeset
103
heinrichsweikamp
parents:
diff changeset
104 ; Dummy clk for parity bit
heinrichsweikamp
parents:
diff changeset
105 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
106 nop
heinrichsweikamp
parents:
diff changeset
107 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
108 bsf mcp_ncs ; cs=1
heinrichsweikamp
parents:
diff changeset
109 bsf TRISG,0 ; CLK input
heinrichsweikamp
parents:
diff changeset
110 return
heinrichsweikamp
parents:
diff changeset
111
heinrichsweikamp
parents:
diff changeset
112 mcp_write_config_reg: ; Writes mcp_temp+0 to config #WREG
heinrichsweikamp
parents:
diff changeset
113 movwf mcp_temp+2 ; Save config#
heinrichsweikamp
parents:
diff changeset
114 bcf TRISG,0 ; CLK output
heinrichsweikamp
parents:
diff changeset
115 clrf mcp_temp+3 ; for parity
heinrichsweikamp
parents:
diff changeset
116 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
117 bsf mcp_ncs ; cs=1
heinrichsweikamp
parents:
diff changeset
118 nop
heinrichsweikamp
parents:
diff changeset
119 bcf mcp_ncs ; cs=0
heinrichsweikamp
parents:
diff changeset
120 bcf TRISB,3 ; mcp_lf_data output
heinrichsweikamp
parents:
diff changeset
121 bsf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
122 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
123 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
124 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
125 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
126 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
127 bcf mcp_clk ; clk=0 ; Write command done.
heinrichsweikamp
parents:
diff changeset
128
heinrichsweikamp
parents:
diff changeset
129 ; Now, 4Bit register address
heinrichsweikamp
parents:
diff changeset
130 movlw .4
heinrichsweikamp
parents:
diff changeset
131 movwf mcp_temp+1 ; Bit counter
heinrichsweikamp
parents:
diff changeset
132 mcp_write_config_reg1:
heinrichsweikamp
parents:
diff changeset
133 btfss mcp_temp+2,3
heinrichsweikamp
parents:
diff changeset
134 bcf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
135 btfsc mcp_temp+2,3
heinrichsweikamp
parents:
diff changeset
136 bsf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
137 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
138 rlncf mcp_temp+2,F ; shift byte left no carry
heinrichsweikamp
parents:
diff changeset
139 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
140 decfsz mcp_temp+1,F ; 4Bit done?
heinrichsweikamp
parents:
diff changeset
141 bra mcp_write_config_reg1 ; Not yet...
heinrichsweikamp
parents:
diff changeset
142
heinrichsweikamp
parents:
diff changeset
143 ; 8Bit data
heinrichsweikamp
parents:
diff changeset
144 movlw .8
heinrichsweikamp
parents:
diff changeset
145 movwf mcp_temp+1 ; Bit counter
heinrichsweikamp
parents:
diff changeset
146 mcp_write_config_reg2:
heinrichsweikamp
parents:
diff changeset
147 btfss mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
148 bcf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
149 btfsc mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
150 bsf mcp_lf_data
heinrichsweikamp
parents:
diff changeset
151 btfsc mcp_temp+0,7
heinrichsweikamp
parents:
diff changeset
152 incf mcp_temp+3,F ; count 1's...
heinrichsweikamp
parents:
diff changeset
153 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
154 rlncf mcp_temp+0,F ; shift byte left no carry
heinrichsweikamp
parents:
diff changeset
155 bcf mcp_clk ; clk=0
heinrichsweikamp
parents:
diff changeset
156 decfsz mcp_temp+1,F ; 8Bit done?
heinrichsweikamp
parents:
diff changeset
157 bra mcp_write_config_reg2 ; Not yet...
heinrichsweikamp
parents:
diff changeset
158
heinrichsweikamp
parents:
diff changeset
159 ; 1bit parity
heinrichsweikamp
parents:
diff changeset
160 btfss mcp_temp+3,0
heinrichsweikamp
parents:
diff changeset
161 bsf mcp_lf_data ; Set row parity bit
heinrichsweikamp
parents:
diff changeset
162 btfsc mcp_temp+3,0
heinrichsweikamp
parents:
diff changeset
163 bcf mcp_lf_data ; clear row parity bit
heinrichsweikamp
parents:
diff changeset
164 bsf mcp_clk ; clk=1
heinrichsweikamp
parents:
diff changeset
165 bcf mcp_clk ; clk=0 ; Parity bit done.
heinrichsweikamp
parents:
diff changeset
166
heinrichsweikamp
parents:
diff changeset
167 bsf TRISB,3 ; mcp_lf_data input again
heinrichsweikamp
parents:
diff changeset
168 bsf mcp_ncs ; cs=1
heinrichsweikamp
parents:
diff changeset
169 bsf TRISG,0 ; CLK input
heinrichsweikamp
parents:
diff changeset
170 return
heinrichsweikamp
parents:
diff changeset
171
heinrichsweikamp
parents:
diff changeset
172 global mcp_reset
heinrichsweikamp
parents:
diff changeset
173 mcp_reset: ; reset RX chip# (Normal mode)
heinrichsweikamp
parents:
diff changeset
174 ; Make sure row parity bit is correct
heinrichsweikamp
parents:
diff changeset
175 ; yyyaaaa01234567P
heinrichsweikamp
parents:
diff changeset
176 ; yyy: Command
heinrichsweikamp
parents:
diff changeset
177 ; aaaa: Address
heinrichsweikamp
parents:
diff changeset
178 ; 0-7: Data
heinrichsweikamp
parents:
diff changeset
179 ; P: Parity bit. Set/Clear that 0-7+P are odd number of ones
heinrichsweikamp
parents:
diff changeset
180 ; Current config:
heinrichsweikamp
parents:
diff changeset
181 banksel buffer
heinrichsweikamp
parents:
diff changeset
182 movlw b'10100100' ; Config0: LCZ disabled, Wakeup => High = 2ms, Low = 2ms
heinrichsweikamp
parents:
diff changeset
183 movwf buffer+0
heinrichsweikamp
parents:
diff changeset
184 movlw b'00000000' ; Config1: +20pF LCX Normal mode
heinrichsweikamp
parents:
diff changeset
185 ; movlw b'01000000' ; Config1: +20pF LCX carrier out mode
heinrichsweikamp
parents:
diff changeset
186 movwf buffer+1
heinrichsweikamp
parents:
diff changeset
187 movlw b'00000000' ; Config2: +25pF LCY
heinrichsweikamp
parents:
diff changeset
188 movwf buffer+2
heinrichsweikamp
parents:
diff changeset
189 movlw b'00000000' ; Config3
heinrichsweikamp
parents:
diff changeset
190 movwf buffer+3
heinrichsweikamp
parents:
diff changeset
191 movlw b'00000000' ; Config4
heinrichsweikamp
parents:
diff changeset
192 movwf buffer+4
heinrichsweikamp
parents:
diff changeset
193 ; movlw b'00001111' ; Config5 33%
heinrichsweikamp
parents:
diff changeset
194 ; movlw b'00101111' ; Config5 14%
heinrichsweikamp
parents:
diff changeset
195 movlw b'10011111' ; Config5 60%
heinrichsweikamp
parents:
diff changeset
196 movwf buffer+5
heinrichsweikamp
parents:
diff changeset
197 bra mcp_reset_common
heinrichsweikamp
parents:
diff changeset
198
heinrichsweikamp
parents:
diff changeset
199 global mcp_reset_rssi
heinrichsweikamp
parents:
diff changeset
200 mcp_reset_rssi: ; reset RX chip# for RSSI mode
heinrichsweikamp
parents:
diff changeset
201 ; Make sure row parity bit is correct
heinrichsweikamp
parents:
diff changeset
202 ; yyyaaaa01234567P
heinrichsweikamp
parents:
diff changeset
203 ; yyy: Command
heinrichsweikamp
parents:
diff changeset
204 ; aaaa: Address
heinrichsweikamp
parents:
diff changeset
205 ; 0-7: Data
heinrichsweikamp
parents:
diff changeset
206 ; P: Parity bit. Set/Clear that 0-7+P are odd number of ones
heinrichsweikamp
parents:
diff changeset
207 ; Current config:
heinrichsweikamp
parents:
diff changeset
208 banksel buffer
heinrichsweikamp
parents:
diff changeset
209 movlw b'10101000' ; Config0: LCZ disabled, Wakeup => High = 2ms, Low = 2ms
heinrichsweikamp
parents:
diff changeset
210 movwf buffer+0
heinrichsweikamp
parents:
diff changeset
211 movlw b'10000000' ; Config1: +20pF LCX and RSSI Mode
heinrichsweikamp
parents:
diff changeset
212 movwf buffer+1
heinrichsweikamp
parents:
diff changeset
213 movlw b'00000000' ; Config2: +25pF LCY
heinrichsweikamp
parents:
diff changeset
214 movwf buffer+2
heinrichsweikamp
parents:
diff changeset
215 movlw b'00000000' ; Config3
heinrichsweikamp
parents:
diff changeset
216 movwf buffer+3
heinrichsweikamp
parents:
diff changeset
217 movlw b'00000000' ; Config4
heinrichsweikamp
parents:
diff changeset
218 movwf buffer+4
heinrichsweikamp
parents:
diff changeset
219 movlw b'11010000' ; Config5 60%
heinrichsweikamp
parents:
diff changeset
220 movwf buffer+5
heinrichsweikamp
parents:
diff changeset
221 mcp_reset_common:
heinrichsweikamp
parents:
diff changeset
222 banksel TRISB
heinrichsweikamp
parents:
diff changeset
223 bcf TRISB,2
heinrichsweikamp
parents:
diff changeset
224 bcf mcp_ncs ; CS=1
heinrichsweikamp
parents:
diff changeset
225 nop
heinrichsweikamp
parents:
diff changeset
226 bsf mcp_power ; Power-up
heinrichsweikamp
parents:
diff changeset
227 nop
heinrichsweikamp
parents:
diff changeset
228 btfss mcp_power
heinrichsweikamp
parents:
diff changeset
229 bra mcp_reset_common
heinrichsweikamp
parents:
diff changeset
230 WAITMS .10
heinrichsweikamp
parents:
diff changeset
231 ; Compute column parity byte
heinrichsweikamp
parents:
diff changeset
232 banksel buffer
heinrichsweikamp
parents:
diff changeset
233 movf buffer+0,W
heinrichsweikamp
parents:
diff changeset
234 xorwf buffer+1,W
heinrichsweikamp
parents:
diff changeset
235 xorwf buffer+2,W
heinrichsweikamp
parents:
diff changeset
236 xorwf buffer+3,W
heinrichsweikamp
parents:
diff changeset
237 xorwf buffer+4,W
heinrichsweikamp
parents:
diff changeset
238 xorwf buffer+5,W
heinrichsweikamp
parents:
diff changeset
239 xorlw 0xFF
heinrichsweikamp
parents:
diff changeset
240 movwf buffer+6 ; <- Column parity byte
heinrichsweikamp
parents:
diff changeset
241 banksel mcp_temp+0
heinrichsweikamp
parents:
diff changeset
242
heinrichsweikamp
parents:
diff changeset
243 mcp_writebyte_1st b'10100000' ; Reset Command
heinrichsweikamp
parents:
diff changeset
244 mcp_writebyte_2nd b'00000000' ; Dummy byte
heinrichsweikamp
parents:
diff changeset
245
heinrichsweikamp
parents:
diff changeset
246 mcp_writebyte_1st b'00100000' ; Clamp off
heinrichsweikamp
parents:
diff changeset
247 mcp_writebyte_2nd b'00000000' ; Dummy byte
heinrichsweikamp
parents:
diff changeset
248
heinrichsweikamp
parents:
diff changeset
249 movff buffer+0,mcp_temp+0 ; Data byte
heinrichsweikamp
parents:
diff changeset
250 mcp_write_config .0
heinrichsweikamp
parents:
diff changeset
251 movff buffer+1,mcp_temp+0 ; Data byte
heinrichsweikamp
parents:
diff changeset
252 mcp_write_config .1
heinrichsweikamp
parents:
diff changeset
253 movff buffer+2,mcp_temp+0 ; Data byte
heinrichsweikamp
parents:
diff changeset
254 mcp_write_config .2
heinrichsweikamp
parents:
diff changeset
255 movff buffer+3,mcp_temp+0 ; Data byte
heinrichsweikamp
parents:
diff changeset
256 mcp_write_config .3
heinrichsweikamp
parents:
diff changeset
257 movff buffer+4,mcp_temp+0 ; Data byte
heinrichsweikamp
parents:
diff changeset
258 mcp_write_config .4
heinrichsweikamp
parents:
diff changeset
259 movff buffer+5,mcp_temp+0 ; Data byte
heinrichsweikamp
parents:
diff changeset
260 mcp_write_config .5
heinrichsweikamp
parents:
diff changeset
261 movff buffer+6,mcp_temp+0 ; Data byte (Column parity byte)
heinrichsweikamp
parents:
diff changeset
262 mcp_write_config .6
heinrichsweikamp
parents:
diff changeset
263
heinrichsweikamp
parents:
diff changeset
264 ; mcp_writebyte_1st b'11000000' ; Read from Config0
heinrichsweikamp
parents:
diff changeset
265 ; mcp_writebyte_2nd b'00000000' ; Dummy clks + Odd Parity Bit (Bit0)
heinrichsweikamp
parents:
diff changeset
266 ; call mcp_readbyte ; read into mcp_temp+0
heinrichsweikamp
parents:
diff changeset
267 return
heinrichsweikamp
parents:
diff changeset
268
heinrichsweikamp
parents:
diff changeset
269
heinrichsweikamp
parents:
diff changeset
270 END