void init()
{
OSCCONbits.IDLEN = 0;
OSCCONbits.IRCF2 = 1; //16MHz
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF0 = 1;
OSCCONbits.SCS0 = 0; // Internal oscillator selected
OSCCONbits.SCS1 = 0;
LATB=0X00;
TRISBbits.TRISB0 = 1; //配置RB0输入
TRISBbits.TRISB2 = 1;
TRISBbits.TRISB3 = 1;
TRISBbits.TRISB1 = 0; //配置RB1输出,P1B
TRISBbits.TRISB4 = 0; //配置RB4输出,P1A
TRISBbits.TRISB5 = 1; //配置RB5输出
LATC=0X00;
TRISCbits.TRISC3 = 1; //配置RC3输入
TRISCbits.TRISC4 = 0; //配置RC4输出
TRISCbits.TRISC7 = 0; //配置RC7输出
INTCON=0X00;
INTCONbits.GIE=1; //打开总中断
INTCONbits.PEIE=1; //使能外设中断
INTCONbits.INT0IE=1; //开启INT0中断
INTCON2bits.INTEDG0=1; //INT0上升沿中断
INTCONbits.INT0IF=0; //INT0中断标志清零
}
void delay(unsigned int t_ms)
{
unsigned int j;
for(j=0;j<t_ms;j++);
}
void interrupt myIsr(void)
{
if(INTCONbits.INT0IF==1)
{
INTCONbits.INT0IF=0;
RC4=!RC4;
}
}
void main()
{
init();
while(1)
{
;
}
}