unsigned int num_time0;
void delay_TM0(unsigned int x) //Time0 定时
{
OPTION_REGbits.TMR0CS=0; //定时模式
OPTION_REGbits.PSA=1; //不分频
INTCONbits.T0IF=0;
INTCONbits.T0IE=1;
TMR0=0xAA; //定时100us
INTCONbits.GIE=1;
num_time0=x;
while(num_time0);
}
void interrupt ISR(void)
{
if(INTCONbits.TMR0IF==1)
{
TMR0=0xAA;
INTCONbits.TMR0IF=0;
num_time0--;
}
} |