lignin
Junior Member level 2
my aim is simple : flash led every 1 second ; I am using mplab and my code is below. I think my code is correct but in simulation , led is not flashing. please help me whats the problem
Code:
#include<pic.h>
#include<PIC16F877A.h>
#define _XTAL_FREQ 4000000;
int i=0;
void init(void);
void main()
{
init();
while(1);
}
void init()
{
TRISB=0X00;
PORTB=0X00;
GIE=1;
T1OSCEN=0;
T1SYNC=1;
T1CKPS1=0;
T1CKPS0=0;
TMR1CS=0;
TMR1H=-50000/256;
TMR1L=-50000%256;
TMR1IE=1;
TMR1IF=0;
TMR1ON=1;
}
static void interrupt
timer1_int(void)
{
if(TMR1IF)
{
i++;
if(i==20)
{
RB1=!RB1;
i=0;
}
TMR1IF=0;
TMR1ON=0;
TMR1H=-50000/256;
TMR1L=-50000%256;
TMR1ON=1;
}
}