;
-; __config config
+ include /usr/share/gputils/header/p18f458.inc
- db 0x00
+; __config _CONFIG1L, 0xff
+ __config _CONFIG1H, _OSCS_OFF_1H & _ECIO_OSC_1H
+ __config _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
+ __config _CONFIG2H, _WDT_OFF_2H
+; __config _CONFIG3L, 0xff
+; __config _CONFIG3H, 0xff
+ __config _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_ON_4L
+; __config _CONFIG4H, 0xff
+ __config _CONFIG5L, 0xff
+ __config _CONFIG5H, 0xff
+ __config _CONFIG6L, 0xff
+ __config _CONFIG6H, 0xff
+ __config _CONFIG7L, 0xff
+ __config _CONFIG7H, 0xff
-__config
- db 0x00, 0x15, 0x00, 0x00
- db 0x00, 0x00, 0x85, 0x00
- db 0x0f, 0xc0, 0x0f, 0xe0
- db 0x0f, 0x40
+ACCSFR equ 0x0f00
- end
+COUNTFAST equ 0x00
+COUNTMEDIUM equ 0x01
+COUNTSLOW equ 0x02
+
+SLOWEXP equ 3 ; 2^3 * 40ms = 320ms
+
+; 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.
+
+start
+ bcf TRISA-ACCSFR, 0, 0
+loop
+ btg LATA-ACCSFR, 0, 0
+
+ ; 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
+
+ goto loop
+
+ end
;
-; __config config
+ include /usr/share/gputils/header/p18f458.inc
- db 0x00
+; __config _CONFIG1L, 0xff
+ __config _CONFIG1H, _OSCS_OFF_1H & _ECIO_OSC_1H
+ __config _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
+ __config _CONFIG2H, _WDT_OFF_2H
+; __config _CONFIG3L, 0xff
+; __config _CONFIG3H, 0xff
+ __config _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_ON_4L
+; __config _CONFIG4H, 0xff
+ __config _CONFIG5L, 0xff
+ __config _CONFIG5H, 0xff
+ __config _CONFIG6L, 0xff
+ __config _CONFIG6H, 0xff
+ __config _CONFIG7L, 0xff
+ __config _CONFIG7H, 0xff
-__config
- db 0x00, 0x15, 0x00, 0x00
- db 0x00, 0x00, 0x85, 0x00
- db 0x0f, 0xc0, 0x0f, 0xe0
- db 0x0f, 0x40
+ACCSFR equ 0x0f00
- end
+COUNTFAST equ 0x00
+COUNTMEDIUM equ 0x01
+COUNTSLOW equ 0x02
+
+SLOWEXP equ 3 ; 2^3 * 40ms = 320ms
+
+; 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.
+
+start
+ bcf TRISA-ACCSFR, 0, 0
+loop
+ btg LATA-ACCSFR, 0, 0
+
+ ; 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
+
+ goto loop
+
+ end
;
-; __config config
+ include /usr/share/gputils/header/p18f458.inc
- db 0x00
+; __config _CONFIG1L, 0xff
+ __config _CONFIG1H, _OSCS_OFF_1H & _ECIO_OSC_1H
+ __config _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L
+ __config _CONFIG2H, _WDT_OFF_2H
+; __config _CONFIG3L, 0xff
+; __config _CONFIG3H, 0xff
+ __config _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVR_ON_4L
+; __config _CONFIG4H, 0xff
+ __config _CONFIG5L, 0xff
+ __config _CONFIG5H, 0xff
+ __config _CONFIG6L, 0xff
+ __config _CONFIG6H, 0xff
+ __config _CONFIG7L, 0xff
+ __config _CONFIG7H, 0xff
-__config
- db 0x00, 0x15, 0x00, 0x00
- db 0x00, 0x00, 0x85, 0x00
- db 0x0f, 0xc0, 0x0f, 0xe0
- db 0x0f, 0x40
+ACCSFR equ 0x0f00
- end
+COUNTFAST equ 0x00
+COUNTMEDIUM equ 0x01
+COUNTSLOW equ 0x02
+
+SLOWEXP equ 3 ; 2^3 * 40ms = 320ms
+
+; 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.
+
+start
+ bcf TRISA-ACCSFR, 0, 0
+loop
+ btg LATA-ACCSFR, 0, 0
+
+ ; 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
+
+ goto loop
+
+ end