chiark / gitweb /
giant diffs of clock speed change
authorian <ian>
Sat, 26 Nov 2005 01:34:12 +0000 (01:34 +0000)
committerian <ian>
Sat, 26 Nov 2005 01:34:12 +0000 (01:34 +0000)
23 files changed:
cebpic/Makefile
cebpic/flow-control-test.asm
cebpic/i2c-test-reply.asm
cebpic/i2c-test.asm
cebpic/led-flash.asm
cebpic/morsepanic.asm
cebpic/nmra-stream.asm
cebpic/panic.asm
cebpic/reply-serial.asm
cebpic/send-serial.asm
cebpic/tblrd_test.asm
detpic/common.inc
detpic/i2clib.asm
detpic/nmra-stream.asm
detpic/panic.asm
detpic/test-sofar.asm
iwjpictest/Makefile
iwjpictest/clockvaries.inc [new file with mode: 0644]
iwjpictest/copybits.asm
iwjpictest/flasher.asm
iwjpictest/harness.asm
iwjpictest/serialloop.asm
pic.make

index 0a9ea5ea5e94cfa0eeaab833844d2f10aefc508e..6f418fc51c7a95841079a9471c08ee315a01c91d 100644 (file)
@@ -9,7 +9,7 @@ PROGRAMS=       led-flash send-serial panic reply-serial        \
 ROUTINES=      routines-led
 LIBS=          routines.lib                            
 
-INCLUDES=      common.inc pindata.inc
+INCLUDES=      common.inc pindata.inc ../iwjpictest/clockvaries.inc
 
 include manypics.make
 
index f07a12cdd8a4a3884a06bd4e40336d82dc06026d..a22fc6c398c2c368395034a61763e19ac7314a9c 100644 (file)
@@ -3,6 +3,7 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
        code
 start
@@ -10,15 +11,11 @@ start
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
         bsf    RCSTA,7,0       ; serial port enable (p182)
+       bsc_txsta_brgh          ; set high or low baud rate
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
-
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 ; set pin 24 to low (transmission allowed from computer)
 
index 2d2083523dcbe3cce0b153d6a86160f26cc48292..3e6e958b54eb6e4a6db229b1c73128e68af3544f 100644 (file)
@@ -42,6 +42,7 @@
         include common.inc
         include morse-auto.inc
         include ../iwjpictest/insn-aliases.inc
+        include ../iwjpictest/clockvaries.inc
 
        extern  led_green
        extern  led_red
@@ -262,10 +263,7 @@ panic_routine
 ; re-initialise timer0 config
         bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
         bcf     T0CON,5,0       ; timer0 use internal clock
-        bcf     T0CON,3,0       ; use prescaler
-        bcf     T0CON,2,0       ; }
-        bsf     T0CON,1,0       ; } prescale value 1:16 (13ms x 16)
-        bsf     T0CON,0,0       ; }
+       bsc_morse_t0con_012     ; use prescaler? and configure it
 
 ; get # bytes of morse msg, # registers in panic readout, message start addr.
 ; back from condensed message start addr. stored in PANIC_ADDRESS
@@ -567,17 +565,15 @@ serial_setup
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
        
 ; initial config - RCSTA register p182
         bsf    RCSTA,7,0       ; serial port enable (p182)
        bcf     RCSTA,6,0       ; 8-bit reception
        bsf     RCSTA,4,0       ; enable continuous receive
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 ; interrupt set-up for serial receive
        bcf     IPR1,5,0        ; set to low-priority interrupt
@@ -675,11 +671,8 @@ i2c_setup_if_master
        movwf   SSPCON1,0       ;  CKP unused, set to 0; master mode.
 
 ; set baud rate
-       movlw   100-1
-       movwf   SSPADD,0        ; set baud rate; clock=Fosc/(4*(SSPADD+1))
-                               ; Fosc=20MHz, currently want clock=50kHz
-                               ; => SSPADD=99
-
+       movlw   i2c_sspadd
+       movwf   SSPADD,0
        goto    i2c_setup_endif_master_slave
 
 i2c_setup_if_slave
index 0c7e62a914b0cf7b98c8d3ed2139a2fcbbcfac4e..8099e97467bba718ca5352f093c850df1b7f04aa 100644 (file)
@@ -26,6 +26,7 @@
 ; boilerplate:
 
         include         /usr/share/gputils/header/p18f458.inc
+        include         ../iwjpictest/clockvaries.inc
        radix           dec
 
        extern  led_green
@@ -316,17 +317,15 @@ serial_setup
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
        
 ; initial config - RCSTA register p182
         bsf    RCSTA,7,0       ; serial port enable (p182)
        bcf     RCSTA,6,0       ; 8-bit reception
        bsf     RCSTA,4,0       ; enable continuous receive
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 ; interrupt set-up for serial receive
        bcf     IPR1,5,0        ; set to low-priority interrupt
@@ -424,11 +423,8 @@ i2c_setup_if_master
        movwf   SSPCON1,0       ;  CKP unused, set to 0; master mode.
 
 ; set baud rate
-       movlw   100-1
-       movwf   SSPADD,0        ; set baud rate; clock=Fosc/(4*(SSPADD+1))
-                               ; Fosc=20MHz, currently want clock=50kHz
-                               ; => SSPADD=99
-
+       movlw   i2c_sspadd
+       movwf   SSPADD,0
        goto    i2c_setup_endif_master_slave
 
 i2c_setup_if_slave
@@ -517,10 +513,7 @@ informative_panic
 ; re-initialise timer0 config
         bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
         bcf     T0CON,5,0       ; timer0 use internal clock
-        bcf     T0CON,3,0       ; use prescaler
-        bsf     T0CON,2,0       ; }
-        bcf     T0CON,1,0       ; } prescale value 1:32 (13ms x 32)
-        bcf     T0CON,0,0       ; }
+       bsc_morse_t0con_012     ; use prescaler? and configure it
 
 ; 
 
index f7a977b93c9a81c6b5381dcfe06f7a87b9c97bf8..0a79e35757e556c165f5e025badadf91e8ae5a91 100644 (file)
@@ -1,6 +1,7 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
        code
 start
@@ -9,10 +10,7 @@ start
 ; timer initial config
        bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode     
        bcf     T0CON,5,0       ; timer0 use internal clock
-       bcf     T0CON,3,0       ; use prescaler
-       bsf     T0CON,2,0       ; }     
-       bcf     T0CON,1,0       ; } prescale value 1:32 (13ms x 32)
-       bcf     T0CON,0,0       ; }
+       bsc_morse_t0con_012     ; use prescaler? and configure it
 ; actually do stuff
        call    green
        call    waiting
index 2557bed9257b201c1c621a94b5b9f6f6fc564e6c..9f5a5184d97ae9b3ff29169d97da752286e07ae3 100644 (file)
@@ -11,6 +11,7 @@
        include common.inc
        include morse-auto.inc
        include ../iwjpictest/insn-aliases.inc
+       include ../iwjpictest/clockvaries.inc
 
        extern  led_green
        extern  led_red
@@ -109,17 +110,15 @@ vector_reset
         bcf     TXSTA,6,0       ; p181, set 8-bit mode
         bsf     TXSTA,5,0       ; transmit enable
         bcf     TXSTA,4,0       ; asynchronous mode
-        bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
 
 ; initial config - RCSTA register p182
         bsf     RCSTA,7,0       ; serial port enable (p182)
         bcf     RCSTA,6,0       ; 8-bit reception
         bsf     RCSTA,4,0       ; enable continuous receive
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-        bsf     SPBRG,7,0
-        bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 ; interrupt set-up for serial receive
         bcf     IPR1,5,0        ; set to low-priority interrupt
@@ -158,10 +157,7 @@ panic_routine
 ; re-initialise timer0 config
         bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
         bcf     T0CON,5,0       ; timer0 use internal clock
-        bcf     T0CON,3,0       ; use prescaler
-        bcf     T0CON,2,0       ; }
-        bsf     T0CON,1,0       ; } prescale value 1:16 (13ms x 16)
-        bsf     T0CON,0,0       ; }
+       bsc_morse_t0con_012     ; use prescaler? and configure it
 
 ; get # bytes of morse msg, # registers in panic readout, message start addr.
 ; back from condensed message start addr. stored in PANIC_ADDRESS
index 97c890becc5c79db794a3847475dda4d2bb9886e..0f6b266fdee587b5c9f30cde3a2470db22e3e973 100644 (file)
@@ -14,6 +14,7 @@
 
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
 
 NMRACTRL       equ     0x4     ; byte 4: state relevant to NMRA control
@@ -100,7 +101,7 @@ initialise
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh
        
 ; initial config - RCSTA register p182
         bsf    RCSTA,7,0       ; serial port enable (p182)
@@ -109,8 +110,8 @@ initialise
 
 ; set SPBRG to get correct baud rate according to table top right p186
 ; (Tosc = 20MHz, desired baud rate = 9600)
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+       movlw   serial_spbrg
+       movwf   SPBRG,0
 
 
        debug   0x0A    ; LF to terminak
index 4d885ce534a144e8ee3ca92c7282e79bcad79cae..9e1ac2cc08bb62d83c2adb087717ea813587fb5b 100644 (file)
@@ -9,6 +9,7 @@
 ; 10 10 10 00 | 1110 1110 | 1110 00 10 | 10 10
 
        include common.inc
+       include ../iwjpictest/clockvaries.inc
 
        extern  led_green
        extern  led_red
@@ -124,17 +125,15 @@ vector_reset
         bcf     TXSTA,6,0       ; p181, set 8-bit mode
         bsf     TXSTA,5,0       ; transmit enable
         bcf     TXSTA,4,0       ; asynchronous mode
-        bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
 
 ; initial config - RCSTA register p182
         bsf     RCSTA,7,0       ; serial port enable (p182)
         bcf     RCSTA,6,0       ; 8-bit reception
         bsf     RCSTA,4,0       ; enable continuous receive
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-        bsf     SPBRG,7,0
-        bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 ; interrupt set-up for serial receive
         bcf     IPR1,5,0        ; set to low-priority interrupt
@@ -204,10 +203,7 @@ informative_panic
 ; re-initialise timer0 config
         bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
         bcf     T0CON,5,0       ; timer0 use internal clock
-        bcf     T0CON,3,0       ; use prescaler
-        bsf     T0CON,2,0       ; }
-        bcf     T0CON,1,0       ; } prescale value 1:32 (13ms x 32)
-        bcf     T0CON,0,0       ; }
+       bsc_morse_t0con_012     ; use prescaler? and configure it
 
        clrf    BLANK,0
 panic_loop
index fec173bd5c4365ac86c7ddd73900839cab89c53c..037ef823c2e61a87bc9965aafc922bfb8a7920f8 100644 (file)
@@ -1,6 +1,7 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
        extern  led_green
        extern  led_red
@@ -28,17 +29,15 @@ initialise_serial
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
        
 ; initial config - RCSTA register p182
         bsf    RCSTA,7,0       ; serial port enable (p182)
        bsf     RCSTA,6,0       ; 8-bit reception
        bsf     RCSTA,4,0       ; enable continuous receive
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 ; interrupt set-up for serial receive
        bsf     PIE1,5,0        ; enable USART receive interrupt (p85)
@@ -53,11 +52,7 @@ initialise_serial
         bcf     T0CON,6,0       ; p107 Timer0 -> 16bit mode
         bcf     T0CON,5,0       ; timer0 use internal clock
        bcf     INTCON,5,0      ; clear TMR0IE => mask interrupt
-        bcf     T0CON,3,0       ; use prescaler
-        bcf     T0CON,2,0       ; }
-        bsf     T0CON,1,0       ; } prescale value 1:8 (13ms x 8)
-        bcf     T0CON,0,0       ; }
-
+       bsc_morse_t0con_012     ; use prescaler? and configure it
 
 main
        call    led_green
index d02314c7b6889d874031c292d26dfcbb073bc747..1d1b148dae799e791513a6022669d427f78ab87a 100644 (file)
@@ -1,6 +1,7 @@
 ; pin 21 (per-pic-led, RD2/PSP2/C1IN) states: high H = green, low L = red, float Z = black
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
        code
 start
@@ -8,14 +9,11 @@ start
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
         bsf    RCSTA,7,0       ; serial port enable (p182)
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
        call    initialiseascii
 
index 13f1467e506b2fa1df4840ada03ce634fbbbffc9..5f42430e818482774a6f15b24e93fffc68758fdc 100644 (file)
@@ -9,6 +9,7 @@
 
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
        extern  led_green
        extern  led_red
@@ -115,17 +116,15 @@ initialise
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh          ; set high or low baud rate
        
 ; initial config - RCSTA register p182
         bsf    RCSTA,7,0       ; serial port enable (p182)
        bcf     RCSTA,6,0       ; 8-bit reception
        bsf     RCSTA,4,0       ; enable continuous receive
 
-; set SPBRG to get correct baud rate according to table top right p186
-; (Tosc = 20MHz, desired baud rate = 9600)
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+; set SPBRG to get correct baud rate
+       movlw_movwf_spbrg
 
 
 ; interrupt set-up for serial receive
index f6388f808419378bbbb06bf268402e87335a9e83..473d420b47f7aca56ed3eb42db10f79563f463aa 100644 (file)
@@ -9,6 +9,7 @@
        include         panic.inc
        include         morse+auto.inc
        include         ../iwjpictest/insn-aliases.inc
+       include         ../iwjpictest/clockvaries.inc
 
 ;****************************************************************************
 ; MACROS
index f2af7852cc27d768177bcfde0cd30c3ecb908eb6..10a6f5998cf1efd4495bd4c8fb262c520a4adbcb 100644 (file)
@@ -6,6 +6,7 @@
  include /usr/share/gputils/header/p18f458.inc
  radix dec
  include ../iwjpictest/insn-aliases.inc
+ include ../iwjpictest/clockvaries.inc
  include panic.inc
  include morse+auto.inc
 
@@ -90,8 +91,8 @@ slave2addr
 
 ;----------
 i2cm_init
-               mov_lw  100-1   ; baud rate = Fosc/(4*(SSPADD+1))
-               mov_wf  SSPADD  ; Fosc=20MHz, so SSPADD==99 means 50kbit/s
+               mov_lw  i2c_sspadd
+               mov_wf  SSPADD
                clr_f   st
                mov_lw  0x08    ; !SSPEN, Master mode
                mov_wf  SSPCON1
index 97c890becc5c79db794a3847475dda4d2bb9886e..0f6b266fdee587b5c9f30cde3a2470db22e3e973 100644 (file)
@@ -14,6 +14,7 @@
 
 
         include         /usr/share/gputils/header/p18f458.inc
+       include         ../iwjpictest/clockvaries.inc
 
 
 NMRACTRL       equ     0x4     ; byte 4: state relevant to NMRA control
@@ -100,7 +101,7 @@ initialise
         bcf     TXSTA,6,0      ; p181, set 8-bit mode
        bsf     TXSTA,5,0       ; transmit enable
        bcf     TXSTA,4,0       ; asynchronous mode
-       bsf     TXSTA,2,0       ; set high baud rate
+       bsc_txsta_brgh
        
 ; initial config - RCSTA register p182
         bsf    RCSTA,7,0       ; serial port enable (p182)
@@ -109,8 +110,8 @@ initialise
 
 ; set SPBRG to get correct baud rate according to table top right p186
 ; (Tosc = 20MHz, desired baud rate = 9600)
-       bsf     SPBRG,7,0
-       bsf     SPBRG,0,0
+       movlw   serial_spbrg
+       movwf   SPBRG,0
 
 
        debug   0x0A    ; LF to terminak
index 6e9c62b962b1244a3b6db11cd21a5b4708673fa9..c7f6e2f53c23f6192526b6c047916148c43765ad 100644 (file)
@@ -45,11 +45,8 @@ panic_routine
        clr_f    STKPTR         ; avoids stack overruns
 
 ; re-initialise timer0 config
-       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
+       mov_lw  (1<<TMR0ON) | morse_t0scale ; Enable, 16-bit, timer, prescaler
+       mov_wf  T0CON
 
 ; get # bytes of morse msg, # registers in panic readout, message start addr.
 ; back from condensed message start addr. stored in panic_address
@@ -241,11 +238,11 @@ waiting
 ; waits for a fixed interval, depending on the configuration of TMR0
 
         bc_f           INTCON,2        ; clear timer0 interrupt bit (p109)
-; Interrupt happens on overflow.  So start at 65535-waiting_t0cycles:
-       mov_lw  (65535-waiting_t0cycles) / 256
+; Interrupt happens on overflow.  So start at 65535-morse_t0cycles:
+       mov_lw  (65535-morse_t0cycles) / 256
        mov_wf  TMR0H           ; p107 set high byte of timer0 (buffered,
                                 ; only actually set when write to tmr0l occurs)
-       mov_lw  (65535-waiting_t0cycles) & 0xff
+       mov_lw  (65535-morse_t0cycles) & 0xff
         mov_wf         TMR0L           ; set timer0 low byte - timer now set
 waiting_loop
         bt_f_if0 INTCON,TMR0IF         
index 15c0e1a630df277ae995bef618e5ed150dd23ec8..5894eaf09af33e432a94fc61a69efbc925a2baa2 100644 (file)
@@ -76,7 +76,6 @@ picno res     1
 delay_countfast                res     1
 delay_countmedium      res     1
 delay_countslow                res     1
-delay_slowexp          equ     2       ; 2^2 * 40ms = 160ms
 
        code
 
@@ -319,35 +318,8 @@ s_buffer_reset
        return
 
 ;======================================================================
-; delay routine, nicked from flasher.asm
-
-delay
-       ; set a bit which says how fast the led
-       ; should flash and count down from 2^(that bit)
-       bsf             delay_countslow, delay_slowexp, 0
-delayslow_loop
-
-delaymedium_loop
-
-delayfast_loop
-       decfsz          delay_countfast, 1, 0   ; 1 cycle
-       goto            delayfast_loop          ; 2 cycles (skipped or not)
-; exited delayfast_loop                                ; total: 3 * 256 = 768 cycles
-                                               
-
-       decfsz          delay_countmedium, 1, 0 ; 1 cycle
-       goto            delaymedium_loop        ; 2 cycles (skipped or not)
-; exited delaymedium_loop                      ; total: ~198000 cycles
-
-                                               ; each cycle 0.2us
-                                               ; so each medium loop is ~40ms
-
-       decfsz          delay_countslow, 1, 0
-       goto            delayslow_loop
-; exited delayslow_loop
-
-       return
 
+ define_busywait_delay ; from iwjpictest/clockvaries.inc
 
 ;======================================================================
 ; SERIAL LIBRARY
@@ -358,10 +330,10 @@ delayfast_loop
 ;----------------------------------------
 serial_setup
 ; W            undefined       undefined
-       mov_lw          (1<<TXEN) | (1<<BRGH) | (1<<TRMT)
-       mov_wf          TXSTA   ; asynch xmit enabled, high baud rate, 8-bit,
-       mov_lw          129
-       mov_wf          SPBRG   ; 9600bps (with BRGH)
+       mov_lw          (1<<TXEN) | serial_brgh | (1<<TRMT)
+       mov_wf          TXSTA   ; asynch xmit enabled, high baud rate?, 8-bit,
+       mov_lw          serial_spbrg
+       mov_wf          SPBRG
 serial_receive_reset ;from serial_read_if_error
        mov_lw          (1<<SPEN) | (1<<CREN)
        mov_wf          RCSTA   ; enable serial port, continuous rx, 8-bit
index 02dacca1333791255465ac3ac8a82ac6fb623898..03caaa26d3f6cd5424049621273222e096b8483a 100644 (file)
@@ -6,7 +6,7 @@ INSN_TARGETS=   insn-aliases.inc \
 
 PROGRAMS=      flasher copybits serialloop harness
 
-INCLUDES=      insn-aliases.inc  onecopybit.inc  test.inc
+INCLUDES=      insn-aliases.inc  onecopybit.inc  test.inc  clockvaries.inc
 
 include ../common.make
 
