📄 842slave.lst
字号:
842SLAVE PAGE 1
1 ;********************************************************************
2 ;
3 ; Author : ADI - Apps www.analog.com/MicroConverter
4 ;
5 ; Date : October 2003
6 ;
7 ; File : SPIslave.asm
8 ;
9 ; Hardware : ADuC842/ADuC843
10 ;
11 ; Include File : UARTIO.asm - serial I/O routines
12 ;
13 ; Description : Demonstrates an example slave mode SPI interface.
14 ; Code is intended for use with companion code file
15 ; '842mstr.asm' running on a second MicroConverter
16 ; chip. Chips must have SCLK, MOSI, MISO, & GND pins
17 ; connected together, and P3.5 pin on master must
18 ; connect to SS pin on slave.
19 ;
20 ; If using the ADuC842 eval board, you can
21 ; simply connect the 5-pin SPI header directly
22 ; to that of the master board.
23 ;
24 ; Once hardware is connected, download code to both
25 ; master & slave devices ('842mstr' to the master,
26 ; '842slave' to the slave). Reset the slave first,
27 ; and then the master. The slave will sit with the
28 ; LED off until the master starts exchanging data
29 ; with it at which time its LED will start blinking
30 ; in sync (or 180皁ut of phase) with that of the
31 ; master. When first launched, both master and slave
32 ; are transmitting zeros repeatedly on the SPI port.
33 ; Pressing the INT0 button on either master or slave
34 ; increments the value it is transmitting. Received
35 ; SPI data is relayed out the UART and can be viewed
36 ; on any VT100 terminal or terminal emulator at
37 ; 9600baud/8bits/noparity/1stopbit. Characters sent
38 ; from the terminal to the MicroConverter will update
39 ; the value being transmitted by SPI.
40 ;
41 ;********************************************************************
42
43 $MOD842 ; Use 8052 & ADuC842 predefined symbols
44
00B4 45 LED EQU P3.4 ; P3.4 drives red LED on eval board
46
47 ;____________________________________________________________________
48 ; DEFINE VARIABLES IN INTERNAL RAM
---- 49 DSEG
0060 50 ORG 0060h
0060 51 INPUT: DS 1 ; data byte received by SPI
0061 52 OUTPUT: DS 1 ; data byte to send by SPI
53
54 ;____________________________________________________________________
55 ; BEGINNING OF CODE
---- 56 CSEG
57
0000 58 ORG 0000h
842SLAVE PAGE 2
0000 02004B 59 JMP MAIN ; jump to main program
60
61 ;____________________________________________________________________
62 ; INTERRUPT VECTOR SPACE
0003 63 ORG 0003h ; (.................... INT0 ISR)
64
0003 0561 65 INC OUTPUT
0005 32 66 RETI
67
003B 68 ORG 003Bh ; (.................... SPI ISR)
69
003B 85F760 70 MOV INPUT,SPIDAT ; get data just received by SPI
003E 8561F7 71 MOV SPIDAT,OUTPUT ; update next byte to transmit
0041 C3 72 CLR C ; clear C indicates transfer complete
0042 32 73 RETI
74
75 ;====================================================================
76 ; MAIN PROGRAM
004B 77 ORG 004Bh
78
004B 79 MAIN:
004B 75D703 80 MOV PLLCON,#03H
004E 758107 81 MOV SP,#007h
82
83 ; CONFIGURE UART...
0051 759E83 84 MOV T3CON,#083h
0054 759D2D 85 Mov T3FD,#02Dh
0057 759852 86 MOV SCON,#052h
87
88 ; CONFIGURE SPI...
89
005A 75F824 90 MOV SPICON,#024h ; configure SPI port for:
91 ; CPHA=1, CPOL=0, slave
005D 75A901 92 MOV IEIP2,#1 ; enable SPI interrupt
93
94 ; CONFIGURE INTERRUPT 0...
95
0060 D288 96 SETB IT0 ; INT0 edge triggered
0062 D2A8 97 SETB EX0 ; enable INT0 interrupt
98
99 ; ENABLE INTERRUPTS & ENTER MAIN LOOP...
100
0064 756100 101 MOV OUTPUT,#0 ; set initial value for output byte..
0067 75F700 102 MOV SPIDAT,#0 ; ..including very fisrt output byte
006A D2AF 103 SETB EA ; enable inturrupts
104
006C B2B4 105 LOOP: CPL LED ; flash the LED on the eval board
006E D3 106 SETB C
006F 40FE 107 JC $ ; wait here to receive SPI transfer
0071 E560 108 MOV A,INPUT ; send value received by SPI..
0073 1200A6 109 CALL SENDVAL ; ..out the UART as 2 hex chars
0076 900121 110 MOV DPTR,#SEPERATOR ; send line-feed & crdg-return..
0079 120086 111 CALL SENDSTRING ; ..out the UART
007C 3098ED 112 JNB RI,LOOP ; repeat (unless UART data received)
113
114 ; WHEN UART DATA RECEIVED, MOVE DATA TO SPI OUTPUT...
115
007F 859961 116 MOV OUTPUT,SBUF ; update OUTPUT byte to new value
842SLAVE PAGE 3
0082 C298 117 CLR RI ; must clear RI
0084 80E6 118 JMP LOOP ; back to main loop
119
120 ;____________________________________________________________________
121 ; SUBROUTINE INCLUDE FILE
122
=1 123 $INCLUDE(UARTIO.asm)
=1 124 ;********************************************************************
=1 125 ;
=1 126 ; Author : ADI - Apps www.analog.com/MicroConverter
=1 127 ;
=1 128 ; Date : January 2001
=1 129 ;
=1 130 ; File : UARTIO.asm
=1 131 ;
=1 132 ; Hardware : any 8051 based microcontroller or MicroConverter
=1 133 ;
=1 134 ; Description : standard UART I/O subroutines. total size of this
=1 135 ; code when assembled is 155 bytes. routines for use
=1 136 ; external to this file are:
=1 137 ;
=1 138 ; SENDSTRING - sends a string of characters
=1 139 ; SENDCHAR - sends a single character
=1 140 ; SENDVAL - sends a byte as 2 ASCII characters
=1 141 ; HEX2ASCII - converts from HEX to ASCII
=1 142 ; ASCII2HEX - converts from ASCII to HEX
=1 143 ; GETCHAR - gets a single character
=1 144 ; GETVAL - gets a byte as 2 ASCII characters
=1 145 ;
=1 146 ;********************************************************************
=1 147
=1 148 ;____________________________________________________________________
=1 149 ; SENDSTRING
=1 150
0086 =1 151 SENDSTRING: ; sends ASCII string to UART starting at location
=1 152 ; DPTR and ending with a null (0) value
=1 153
0086 C0E0 =1 154 PUSH ACC
0088 C0F0 =1 155 PUSH B
008A E4 =1 156 CLR A
008B F5F0 =1 157 MOV B,A
008D E5F0 =1 158 IO0010: MOV A,B
008F 05F0 =1 159 INC B
0091 93 =1 160 MOVC A,@A+DPTR
0092 6005 =1 161 JZ IO0020
0094 12009E =1 162 CALL SENDCHAR
0097 80F4 =1 163 JMP IO0010
0099 D0F0 =1 164 IO0020: POP B
009B D0E0 =1 165 POP ACC
=1 166
009D 22 =1 167 RET
=1 168
=1 169 ;____________________________________________________________________
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -