📄 i2cslave.lst
字号:
I2CSLAVE PAGE 1
1 ;======================================================================
2 ;
3 ; Author : ADI - Apps www.analog.com/MicroConverter
4 ;
5 ; Date : May 2002
6 ;
7 ; File : i2cslave.asm
8 ;
9 ; Hardware : ADuC814
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 $MOD814
24
25 ;____________________________________________________________________
26 ; DEFINE VARIABLES IN INTERNAL RAM
27
0030 28 BYTECNT DATA 30h ; byte counter for I2C routines
0031 29 INPUT DATA 31h ; data recieved from master
0032 30 OUTPUT DATA 32h ; data to be transmitted to master
31
0000 32 GO BIT 00h ; flag to wait for interrupts
0001 33 FIRST BIT 01h ; flag to indicate first receive Int
34
00B4 35 LED EQU P3.4 ; P3.4 drives the LED on eval board
36
37 ;____________________________________________________________________
38 ; BEGINNING OF CODE
---- 39 CSEG
0000 40 ORG 0000h
0000 020060 41 JMP MAIN
42 ;____________________________________________________________________
43 ; INT0 ISR
0003 44 ORG 0003h
0003 0532 45 INC OUTPUT
0005 32 46 RETI
47 ;____________________________________________________________________
48 ; I2C ISR
003B 49 ORG 003Bh
50
003B 20E90B 51 JB I2CTX, SLAVE_TRANSMITTER
52
003E 53 SLAVE_RECEIVER:
003E 200110 54 JB FIRST, ENDINT1 ; if first INT then wait for next int
0041 D200 55 SETB GO ; reception complete
0043 859A31 56 MOV INPUT, I2CDAT ; store data received in INPUT
0046 020051 57 JMP ENDINT1
58
I2CSLAVE PAGE 2
0049 59 SLAVE_TRANSMITTER:
0049 D200 60 SETB GO ; transmission complete
004B 85329A 61 MOV I2CDAT, OUTPUT ; move data to be transmitted into I2CDAT
004E 020053 62 JMP ENDINT2 ; Note: On the ADuC824/816 the read or
63 ; write of I2CDAT register
64 ; automatically clears i2ci. If
65 ; I2CI is cleared twice then the
66 ; microconverter will hang.)
67
0051 68 ENDINT1:
0051 C2E8 69 CLR I2CI ; clear I2C interrupt bit (812 only)
0053 70 ENDINT2:
0053 C201 71 CLR FIRST ; address has already been received
0055 32 72 RETI
73
74 ;____________________________________________________________________
75 ; MAIN PROGRAM
0060 76 ORG 0060h
0060 77 MAIN:
78
79
80 ; configure the UART ADuC812s
0060 75CBFF 81 MOV RCAP2H,#0FFh ; config UART for 9830baud
0063 75CAF9 82 MOV RCAP2L,#-7 ; (close enough to 9600baud)
0066 75CDFF 83 MOV TH2,#0FFh
0069 75CCF9 84 MOV TL2,#-7
006C 759852 85 MOV SCON,#52h
006F 75C834 86 MOV T2CON,#34h
87
88 ; configure pins for 812s
0072 759C01 89 MOV CFG814,#01H
90
91 ;configure and enable interrupts
92 ; MOV IE2,#01h ; enable I2C interrupt
0075 75A901 93 MOV IEIP2,#01h ; enable I2C interrupt
0078 D2A8 94 SETB EX0 ; enable INT0
007A D288 95 SETB IT0 ; INT0 edge triggered
007C D2AF 96 SETB EA ; allow all the interrupts
97
98 ;initialize settings
007E 759B44 99 MOV I2CADD,#044h ; slave address is 44h
0081 75E800 100 MOV I2CCON,#00h ; slave mode (default=>not necessary)
0084 C200 101 CLR GO ; clear flag to wait for interrupt
102 ; GO is set once data is TX'd or RX'd
0086 D201 103 SETB FIRST ; FIRST is cleared after receiving the
104 ; first SLAVE receiver interrupt
105
0088 753200 106 MOV OUTPUT,#0 ; first byte to be transmitted is 40h
008B C2B4 107 CLR LED
108
008D 109 WAITFORDATA:
008D 3000FD 110 JNB GO,$ ; ----- wait for i2c interrupt ------
111 ; If it is in receive mode, it will
112 ; wait here for a second interrupt (as
113 ; the first interrupt only contains the
114 ; slave address in I2CDAT).
115 ; In transmit mode the tranmission will
116 ; occur after the first interrupt.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -