📄 slavuart.lst
字号:
SLAVUART PAGE 1
1 ;====================================================================
2 ;
3 ; Author : ADI - Apps
4 ;
5 ; Date : October 2003
6 ;
7 ; File : SLAVuart.asm
8 ;
9 ; Hardware : ADuC842
10 ;
11 ; Description : This slave program transmits the numbers 11-20 in
12 ; binary form continuously down the SPI serial port
13 ; after receiving a clock signal.
14 ;
15 ; After the transmission of each byte the incoming
16 ; byte is saved in order at an internal RAM address
17 ; between #40h and #50h.
18 ;
19 ; This program can be used with the master program
20 ; MASTuart.asm (which generates a clock signal for
21 ; the slave)
22 ;
23 ; After the 16 input bytes have been stored in memory
24 ; the values in memory are outputted up the UART to
25 ; the PC where they can be viewed on screen by a
26 ; program such as Hyperterminal. After each
27 ; transmission up the UART the program is delayed for
28 ; 1s before returning from the interrupt. It then
29 ; waits for the next data byte from the SPI port
30 ; which will arrive about 4s later if used with the
31 ; Master program (MASTuart.asm).
32 ;
33 ; The Slave program (SLAVuart.asm) should be started
34 ; after the master program (MASTuart.asm) but within
35 ; the time delay of 2s in order that the slave
36 ; program is synchronised by the first outputted
37 ; clock of the master.
38 ;
39 ; The clock is inputted at sclock (pin 26)
40 ; The data is outputted at MISO (pin 14)
41 ; The data is inputted at sdata/MOSI (pin 27)
42 ;====================================================================
43 ;
44 $MOD842 ;Use 8052 predefined Symbols
45
00B4 46 LED EQU P3.4
0000 47 FLAG BIT 00H
48
49 ;____________________________________________________________________
50 ; BEGINNING OF CODE
---- 51 CSEG
0000 52 ORG 0000H
53
0000 020060 54 JMP MAIN
55 ;____________________________________________________________________
56 ; SPI INTERRUPT ROUTINE
003B 57 ORG 003BH
003B C200 58 CLR FLAG ; Clear flag to leave LOOP2
SLAVUART PAGE 2
59
003D A7F7 60 MOV @R1, SPIDAT ; move input into memory
003F 09 61 INC R1 ; increment memory location so new
62 ; data is stored in new address
63
0040 B95003 64 CJNE R1, #50H, CONT ; reset memory location to 40h when
65 ; memory location reaches 50h saving
66 ; 16 bytes of data
67
0043 120088 68 CALL SNDUART
69
0046 32 70 CONT: RETI
71
72
73 ;====================================================================
74
0060 75 ORG 0060H ; Start code at address above interrupts
76
0060 77 MAIN: ; Main program
0060 75D703 78 MOV PLLCON,#03H
0063 759E83 79 MOV T3CON,#083h
0066 759D2D 80 MOV T3FD,#02Dh
0069 759852 81 MOV SCON,#052h
82
006C 75F824 83 MOV SPICON,#24h ; Initialise SPICON to have
84 ; -Enable SPI serial port
85 ; -slave mode select
86 ; -CPOL=0, clk idling low
87 ; -CPHA=1
88 ; note: it is important to have CPHA in the master and the slave
89 ; program equal, otherwise uncertainty will exist, as the input
90 ; will be measued during its change of state, and not is at
91 ; its final value.
92
006F 75A901 93 MOV IEIP2, #01h ; Enable SPI interrupt
0072 D2AF 94 SETB EA ; Enable interrupts
95
0074 7940 96 MOV R1, #40h ; initialise R1 to 40 to store the
97 ; input data from memory location 40
0076 780A 98 MOV R0, #0AH ; initialise R0 to 10
99
0078 100 TRNSMT:
0078 08 101 INC R0
0079 88F7 102 MOV SPIDAT, R0 ; transmit the current value on R0
007B D200 103 SETB FLAG ; set flag so that we wait here until
104 ; the spi interrupt routine clears
105 ; the FLAG
106
007D 2000FD 107 JB FLAG, $ ; stay here until flag is cleared
108 ; by interrupt
109
110 ; check if R0 is equal to 20. If so the number 20 has been
111 ; transmitted and we should reset R0 to 10 to start transmission
112 ; from 11 again.
0080 E8 113 MOV A, R0
0081 B414F4 114 CJNE A, #14H, TRNSMT ; if R0 is not 20, jump to TRNSMT
0084 780A 115 MOV R0, #0AH ; if R0=20 make R0=10 & jump to TRNSMT
0086 80F0 116 JMP TRNSMT
SLAVUART PAGE 3
117
118
119 ; Transmit the values in locations 40h->50h up the UART wait for
120 ; 1 seconds and then transmit and receive values to/from the Master
121 ; again down the SPI port.
122
0088 123 SNDUART:
0088 B2B4 124 CPL LED ;CPL LED with each transmission
008A 900100 125 MOV DPTR, #TITLE
008D 1200B4 126 CALL SENDSTRING ; write title block on screen
127
0090 7940 128 MOV R1, #40h ; move value at address 40 into R2
0092 E7 129 MOV A, @R1
0093 FA 130 MOV R2, A
0094 131 NEXT: ; Put new value on a new line
0094 740A 132 MOV A, #10 ; Transmit a linefeed (= ASCII 10)
0096 1200CC 133 CALL SENDCHAR
0099 740D 134 MOV A, #13 ;Transmit a carriage return (=ASCII 13)
009B 1200CC 135 CALL SENDCHAR
136
009E EA 137 MOV A, R2 ; Transmit R2 i.e. value @ address R1
009F 1200D4 138 CALL SENDVAL
00A2 09 139 INC R1 ; Increment address
00A3 E7 140 MOV A, @R1
00A4 FA 141 MOV R2, A ; R2 holds the value @ addrR1
142
00A5 E9 143 MOV A, R1 ; Check if at address 50h
00A6 B450EB 144 CJNE A, #50h, NEXT ; if not jump to Next
00A9 0200AC 145 JMP WAIT1S ; if so wait 1s and repeat
146
00AC 7464 147 WAIT1S: MOV A, #100 ; wait for time less than master to
148 ; synchronise with the master
00AE 1200F4 149 CALL DELAY
00B1 7940 150 MOV R1, #40h ; store new inputs at address 40h again
00B3 22 151 RET
152
153
154 ;____________________________________________________________________
155 ; SENDSTRING
156
00B4 157 SENDSTRING: ; sends ASCII string to UART starting at location
158 ; DPTR and ending with a null (0) value
159
00B4 C0E0 160 PUSH ACC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -