SSP2STAT=0x00;SSP2CON1=0x0;SSP2CON3=0x0;SSP2ADD=0x03;PIR2位.SSP2IF=0x03;PIR2比特.SSP2P2IF=0;PI2比特.SSP2IF=0;PIE2比特.SSP2IE=0;PIE2bits.SSP2IE=1;LATC=0XX=0XX=0X00;LATC=0x00=0x00;WPUA=0x00;WPUC=0x00;WPUC=0x00=0x00;ANSELA=0x37;ANSELC=0x37;ANSELC=0x05;ANSELC=0x05;0x05;TRISC=0gt;MSSP2:SCL2;RC1PPSbits.RC1PPS=0x1B;t;MSSP2:SDA2;#pragma config FEXTOSC=OFF//FEXTOSC外部振荡器模式选择位->未启用的振荡器#pragma config RSTOSC=HFINT1//COSC位的断电默认值->HFINTOSC#pragma config CLKOUTEN=OFF//Clock Out Enable bit-> CLKOUT功能被禁用;I/O或oscOSC2#pragma config CSWEN=ON//Clock Switch Enable bit->写入NOSC和NDIV上的振荡器功能#pragma config FCMEN=ON//Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor Enable//CONFIG2#pragma config MCLRE=ON//Master Clear Enable bit-> MCLR/VPP引脚功能离子是MCLR;弱上拉启用#pragma配置PWRTE=OFF//上电定时器启用位->PWRT禁用#pragma配置WDTE=OFF//看门狗定时器启用位->WDT禁用;SWDTEN被忽略#pragma配置LPBOREN=OFF//低功率BOR启用位->ULPBOR禁用#pragma配置BOREN=ON//Brown-out Reset Enable位->Brown-out Reset启用,SBOREN位忽略#pragma配置BORV=LOW//Brown-out Reset电压选择位->Brown-out电压(Vbor),设置为2.45V#pragma配置PPS1WAY=ON//PPSLOCK位单向设置Enable位-> PPSLOCK位只能被清除和设置一旦;在一个清除/设置周期#pragma配置STVREN=ON//堆栈溢出/下溢复位启用位>堆栈溢出或下溢将导致复位#pragma配置DEBUG=OFF//调试器启用位>后台调试器禁用//CONFIG3#pragma配置WRT=OFF//用户NVM自写保护位->写保护#pragma配置LVP=ON//低压编程启用位->低压编程启用。MCLR/VPP引脚功能是MCLR。忽略MCLRE配置位。//CONFIG4#pragma配置CP=OFF//用户NVM程序内存代码保护位->用户NVM代码保护禁用#pragma配置CPD=OFF//数据NVM内存代码保护位->数据NVM代码保护禁用
以上来自于百度翻译
以下为原文
SSP2STAT = 0x00;
SSP2CON1 = 0x28;
SSP2CON3 = 0x00;
SSP2ADD = 0x03;
PIR2bits.SSP2IF = 0;
PIE2bits.SSP2IE = 1;
LATA = 0x00;
LATC = 0x00;
WPUA = 0x00;
WPUC = 0x00;
ANSELA = 0x37;
ANSELC = 0x05;
TRISC = 0x3A;
TRISA = 0x13;
RC4PPSbits.RC4PPS = 0x1A; //RC4->MSSP2:SCL2;
RC1PPSbits.RC1PPS = 0x1B; //RC1->MSSP2:SDA2;
#pragma config FEXTOSC = OFF // FEXTOSC External Oscillator mode Selection bits->Oscillator not enabled
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits->HFINTOSC
#pragma config CLKOUTEN = OFF // Clock Out Enable bit->CLKOUT function is disabled; I/O or oscillator function on OSC2
#pragma config CSWEN = ON // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor is enabled
// CONFIG2
#pragma config MCLRE = ON // Master Clear Enable bit->MCLR/VPP pin function is MCLR; Weak pull-up enabled
#pragma config PWRTE = OFF // Power-up Timer Enable bit->PWRT disabled
#pragma config WDTE = OFF // Watchdog Timer Enable bits->WDT disabled; SWDTEN is ignored
#pragma config LPBOREN = OFF // Low-power BOR enable bit->ULPBOR disabled
#pragma config BOREN = ON // Brown-out Reset Enable bits->Brown-out Reset enabled, SBOREN bit ignored
#pragma config BORV = LOW // Brown-out Reset Voltage selection bit->Brown-out voltage (Vbor) set to 2.45V
#pragma config PPS1WAY = ON // PPSLOCK bit One-Way Set Enable bit->The PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable bit->Stack Overflow or Underflow will cause a Reset
#pragma config DEBUG = OFF // Debugger enable bit->Background debugger disabled
// CONFIG3
#pragma config WRT = OFF // User NVM self-write protection bits->Write protection off
#pragma config LVP = ON // Low Voltage Programming Enable bit->Low Voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored.
// CONFIG4
#pragma config CP = OFF // User NVM Program Memory Code Protection bit->User NVM code protection disabled
#pragma config CPD = OFF // Data NVM Memory Code Protection bit->Data NVM code protection disabled