timer1中断的编程技术
#includesystemio();
const char table[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
unsigned int i=0;
main()
{
systemio(); //I/O初始化
T1CON=0x30;
TMR1IE=1;
PEIE=1; GIE=1;
TMR1L=0x00;
TMR1H=0x00;
TMR1ON=1;
while(1)
{;}
}
void interrupt tmr(void)
{
TMR1IF=0;
TMR1ON=0;
if (i>7)
{
i=0;
}
else
{
PORTD=table;
i=i+1;
}
TMR1L=0x00;
TMR1H=0x00;
TMR1ON=1;
}
systemio()
{
TRISD=0x00;
PORTD=0x00;
}
页:
[1]