各位老师:本人采用PIC单片机,关于16F1828定时器TIME0有疑问:
1、TIME0怎么没有启动位?看官网16F示例代码是写入OPTION_REG后等待T0溢出。是否就是对OPTION_REG的操作或者TMR0CS位操作就是启动定时器?
2、1828手册184页上说对TMR0的操作会清除预分频;“预分频器是不可读写的。写TMR0 寄存器的所有指令都会清零预分频器。”;这样不是每次写TMR0后再进行分频操作,定时时间能准吗?
void main(void) {
OSCCON = 0b00111000; //500KHz clock speed
TRISC = 0; //all LED pins are outputs
LATC = 0;
OPTION_REG = 0b00000111; //1:256 prescaler for a delay of: (insruction-cycle * 256-counts)*prescaler = ((8uS * 256)*256) =~ 524mS
LATCbits.LATC4 = 1; //start with DS4 lit
while (1) {
while (!INTCONbits.TMR0IF) continue; //you can let the PIC do work here, but for now we will wait for the flag
INTCONbits.T0IF = 0; //flag MUST be cleared in software
LATC >> = 1; //rotate the LEDs
if (STATUSbits.C) //when the last LED is lit, restart the pattern
LATCbits.LATC3 = 1;
}
|