周一到周五的零碎时间我写了一个PIC的定时器程序。大学毕业以后没人发奖状。就想用博客来记录进入社会以后正在做的事情。
1PIC12F675有中断有TMR0 和TMR1,8位和16位。用起来很精确。
2计时器初值算法:T0 =(256-(X-1))*4/4MHz*P.
3 P是分频比1:32。X是计时器初值。
4 不废话,上程序。
#include
#include
#include
#include
// #pragma config statements should precede project file
includes.
// Use project enums instead of #define for ON and OFF.
// CONFIG
#pragma config FOSC = INTRCCLK // Oscillator
Selection bits (INTOSC oscillator: CLKOUT function on
GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE =
OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE =
OFF // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE =
OFF // GP3/MCLR pin function select (GP3/MCLR pin function is digital
I/O,