udata_acs
+; used in panic routine for temporary storage:
+
flash_pattern res 1
morse_counter res 1
register_counter res 1
bit_counter res 1
-; used in panic macro for temporary storage
-panic_address res 1 ; stores condensed form of message start addr.
-panic_morse res 1 ; stores # bytes of morse msg in panic readout
-panic_regs res 1 ; stores # registers in panic readout
+panic_address res 1 ; condensed form of message start addr.
+panic_morse res 1 ; # bytes of morse msg in panic readout
+panic_regs res 1 ; # registers in panic readout
;****************************************************************************
;****************************************************************************
-; first, copy the panic message address out of WREG
-
- mov_wf panic_address
-
panic_routine
; switch off interrupts and power
; reconfigure timer0 for writing diagnostic msg to the LED
clr_f INTCON ; disable all interrupts EVER
bc_f PORTC,1 ; switch off booster
+; now we have time to copy the panic message address out of WREG
+; (turning off interrupts is urgent (we might get interrupted while
+; panicing which would be bad because we might forget to panic).
+
+ mov_wf panic_address
+
; re-initialise timer0 config
bc_f T0CON,6 ; p107 Timer0 -> 16bit mode
; back from condensed message start addr. stored in panic_address
panic_loop
- mov_lw 4
+ mov_lw 4 ; size of each message's details
mul_wf panic_address
mov_ff PRODL,TBLPTRL
mov_ff PRODH,WREG
call waiting
call waiting
call waiting
- call morsemsg ; transmit SOS in red
+ call morsemsg ; transmit morse in red
call led_black
call waiting
call waiting
; PANIC SUBROUTINES
morsemsg
-; wrapper round readout to flash the per-pic led red for a
-; (currently 4-byte) morse msg
+; wrapper round morse_readout to flash the per-pic led red for a morse msg
morse_msg_start
clr_f morse_counter ; clear loop counter
;--------------------------
morse_readout
-; Flashes the per-pic led red(0) in a specified pattern.
+; Flashes the per-pic led and black in a specified pattern.
;
; The pattern is specified as the state for 8 identically-long time
; periods each as long as a morse `dot', encoded into a byte with
; flash_pattern flash pattern preserved
; bit_counter any undefined
- clr_f bit_counter ; clear loop counter
+ mov_lw 8
+ mov_wf bit_counter
rr_f flash_pattern
morse_readout_loop
- mov_fw panic_regs
- cmp_fw_ifge bit_counter ; if loop counter >=panic_regs, return
+ dec_f_ifz bit_counter ; done all the bits yet ?
return
+ ; No:
rl_f flash_pattern ; top bit goes into N,
;ie Negative if 1
call led_red
morse_readout_endif_led
- inc_f bit_counter ; increment loop counter
- call waiting
bra morse_readout_loop
;--------------------------
register_readout_loop
- movlw 8
+ mov_lw 8
cmp_fw_ifge bit_counter ; if loop counter >=8 (register
; length), return
return
- movlw 4
+ mov_lw 4
cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length),
; skip insertion of extra black space
goto not_nybble_boundary
call waiting
not_nybble_boundary
- rlncf flash_pattern,1 ; top bit goes into N flag,
+ rl_f flash_pattern ; top bit goes into N flag,
; ie Negative if 1
- bn register_readout_if_led_1
+ bra_n register_readout_if_led_1
register_readout_if_led_0
call led_red
clr_f TMR0H ; p107 set high byte of timer0 to 0 (buffered,
; only actually set when write to tmr0l occurs)
clr_f TMR0L ; set timer0 low byte - timer now set to 0000h
-loop
+waiting_loop
bt_f_if0 INTCON,TMR0IF
- bra loop ; wait for timer0 interrupt
+ bra waiting_loop ; wait for timer0 interrupt
return