📄 i2c_master.lst
字号:
ARM COMPILER V2.42, I2C_Master 11/08/08 15:14:09 PAGE 1
ARM COMPILER V2.42, COMPILATION OF MODULE I2C_Master
OBJECT MODULE PLACED IN I2C_Master.OBJ
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe I2C_Master.c THUMB DEBUG TABS(4)
stmt level source
1 #include <ADuC7026.h>
2 #include <I2C_Master.h>
3
4 //Device address for ADXL345
5 #define I2CWRITEADDR 0xA6 // I2C address for wirte
6 #define I2CREADADDR 0xA7 // I2C address for read
7
8 //I2C process step, used for ADuC702X I2C master
9 #define I2C_IDLE 0 //I2C idle
10 #define I2C_WRITE1 1 //write 1 byte
11 #define I2C_WRITE2 2 //write 2 byte
12 #define I2C_READ 3 //I2C read
13 #define I2C_SET_ADDR 4 //set I2C read register address
14
15
16 unsigned char I2CWriteValue; //data to write
17 signed char ReadRegister; //data read back from register
18 unsigned char Status =I2C_IDLE; //I2C process step, initialize with Idle
19
20 //write "WriteValue" to "RegisterAddr" of ADXL345
21 void I2C_WRITE_REGISTER(unsigned char RegisterAddr, unsigned char WriteValue)
22 {
23 1
24 1 Status = I2C_WRITE1; //write 1 byte
25 1 I2CWriteValue = WriteValue; //set Writevalue
26 1 I2C1ADR = I2CWRITEADDR; // set device address for I2C write
27 1 I2C1MTX = RegisterAddr; // set regsiter address
28 1
29 1 while(I2C_IDLE != Status) // wait until I2C command finish
30 1 {
31 2 ;
32 2 }
33 1
34 1 }
35
36 // Set register address for I2C read command
37 void I2C_SET_READ_ADDR(unsigned char RegisterAddr)
38 {
39 1 Status = I2C_SET_ADDR; // set I2C read register address
40 1
41 1 I2C1ADR = I2CWRITEADDR; //set device address for I2C write
42 1 I2C1MTX = RegisterAddr; //set regsiter address
43 1
44 1 while (I2C_IDLE != Status) // wait until I2C command finish
45 1 {
46 2 ;
47 2 }
48 1 }
49
50 //Read register from ADXL345
51 signed char I2C_READ_REGISTER(unsigned char RegisterAddr)
52 {
53 1
54 1
55 1 I2C_SET_READ_ADDR(RegisterAddr); // set I2C read register address
56 1 Status = I2C_READ; //I2C read
57 1 I2C1ADR = I2CREADADDR; //set device address for I2C read
58 1
59 1
ARM COMPILER V2.42, I2C_Master 11/08/08 15:14:09 PAGE 2
60 1 while (I2C_IDLE != Status) // wait until I2C command finish
61 1 {
62 2 ;
63 2 }
64 1
65 1
66 1 return ReadRegister; //return result
67 1
68 1
69 1 }
70
71 //I2C interrupt
72 void FIQ_Handler() __fiq
73 {
74 1
75 1 // Master Transmit
76 1 if(((I2C1MSTA & 0x4) == 0x4) && (Status == I2C_WRITE1) ) // 1 byte (register address) has been send out,
- then send the 2 byte (write value)
77 1 {
78 2 Status = I2C_WRITE2;
79 2 I2C1MTX = I2CWriteValue;
80 2 }
81 1 else if(((I2C1MSTA & 0x4) == 0x4) && (Status == I2C_WRITE2)) // 2 byte (write value) has been send out,
- write command finished
82 1 {
83 2 Status = I2C_IDLE;
84 2 }
85 1
86 1 else if(((I2C1MSTA & 0x4) == 0x4) && (Status == I2C_SET_ADDR)) // set I2C read register address finish
-ed
87 1 {
88 2 Status = I2C_IDLE;
89 2 }
90 1
91 1 // Master Receive
92 1 else if (((I2C1MSTA & 0x8) == 0x8) && (Status == I2C_READ)) // read command finished,
93 1 {
94 2 ReadRegister = I2C1MRX;
95 2 Status = I2C_IDLE;
96 2 }
97 1 }
ARM COMPILER V2.42, I2C_Master 11/08/08 15:14:09 PAGE 3
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** PUBLICS:
PUBLIC I2C_WRITE_REGISTER?T
PUBLIC I2C_READ_REGISTER?T
PUBLIC I2C_SET_READ_ADDR?T
PUBLIC FIQ_Handler?A
PUBLIC I2CWriteValue
PUBLIC ReadRegister
PUBLIC Status
*** DATA SEGMENT '?DT0?I2C_Master':
00000000 I2CWriteValue:
00000000 DS 1
00000001 ReadRegister:
00000001 DS 1
00000002 Status:
00000002 BEGIN_INIT
00000002 00 DB 0x0
00000003 END_INIT
*** CODE SEGMENT '?PR?I2C_WRITE_REGISTER?T?I2C_Master':
21: void I2C_WRITE_REGISTER(unsigned char RegisterAddr, unsigned char WriteValue)
00000000 1C0B MOV R3,R1 ; WriteValue
00000002 ---- Variable 'WriteValue' assigned to Register 'R3' ----
00000002 1C02 MOV R2,R0 ; RegisterAddr
00000004 ---- Variable 'RegisterAddr' assigned to Register 'R2' ----
24: Status = I2C_WRITE1; //write 1 byte
00000004 2101 MOV R1,#0x1
00000006 4800 LDR R0,=Status ; Status
00000008 7001 STRB R1,[R0,#0x0] ; Status
25: I2CWriteValue = WriteValue; //set Writevalue
0000000A 1C19 MOV R1,R3 ; WriteValue
0000000C 4800 LDR R0,=I2CWriteValue ; I2CWriteValue
0000000E 7001 STRB R1,[R0,#0x0] ; I2CWriteValue
26: I2C1ADR = I2CWRITEADDR; // set device address for I2C write
00000010 21A6 MOV R1,#0xA6
00000012 4800 LDR R0,=0xFFFF091C
00000014 6001 STR R1,[R0,#0x0]
27: I2C1MTX = RegisterAddr; // set regsiter address
00000016 1C10 MOV R0,R2 ; RegisterAddr
00000018 0601 LSL R1,R0,#0x18 ; RegisterAddr
0000001A 0E09 LSR R1,R1,#0x18
0000001C 4800 LDR R0,=0xFFFF0914
0000001E 6001 STR R1,[R0,#0x0]
32: }
00000020 L_1:
00000020 4800 LDR R0,=Status ; Status
00000022 7800 LDRB R0,[R0,#0x0] ; Status
00000024 2800 CMP R0,#0x0
00000026 D1FB BNE L_1 ; T=0x00000020
34: }
00000028 4770 BX R14
0000002A ENDP ; 'I2C_WRITE_REGISTER?T'
*** CODE SEGMENT '?PR?I2C_SET_READ_ADDR?T?I2C_Master':
37: void I2C_SET_READ_ADDR(unsigned char RegisterAddr)
00000000 1C01 MOV R1,R0 ; RegisterAddr
00000002 ---- Variable 'RegisterAddr' assigned to Register 'R1' ----
39: Status = I2C_SET_ADDR; // set I2C read register address
00000002 2204 MOV R2,#0x4
00000004 4800 LDR R0,=Status ; Status
00000006 7002 STRB R2,[R0,#0x0] ; Status
41: I2C1ADR = I2CWRITEADDR; //set device address for I2C write
00000008 22A6 MOV R2,#0xA6
0000000A 4800 LDR R0,=0xFFFF091C
ARM COMPILER V2.42, I2C_Master 11/08/08 15:14:09 PAGE 4
0000000C 6002 STR R2,[R0,#0x0]
42: I2C1MTX = RegisterAddr; //set regsiter address
0000000E 1C08 MOV R0,R1 ; RegisterAddr
00000010 0601 LSL R1,R0,#0x18 ; RegisterAddr
00000012 0E09 LSR R1,R1,#0x18
00000014 4800 LDR R0,=0xFFFF0914
00000016 6001 STR R1,[R0,#0x0]
47: }
00000018 L_5:
00000018 4800 LDR R0,=Status ; Status
0000001A 7800 LDRB R0,[R0,#0x0] ; Status
0000001C 2800 CMP R0,#0x0
0000001E D1FB BNE L_5 ; T=0x00000018
48: }
00000020 4770 BX R14
00000022 ENDP ; 'I2C_SET_READ_ADDR?T'
*** CODE SEGMENT '?PR?I2C_READ_REGISTER?T?I2C_Master':
51: signed char I2C_READ_REGISTER(unsigned char RegisterAddr)
00000000 B500 PUSH {LR}
00000002 1C01 MOV R1,R0 ; RegisterAddr
00000004 ---- Variable 'RegisterAddr' assigned to Register 'R1' ----
55: I2C_SET_READ_ADDR(RegisterAddr); // set I2C read register address
00000004 1C08 MOV R0,R1 ; RegisterAddr
00000006 0600 LSL R0,R0,#0x18 ; RegisterAddr
00000008 0E00 LSR R0,R0,#0x18
0000000A F7FF BL I2C_SET_READ_ADDR?T ; T=0x0001 (1)
0000000C FFF9 BL I2C_SET_READ_ADDR?T ; T=0x0001 (2)
56: Status = I2C_READ; //I2C read
0000000E 2103 MOV R1,#0x3
00000010 4800 LDR R0,=Status ; Status
00000012 7001 STRB R1,[R0,#0x0] ; Status
57: I2C1ADR = I2CREADADDR; //set device address for I2C read
00000014 21A7 MOV R1,#0xA7
00000016 4800 LDR R0,=0xFFFF091C
00000018 6001 STR R1,[R0,#0x0]
63: }
0000001A L_9:
0000001A 4800 LDR R0,=Status ; Status
0000001C 7800 LDRB R0,[R0,#0x0] ; Status
0000001E 2800 CMP R0,#0x0
00000020 D1FB BNE L_9 ; T=0x0000001A
66: return ReadRegister; //return result
00000022 4800 LDR R0,=ReadRegister ; ReadRegister
00000024 7800 LDRB R0,[R0,#0x0] ; ReadRegister
00000026 0600 LSL R0,R0,#0x18
00000028 1600 ASR R0,R0,#0x18
69: }
0000002A BC08 POP {R3}
0000002C 4718 BX R3
0000002E ENDP ; 'I2C_READ_REGISTER?T'
*** CODE SEGMENT '?PR?FIQ_Handler?A?I2C_Master':
76: if(((I2C1MSTA & 0x4) == 0x4) && (Status == I2C_WRITE1) ) // 1 byte (register address) has been send out, then se
-nd the 2 byte (write value)
00000000 E5108000 LDR R0,=0xFFFF0900
00000004 E5988000 LDR R8,[R8,#0x0]
00000008 E3180004 TST R8,#0x0004
0000000C 0A00000C BEQ L_14 ; Targ=0x44
00000010 E5108000 LDR R0,=Status ; Status
00000014 E5D88000 LDRB R8,[R8,#0x0] ; Status
00000018 E3580001 CMP R8,#0x0001
0000001C 1A000008 BNE L_14 ; Targ=0x44
78: Status = I2C_WRITE2;
00000020 E3A09002 MOV R9,#0x2
00000024 E5108000 LDR R0,=Status ; Status
00000028 E5C89000 STRB R9,[R8,#0x0] ; Status
79: I2C1MTX = I2CWriteValue;
ARM COMPILER V2.42, I2C_Master 11/08/08 15:14:09 PAGE 5
0000002C E5108000 LDR R0,=I2CWriteValue ; I2CWriteValue
00000030 E5D88000 LDRB R8,[R8,#0x0] ; I2CWriteValue
00000034 E1A09008 MOV R9,R8
00000038 E5108000 LDR R0,=0xFFFF0914
0000003C E5889000 STR R9,[R8,#0x0]
80: }
00000040 EA000028 B L_15 ; Targ=0xE8
00000044 L_14:
81: else if(((I2C1MSTA & 0x4) == 0x4) && (Status == I2C_WRITE2)) // 2 byte (write value) has been send out, write c
-ommand finished
00000044 E5108000 LDR R0,=0xFFFF0900
00000048 E5988000 LDR R8,[R8,#0x0]
0000004C E3180004 TST R8,#0x0004
00000050 0A000007 BEQ L_16 ; Targ=0x74
00000054 E5108000 LDR R0,=Status ; Status
00000058 E5D88000 LDRB R8,[R8,#0x0] ; Status
0000005C E3580002 CMP R8,#0x0002
00000060 1A000003 BNE L_16 ; Targ=0x74
83: Status = I2C_IDLE;
00000064 E3A09000 MOV R9,#0x0
00000068 E5108000 LDR R0,=Status ; Status
0000006C E5C89000 STRB R9,[R8,#0x0] ; Status
84: }
00000070 EA00001C B L_15 ; Targ=0xE8
00000074 L_16:
86: else if(((I2C1MSTA & 0x4) == 0x4) && (Status == I2C_SET_ADDR)) // set I2C read register address finished
00000074 E5108000 LDR R0,=0xFFFF0900
00000078 E5988000 LDR R8,[R8,#0x0]
0000007C E3180004 TST R8,#0x0004
00000080 0A000007 BEQ L_18 ; Targ=0xA4
00000084 E5108000 LDR R0,=Status ; Status
00000088 E5D88000 LDRB R8,[R8,#0x0] ; Status
0000008C E3580004 CMP R8,#0x0004
00000090 1A000003 BNE L_18 ; Targ=0xA4
88: Status = I2C_IDLE;
00000094 E3A09000 MOV R9,#0x0
00000098 E5108000 LDR R0,=Status ; Status
0000009C E5C89000 STRB R9,[R8,#0x0] ; Status
89: }
000000A0 EA000010 B L_15 ; Targ=0xE8
000000A4 L_18:
92: else if (((I2C1MSTA & 0x8) == 0x8) && (Status == I2C_READ)) // read command finished,
000000A4 E5108000 LDR R0,=0xFFFF0900
000000A8 E5988000 LDR R8,[R8,#0x0]
000000AC E3180008 TST R8,#0x0008
000000B0 0A00000C BEQ L_15 ; Targ=0xE8
000000B4 E5108000 LDR R0,=Status ; Status
000000B8 E5D88000 LDRB R8,[R8,#0x0] ; Status
000000BC E3580003 CMP R8,#0x0003
000000C0 1A000008 BNE L_15 ; Targ=0xE8
94: ReadRegister = I2C1MRX;
000000C4 E5108000 LDR R0,=0xFFFF0910
000000C8 E5989000 LDR R9,[R8,#0x0]
000000CC E1A09C09 MOV R9,R9,LSL #24
000000D0 E1A09C29 MOV R9,R9,LSR #24
000000D4 E5108000 LDR R0,=ReadRegister ; ReadRegister
000000D8 E5C89000 STRB R9,[R8,#0x0] ; ReadRegister
95: Status = I2C_IDLE;
000000DC E3A09000 MOV R9,#0x0
000000E0 E5108000 LDR R0,=Status ; Status
000000E4 E5C89000 STRB R9,[R8,#0x0] ; Status
96: }
000000E8 L_15:
97: }
000000E8 E25EF004 SUBS R15,R14,#0x0004
000000EC ENDP ; 'FIQ_Handler?A'
ARM COMPILER V2.42, I2C_Master 11/08/08 15:14:09 PAGE 6
Module Information Static
----------------------------------
code size = ------
data size = 3
const size = ------
End of Module Information.
ARM COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -