?? main.lst
字號:
ARM COMPILER V2.00f, main 20/02/05 12:43:48 PAGE 1
ARM COMPILER V2.00f, COMPILATION OF MODULE main
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe main.c THUMB OPTIMIZE(7,SPEED) BROWSE DEBUG TABS(4)
stmt level source
1 /************************************************************/
2 /* PROJECT NAME: I2C */
3 /* Project: LPC2100 Training course */
4 /* Engineer: T Martin tmartin@hitex.co.uk */
5 /* Filename: MAIN.C */
6 /* Language: C */
7 /* Compiler: Keil ARM V1.3 */
8 /* Assembler: */
9 /* */
10 /************************************************************/
11 /* COPYRIGHT: Hitex UK Ltd 2004 */
12 /* LICENSE: THIS VERSION CREATED FOR FREE DISTRIBUTION */
13 /************************************************************/
14 /* Function: */
15 /* */
16 /* Interrupt driven I2C example for LPC2106 */
17 /* */
18 /* The Transfer byte routine starts a single byte transfer */
19 /* on the I2C bus. The development board has two port */
20 /* expanders one at address 0x42 with a 7 segment LCD a */
21 /* second at 0x41 with a four switch header. The code reads */
22 /* the switches and writes the pattern to the LED's */
23 /* */
24 /* Oscillator frequency 14.7456 Mhz */
25 /* Target board Ashling EVBA7 */
26 /************************************************************/
27
28 #include <LPC210x.H>
29 #include <stdarg.h>
30
31 void I2CISR (void) __irq ; //I2C interrupt routine
32 void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,...); //Background
-call to start master send and receive byte transfers
33
34 unsigned char message[4] = {0x01,0x02,0x03,0x04};
35 unsigned char messageIn[4];
36 unsigned char *I2CData,
37 I2Counter,
38 I2CAddress,
39 MemAddress,
40 lock; //Define Function prototypes and Global variables
41
42
43 int main(void)
44 {
45 1
46 1 lock = 0; //Initilise the lock flag
47 1
48 1 VICVectCntl1 = 0x00000029; //select a priority slot for a given interrupt
49 1 VICVectAddr1 = (unsigned)I2CISR; //pass the address of the IRQ into the VIC slot
50 1 VICIntEnable = 0x00000200; //enable interrupt
51 1
52 1 PINSEL0 = 0x50; //Switch GPIO to I2C pins
53 1
54 1 I2SCLH = 0x08; //Set bit rate 14.7456Mhz/VPBDIV+SCLH+SCLL = 14.7456/4+8+8 = 57.6Khz
55 1 I2SCLL = 0x08;
56 1
57 1 I2CTransferByte(0x40,0,4,message); //write data to the I2C Memory
58 1 I2CTransferByte(0x40,0,0); //set address to zero
ARM COMPILER V2.00f, main 20/02/05 12:43:48 PAGE 2
59 1 I2CTransferByte(0x41,0,4,messageIn); //read back data
60 1
61 1 while(1)
62 1 {
63 2 ;
64 2 }
65 1 }
66
67
68 void I2CTransferByte(unsigned int I2CAddr,unsigned char MemAddr,unsigned char count,...)
69 {
70 1 va_list ap;
71 1 va_start(ap,count);
72 1
73 1 while(lock == 1) //Wait for interrupt to signal end of I2C activity
74 1 {
75 2 ;
76 2 }
77 1 lock = 1; //Set I2C bus as active
78 1
79 1 I2CAddress = I2CAddr; //Place address and data in Globals to be used by the interrupt
80 1 if(count >0)
81 1 {
82 2 I2CData = va_arg(ap,unsigned char *);
83 2 }
84 1 I2Counter = count;
85 1 MemAddress = MemAddr;
86 1 I2CONCLR = 0x000000FF; //Clear all I2C settings
87 1 I2CONSET = 0x00000040; //Enable the I2C interface
88 1 I2CONSET = 0x00000020; //Start condition
89 1 va_end(ap);
90 1 }
91
92
93 void I2CISR (void) __irq //I2C interrupt routine
94 {
95 1
96 1 switch (I2STAT) //Read result code and switch to next action
97 1 {
98 2 // Start and Send byte conditions
99 2
100 2 case ( 0x08): //Start bit
101 2 I2CONCLR = 0x20; //Clear start bit
102 2 I2DAT = I2CAddress; //Send address and write bit
103 2 break;
104 2
105 2 case (0x18): //Slave address+W, ACK
106 2 I2DAT = MemAddress; //Write Mem,ory start address to tx register
107 2 break;
108 2
109 2 case (0x20): //Salve address +W, Not ACK
110 2 I2DAT = I2CAddress; //Resend address and write bi
111 2 break;
112 2
113 2 case (0x28):
114 2 if(I2Counter-->0) //Data sent, Ack
115 2 {
116 3 I2DAT = *I2CData; //Write data to tx register
117 3 I2CData++;
118 3 }
119 2 else
120 2 {
121 3 I2CONSET = 0x10; //Stop condition
122 3 lock = 0; //Signal end of I2C activity
123 3 }
124 2 break;
ARM COMPILER V2.00f, main 20/02/05 12:43:48 PAGE 3
125 2
126 2 case (0x30) : //Data sent, NOT Ack
127 2 I2DAT = *I2CData; //Write data to tx register
128 2 break;
129 2
130 2
131 2 //Receive byte conditions
132 2
133 2 case (0x40) : //Slave Address +R, ACK
134 2 I2CONSET = 0x04; //Enable ACK for data byte
135 2 break;
136 2
137 2 case (0x48) : //Slave Address +R, Not Ack
138 2 I2CONSET = 0x20; //Resend Start condition
139 2 break;
140 2
141 2 case (0x50) : //Data Received, ACK
142 2 if(--I2Counter>0)
143 2 {
144 3 *I2CData = I2DAT;
145 3 I2CData++;
146 3 }
147 2 else
148 2 {
149 3 I2CONSET = 0x10; //Stop condition
150 3 lock = 0; //Signal end of I2C activity
151 3 }
152 2 break;
153 2
154 2 case (0x58): //Data Received, Not Ack
155 2 I2CONSET = 0x20; // Resend Start condition
156 2 break;
157 2
158 2 default :
159 2 break;
160 2
161 2 }
162 1
163 1 I2CONCLR = 0x08; //Clear I2C interrupt flag
164 1 VICVectAddr = 0x00000000; //Clear interrupt in
165 1
166 1 }
ARM COMPILER V2.00f, main 20/02/05 12:43:48 PAGE 4
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN NUMBER (__startup)
*** PUBLICS:
PUBLIC I2CISR?A
PUBLIC I2CTransferByte?T
PUBLIC main
PUBLIC message
PUBLIC messageIn
PUBLIC I2CData
PUBLIC I2Counter
PUBLIC I2CAddress
PUBLIC MemAddress
PUBLIC lock
*** DATA SEGMENT '?DT0?main':
00000000 I2CData:
00000000 DS 4
00000004 message:
00000004 BEGIN_INIT
00000004 01 DB 0x1
00000005 02 DB 0x2
00000006 03 DB 0x3
00000007 04 DB 0x4
00000008 END_INIT
00000008 messageIn:
00000008 DS 4
0000000C I2Counter:
0000000C DS 1
0000000D I2CAddress:
0000000D DS 1
0000000E MemAddress:
0000000E DS 1
0000000F lock:
0000000F DS 1
*** CODE SEGMENT '?PR?main?main':
43: int main(void)
00000000 B500 PUSH {LR}
46: lock = 0; //Initilise the lock flag
00000002 2100 MOV R1,#0x0
00000004 4800 LDR R0,=lock ; lock
00000006 7001 STRB R1,[R0,#0x0] ; lock
48: VICVectCntl1 = 0x00000029; //select a priority slot for a given interrupt
00000008 2129 MOV R1,#0x29
0000000A 4800 LDR R0,=0xFFFFF204
0000000C 6001 STR R1,[R0,#0x0]
49: VICVectAddr1 = (unsigned)I2CISR; //pass the address of the IRQ into the VIC slot
0000000E 4900 LDR R1,=I2CISR?A ; I2CISR?A
00000010 4800 LDR R0,=0xFFFFF104
00000012 6001 STR R1,[R0,#0x0]
50: VICIntEnable = 0x00000200; //enable interrupt
00000014 4980 LDR R1,=0x200
00000016 4800 LDR R0,=0xFFFFF010
00000018 6001 STR R1,[R0,#0x0]
52: PINSEL0 = 0x50; //Switch GPIO to I2C pins
0000001A 2150 MOV R1,#0x50
0000001C 4800 LDR R0,=0xE002C000
0000001E 6001 STR R1,[R0,#0x0]
54: I2SCLH = 0x08; //Set bit rate 14.7456Mhz/VPBDIV+SCLH+SCLL = 14.7456/4+8+8 = 57.6Khz
00000020 2108 MOV R1,#0x8
00000022 4800 LDR R0,=0xE001C010
00000024 8001 STRH R1,[R0,#0x0]
ARM COMPILER V2.00f, main 20/02/05 12:43:48 PAGE 5
55: I2SCLL = 0x08;
00000026 2108 MOV R1,#0x8
00000028 4800 LDR R0,=0xE001C014
0000002A 8001 STRH R1,[R0,#0x0]
57: I2CTransferByte(0x40,0,4,message); //write data to the I2C Memory
0000002C 4800 LDR R3,=message ; message
0000002E 2040 MOV R0,#0x40
00000030 2100 MOV R1,#0x0
00000032 2204 MOV R2,#0x4
00000034 F7FF BL I2CTransferByte?T ; T=0x0001 (1)
00000036 FFE4 BL I2CTransferByte?T ; T=0x0001 (2)
58: I2CTransferByte(0x40,0,0); //set address to zero
0000003A 2040 MOV R0,#0x40
0000003C 2100 MOV R1,#0x0
0000003E 2200 MOV R2,#0x0
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -