User Guide

Code
2021
Microchip Technology Inc. and its subsidiaries
DS50003218A-page 31
* Function to Initialize SPI1 Module
****************************************************************/
void SPI1_Initialize(void)
{
SSP1CON1=0;
SSP1STAT=0;
SSP1ADD=0;
//Setup PPS Pins
ANSELBbits.ANSELB1=0; //Make the PORTS digital
ANSELBbits.ANSELB2=0; //Make the PORTS digital
ANSELBbits.ANSELB3=0; //Make the PORTS digital
TRISBbits.TRISB1=0; //Make port output
TRISBbits.TRISB2=1; //Make port output
TRISBbits.TRISB3=0;
//PPS pin assignment
SSP1CLKPPS = 9;
SSP1DATPPS = 10;
RB1PPS = 15;
RB3PPS = 16;
SSP1STAT = 0x40;
SSP1CON1 = 0x00;
SSP1ADD = 0x03;
SSP1CON1bits.SSPEN = 1;
}
/****************************************************************
* Initialize the Switch
****************************************************************/
void SwitchInit(void)
{
DIGTAL_SWITCH1=0; //Make the port digital
TRIS_SWITCH1=1; //Make the port input
DIGTAL_SWITCH2=0;
TRIS_SWITCH2=1;
}
/****************************************************************
* Check for Switch1 pressed
****************************************************************/
void SW1(void)
{
if(SWITCH1==0)