采用单片机c语言编写的,代码如下:
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=0;
#pragma interrupt_handler miao:9
#pragma data:code
// T/C1中断入口
void miao(void)
{
if(num==100)
{num=0;}
else
{num++;}
TCNT1H=0X85;//重新装载T/C1的初值
TCNT1L=0XED;
}
void Time1Init(void)
{
TCCR1B=0X04;//选择时钟为晶振256分频即31250HZ
TCNT1H=0X85;//定时1S (65536-初值)*(1/定时器的时钟)=1S
TCNT1L=0XED;//对定时器的初值设置时先写高位数据后写低位,读时则相反
TIMSK|=BIT(2);//T/C1溢出中断使能
}