chiark / gitweb /
change timings to 18wpm morse; clever "waiting2 bsr waiting // waiting ..." trick...
authorian <ian>
Tue, 22 Nov 2005 22:57:28 +0000 (22:57 +0000)
committerian <ian>
Tue, 22 Nov 2005 22:57:28 +0000 (22:57 +0000)
detpic/panic.asm

index 7e724fbd15350cc7c86703664bcac1e0e6d87720..3678ac1f994805431c6ee7aeb51c6ed7ce39eedd 100644 (file)
@@ -42,15 +42,14 @@ panic_routine
 ;  panicing which would be bad because we might forget to panic).
 
         mov_wf   panic_address
-
+       clr_f    STKPTR         ; avoids stack overruns
 
 ; re-initialise timer0 config
-        bc_f     T0CON,6       ; p107 Timer0 -> 16bit mode
-        bc_f     T0CON,5       ; timer0 use internal clock
-        bc_f     T0CON,3       ; use prescaler
-        bc_f     T0CON,2       ; }
-        bs_f     T0CON,1       ; } prescale value 1:8 (13ms x 8)
-        bc_f     T0CON,0       ; }
+       mov_lw  (1<<TMR0ON) | 011b ; Enable, 16-bit, timer, prescaler 1:16
+       mov_wf  T0CON   ; => PSout is 312.5kHz or 3.2us per period  (DS p108)
+ ; We want to wait 66ms (morse at 18wpm according to the PARIS standard
+ ; is a unit time of 66ms), or 20,833 PSout cycles:
+waiting_t0cycles equ 20833 ; see by `waiting', below
 
 ; get # bytes of morse msg, # registers in panic readout, message start addr.
 ; back from condensed message start addr. stored in panic_address
@@ -78,22 +77,14 @@ panic_loop
        swap_f  panic_regs      ; panic_regs now contains # registers to read
 
        call    led_black
-       call    waiting
-       call    waiting
-       call    waiting
-       call    waiting
-       call    waiting
-       call    waiting
-       call    waiting
-       call    waiting
+       call    waiting16
        call    morsemsg        ; transmit morse in red
        call    led_black
-       call    waiting
-       call    waiting
-       call    waiting
-       call    waiting
+       call    waiting8
+       call    waiting4
        call    registermsg     ; transmit contents of registers in 
                                ; red(=low) and blue(=high)
+       call    waiting16
         goto    panic_loop
 
 ;****************************************************************************
@@ -184,8 +175,7 @@ register_loop
 
        inc_f           register_counter        ;increment loop counter
 
-       call            waiting
-       call            waiting
+       call            waiting8
        goto            register_loop
 
 ;--------------------------
@@ -217,7 +207,7 @@ register_readout_loop
         cmp_fw_ifne    bit_counter     ; if loop counter !=4 (nybble length), 
                                        ; skip insertion of extra black space
        goto            not_nybble_boundary
-       call            waiting
+       call            waiting4
 
 not_nybble_boundary
         rl_f           flash_pattern           ; top bit goes into N flag, 
@@ -243,13 +233,20 @@ register_readout_endif_led
 ; GENERAL SUBROUTINES
 
 ;----------------------------------------
+waiting16      rcall   waiting8
+waiting8       rcall   waiting4
+waiting4       rcall   waiting2
+waiting2       rcall   waiting
 waiting
 ; waits for a fixed interval, depending on the configuration of TMR0
 
         bc_f           INTCON,2        ; clear timer0 interrupt bit (p109)
-        clr_f          TMR0H           ; p107 set high byte of timer0 to 0 (buffered,
+; Interrupt happens on overflow.  So start at 65535-waiting_t0cycles:
+       mov_lw  (65535-waiting_t0cycles) / 256
+       mov_wf  TMR0H           ; p107 set high byte of timer0 (buffered,
                                 ; only actually set when write to tmr0l occurs)
-        clr_f          TMR0L           ; set timer0 low byte - timer now set to 0000h
+       mov_lw  (65535-waiting_t0cycles) & 0xff
+        mov_wf         TMR0L           ; set timer0 low byte - timer now set
 waiting_loop
         bt_f_if0 INTCON,TMR0IF         
         bra     waiting_loop   ; wait for timer0 interrupt