PIC16F877A单片机的Timer1是16位的,我们利用此定时器实现一个10ms的定时,在定时中断里我们再判断1s是否到了,到了之后将LED灯状态取反。
#include <htc.h>
#define u8 unsigned char
#define u16 unsigned int
__CONFIG(0xFF32);
#define LED PORTD
char Counter=0;
void timer1_init()
{
T1CKPS0=1; //1:8
T1CKPS1=1;
TMR1CS=0; //定时器模式
TMR1IE=1;
TMR1H=0xfb; //10ms@4MHz
TMR1L=0x1e;
TMR1ON=1;
PEIE=1;
GIE=1;
}
|