-----------------------------------------------
目的50ms led翻转 ,仿真出来200ms才翻转
----------------------------------------------
#include<pic.h>
#define led RB0
void portinit(void)
{
TRISB=0x00;
PORTB=0x00;
}
void tmr1init(void)
{
TMR1H=(65536-50000)/256;
TMR1L=(65536-50000)%256;//50ms
INTCON=0xC0;//0xc0 全局中断使能GIE PEIE均置1
TMR1IE=1;//定时中断使能
T1CON=0x01;//设置分频比1:1
}
void interrupt isr(void)
{
if(TMR1IF==1)
{
TMR1IF=0;
TMR1H=(65536-50000)/256;
TMR1L=(65536-50000)%256;
PORTB=~PORTB;
}
}
void main(void)
{
portinit();
tmr1init();
while(1);
}