void interrupt_usart(void) //function to usart interrupt
{
uchar res;
if(RCIE&&RCIF) //receive data
{
res =RCREG;
if(RS485_RX_CNT<12) //the numbers of receive data less than the length of receice buffer array
{
RS485_RX_BUF[RS485_RX_CNT]=res;//save data to an receive buffer array
RS485_RX_CNT++; // the numbers of receive data plus one
}
}
}
//timer0中断初始化以及中断处理函数
void Init_Tim0() //intialize timer 0
{
RCONbits.IPEN =1;
TMR0IP=0; //
INTCON=0xA0; //enable global interrupt and timer 0 interrupt
INTCON2bits.TMR0IP=1;
TMR0=255; //set counter initial value 250
T0CON=0xc4; //enable timer 0 and timer 0 is configured an 8-bit timer
GIEL=1; //enable global interrupt
PEIE=1; //enable peripheral interrupt
TMR0IE=1; //enable timer 0 interript
}
/**************************
S3
S1 S2 S5
S4
***************************/
void interrupt timer0() //funciton to timer 0 interrupt
{
TMR0IF=0; //clear timer 0 interrupt flag bit
count++;
uchar keynum=0;
……
}