|
نحن فى انتظارك اخى وليد اتمنى ان تبدا بال communication مثل spi i2c
|
لن أتناول هذه الجزئية كما أشرت فى بداية الموضوع لعيوبها التى لا تتوافق مع مشاريعى رغم ما بها من مميزات أخرى وأنى لم أستخدمها من قبل لكن إليك هذا المثال وهو منقول لعل به ما تريد
Serial EEPROM
I2C or I

C stands for
Inter-Integrated Circuit and is pronounced I-squared-C. This is another way chips (i.e. PICs) can communicate between themselves. It is simple, cheap, and somewhat slow (from the chip’s point of view), and has been widely used for more than twenty years now. Similar to USART and SPI, the data is transferred in serial manner, i.e. bit-by-bit, through a single wire. Unlike the SPI, this standard uses only two bi-directional wires in total, one for data and one for the clock. It also allows for over 1000 chips to be inter-connected over only two wires, and it is designed to allow the chips to be safely added to or removed from the bus without turning off the power. This and the fact that it has been invented and supported by Philips, can explain such a popularity of this standard.
From BASIC user’s point of view, using I2C looks pretty much like using the SPI. You have to:
Initiate communication between ICs;
We will demonstrate this by connecting a 24c02 EEPROM to our PIC. Here is how to connect them:
' Example of communication with 24c02 EEPROM
كود:
' Example of communication with 24c02 EEPROM
program i2c_test
dim EE_adr as byte
dim EE_data as byte
dim jj as word
main:
I2C_init(100000) ' initialize full master mode
TRISD = 0 ' PORTD is output
PORTD = $FF ' initialize PORTD
I2C_Start ' issue I2C start signal
I2C_Wr($A2) ' send byte via I2C(command to 24cO2)
EE_adr = 2
I2C_Wr(EE_adr) ' send byte(address for EEPROM)
EE_data = $AA
I2C_Wr(EE_data) ' send data(data that will be written)
I2C_Stop ' issue I2C stop signal
for jj = 0 to 65500 ' pause while EEPROM writes data
nop
next jj
I2C_Start ' issue I2C start signal
I2C_Wr($A2) ' send byte via I2C
EE_adr = 2
I2C_Wr(EE_adr) ' send byte (address for EEPROM)
I2C_Repeated_Start ' issue I2C signal repeated start
I2C_Wr($A3) ' send byte (request data from EEPROM)
EE_data = I2C_Rd(1) ' read data
I2C_Stop ' issue I2C stop signal
PORTD = EE_data ' show data on PORTD
noend: ' endless loop
goto noend
end.
You can find more details on I2C routines’ syntax in Chapter 5: Built-in and Library Routines. You shouldn’t bother yourself too much about the meaning of the I2C_Start and I2C_Repeated_Start routines – that’s the way your PIC performs the initialization of its I2C device.
أتمنى أن تكون وصلت المعلومة