//**********************************MASTER******************//
#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
SSPBUF=0X42; //data register
while(SSPIF==0); //till the bit is not send
SSPBUF=0;
SSPIF=0;
while(1)
{
PORTD=SSPBUF;
}
}
//******************************************************************//
//**********************************SLAVE***************************//
#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()
{
int i=0;
//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)
{
//PORTD=i++;
SSPBUF=0X55;
while(SSPIF==0);
SSPIF=0;
}
}
//****************************************************************//
No comments:
Post a Comment