公司开发产品用到九齐NY8B062E单片机,需要用到24C08和摇控解码,现在主要问题是想要做一个10us延时,配置8M 2T,定时器1做的20m延时中断算比较准,但用定时器0做10us中断或直接用delay()函数都无法做到10us,最低做到600多us!
void main(void)
{
unsigned char R_shift_regl = 0xFF;
//;Initial GPIO
IOSTB = C_PB5_Input | C_PB4_Input | C_PB1_Input; // Set PB0 & PB1 to input mode,others set to output mode
PORTB = 0x07; // PB0、PB1 & PB2 are output High
DISI();
//;Initial Timer0
PCON1 = C_TMR0_Dis; // Disable Timer0
TMR0 = 0xC8; // Load 0x00 to TMR0 (Initial Timer0 register)
//T0MD = C_TMR0_LowClk | C_PS0_Div2 ; // Prescaler0 is assigned to Timer0, Prescaler0 dividing rate = 1:8,clock source is instruction clock
T0MD = 0X00;
//;--Initial WDT (if WDT needs prescaler0 dividing rate )--------------------------------------------------
// T0MD = C_PS0_WDT // Prescaler0 is assigned to WDT, Prescaler0 dividing rate = 1:2 (WDT select interrupt)
//;--------------------------------------------------------------------------------------------------------
//;Initial Timer1
TMRH = 0x20;
TMR1 = 0x71; // Load 0xFF to TMR1 (Initial Timer1 register)
T1CR1 = C_TMR1_Reload | C_TMR1_En; // Enable Timer1, Initial value reloaded from TMR1, Non-stop mode
T1CR2 = C_TMR1_ClkSrc_Inst | C_PS1_Div128; // Enable Prescaler1, Prescaler1 dividing rate = 1:4, Timer1 clock source is instruction clock
//;Setting Interrupt Enable Register
INTE = C_INT_WDT | C_INT_TMR1 | C_INT_TMR0; // Enable Timer0、Timer1、WDT overflow interrupt
//;Initial Power control register
PCON = C_WDT_En | C_LVR_En; // Enable WDT , Enable LVR
//;Enable Timer0 & Global interrupt bit
PCON1 = C_TMR0_En; // Enable Timer0
ENI(); // Enable all unmasked interrupts
while(1)
{
if(i==1)
{
PORTBbits.PB3 ^=1;
i=0;
}
if(j==1)
{
PORTBbits.PB2 ^=1;
j=0;
}
PORTBbits.PB0 ^=1;
delay_10us(1);
}
}
void isr(void) __interrupt(0)
{
if(INTFbits.T1IF)
{
i=1;
//PORTB ^= (1<<1); // PB1 Toggle
INTF= (unsigned char)~(C_INT_TMR1); // Clear T1IF flag bit
}
if(INTFbits.T0IF)
{
j=1; // PB0 Toggle
INTF= (unsigned char)~(C_INT_TMR0); // Clear T0IF flag bit
}
}
定时器0输出
定时器1输出
嵌入若干条汇编指令nop?