📄 i2c.lst
字号:
179 2 bAck=I2CTransmit(ucSetData);
180 2 if (bAck==TRUE)
181 2 {
182 3 I2CStop();
183 3 continue;
184 3 }
185 2 I2CStop();
186 2 if (bAck==FALSE)
187 2 break;
188 2 }
189 1 }
190 // ********************************************************************************
191 // Function: I2C_Read;
192 // Description: Read a data from I2C slaver.
193 // Input parameters: Byte - ucDevice - I2C slave ID of destination chip.
194 // Byte - ucAddress - Sub address of destination chip.
195 // Output parameters: None.
196 // Return values: None.
197 // ********************************************************************************
198 Byte I2CRead(Byte ucDevice,Byte ucAddress)
199 {
200 1 Byte ucIndex, ucReadData;
201 1 Bool bAck;
202 1
203 1 for(ucIndex=0;ucIndex<5;ucIndex++)
204 1 {
205 2 I2CStart();
206 2 bAck=I2CTransmit(ucDevice);
207 2 if (bAck==1)
208 2 {
209 3 I2CStop();
210 3 continue;
211 3 }
212 2
213 2 bAck=I2CTransmit(ucAddress);
214 2 if (bAck==1)
215 2 {
216 3 I2CStop();
217 3 continue;
218 3 }
219 2
220 2 I2CStart();
221 2 bAck=I2CTransmit(ucDevice|0x01);
222 2 if (bAck==0)
223 2 break;
224 2 I2CStop();
225 2 }
226 1 ucReadData=I2CReceive();
227 1 I2CAck(TRUE);
228 1 I2CStop();
229 1 return ucReadData;
230 1
231 1 }
232
233
234
235 // ********************************************************************************
236 // Function: Register Read
237 // Description: Receive 1 byte of data from slave end with assigned ID and sub address.
-
C51 COMPILER V7.50 I2C 08/11/2008 14:05:22 PAGE 5
238 // Input parameters: Byte - ucSlaveID: I2C slave ID of destination chip.
239 // Byte - ucSubAddr: sub address of destination chip.
240 // Return values: Byte - ucDx: byte of data been received from slave end.
241 // ********************************************************************************
242 Byte GetReg(Byte ucSlaveID,Byte ucSubAddr)
243 {
244 1 Byte ucDx;
245 1 ucDx=I2CRead(ucSlaveID,ucSubAddr);
246 1 return(ucDx);
247 1 }
248
249 // ********************************************************************************
250 // Function: Register Write
251 // Description: Transmite 1 byte of data to slave end with assigned ID and sub address.
-
252 // Input parameters: Byte - ucSlaveID: I2C slave ID of destination chip.
253 // Byte - ucSubAddr: sub address of destination chip.
254 // Byte - ucDx: data to be transmited.
255 // Return values: None.
256 // ********************************************************************************
257 void SetReg(Byte ucSlaveID, Byte ucSubAddr, Byte ucDx)
258 {
259 1 I2CWrite(ucSlaveID,ucSubAddr,ucDx);
260 1 }
261
262 extern Byte gucChipAddress;
263 // ********************************************************************************
264 // Function: InitReg
265 // Description: Install register table into chip.
266 // Input parameters: None.
267 // Return values: None.
268 // ********************************************************************************
269 void InitReg(Byte *pucData)
270 {
271 1 Byte ucIndex, ucData;
272 1 while(1)
273 1 {
274 2 if (*pucData == DATA_COMMAND)
275 2 {
276 3 if (*((Byte *)(pucData + 1)) == DATA_END)
277 3 {
278 4 break;
279 4 }
280 3 else if (((*((Byte *)(pucData + 1))) & COMMAND_DELAY) == COMMAND_DELAY)
281 3 {
282 4 Delay((*((Byte *)(pucData + 1))) & DELAY_VALUE);
283 4 pucData += 2;
284 4 }
285 3 else if ((*((Byte *)(pucData + 1))) < PAGE_ADDRESS_MAX)
286 3 {
287 4 ucIndex = *pucData++;
288 4 ucData = *pucData++;
289 4 I2CWrite(gucChipAddress, ucIndex, ucData);
290 4 }
291 3 else
292 3 {
293 4 ucIndex = *pucData++;
294 4 ucData = *pucData++;
295 4 // set I2C addres
296 4 gucChipAddress = ucData << 1;
297 4 }
298 3 }
C51 COMPILER V7.50 I2C 08/11/2008 14:05:22 PAGE 6
299 2 else
300 2 {
301 3 ucIndex = *pucData++;
302 3 ucData = *pucData++;
303 3 I2CWrite(gucChipAddress, ucIndex, ucData);
304 3 }
305 2 }
306 1 }
307
308 // ********************************************************************************
309 // Function: Delay
310 // Description: Delay for Time
311 // Input parameters: None.
312 // Return values: None.
313 // ********************************************************************************
314 void Delay(int uiTime_ms)
315 {
316 1 int uiTemp1, uiTemp2;
317 1 for (uiTemp1 = 0; uiTemp1 < uiTime_ms; uiTemp1++)
318 1 {
319 2 for (uiTemp2 = 0; uiTemp2 < ONEMS; uiTemp2++);
320 2 }
321 1 }
322
323
324 void srgb_write(unsigned char addr, unsigned char dat)
325 {
326 1 unsigned int uiDat;
327 1 char i;
328 1
329 1 uiDat = addr;
330 1 uiDat <<= 8;
331 1 uiDat += dat;
332 1
333 1 TFT_CS = 1;
334 1 scl= 0;
335 1 sda= 0;
336 1 TFT_CS = 0;
337 1
338 1 for (i = 0; i < 16; i = i + 1)
339 1 {
340 2 sda= (uiDat & 0x8000) == 0x8000 ;
341 2 scl= 1;
342 2 scl = 0;
343 2 uiDat <<= 1;
344 2 }
345 1
346 1
347 1 TFT_CS = 0;
348 1 TFT_CS = 1;
349 1
350 1 }
*** WARNING C316 IN LINE 350 OF I2C.C: unterminated conditionals
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 542 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 13
IDATA SIZE = ---- ----
C51 COMPILER V7.50 I2C 08/11/2008 14:05:22 PAGE 7
BIT SIZE = ---- 4
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -