1 ;----------------------------------------------------------------------
2 ; various definitions for clock variation
6 ;----------------------------------------------------------------------
7 ; for serial port at 9600
8 ; according to table in datasheet top right p186
11 serial_brgh equ (1<<BRGH)
15 serial_brgh equ (1<<BRGH)
19 serial_brgh equ (1<<BRGH)
20 serial_spbrg equ 6 ; 7% error :-(
25 bsf TXSTA,2,0 ; set high baud rate
27 bcf TXSTA,2,0 ; set low baud rate
31 movlw_movwf_spbrg macro
34 error "unsupported clock speed (serial_spbrg)"
40 ;----------------------------------------------------------------------
43 i2c_sspadd equ (mclock/(50*4)) - 1 ; 50kbit/s
45 ;----------------------------------------------------------------------
46 ; NMRA at 50us per division
47 ; ... uh, this isn't going to work at 1MHz because that's only 12.5
48 ; insns per NMRA division
51 ;----------------------------------------------------------------------
52 ; busy-wait delay loop, originally from flasher.asm
54 implement_busywait_delay macro tclock
56 ; we always leave each loop when its counter has reached 0, so on
57 ; entry we assume it's already 0. For the loops which want to
58 ; count all the way (256 iterations) that's good.
60 ; set a bit which says how fast the led
61 ; should flash and count down from 2^(that bit)
64 local medium_cycles=198000
67 local medium_cycles=768
69 ; now 1/(medium_period in ms)
70 ; = tclock / (medium_cycles*4)
71 movlw 50 * tclock / medium_cycles ; 200ms
72 movwf delay_countslow, 0
75 local delaymedium_loop
83 decfsz delay_countfast, 1, 0 ; 1 cycle
84 goto delayfast_loop ; 2 cycles (skipped or not)
85 ; exited delayfast_loop ; total: 3 * 256 = 768 cycles
89 decfsz delay_countmedium, 1, 0 ; 1 cycle
90 goto delaymedium_loop ; 2 cycles (skipped or not)
91 ; exited delaymedium_loop ; total: ~198000 cycles
92 ; or ~768 cycles (no fast)
94 decfsz delay_countslow, 1, 0
96 ; exited delayslow_loop
100 define_busywait_delay macro
102 implement_busywait_delay clock