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
14 include ../iwjpictest/clockvaries.inc
20 ;---------------------------------------------------------------------------
21 ; reserved access bank locations
23 WREG2 equ 00h ; a 2nd working reg :-)
24 WREG3 equ 01h ; a 3rd working reg :-)
25 WREG4 equ 02h ; a 4th working reg :-)
26 BLANK equ 03h ; register full of zeros
27 TESTFLASH equ 04h ; test LED flash pattern
31 ;---------------------------------------------------------------------------
32 ; memory location definitions
34 ERROR_BUF_PAGE equ 3 ; error codes on flash p3
35 F_ERROR_U equ 30h ; upper part of error memory locations
36 F_SOS_H equ 00h ; high (middle) part of SOS error memory loc.
37 F_SOS_L equ 00h ; lower part of SOS error memory loc.
40 ;---------------------------------------------------------------------------
43 err_SOS equ 0 ; msg 0 = SOS
45 ;****************************************************************************
46 ; VECTORS: special locations, where the PIC starts executing
54 ; high priority interrupt
59 ; low priority interrupt
64 ;****************************************************************************
67 ;----------------------------------------
68 ; errmsg(ERRCODE,COLOUR)
69 ; reads the chosen error msg out of flash and transmits by
70 ; flashing LED in chosen colour [1 = blue (=green), 0 = orange (=red)]
73 ;errmsg macro ERRCODE, COLOUR
82 ;----------------------------------------
84 ; Flashes the per-pic led red and black in a specified pattern.
85 ; The pattern is specified as the state for 8 identically-long time
86 ; periods each as long as a morse `dot', encoded into a byte with
87 ; most significant bit first.
90 ; WREG2 flash pattern preserved
93 clrf WREG4,0 ; clear loop counter (WREG4)
98 cpfslt WREG4,0 ; if loop counter >=8, return
101 rlncf WREG2,1 ; top bit goes into N flag, ie Negative if 1
105 bra readout_endif_led
110 incf WREG4,1,0 ; increment loop counter
114 ;****************************************************************************
118 ;****************************************************************************
123 ; enable interrupts so that this can be used as a trigger for the
126 ; initial config - TXSTA register p181
127 bcf TXSTA,6,0 ; p181, set 8-bit mode
128 bsf TXSTA,5,0 ; transmit enable
129 bcf TXSTA,4,0 ; asynchronous mode
130 bsc_txsta_brgh ; set high or low baud rate
132 ; initial config - RCSTA register p182
133 bsf RCSTA,7,0 ; serial port enable (p182)
134 bcf RCSTA,6,0 ; 8-bit reception
135 bsf RCSTA,4,0 ; enable continuous receive
137 ; set SPBRG to get correct baud rate
140 ; interrupt set-up for serial receive
141 bcf IPR1,5,0 ; set to low-priority interrupt
143 ;---------------------------------------------------------------------------
146 ; globally enable interrupts - p77
147 bsf RCON,7,0 ; enable priority levels
148 bsf INTCON,7,0 ; enable high-priority interrupts
149 bsf INTCON,6,0 ; enable low-priority interrupts
150 bsf PIE1,5,0 ; enable USART receive interrupt (p85)
152 ;---------------------------------------------------------------------------
154 ; write error code for SOS into flash memory (starting at 30 0000h)
155 ; movlw F_ERROR_H ; set table pointer to point to
156 ; movwf TBLPTRU ; start of flash p3
162 ; write message into memory, incrementing tbl pointer each time
180 ;---------------------------------------------------------------------------
181 ; turn LED green if we have made it this far....
188 ;****************************************************************************
189 ; INTERRUPT SUBROUTINES
192 goto informative_panic
195 ; switch off interrupts and power
196 ; reconfigure timer0 for writing diagnostic msg to the LED
198 clrf INTCON,0 ; disable all interrupts EVER
199 bcf PORTC,1,0 ; switch off booster
205 ; re-initialise timer0 config
206 morse_t0setup mclock, (1<<TMR0ON), -1, -1
210 ; errmsg err_SOS,0 ; transmit SOS in red
211 movff TESTFLASH,WREG2
213 ; readout BLANK,0 ; transmit blank buffer
218 ;****************************************************************************
219 ; GENERAL SUBROUTINES
221 ;----------------------------------------
223 ; waits for a fixed interval, depending on the configuration of TMR0
225 bcf INTCON,2,0 ; clear timer0 interrupt bit (p109)
226 clrf TMR0H,0 ; p107 set high byte of timer0 to 0 (buffered,
227 ; only actually set when write to tmr0l occurs)
228 clrf TMR0L,0 ; set timer0 low byte - timer now set to 0000h
230 btfss INTCON,2,0 ; check whether timer0 interrupt has been set -
231 ; skip next instruction if so
236 ;****************************************************************************