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 ;----------------------------------------------------------------------
44 i2c_sspadd equ (mclock/(i2c_kbitpersec*4)) - 1 ; 50kbit/s
46 ;----------------------------------------------------------------------
47 ; NMRA at 50us per division
48 ; ... uh, this isn't going to work at 1MHz because that's only 12.5
49 ; insns per NMRA division
52 ;----------------------------------------------------------------------
53 ; busy-wait delay loop, originally from flasher.asm
55 implement_busywait_delay macro tclock
57 ; we always leave each loop when its counter has reached 0, so on
58 ; entry we assume it's already 0. For the loops which want to
59 ; count all the way (256 iterations) that's good.
61 ; set a bit which says how fast the led
62 ; should flash and count down from 2^(that bit)
65 local medium_cycles=198000
68 local medium_cycles=768
70 ; now 1/(medium_period in ms)
71 ; = tclock / (medium_cycles*4)
72 movlw 50 * tclock / medium_cycles ; 200ms
73 movwf delay_countslow, 0
76 local delaymedium_loop
84 decfsz delay_countfast, 1, 0 ; 1 cycle
85 goto delayfast_loop ; 2 cycles (skipped or not)
86 ; exited delayfast_loop ; total: 3 * 256 = 768 cycles
90 decfsz delay_countmedium, 1, 0 ; 1 cycle
91 goto delaymedium_loop ; 2 cycles (skipped or not)
92 ; exited delaymedium_loop ; total: ~198000 cycles
93 ; or ~768 cycles (no fast)
95 decfsz delay_countslow, 1, 0
97 ; exited delayslow_loop
101 define_busywait_delay macro
103 implement_busywait_delay clock