4 ; * copies input signals from input pins to output pins, as shown in
5 ; the `TEST-LEFT' and `TEST-RIGHT' PIC pinout diagrams;
6 ; * flashes PER-PIC-LED (pin 21) and FLASHER (pin 2) in the
7 ; pattern [high-low] with 50% duty cycle with period approx 660ms
8 ; (assuming 20MHz clock input).
9 ; * leaves all other pins set to their default states (usually Z).
11 include /usr/share/gputils/header/p18f458.inc
12 include onecopybit.inc
22 OUTEREXP equ 7 ; 2^7 * 2.6ms = 332ms
25 OUTEREXP equ 2 ; 2^2 * 52ms = 208ms
29 ; we always leave each loop when its counter has reached 0, so on
30 ; entry we assume it's already 0. For the loops which want to
31 ; count all the way (256 iterations) that's good.
36 bcf TRISA, 0, 0 ; enable flasher pin output
37 bcf TRISD, 2, 0 ; enable per-pic led output
38 movlw 0x07 ; turn off A-to-D so we get
39 movwf ADCON1, 0 ; digital inputs on RA0-3 (AN0-3)
40 bcf TRISD, 4, 0 ; enable output D
41 movlw 0x1f ; enable outputs E,F,G
42 movwf TRISC, 0 ; (RC7,6,5)
45 btg LATA, 0, 0 ; toggle flasher pin output
46 btg LATD, 2, 0 ; toggle per-pic led output
48 ; set a bit which says how fast the led
49 ; should flash and count down from 2^(that bit)
50 bsf COUNTOUTER, OUTEREXP, 0
55 copybiti PORTB, 5, TRISA, 0x06 ; C enable
56 copybit PORTB, 4, LATA, 0x06 ; C data
57 copybiti PORTB, 3, TRISA, 0x18 ; B enable
58 copybit PORTB, 2, LATA, 0x18 ; B data
59 copybiti PORTB, 1, TRISA, 0x20 ; A enable
60 copybiti PORTB, 1, TRISE, 0x01 ; A enable
61 copybit PORTB, 0, LATA, 0x20 ; A data
62 copybit PORTB, 0, LATE, 0x01 ; A data
64 copybiti PORTA, 6, LATD, 0x10 ; D
65 copybiti PORTC, 0, LATC, 0x80 ; E
66 copybiti PORTC, 1, LATC, 0x40 ; F
67 copybiti PORTC, 2, LATC, 0x20 ; G
68 ; 12 x copybit @6 = 48cy
70 decfsz COUNTINNER, 1, 0 ; 1 cycle
71 goto delayinner_loop ; 2 cycles (skipped or not)
72 ; exited delayinner_loop ; total: 51cy * 256 = 13056cy
75 ; so each inner loop is ~2.6ms
77 decfsz COUNTOUTER, 1, 0
79 ; exited delayouter_loop