#include "htc.h"
//相关宏定义
unsigned char a = 0;
unsigned char b = 0;
/*初始化D端口*/
void port_init()
{
TRISD = 0x00 ;
RD0 = 0;
RD1 = 0;
}
/*定时器1初始化*/
void time1_init()
{
INTCON = 0xC0 ; //开启全局中断
T1CON = 0x31 ; //定时器开启
TMR1IE = 1 ;//允许开启定时器1中断
TMR1IF = 0 ;//清楚中断标志位
TMR1H = 0xFB ;//定时为10ms
TMR1L = 0x20 ;
}
/*定时器中断程序*/
void interrupt time1()
{
TMR1IF = 0 ;
TMR1H = 0xFB ;
TMR1L = 0x20 ;
a ++ ;//计数
b ++ ;
}
void main()
{
port_init();
time1_init();
while(1)
{
if( a == 5 )//经过五次中断时 T= 5*10ms=50ms
{
RD0 = !RD0 ;//取反,灯闪烁
a = 0 ;
}
if( b == 25 )//经过25次中断时 T= 25*10ms = 250ms
{
RD1 = !RD1 ;//取反,灯闪烁
b = 0 ;
}
}
}
不知道是不是你要的答案。