Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC16f877a to PIC16f877a communication using I2C

Status
Not open for further replies.

starguard2527

Newbie level 4
Joined
Aug 6, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,323
Hello,

Guys i am doing a project in which i need to communicate between two 16f877a controllers. and the restriction is to use i2c. i have developed a hardware in which one pic is the master and other is the slave. there is an lcd connected to the slave. not the task is to transmit data from master to slave and display it on lcd.

diagramatically:

Master PIC >> Slave PIC>> 16x2 LCD

i am using mikro c for this and the code which i have written is as follow:


MASTER CODE:
void main() {

while(1){
i2c1_init(100000);
i2c1_start();
i2c1_wr(0x02);
i2c1_wr(0x69);
i2c1_stop();
delay_ms(250);
}
}


SLAVE CODE:
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB7_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB4_bit;

unsigned short get_rid_of_addr(void);
unsigned short get_i2c_data(void);



void main(){
char fb_val_txt[4];
trisc=0b00011000;
trisb.F0=1;
SSPCON=0b00010110;
SSPCON2.F0=0;
GCEN_bit=0;
SSPSTAT.F6=0;
SSPSTAT.F7=1;
SSPADD=0x01;
CKE_bit=0;
SSPEN_bit=1;
lcd_init();
lcd_out(1,1,"Executing");
while(portb.F0==0);
while(1){
get_rid_of_addr();
ByteToStr(get_i2c_data(),fb_val_txt);
CKP_bit=1;
Lcd_Cmd(_LCD_CLEAR);
lcd_out(1,1,fb_val_txt);
delay_ms(250);
}
lcd_out(2,1,"Exiting");
}

unsigned short get_rid_of_addr(void){
short dummy,i=0;
GIE_bit=1;
PEIE_bit=1;
SSPIE_bit=1;

lcd_out(2,1,"getting rid");
while( SSPIF_bit==0)
{
i=2;
if (SSPOV_bit==1)
lcd_out(1,1,"Overflow");
}
lcd_cmd(_LCD_CLEAR);
lcd_out(i,1,"got it");
delay_ms(500);
dummy=SSPBUF;
SSPIF_bit=0;
CKP_bit=1;
return dummy;
}
unsigned short get_i2c_data(void){
unsigned short dat;
while(SSPIF_bit==0)
{
dat=0;
}
dat=SSPBUF;
SSPIF_bit=0;
CKP_bit=1;
return dat;
}


I have also heard that pic16f877a has some hardware problems with i2c interface. is it a truth or myth....

PLEASE PLEASE PLEASE HELP ME OUT... Thanks in advance.
 

The link no longer valid.
Anyone have a current location of the doc?
Tearo
 

Ok. Here is the projects you want.

1. Master Sends data to slave and slave displays it on its LCD.

2. Master requests data from slave and slave sends its ADC data to master and master displays it on its LCD.

I have done this for PIC16F877A to PIC16F877A.
 

Attachments

  • I2C Master Slave mikroC PRO PIC.rar
    192.9 KB · Views: 106
  • I2C Master Slave PIC16F877A.rar
    164 KB · Views: 104
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top