Monday, 19 October 2015

PIC16F877A SPI [SERIAL PERPHERAL INTERFACE] IN FULL DUPLEX MODE



//*****************************TRANSMITER************************//
#include<pic.h>
#include<htc.h>
#define _PIC16F877A_H
#define sck TRISCbits.TRISC3
#define sdi TRISCbits.TRISC4
#define sdo TRISCbits.TRISC5
#define ss TRISAbits.TRISA5
__CONFIG(PWRTE_ON & FOSC_HS & LVP_OFF & WDTE_OFF);
void main()
{
TRISD=0X00;
sdo=0;
sck=0;
sdi=1;
SSPSTAT=0X00;         //in master mode this is zero
SSPCON=0X20;          //for enable serial port
while(1)
{
SSPBUF=0X42;          //data register
SSPIF=0;
while(SSPIF==0);      //till the bit is not send
PORTD=SSPBUF;
BF=0;
while(1);
}
}                                                                                                                                                                                                                                                                                  
//*****************************************************//



//**************************RECEIVER******************************//

#include<pic.h>
#include<htc.h>
#define _PIC16F877A_H
#define sck TRISCbits.TRISC3
#define sdi TRISCbits.TRISC4
#define sdo TRISCbits.TRISC5
#define ss TRISAbits.TRISA5
__CONFIG(PWRTE_ON & FOSC_HS & LVP_OFF & WDTE_OFF);
void delay(unsigned int i)
{
while(i--);
}
void main()
{
TRISD=0X00;
sdo=0;
SSPSTAT=0X00;       //in slave mode this is zero
SSPCON=0X24;        //for enable  //SPI Slave mode, clock = SCK pin. SS pin control enabled.
while(1)
{

SSPBUF=0X81;
SSPIF=0;

while(SSPIF==0);
PORTD=SSPBUF;      //data is show on PORTD
BF=0;              //buffer pin is output pin
while(1);
}
}

//*************************************************************//

No comments:

Post a Comment