Monday 19 October 2015

PIC16F877A SPI [SERIAL PERPHERAL INTERFACE] IN HALF DUPLEX MODE





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




//***********************************RECEIVER*************************//
#include<pic.h>
#include<htc.h>
#define _PIC16F877A_H
#define sck TRISCbits.TRISC3
#define sdi TRISCbits.TRISC4
#define sdo TRISCbits.TRISC5
__CONFIG(PWRTE_ON & FOSC_HS & LVP_OFF & WDTE_OFF);
void main()
{
TRISD=0X00;
SSPSTAT=0X00;       //in slave mode this is zero
SSPCON=0X24;        //for enable  //SPI Slave mode, clock = SCK pin. SS pin control enabled.
while(1)
{
while(SSPIF==0);
PORTD=SSPBUF;      //data is show on PORTD
BF=0;              //buffer pin is output pin
}
}
//***********************************************************************//

No comments:

Post a Comment