PIC16F877單片機定時器0的中斷方式調試程序
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
__CONFIG(0x3B31);
void init(void);
uint intnum;
void main(void)
{
init();
while(1)
{
if(intnum >= 20)//1S到時
{
intnum = 0;
RD0 = !RD0;
}
}
}
void init(void)
{
TRISD = 0; //PORTD引腳為輸出
PORTD = 0; //PORTD引腳為低電平
OPTION = 0x07; //定時器0分頻256
INTCON = 0xa0; //總中斷、T0中斷
TMR0 = 61; //TMR0 = (256-195);
//TR//定時器0沒有啟停位
}
void interrupt time0(void)
{
T0IF = 0; //定時器溢出清零
TMR0 = 61; //重裝初值
intnum++; //累加器,主程序中累加到20*50ms
}