chiark / gitweb /
undo broken deletion
[trains.git] / iwjpictest / serialloop.asm
1 ; -*- fundamental -*-
2
3 ; This program:
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
10
11         include         /usr/share/gputils/header/p18f458.inc
12         radix           dec
13         include         onecopybit.inc
14
15 COUNTINNER      equ             0x00
16 COUNTOUTER      equ             0x02
17
18  if mclock>=20000
19 OUTEREXP                equ             7       ; 2^7 * 1.4ms = 177ms
20  else
21  if mclock==1000
22 OUTEREXP                equ             3       ; 2^3 * 28ms = 224ms
23  endif
24  endif
25
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.
29
30         code
31
32 start
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
37
38 loop
39         btg             LATD, 2, 0      ; toggle per-pic led output
40
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
44 delayouter_loop
45
46 delayinner_loop
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
53
54         decfsz          COUNTINNER, 1, 0        ; 1 cycle
55         goto            delayinner_loop         ; 2 cycles (skipped or not)
56 ; exited delayinner_loop                        ; total: 27cy * 256 = 6912cy
57
58                                                 ; each cycle 0.2us
59                                                 ; so each inner loop is ~1.4ms
60
61         decfsz          COUNTOUTER, 1, 0
62         goto            delayouter_loop
63 ; exited delayouter_loop
64
65         goto            loop
66
67         end