?? iic.lst
字號:
C51 COMPILER V8.02 IIC 03/26/2007 19:14:28 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE IIC
OBJECT MODULE PLACED IN ..\Output\IIC.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE ..\app\IIC.C LARGE BROWSE INCDIR(..\app;..\Main;..\Port;..\SOURCE) DEBUG OB
-JECTEXTEND PRINT(..\Output\IIC.lst) OBJECT(..\Output\IIC.obj)
line level source
1 /************iic dirver for c8051f020 ************************
2
3 system clock 8M
4
5 ************************************************************/
6 #include "C8051F020.h"
7 #include "IIC.h"
8
9 static void GetBus ( void );
10 static void Delay_IIC( void );
11 static void SendByte( unsigned char dataa );
12
13 static void Delay_IIC()
14 {
15 1 unsigned char i=10;
16 1 while(i--);
17 1 }
18 static void Delay(unsigned char i)
19 {
20 1 unsigned char a;
21 1 while(i--)
22 1 for(a=0;a<255;a++);
23 1 }
24 static void GetBus()
25 {
26 1 Delay(10);
27 1 while (BUSY==1)
28 1 {
29 2 STO = 1;
30 2 Delay(10);
31 2 }
32 1
33 1 SMB0CN=RELEASE_BUS_STA;
34 1 while(SI==0);
35 1 if (SMB0STA != 0X08)
36 1 {
37 2 STO = 1;
38 2 SI = 0;
39 2 return;
40 2 }
41 1 STA = 0;
42 1 }
43
44 static void SendByte( unsigned char dataa )
45 {
46 1 SMB0DAT=dataa;
47 1 SMB0CN=RELEASE_BUS_ACK;
48 1 while(SI==0);
49 1 } // waitting......
50
51
52
53 /*
54 函數(shù):SmbRec
C51 COMPILER V8.02 IIC 03/26/2007 19:14:28 PAGE 2
55 功能:I2C 總線綜合接收函數(shù),從從機接收多個字節(jié)的數(shù)據(jù)
56 參數(shù):
57 slaveAddr:從機地址(7 位純地址,不含讀寫位)
58 subAddr:從機的子地址
59 subMod:子地址模式,0-無子地址,1-單字節(jié)子地址,
60 *recPtr:保存接收到的數(shù)據(jù)
61 size:數(shù)據(jù)的字節(jié)數(shù)
62 返回:
63 1:接收成功
64 0:在接收過程中出現(xiàn)異常
65 */
66 unsigned char SmbRec(unsigned char slaveAddr,
67 unsigned char *subAddress,
68 unsigned char subAddressType,
69 unsigned char size,
70 unsigned char *recPtr )
71 {
72 1 unsigned char counter;
73 1 Delay_IIC();
74 1 GetBus();
75 1 Delay_IIC();
76 1 slaveAddr=slaveAddr<<1;//七位地址左移1位變?yōu)榘宋? 77 1 SendByte(slaveAddr+0 ) ; // send slaadd + r 使地址為讀地址
78 1 Delay_IIC();
79 1 if(SMB0STA!=0X18)
80 1 {
81 2 STO = 1;
82 2 return(0);
83 2 }
84 1 if(subAddressType == ONE_BYTE_SUBA)
85 1 {
86 2 SendByte(*subAddress);
87 2 if(SMB0STA != 0x28)
88 2 {
89 3 STO = 1;
90 3 return 0;
91 3 }
92 2 }
93 1 if(subAddressType == TWO_BYTE_SUBA)
94 1 {
95 2 SendByte(*subAddress);
96 2 if(SMB0STA != 0x28)
97 2 {
98 3 STO = 1;
99 3 return 0;
100 3 }
101 2 subAddress++;
102 2 SendByte(*subAddress);
103 2 if(SMB0STA != 0x28)
104 2 {
105 3 STO = 1;
106 3 return 0;
107 3 }
108 2 }
109 1 Delay_IIC();
110 1 SMB0CN = RELEASE_BUS_STA; //從新發(fā)送STA = 1 繼續(xù)獲得總線
111 1 while (SI == 0);
112 1 if (SMB0STA !=0X10)
113 1 {
114 2 STA = 0;
115 2 STO =1;
116 2 return 0;
C51 COMPILER V8.02 IIC 03/26/2007 19:14:28 PAGE 3
117 2 }
118 1 STA = 0;
119 1 Delay_IIC();
120 1 SendByte(slaveAddr+1); //讀地址
121 1 Delay_IIC();
122 1 if (SMB0STA != 0x40)
123 1 {
124 2 SMB0CN = GENERATE_STOP;
125 2 return 0;
126 2 }
127 1 for(counter=0;counter<(size-1);counter++)
128 1 {
129 2 SMB0CN=RELEASE_BUS_ACK; // set ACK
130 2 while (SI==0);
131 2 if (SMB0STA!=0X50)
132 2 {
133 3 SMB0CN=GENERATE_STOP;
134 3 return(0);
135 3 }
136 2 *recPtr=SMB0DAT;
137 2 recPtr++;
138 2 }
139 1 SMB0CN=RELEASE_BUS_NACK; // set NACK
140 1 while(SI==0); // receive the last byte data
141 1 *recPtr=SMB0DAT;
142 1 SMB0CN=GENERATE_STOP;
143 1 Delay_IIC();
144 1 return(1);
145 1 }
146 /*
147 函數(shù):SmbSend
148 功能:I2C 總線綜合發(fā)送函數(shù),從主機發(fā)送多個字節(jié)的數(shù)據(jù)
149 參數(shù):
150 slaveAddr:從機地址(7位純地址,不含讀寫位)
151 subAddr:從機的子地址
152 subMod:子地址模式,0-無子地址,1-單字節(jié)子地址,
153 *recPtr:發(fā)送的字節(jié)
154 size:數(shù)據(jù)的字節(jié)數(shù)
155 返回:
156 0:接收成功
157 1:在接收過程中出現(xiàn)異常
158 */
159
160 unsigned char SmbSend (unsigned char slaveAddr, unsigned char *subAddress, unsigned char subAddressType, u
-nsigned char size, unsigned char *sendPtr)
161 {
162 1 unsigned char counter;
163 1 GetBus();
164 1 Delay_IIC();
165 1 slaveAddr=slaveAddr<<1;
166 1 SendByte(slaveAddr+0);//寫信號時地址加零
167 1 if(SMB0STA!=0X18)
168 1 {
169 2 STO=1;
170 2 SI = 0;
171 2 return(0);
172 2 }
173 1 if(subAddressType == ONE_BYTE_SUBA)
174 1 {
175 2 SendByte(*subAddress);
176 2 if(SMB0STA != 0x28)
177 2 {
C51 COMPILER V8.02 IIC 03/26/2007 19:14:28 PAGE 4
178 3 STO = 1;
179 3 return 0;
180 3 }
181 2 }
182 1 if(subAddressType == TWO_BYTE_SUBA)
183 1 {
184 2 SendByte(*subAddress);
185 2 if(SMB0STA != 0x28)
186 2 {
187 3 STO = 0;
188 3 return 0;
189 3 }
190 2 subAddress++;
191 2 SendByte(*subAddress);
192 2 if(SMB0STA != 0x28)
193 2 {
194 3 STO = 1;
195 3 return 0;
196 3 }
197 2 }
198 1 for(counter=0;counter<size; counter++)
199 1 {
200 2 SendByte ( *sendPtr );
201 2 if( SMB0STA!=0X28 )
202 2 {
203 3 STO=1;
204 3 SI = 0;
205 3 return(0);
206 3 }
207 2 sendPtr++;
208 2 }
209 1 SMB0CN=GENERATE_STOP;
210 1 Delay_IIC(); // stop the bus
211 1 return(1);
212 1 } // end SmbSend
213
214
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 431 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- 18
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -