| MODULE PIO; (*NW 16.10.2014 PIC Input/Output for RISC*) |
| .MODULE PIO (KEY E4FAD793, VERSION 1, SIZE 000001C4) |
| .FIXUP T 0H |
| IMPORT SYSTEM; |
| |
| (* PIC interface, output: |
| D0 = PIC B7 data out |
| D1 = PIC B6 clk out |
| D2 = PIC A4 data in *) |
| |
| CONST gpio = -32; gpoc = -28; (*I/O addresses*) |
| |
| PROCEDURE del(i: INTEGER); |
| BEGINa |
0000 | a(4EE90008): SUB SP, SP, 8H |
0001 | a(AFE00000): STR LNK, SP, 0H |
0002 | a(A0E00004): STR R0, SP, 4H |
| REPEAT DEC(i) UNTILb i = 0 |
0003 | b(80E00004): LDR R0, SP, 4H |
0004 | b(40090001): SUB R0, R0, 1H |
0005 | b(A0E00004): STR R0, SP, 4H |
| ENDc del; |
0006 | c(80E00004): LDR R0, SP, 4H |
0007 | c(E9FFFFFB): BNE -5 [0003H] |
0008 | c(8FE00000): LDR LNK, SP, 0H |
0009 | c(4EE80008): ADD SP, SP, 8H |
000A | c(C700000F): B LNK |
| |
| PROCEDURE Send*(x: LONGINT); |
| VAR i: INTEGER; |
| BEGINd (*send byte*) |
000B | d .PROC 1 |
000B | d(4EE9000C): SUB SP, SP, CH |
000C | d(AFE00000): STR LNK, SP, 0H |
000D | d(A0E00004): STR R0, SP, 4H |
| FOR i := 0 TOe 7 DO |
000E | e(40000000): MOV R0, R0, 0H |
| SYSTEMf.PUT(gpio, x MOD 2 +g 2)h;i del(60)j;k SYSTEM.PUT(gpio, x MOD 2)l;m del(25)n;o x := x DIV 2 |
000F | f(41090007): SUB R1, R0, 7H |
0010 | f(EE000014): BGT 20 [0025H] |
0011 | f(A0E00008): STR R0, SP, 8H |
0012 | g(80E00004): LDR R0, SP, 4H |
0013 | g(40040001): AND R0, R0, 1H |
0014 | h(40080002): ADD R0, R0, 2H |
0015 | i(5100FFE0): MOV R1, R0, FFFFFFE0H |
0016 | i(A0100000): STR R0, R1, 0H |
0017 | j(4000003C): MOV R0, R0, 3CH |
0018 | k(F7FFFFE7): BL -25 [0000H] |
0019 | l(80E00004): LDR R0, SP, 4H |
001A | l(40040001): AND R0, R0, 1H |
001B | m(5100FFE0): MOV R1, R0, FFFFFFE0H |
001C | m(A0100000): STR R0, R1, 0H |
001D | n(40000019): MOV R0, R0, 19H |
001E | o(F7FFFFE1): BL -31 [0000H] |
| ENDp ;q |
001F | p(80E00004): LDR R0, SP, 4H |
0020 | p(40020001): ASR R0, R0, 1H |
0021 | p(A0E00004): STR R0, SP, 4H |
0022 | q(80E00008): LDR R0, SP, 8H |
0023 | q(40080001): ADD R0, R0, 1H |
0024 | q(E7FFFFEA): B -22 [000FH] |
| SYSTEM.PUT(gpio, 0);r del(100)s |
0025 | r(5000FFE0): MOV R0, R0, FFFFFFE0H |
0026 | r(41000000): MOV R1, R0, 0H |
0027 | r(A1000000): STR R1, R0, 0H |
0028 | s(40000064): MOV R0, R0, 64H |
| ENDt Send; |
0029 | t(F7FFFFD6): BL -42 [0000H] |
002A | t(8FE00000): LDR LNK, SP, 0H |
002B | t(4EE8000C): ADD SP, SP, CH |
002C | t(C700000F): B LNK |
| |
| PROCEDURE Receive*(VAR x: LONGINT); |
| VAR i, x0: INTEGER; |
| BEGINu (*receive byte*) x0 := 0;v |
002D | u .PROC 2 |
002D | u(4EE90010): SUB SP, SP, 10H |
002E | u(AFE00000): STR LNK, SP, 0H |
002F | u(A0E00004): STR R0, SP, 4H |
0030 | v(40000000): MOV R0, R0, 0H |
0031 | v(A0E0000C): STR R0, SP, CH |
| REPEAT UNTIL ~SYSTEM.BIT(gpio, 2);w |
0032 | w(5000FFE0): MOV R0, R0, FFFFFFE0H |
0033 | w(80000000): LDR R0, R0, 0H |
0034 | w(40030003): ROR R0, R0, 3H |
0035 | w(E0FFFFFC): BMI -4 [0032H] |
| FOR i := 0 TOx 7 DO |
0036 | x(40000000): MOV R0, R0, 0H |
| SYSTEMy.PUT(gpio, 2);z del(60)a;b |
0037 | y(41090007): SUB R1, R0, 7H |
0038 | y(EE000018): BGT 24 [0051H] |
0039 | y(A0E00008): STR R0, SP, 8H |
003A | z(5000FFE0): MOV R0, R0, FFFFFFE0H |
003B | z(41000002): MOV R1, R0, 2H |
003C | z(A1000000): STR R1, R0, 0H |
003D | a(4000003C): MOV R0, R0, 3CH |
003E | b(F7FFFFC1): BL -63 [0000H] |
| IF SYSTEM.BIT(gpio, 2) THENc x0 := x0 + 100H ENDd ; |
003F | c(5000FFE0): MOV R0, R0, FFFFFFE0H |
0040 | c(80000000): LDR R0, R0, 0H |
0041 | c(40030003): ROR R0, R0, 3H |
0042 | c(E8000003): BPL 3 [0046H] |
0043 | d(80E0000C): LDR R0, SP, CH |
0044 | d(40080100): ADD R0, R0, 100H |
0045 | d(A0E0000C): STR R0, SP, CH |
| SYSTEM.PUT(gpio, 0);e del(25)f;g x0 := ROR(x0, 1) |
0046 | e(5000FFE0): MOV R0, R0, FFFFFFE0H |
0047 | e(41000000): MOV R1, R0, 0H |
0048 | e(A1000000): STR R1, R0, 0H |
0049 | f(40000019): MOV R0, R0, 19H |
004A | g(F7FFFFB5): BL -75 [0000H] |
| ENDh ;i |
004B | h(80E0000C): LDR R0, SP, CH |
004C | h(40030001): ROR R0, R0, 1H |
004D | h(A0E0000C): STR R0, SP, CH |
004E | i(80E00008): LDR R0, SP, 8H |
004F | i(40080001): ADD R0, R0, 1H |
0050 | i(E7FFFFE6): B -26 [0037H] |
| x := x0 |
| ENDj Receive; |
0051 | j(80E0000C): LDR R0, SP, CH |
0052 | j(81E00004): LDR R1, SP, 4H |
0053 | j(A0100000): STR R0, R1, 0H |
0054 | j(8FE00000): LDR LNK, SP, 0H |
0055 | j(4EE80010): ADD SP, SP, 10H |
0056 | j(C700000F): B LNK |
| |
| PROCEDURE Reset*; |
| BEGINk SYSTEM.PUT(gpio, 0);l SYSTEM.PUT(gpoc, 3) (*set bit 0, 1 to output*) |
0057 | k .PROC 3 |
0057 | k .COMMAND Reset |
0057 | k(4EE90004): SUB SP, SP, 4H |
0058 | k(AFE00000): STR LNK, SP, 0H |
0059 | l(5000FFE0): MOV R0, R0, FFFFFFE0H |
005A | l(41000000): MOV R1, R0, 0H |
005B | l(A1000000): STR R1, R0, 0H |
| ENDm Reset; |
005C | m(5000FFE4): MOV R0, R0, FFFFFFE4H |
005D | m(41000003): MOV R1, R0, 3H |
005E | m(A1000000): STR R1, R0, 0H |
005F | m(8FE00000): LDR LNK, SP, 0H |
0060 | m(4EE80004): ADD SP, SP, 4H |
0061 | m(C700000F): B LNK |
| |
| BEGINn Reset |
0062 | n .PROC 0 |
0062 | n .ENTRYPOINT |
0062 | n(4EE90004): SUB SP, SP, 4H |
0063 | n(AFE00000): STR LNK, SP, 0H |
| ENDo PIO.p |
0064 | o(F7FFFFF2): BL -14 [0057H] |
0065 | p(8FE00000): LDR LNK, SP, 0H |
0066 | p(4EE80004): ADD SP, SP, 4H |
0067 | p(C700000F): B LNK |