1 ; program writes SOS msg into flash then turns LED green
2 ; when serial interrupt received, turns off interrupts, turns off
3 ; power, transmits contents of SSPCON1 by flashing LED red, repeats
4 ; (next version will transmit SOS code first, then contents of
8 ; to start, need to write into flash, starting at 30 0000h:
9 ; 10 10 10 00 | 1110 1110 | 1110 00 10 | 10 10
12 include morse-auto.inc
13 include ../iwjpictest/insn-aliases.inc
19 ;---------------------------------------------------------------------------
20 ; reserved access bank locations
24 register_counter res 1
26 BLANK res 1 ; register full of zeros
27 TESTFLASH res 1 ; test LED flash pattern
29 ; used in panic macro for temporary storage
30 PANIC_ADDRESS res 1 ; stores condensed form of message start addr.
31 PANIC_MORSE res 1 ; stores # bytes of morse msg in panic readout
32 PANIC_REGS res 1 ; stores # registers in panic readout
35 ;---------------------------------------------------------------------------
36 ; memory location definitions
38 ERROR_BUF_PAGE equ 3 ; error codes on flash p3
39 F_ERROR_U equ 00h ; upper part of error memory locations
40 F_SOS_H equ 40h ; high (middle) part of SOS error memory loc.
41 F_SOS_L equ 00h ; lower part of SOS error memory loc.
44 ;****************************************************************************
48 ;****************************************************************************
50 ; first, copy the panic message address out of WREG
55 ; switch off interrupts and power
56 ; reconfigure timer0 for writing diagnostic msg to the LED
58 clr_f INTCON ; disable all interrupts EVER
59 bc_f PORTC,1 ; switch off booster
62 ; re-initialise timer0 config
63 bc_f T0CON,6 ; p107 Timer0 -> 16bit mode
64 bc_f T0CON,5 ; timer0 use internal clock
65 bc_f T0CON,3 ; use prescaler
67 bs_f T0CON,1 ; } prescale value 1:16 (13ms x 16)
70 ; get # bytes of morse msg, # registers in panic readout, message start addr.
71 ; back from condensed message start addr. stored in PANIC_ADDRESS
78 add_lw (morse_messages_start)/256
82 tblrd *+ ; read 1st byte of error message
83 ; (gives # bytes morse, # bytes registers)
85 mov_ff TABLAT,PANIC_MORSE
87 and_wff PANIC_MORSE ; PANIC_MORSE now contains # bytes of morse msgs
89 mov_ff TABLAT,PANIC_REGS
92 swap_f PANIC_REGS ; PANIC_REGS now contains # registers to read
99 call morsemsg ; transmit SOS in red
105 call registermsg ; transmit contents of TESTFLASH in
106 ; red(=low) and blue(=high)
109 ;****************************************************************************
113 ; wrapper round readout to flash the per-pic led red for a
114 ; (currently 4-byte) morse msg
117 clr_f morse_counter ; clear loop counter
121 cmp_fw_ifge morse_counter ; if loop counter >=PANIC_MORSE
122 return ; return to panic
125 mov_ff TABLAT,flash_pattern
131 ;--------------------------
134 ; Flashes the per-pic led red(0) in a specified pattern.
136 ; The pattern is specified as the state for 8 identically-long time
137 ; periods each as long as a morse `dot', encoded into a byte with
138 ; most significant bit first.
141 ; flash_pattern flash pattern preserved
142 ; bit_counter any undefined
144 clr_f bit_counter ; clear loop counter
149 cmp_fw_ifge bit_counter ; if loop counter >=PANIC_REGS, return
152 rl_f flash_pattern ; top bit goes into N,
154 bra_n morse_readout_if_led_1
156 morse_readout_if_led_0
158 bra morse_readout_endif_led
160 morse_readout_if_led_1
163 morse_readout_endif_led
164 inc_f bit_counter ; increment loop counter
166 bra morse_readout_loop
168 ;--------------------------
169 ;--------------------------
173 clr_f register_counter ; clear loop counter
177 cmp_fw_ifge register_counter ; if loop counter >=PANIC_REGS
178 return ; return to panic
182 mov_fw TABLAT ; TABLAT has the 8-bit version
183 mov_wf FSR0L ; of the address. So, 8 bits
184 ; go straight into FSR0L.
186 mov_lw 0x0f ; For FSR0H, we see if the
187 mov_fw FSR0H ; address XX is >=0x60.
188 ; If it is then we meant 0xfXX;
189 mov_lw 0x5f ; if not then we meant 0x0XX.
190 cmp_fw_ifle FSR0L ; (This is just like PIC does
191 clr_f FSR0H ; for insns using Access Bank)
193 mov_ff INDF0,flash_pattern
194 call register_readout
196 inc_f register_counter ;increment loop counter
202 ;--------------------------
206 ; Flashes the per-pic led red(0) and green(1) in a specified pattern.
207 ; (black gap between each bit)
209 ; The pattern is specified as the state for 8 identically-long time
210 ; periods each as long as a morse `dot', encoded into a byte with
211 ; most significant bit first.
214 ; flash_pattern flash pattern preserved
215 ; bit_counter any undefined
217 clr_f bit ; clear loop counter
221 register_readout_loop
223 cmp_fw_ifge bit_counter ; if loop counter >=8 (register
228 cmp_fw_ifne bit_counter ; if loop counter !=4 (nybble length),
229 ; skip insertion of extra black space
230 goto not_nybble_boundary
234 rlncf flash_pattern,1 ; top bit goes into N flag,
236 bn register_readout_if_led_1
238 register_readout_if_led_0
240 bra register_readout_endif_led
242 register_readout_if_led_1
245 register_readout_endif_led
246 inc_f bit_counter,1 ; increment loop counter
250 bra register_readout_loop
253 ;****************************************************************************
254 ; GENERAL SUBROUTINES
256 ;----------------------------------------
258 ; waits for a fixed interval, depending on the configuration of TMR0
260 bc_f INTCON,2 ; clear timer0 interrupt bit (p109)
261 clr_f TMR0H ; p107 set high byte of timer0 to 0 (buffered,
262 ; only actually set when write to tmr0l occurs)
263 clr_f TMR0L ; set timer0 low byte - timer now set to 0000h
265 bt_f_if0 INTCON,TMR0IF
266 bra loop ; wait for timer0 interrupt
270 ;****************************************************************************