📄 i2cslave.lst
字号:
I2CSLAVE PAGE 1
1 ;======================================================================
2 ;
3 ; Author : ADI - Apps www.analog.com/MicroConverter
4 ;
5 ; Date : Oct 2000
6 ;
7 ; File : i2cslave.asm
8 ;
9 ; Hardware : ADuC812 (commented out = ADuC816/ADuC824)
10 ;
11 ; Description : Code for a slave in an I2C system. This code will
12 ; continuously receive and transmit a byte over the I2C
13 ; interface, then send the received byte out the UART,
14 ; then check if a character had been entered in the UART.
15 ; If so, it will send the ASCII value of the character
16 ; entered to the slave, the next time it transmits a byte.
17 ;
18 ; Reference : Tech Note, uC001: "MicroConverter I2C Compatible
19 ; Interface" find it at www.analog.com/microconverter
20 ;
21 ;======================================================================
22
23 $MOD812 ; use ADuC812 & 8052 predefined symbols
24 ;$MOD816
25 ;$MOD824
26
27
28 ;____________________________________________________________________
29 ; DEFINE VARIABLES IN INTERNAL RAM
30
0030 31 BYTECNT DATA 30h ; byte counter for I2C routines
0031 32 INPUT DATA 31h ; data recieved from master
0032 33 OUTPUT DATA 32h ; data to be transmitted to master
34
0000 35 GO BIT 00h ; flag for all the interrupts
0001 36 FIRST BIT 01h ; flag for recieve mode interrupt
0002 37 TR BIT 02h ; flag for transmit mode interrupt
38
00B4 39 LED EQU P3.4 ; P3.4 drives the LED on eval board
40
41 ;____________________________________________________________________
42 ; BEGINNING OF CODE
---- 43 CSEG
0000 44 ORG 0000h
0000 020060 45 JMP MAIN
46 ;____________________________________________________________________
47 ; INT0 ISR
0003 48 ORG 0003h
0003 0532 49 INC OUTPUT
0005 32 50 RETI
51 ;____________________________________________________________________
52 ; I2C ISR
003B 53 ORG 003Bh
54
003B 20E90D 55 JB I2CTX,TRANSMIT ; if slave-transmitter get data ready
56
003E 57 RECEIVE:
003E C202 58 CLR TR ; FLAG to indicate that this time
I2CSLAVE PAGE 2
59 ; we were receiving (not trans'ting)
0040 20010F 60 JB FIRST, ENDINT1 ; no need to store the address
0043 D200 61 SETB GO ; reception complete
0045 859A31 62 MOV INPUT, I2CDAT ; store data recieved in INPUT
0048 020052 63 JMP ENDINT1 ; ERROR => end interrupt
64
004B 65 TRANSMIT:
004B D202 66 SETB TR ; FLAG to indicate that this time
67 ; we were transmitting (not receiving)
004D D200 68 SETB GO ; transmission complete
004F 85329A 69 MOV I2CDAT,OUTPUT ; move data to be transmitted into I2CDAT
70 ; JMP ENDINT2 ; Note: On the ADuC824/816 the read or
71 ; write of I2CDAT register
72 ; automatically clears i2ci. If
73 ; I2CI is cleared twice then the
74 ; microconverter will hang.)
75
0052 76 ENDINT1:
0052 C2E8 77 CLR I2CI ; clear I2C interrupt bit (812 only)
0054 78 ENDINT2:
0054 C201 79 CLR FIRST ; address has already been recieved
80
0056 32 81 RETI
82
83
84 ;____________________________________________________________________
85 ; MAIN PROGRAM
0060 86 ORG 0060h
0060 87 MAIN:
88
89 ; configure the UART ADuC812
0060 759852 90 MOV SCON,#52h ; configure UART for 9600baud..
0063 758920 91 MOV TMOD,#20h ; ..assuming 11.0592MHz crystal
0066 758DFD 92 MOV TH1,#-3
0069 D28E 93 SETB TR1
94
95 ; configure the UART ADuC824/ADuC816
96 ; MOV RCAP2H,#0FFh ; config UART for 9830baud
97 ; MOV RCAP2L,#-5 ; (close enough to 9600baud)
98 ; MOV TH2,#0FFh
99 ; MOV TL2,#-5
100 ; MOV SCON,#52h
101 ; MOV T2CON,#34h
102
103 ;configure and enable interrupts
006B 75A901 104 MOV IE2,#01h ; enable I2C interrupt
105 ; MOV IEIP2,#01h ; enable I2C interrupt
006E D2A8 106 SETB EX0 ; enable INT0
0070 D288 107 SETB IT0 ; INT0 edge triggered
0072 D2AF 108 SETB EA ; allow all the interrupts
109
110
111 ;initialise settings
0074 759B44 112 MOV I2CADD,#044h ; slave address is 44h
0077 75E800 113 MOV I2CCON,#00h ; slave mode
007A C200 114 CLR GO ; clear flag used in the interrupt
115
007C 753200 116 MOV OUTPUT,#0 ; TX 0 as default
I2CSLAVE PAGE 3
007F D2B4 117 SETB LED
118
0081 119 RESET:
0081 D201 120 SETB FIRST ; first byte recieved will be the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -