chiark / gitweb /
undo broken deletion
[trains.git] / iwjpictest / copybits.asm
1 ; -*- fundamental -*-
2
3 ; This program:
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).
10
11         include         /usr/share/gputils/header/p18f458.inc
12         include         onecopybit.inc
13
14         radix           dec
15
16 ACCSFR          equ             0x0f00
17
18 COUNTINNER      equ             0x00
19 COUNTOUTER      equ             0x02
20
21  if mclock>=20000
22 OUTEREXP                equ             7       ; 2^7 * 2.6ms = 332ms
23  else
24  if mclock==1000
25 OUTEREXP                equ             2       ; 2^2 * 52ms = 208ms
26  endif
27  endif
28
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.
32
33         code
34
35 start
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)
43
44 loop
45         btg             LATA, 0, 0      ; toggle flasher pin output
46         btg             LATD, 2, 0      ; toggle per-pic led output
47
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
51 delayouter_loop
52
53 delayinner_loop
54
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
63
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
69
70         decfsz          COUNTINNER, 1, 0        ; 1 cycle
71         goto            delayinner_loop         ; 2 cycles (skipped or not)
72 ; exited delayinner_loop                        ; total: 51cy * 256 = 13056cy
73
74                                                 ; each cycle 0.2us
75                                                 ; so each inner loop is ~2.6ms
76
77         decfsz          COUNTOUTER, 1, 0
78         goto            delayouter_loop
79 ; exited delayouter_loop
80
81         goto            loop
82
83         end