diff --git a/iwjpictest/clockvaries.inc b/iwjpictest/clockvaries.inc
new file mode 100644 (file)
index 0000000..8879013
--- /dev/null
@@ -0,0 +1,110 @@
+;----------------------------------------------------------------------
+; various definitions for clock variation
+
+ radix dec
+
+;----------------------------------------------------------------------
+; for serial port at 9600
+; according to table in datasheet top right p186
+
+ if mclock==20000
+serial_brgh equ (1<<BRGH)
+serial_spbrg equ 129
+ endif
+ if mclock==1000
+ endif
+
+bsc_txsta_brgh macro
+ if serial_brgh
+       bsf     TXSTA,2,0       ; set high baud rate
+ else
+       bcf     TXSTA,2,0       ; set low baud rate
+ endif
+ endm
+
+movlw_movwf_spbrg macro
+       movlw   serial_spbrg
+       movwf   SPBRG,0
+       endm
+
+;----------------------------------------------------------------------
+; for i2c at 50kbit/s
+
+; baud rate = Fosc/(4*(SSPADD+1))
+ if mclock==20000
+i2c_sspadd equ 100-1 ; Fosc=20MHz, so SSPADD==99 means 50kbit/s
+ endif
+ if mclock==1000
+ endif
+
+;----------------------------------------------------------------------
+; NMRA at 50us per division
+; ... uh, this isn't going to work at 1MHz because that's only 12.5
+; insns per NMRA division
+
+;----------------------------------------------------------------------
+; for morse at 18wpm according to the PARIS standard
+; (ie a unit time of 66ms) using timer0 (DS p108)
+
+ if mclock==20000
+morse_t0scale equ 0011b ; 1:16 => PSout is 312.5kHz or 3.2us per period
+morse_t0cycles equ 20833 ; see by `waiting', below
+ endif
+ if mclock==1000
+;morse_t0scale equ 0011b ; 1:2 => PSout is 312.5kHz or 3.2us per period
+;morse_t0cycles equ 0
+ endif
+
+bsc_morse_t0con_012 macro
+       movf    T0CON,0,0
+       andlw   0xf0
+       iorlw   morse_t0scale
+       movwf   T0CON,0
+       endm
+
+;----------------------------------------------------------------------
+; busy-wait delay loop, originally from flasher.asm
+
+ if mclock==20000 ; each cycle 0.2us
+delay_fastloop         equ     1       ; each medium loop = ~40ms
+delay_slowexp          equ     2       ; 2^2 * 40ms = 160ms
+ endif
+ if mclock==1000 ; each cycle 4us
+delay_fastloop         equ     0       ; each medium loop = ~3ms
+delay_slowexp          equ     6       ; 2^6 * 3ms = 192ms
+ endif
+
+define_busywait_delay macro
+delay
+
+; we always leave each loop when its counter has reached 0, so on
+; entry we assume it's already 0.  For the loops which want to
+; count all the way (256 iterations) that's good.
+
+       ; set a bit which says how fast the led
+       ; should flash and count down from 2^(that bit)
+       bsf             delay_countslow, delay_slowexp, 0
+delayslow_loop
+
+delaymedium_loop
+
+ if delay_fastloop
+delayfast_loop
+       decfsz          delay_countfast, 1, 0   ; 1 cycle
+       goto            delayfast_loop          ; 2 cycles (skipped or not)
+; exited delayfast_loop                                ; total: 3 * 256 = 768 cycles
+ endif
+                                               
+
+       decfsz          delay_countmedium, 1, 0 ; 1 cycle
+       goto            delaymedium_loop        ; 2 cycles (skipped or not)
+; exited delaymedium_loop                      ; total: ~198000 cycles
+                                               ; or     ~768 cycles (no fast)
+
+       decfsz          delay_countslow, 1, 0
+       goto            delayslow_loop
+; exited delayslow_loop
+
+       return
+
+       endm
index be1ce03bcdb9771693bf2503212cc7f867eb3605..ef01cf3345491b40776e9094ef4d17a3b0639a7d 100644 (file)
        include         /usr/share/gputils/header/p18f458.inc
        include         onecopybit.inc
 
+       radix           dec
+
 ACCSFR         equ             0x0f00
 
 COUNTINNER     equ             0x00
 COUNTOUTER     equ             0x02
 
+ if mclock==20000
 OUTEREXP               equ             7       ; 2^7 * 2.6ms = 332ms
+ endif
+ if mclock==1000
+OUTEREXP               equ             2       ; 2^2 * 52ms = 208ms
+ endif
 
 ; we always leave each loop when its counter has reached 0, so on
 ; entry we assume it's already 0.  For the loops which want to
index e7bac426aa07bb1a4dc7c83c52a0bea9829d214a..85e915baadd36ec62f15b4f0ac5d33fc9a40e176 100644 (file)
@@ -7,17 +7,13 @@
 ;   * leaves all other pins set to their default states (usually Z).
 
        include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
 
-COUNTFAST      equ             0x00
-COUNTMEDIUM    equ             0x01
-COUNTSLOW      equ             0x02
-
-SLOWEXP                equ             2       ; 2^2 * 40ms = 160ms
-
-; we always leave each loop when its counter has reached 0, so on
-; entry we assume it's already 0.  For the loops which want to
-; count all the way (256 iterations) that's good.
+delay_countfast                equ             0x00
+delay_countmedium      equ             0x01
+delay_countslow                equ             0x02
 
+ include clockvaries.inc
        code
 
 start
@@ -60,31 +56,6 @@ black
        call            delay
        goto            delay
 
-delay
-       ; set a bit which says how fast the led
-       ; should flash and count down from 2^(that bit)
-       bsf             COUNTSLOW, SLOWEXP, 0
-delayslow_loop
-
-delaymedium_loop
-
-delayfast_loop
-       decfsz          COUNTFAST, 1, 0         ; 1 cycle
-       goto            delayfast_loop          ; 2 cycles (skipped or not)
-; exited delayfast_loop                                ; total: 3 * 256 = 768 cycles
-                                               
-
-       decfsz          COUNTMEDIUM, 1, 0       ; 1 cycle
-       goto            delaymedium_loop        ; 2 cycles (skipped or not)
-; exited delaymedium_loop                      ; total: ~198000 cycles
-
-                                               ; each cycle 0.2us
-                                               ; so each medium loop is ~40ms
-
-       decfsz          COUNTSLOW, 1, 0
-       goto            delayslow_loop
-; exited delayslow_loop
-
-       return
+ define_busywait_delay
 
        end
index 09716c18fd824e7cf038d5b2a95fa8b11376c42c..eb25d2b65a1a46cb05bdf60a269f6ef5d4b51601 100644 (file)
@@ -50,6 +50,7 @@
        nolist
        include         /usr/share/gputils/header/p18f458.inc
        include         insn-aliases.inc
+       include         clockvaries.inc
 ;      list
        radix           dec
 
@@ -419,9 +420,9 @@ led_green
 ;----------------------------------------
 serial_setup
 ; W            undefined       undefined
-       mov_lw          (1<<TXEN) | (1<<BRGH) | (1<<TRMT)
+       mov_lw          (1<<TXEN) | serial_brgh | (1<<TRMT)
        mov_wf          TXSTA   ; asynch xmit enabled, high baud rate, 8-bit,
-       mov_lw          129
+       mov_lw          serial_spbrg
        mov_wf          SPBRG   ; 9600bps (with BRGH)
 serial_receive_reset ;from serial_read_if_error
        mov_lw          (1<<SPEN) | (1<<CREN)
index ce93bd02a210e9f0555e138a548916bb65e5eabe..c9836a0e9b3e7b1f30cf566676fc7d0181be9021 100644 (file)
@@ -9,12 +9,18 @@
 ; as shown in diagram SERIAL LOOP TEST
 ; 
        include         /usr/share/gputils/header/p18f458.inc
+       radix           dec
        include         onecopybit.inc
 
 COUNTINNER     equ             0x00
 COUNTOUTER     equ             0x02
 
+ if mclock==20000
 OUTEREXP               equ             7       ; 2^7 * 1.4ms = 177ms
+ endif
+ if mclock==1000
+OUTEREXP               equ             3       ; 2^3 * 28ms = 224ms
+ endif
 
 ; we always leave each loop when its counter has reached 0, so on
 ; entry we assume it's already 0.  For the loops which want to
index 45009c60db3f10b36e7b0265d318cf551ee2660c..f652bc54c9fcc5c4348db2539b75486976bd54a6 100644 (file)
--- a/pic.make
+++ b/pic.make
 #   FOO-entire0.hex    FOO.o           idlocs0.o       config.o
 #   perpicNUMBER.hex                   idlocsNUMBER.o  config.o
 
+#ASFLAGS=      -Dmclock=20000d -Dsclock=20000d
+ASFLAGS=       -Dmclock=1000 -Dsclock=1000
+
 LINK=          gplink -m -o $@ $^
-ASSEMBLE=      gpasm -p 18f458
+ASSEMBLE=      gpasm -p 18f458 $(ASFLAGS)
 
 %.o:           %.asm $(INCLUDES)
                $(ASSEMBLE) -c $<