📄 mastuart.lst
字号:
MASTUART PAGE 1
1 ;====================================================================
2 ;
3 ; Author : ADI - Apps
4 ;
5 ; Date : October 2003
6 ;
7 ; File : MASTuart.asm
8 ;
9 ; Hardware ; ADuC842/ADuC843
10 ;
11 ; Description : This Program transmits the numbers 1-10 in binary
12 ; form continuously down the SPI serial port.
13 ; After the transmission of each byte the incoming
14 ; byte is saved in order between internal RAM
15 ; addresses 40h and 50h.
16 ;
17 ; After the 16 bytes have been writen into memory
18 ; the program outputs the received data up the UART
19 ; where it can be viewed using Hyperterminal.
20 ;
21 ; An SPI slave program can be run on a second ADuC832
22 ; to communicate with this master code.
23 ; The Slave program (SLAVuart.asm in the SPI\SLAVE
24 ; directory) should be started after the master
25 ; program (MASTuart.asm) but within the time delay
26 ; of 5s in order that the slave program is
27 ; synchronised by the first outputted clock of the
28 ; master.
29 ;
30 ; The clock is outputted at sclock (pin 26)
31 ; The data is outputted at sdata/MOSI (pin 27)
32 ; The data is inputted at MISO (pin 14)
33 ;====================================================================
34 ;
35 $MOD842 ;Use 8052 predefined Symbols
36
00B4 37 LED EQU P3.4
0000 38 FLAG BIT 00H
39
40 ;____________________________________________________________________
41 ; BEGINNING OF CODE
---- 42 CSEG
0000 43 ORG 0000H
44
0000 020060 45 JMP MAIN
46 ;____________________________________________________________________
47 ; SPI INTERRUPT ROUTINE
003B 48 ORG 003BH
003B D2B5 49 SETB P3.5 ; set the SS bit after transmission
003D C200 50 CLR FLAG ; Clear flag to leave loop
51
003F A7F7 52 MOV @R1, SPIDAT ; move input into memory
0041 09 53 INC R1 ; increment memory location so new
54 ; data is stored in new address
55
0042 B95003 56 CJNE R1, #50H, CONT ; reset memory location to 40h when
57 ; memory location reaches 50h saving
58 ; 16 bytes of data
MASTUART PAGE 2
59
0045 12008C 60 CALL SNDUART ; send the data up the UART
0048 32 61 CONT: RETI
62
63 ;____________________________________________________________________
64 ; MAIN PROGRAM
65
0060 66 ORG 0060H ; Start code at address above interrupts
67
0060 68 MAIN: ; Main program
69
0060 759E83 70 MOV T3CON,#083h
0063 759D2D 71 MOV T3FD,#02Dh
0066 759852 72 MOV SCON,#052h
73
0069 75F837 74 MOV SPICON,#037h ; Initialise SPICON to have
75 ; -bitrate=fosc/64
76 ; -CPHA=1
77 ; -CPOL=0, sclk idling low
78 ; -master mode select
79 ; -Enable SPI serial port
80
006C 75A901 81 MOV IEIP2, #01h ; Enable SPI interrrupt
006F D2AF 82 SETB EA ; Enable interrupts
83
0071 7940 84 MOV R1, #40h ; initialise R1 to 40 to store the
85 ; input data from memory location 40
0073 7800 86 MOV R0, #00H ; initialise R0 to 0 to start
87 ; transmissions from 1
88
89 ; Delay the output of data by 2.0s in order that the slave program
90 ; can be easily synchronised with the master program.
91
0075 74C8 92 MOV A, #200
0077 1200F8 93 CALL DELAY
94
007A 95 TRNSMT:
007A 08 96 INC R0
007B C2B5 97 CLR P3.5 ; clear the SS bit during transmission
007D 88F7 98 MOV SPIDAT, R0 ; transmit the current value on R0
007F D200 99 SETB FLAG ; set flag so that we wait here until
100 ; the spi interrupt routine clears
101 ; the FLAG
102
0081 2000FD 103 JB FLAG, $ ; stay here until flag is cleared
104 ; by interrupt
105
106 ; check if R0 is equal to 10. If so the number 10 has been
107 ; transmitted and we should reset R0 to 0 to start transmission
108 ; from 1 again
109
0084 E8 110 MOV A, R0
0085 B40AF2 111 CJNE A, #0AH, TRNSMT ; if R0 is not 10, jump to TRNSMT
0088 7800 112 MOV R0, #00H ; if R0=10 make R0=0 & jump to TRNSMT
008A 80EE 113 JMP TRNSMT
114
115 ; Transmit the values in locations 40h->50h up the UART wait for
116 ; 5 seconds and then transmit and receive values to/from the slave
MASTUART PAGE 3
117 ; again down the SPI port.
118
008C 119 SNDUART:
008C B2B4 120 CPL LED ;CPL LED with each transmission
008E 900104 121 MOV DPTR, #TITLE
0091 1200B8 122 CALL SENDSTRING ; write title block on screen
123
0094 7940 124 MOV R1, #40h ; move value at address 40 into R2
0096 E7 125 MOV A, @R1
0097 FA 126 MOV R2, A
127
0098 128 NEXT: ; Put new value on a new line
0098 740A 129 MOV A, #10 ; Transmit a linefeed (= ASCII 10)
009A 1200D0 130 CALL SENDCHAR
009D 740D 131 MOV A, #13 ;Transmit a carriage return (=ASCII 13)
009F 1200D0 132 CALL SENDCHAR
133
00A2 EA 134 MOV A, R2 ; Transmit R2 i.e. value @ address R1
00A3 1200D8 135 CALL SENDVAL
00A6 09 136 INC R1 ; Increment address
00A7 E7 137 MOV A, @R1
00A8 FA 138 MOV R2, A ; R2 holds the value @ addrR1
139
00A9 E9 140 MOV A, R1 ; Check if at address 50h
00AA B450EB 141 CJNE A, #50h, NEXT ; if not jump to Next
00AD 0200B0 142 JMP WAIT2S ; if so wait 2s and repeat
143
00B0 74C8 144 WAIT2S: MOV A, #200 ; wait 2s before sending down the
145 ; SPI port again for ease of viewing
146 ; on screen and to allow the slave
147 ; synchronise itself with the master
00B2 1200F8 148 CALL DELAY
00B5 7940 149 MOV R1, #40h ; store new inputs at address 40h again
00B7 32 150 RETI
151
152 ;____________________________________________________________________
153 ; SENDSTRING
154
00B8 155 SENDSTRING: ; sends ASCII string to UART starting at location
156 ; DPTR and ending with a null (0) value
157
00B8 C0E0 158 PUSH ACC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -