3 ; This program sets the LED Green and then
4 ; responds to instructions on the serial port
8 ; R current address for reading (Al = low byte; Ah = high_nybble)
9 ; S current address for setting (Bl = low byte; Ah = high_nybble)
10 ; T top address nybble for next address set
11 ; B bitmask for bit operations
12 ; F flags: flag name weight in FT
13 ; printset 0x80 print every value we write into *S
15 ; prompt is NL CR > SPC initially, then SPC after each command
18 ; 0-9a-f hex digit E := (E & 0x0f)<<4 | (digit value)
19 ; = confirm value print "=", E
20 ; & set bitmask B := E; print "&", B
23 ; . set setting address (low byte) S := TE; print R, ",", S
24 ; , set reading address (low byte) R := TE; print R, ",", S
25 ; ' set top address nybble T := E & 0x0f
26 ; ` set flags F := E; print "`", F
27 ; @ confirm addresses and bitmask print R, ",", S, "&", B
28 ; ~ confirm flags and high nybble print "`", F, "'", T
30 ; predefined addresses and operations
31 ; A B C D E set setting address to PORTx S := 0xf80-0xf84, print op
32 ; H L Z T set TRIS and LAT rel.to PORT modify *(S+0x09), *(S+0x92)
33 ; according to B according to B, and print op
34 ; (T: toggle LAT, clear TRIS) NB address addition no carry
37 ; SPC read and display print *R
38 ; RET, NL set whole byte printset "S", (*S := E)
39 ; TAB read from setting address print "s", *S
42 ; ? read and mask print "?", (*R & B)
43 ; _ read and mask from setting addr printset "_", (*S & B)
44 ; + bitwise or (set bits) printset "+", (*S := *S | B)
45 ; - bitwise and-not (clear bits) printset "-", (*S := *S & ~B)
46 ; ^ bitwise xor (toggle bits) printset "^", (*S := *S ^ B)
48 ; `printset' means print if `printset' flag is set, otherwise just evaluate
50 include /usr/share/gputils/header/p18f458.inc
54 include insn-aliases.inc
55 include clockvaries.inc
58 ;------------------------------------------------------------
59 ; variable declarations and RAM memory map
73 sec_etbf udata_acs 0x30
79 sec_temps udata_acs 0x38
94 ;----------------------------------------
95 serial_literal macro serial_literal_macro_char
96 ; transmits char through the serial port
97 ; W undefined undefined
98 mov_lw serial_literal_macro_char
99 rcall serial_write_char
113 mov_lw (1<<f_printset_bit)
127 rcall serial_read_char
132 checkequal macro check_value, check_label
134 add_lw check_last - check_value
138 check_last set check_value
141 checkatleast macro check_minvalue, check_label
142 ; if it takes, W gets char - check_minvalue
143 add_lw check_last-check_minvalue
148 check_last set check_minvalue
152 checkequal '=', command_byte_confirm
153 checkequal '&', command_byte_bitmask_set
155 checkequal '.', command_address_set_setting
156 checkequal ',', command_address_set_reading
157 checkequal 39, command_address_set_high
158 checkequal '`', command_flags_set
159 checkequal '@', command_address_confirm
160 checkequal '~', command_confirm_flags_highnyb
162 checkequal ' ', command_byte_read
163 checkequal 10, command_byte_set
164 checkequal 13, command_byte_set
165 checkequal 9, command_byte_read_fromset
167 checkequal '?', command_bitwise_read_mask
168 checkequal '_', command_bitwise_read_mask_fromset
169 checkequal '+', command_bitwise_or
170 checkequal '-', command_bitwise_and_not
171 checkequal '^', command_bitwise_xor
173 ; TRIS/LAT operations
174 checkequal 'H', command_trislat_h
175 checkequal 'L', command_trislat_l
176 checkequal 'Z', command_trislat_z
177 checkequal 'T', command_trislat_t
179 ; these checkatleast ranges have to be in descending
180 ; order because of the way that checkatleast works
182 checkatleast 'f'+1, command_ifnot_letterhexdigit
183 checkatleast 'a', command_letterhexdigit
184 command_ifnot_letterhexdigit
186 checkatleast 'E'+1, command_ifnot_portaddr
187 checkatleast 'A', command_portaddr
188 command_ifnot_portaddr
190 checkatleast '9'+1, command_ifnot_digit
191 checkatleast '0', command_digit
196 rcall serial_write_char
200 ;--------------------
203 command_letterhexdigit
213 ;--------------------
214 ; common routines for command loop
216 command_endswitch_set
218 bt_f_if0 f, f_printset_bit
219 bra command_endswitch_set_ifnot_print
222 rcall serial_write_char
224 command_endswitch_phex
225 rcall serial_write_hex
226 command_endswitch_set_ifnot_print
227 bra command_endswitch
229 ;--------------------
232 command_address_set_setting
235 bra command_address_confirm
237 command_address_set_reading
240 bra command_address_confirm
242 command_address_set_high
244 bra command_endswitch
249 bra command_endswitch
251 command_address_confirm
252 rcall confirm_address
253 rcall confirm_bitmask
254 bra command_endswitch
261 rcall serial_write_char
262 bra command_endswitch
264 ;--------------------
268 rcall trislat_setup_indf2_lat
271 rcall trislat_setup_indf2_tris
276 rcall serial_write_char
277 bra command_endswitch
280 rcall trislat_setup_indf2_tris
282 bra command_trislat_echo
285 rcall trislat_setup_indf2_lat
288 bra command_trislat_nz
291 rcall trislat_setup_indf2_lat
293 bra command_trislat_nz
296 trislat_setup_indf2_lat
298 ; INDF2* undefined relevant LAT
300 bra trislat_setup_indf2_any
303 trislat_setup_indf2_tris
305 ; INDF2* undefined relevant TRIS
307 bra trislat_setup_indf2_any
310 trislat_setup_indf2_any
312 ; INDF2* undefined relevant REG
322 ; W undefined undefined
323 ; hex_temp undefined undefined
325 rcall serial_write_hex_digit
327 rcall serial_write_hex
329 rcall serial_write_char
331 rcall serial_write_hex_digit
333 rcall serial_write_hex
336 command_confirm_flags_highnyb
340 rcall serial_write_hex_digit
341 bra command_endswitch
346 ; W undefined undefined
347 ; hex_temp undefined undefined
350 rcall serial_write_hex
356 ; W undefined undefined
357 ; hex_temp undefined undefined
360 rcall serial_write_hex
363 ;--------------------
369 bra command_endswitch_phex
371 command_byte_bitmask_set
373 rcall confirm_bitmask
374 bra command_endswitch
378 bra command_endswitch_phex
384 bra command_endswitch_set
386 command_byte_read_fromset
389 bra command_endswitch_phex
391 ;--------------------
394 command_bitwise_read_mask
398 bra command_endswitch_phex
400 command_bitwise_read_mask_fromset
404 bra command_endswitch_phex
409 bra command_endswitch_set
414 bra command_endswitch_set
416 command_bitwise_and_not
420 bra command_endswitch_set
422 ;----------------------------------------
424 bc_f TRISD, perpicled_bit
425 bs_f LATD, perpicled_bit
429 ;----------------------------------------
431 ; W undefined undefined
432 mov_lw (1<<TXEN) | serial_brgh | (1<<TRMT)
433 mov_wf TXSTA ; asynch xmit enabled, high baud rate, 8-bit,
435 serial_receive_reset ;from serial_read_if_error
436 mov_lw (1<<SPEN) | (1<<CREN)
437 mov_wf RCSTA ; enable serial port, continuous rx, 8-bit
440 ;----------------------------------------
442 ; on errors, sets LED red and transmits *
443 ; W undefined character read
444 serial_read_char_loop
446 bra serial_read_char_loop
448 and_lw (1<<CREN) | (1<<FERR) | (1<<OERR)
450 bra_nz serial_read_if_error
456 rcall serial_write_char
457 rcall serial_receive_reset
458 bra serial_read_char_loop
460 include syncwrite.inc