Merhaba arkadaşlar, ben I2C kullanarak çok basit bir proje yapmak istiyorum. bir pic e bağladığım buton 1 olduğunda diğer picin ucundaki ledi yakmak istiyorum. şimdi hazır bir kod buldum değişiklikleri yaptım fakat çalışmadı. buraya master ve slave kısımlarını koyuyorum hatamı söylerseniz sevinirim.
#use I2C(FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW) //using hardware I2C, built into the PIC, make sure to include this line in any master I2C program
int data; int S1,S2;
void main(void) { set_tris_b(0b11111111); while(TRUE) { S1 = INPUT(PIN_B7); //store switch inputs as S1 and S2 S2 = INPUT(PIN_B4); if ((S1==1)) {
data=1; //incrementing data down } else if (S1==0) { data=0; //incrementing data down } i2c_start(); //begin transmission i2c_write(0x14); //select address of device to communicate with i2c_write(data); //send actual data i2c_stop(); //terminate communication delay_ms(100); //debouncing delay
#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000) //Burayı 4Mega Hz yapmam gerekli mi?
#use I2C(FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW) //using hardware I2C, built into the PIC, make sure to include this line in any master I2C program
int data;
int S1,S2;
void main(void)
{
set_tris_b(0b11111111);
while(TRUE)
{
S1 = INPUT(PIN_B7); //store switch inputs as S1 and S2
S2 = INPUT(PIN_B4);
if ((S1==1))
{
data=1; //incrementing data down
}
else if (S1==0)
{
data=0; //incrementing data down
}
i2c_start(); //begin transmission
i2c_write(0x14); //select address of device to communicate with
i2c_write(data); //send actual data
i2c_stop(); //terminate communication
delay_ms(100); //debouncing delay
}
}
#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use i2c(SLAVE, FAST, SCL=PIN_C3, SDA=PIN_C4, address=0x14, FORCE_HW)
int data = 0,state = 0;
#INT_SSP
void sspinterupt()
{
state = i2c_isr_state(); //State li kısım ne işe yarıyor biliyor musunuz?
if(state < 0x80)
{
data = i2c_read();
}
if(state == 0x80)
{
i2c_write(data);
}
if(data==1){
output_bit(pin_B7,1);
}
}
void main(void)
{
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
set_tris_b(0x00);
while(TRUE){
}
}
DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.
Üye Ol Şimdi DeğilÜye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.