Re: PIC16F628A 軟體 I2C
|
||||
---|---|---|---|---|
初級會員
|
原來如此
受教了
發表於: 2007/12/27 18:12
|
|||
|
Re: PIC16F628A 軟體 I2C
|
||||
---|---|---|---|---|
初級會員
|
謝謝
最近才有空做測試 AN997範例程式的確可用 不過不知為何我自己寫的I2C都不能用 請教一下各位 在PIC上寫軟體I2C需要注意哪些地方呢 我之前都寫8051架構的 最近才開始使用PIC
發表於: 2007/12/26 17:43
|
|||
|
Re: PIC16F628A 軟體 I2C
|
||||
---|---|---|---|---|
新會員
|
同鞋A:
你可以參考Microchip AN997範例程式 , 我用過OK
發表於: 2007/12/11 17:37
|
|||
|
PIC16F628A 軟體 I2C
|
||||
---|---|---|---|---|
初級會員
|
大家好
我是 Microchip 的新手 最近在寫軟體 I2C 可是卻一直連不起來 想請教一下是哪邊有問題 煩請各位指教 謝謝 MCU:PIC16F628A EEPROM:24C16 MPLAB IDE v8.00 PICC v8.05 程式如下: #include <pic.h> #include "global.h" void Delay( void ) { NOP();NOP();NOP();NOP(); } void I2cStart( void ) { SDA = 1; NOP();NOP(); SCL_IO = OUT; SDA_IO = OUT; NOP();NOP(); SDA = H; NOP();NOP(); SCL = H; NOP();NOP(); SDA = L; NOP();NOP(); } void I2cSendAddr( unsigned char SlaveAddr, unsigned char Mode )// Write : Mode = 0, Read : Mode = 1 { unsigned char Addr; signed char i; Addr = SlaveAddr | Mode; for( i=7;i>=0;i-- ) { SCL = L; NOP();NOP(); SDA = ( Addr >> i ) & 0x01; NOP();NOP(); SCL = H; NOP();NOP(); } SDA_IO = IN; SCL = L; NOP();NOP(); SCL = H; NOP();NOP(); } void I2cSendData( unsigned char Data ) { signed char i; SDA_IO = OUT; NOP();NOP(); for( i =7;i>=0;i-- ) { SCL = L; NOP();NOP(); SDA = ( Data >> i) & 0x01; NOP();NOP(); SCL = H; NOP();NOP(); } SDA_IO = IN; SCL = L; NOP();NOP(); SCL = H; NOP();NOP(); } unsigned char I2cRecData( void ) { signed char i; unsigned char temp2; temp2 = 0x00; SDA_IO = IN; NOP();NOP(); for( i=7;i>=0;i-- ) { SCL = L; NOP();NOP(); SCL = H; NOP();NOP(); temp2 << 1; if( SDA == H ) temp2 |= 0x01; } SDA_IO = OUT; NOP();NOP(); SCL = L; NOP();NOP(); SDA = H; NOP();NOP(); SCL = H; NOP();NOP(); return temp2; } void I2cStop( void ) { SDA_IO = OUT; NOP();NOP(); SDA = L; NOP();NOP(); SCL = H; NOP();NOP(); SDA = H; NOP();NOP(); SCL_IO = IN; SDA_IO = IN; NOP();NOP(); } void main( void ) { unsigned char temp1; EEPROM_WRITE(0x03,0x00); I2cStart(); I2cSendAddr(0xa0,0); I2cSendData(0x00); I2cSendData(0xaa); I2cStop(); Delay(); I2cStart(); I2cSendAddr(0xa0,0); I2cSendData(0x00); I2cStart(); I2cSendAddr(0xa0,1); temp1 = I2cRecData(); I2cStop(); EEPROM_WRITE(0x03,temp1); }
發表於: 2007/12/11 16:37
|
|||
|