4 ; * copies serial port flow control and data straight through,
5 ; as a serial port loopback test
6 ; * copies a few bits about
7 ; * flashes PER-PIC-LED
8 ; * leaves all other pins set to their default states (usually Z).
9 ; as shown in diagram SERIAL LOOP TEST
11 include /usr/share/gputils/header/p18f458.inc
13 include onecopybit.inc
19 OUTEREXP equ 7 ; 2^7 * 1.4ms = 177ms
22 OUTEREXP equ 3 ; 2^3 * 28ms = 224ms
26 ; we always leave each loop when its counter has reached 0, so on
27 ; entry we assume it's already 0. For the loops which want to
28 ; count all the way (256 iterations) that's good.
33 bcf TRISD, 2, 0 ; enable per-pic led output
34 bcf TRISC, 6, 0 ; enable TXD output (RC6)
35 bcf TRISC, 5, 0 ; enable FCO output (RC5)
36 bcf TRISD, 4, 0 ; enable output D
39 btg LATD, 2, 0 ; toggle per-pic led output
41 ; set a bit which says how fast the led
42 ; should flash and count down from 2^(that bit)
43 bsf COUNTOUTER, OUTEREXP, 0
47 copybit PORTB, 3, LATA, 0x08 ; A data
48 copybiti PORTD, 7, TRISA, 0x08 ; A enable
49 copybiti PORTA, 6, LATD, 0x10 ; D
50 copybit PORTB, 4, LATC, 0x20 ; serial FC
51 copybit PORTC, 7, LATC, 0x40 ; serial data
52 ; 6 x copybit @6 = 24cy
54 decfsz COUNTINNER, 1, 0 ; 1 cycle
55 goto delayinner_loop ; 2 cycles (skipped or not)
56 ; exited delayinner_loop ; total: 27cy * 256 = 6912cy
59 ; so each inner loop is ~1.4ms
61 decfsz COUNTOUTER, 1, 0
63 ; exited delayouter_loop