Bob Parihar
Member
i am doing a simple project of generating 1 second time delay and i choose timer1 of pic micro controller (PIC16f877a)
the formula i have chosen to compute the time delay is like
so for 1 sec the count value comes out to be 15
register bit selection is as follows
and according to the calculation above my code is for 1 sec as follows( iam using mikroc compiler and proteus for simulation) :
int count=0;
void main() {
TRISC=0; // configuring output port
PORTC.F0=1; // led connected to 1st pin of portC
TMR1H=0x00; // initial count values in timer1 register
TMR1L=0x00;
T1CON=0x01; // explained above in the discription
while(1)
{
while(TMR1IF==0); // monitor the timer1 flag for overflow
count=count+1;
if(count==15)
{
PORTC.F0=~PORTC.F0;
count=0;
}
PIR1.F0=0; //contaning Timer flag register at bit 0
}
}
i think iam doing right but the code does not work
anyone please tell me what wrong with it
i think iam doing right but the code does not work
anyone please tell me what wrong with it
the formula i have chosen to compute the time delay is like

so for 1 sec the count value comes out to be 15
register bit selection is as follows

- TMR1ON=1; // the timer is enable
- TMR1CS=0; // internal clock source
- T1CKPS0=0; // Prescaler value set to “00”
- T1CKPS1=0; // which means 1:1 (no division)
and according to the calculation above my code is for 1 sec as follows( iam using mikroc compiler and proteus for simulation) :
int count=0;
void main() {
TRISC=0; // configuring output port
PORTC.F0=1; // led connected to 1st pin of portC
TMR1H=0x00; // initial count values in timer1 register
TMR1L=0x00;
T1CON=0x01; // explained above in the discription
while(1)
{
while(TMR1IF==0); // monitor the timer1 flag for overflow
count=count+1;
if(count==15)
{
PORTC.F0=~PORTC.F0;
count=0;
}
PIR1.F0=0; //contaning Timer flag register at bit 0
}
}
i think iam doing right but the code does not work
anyone please tell me what wrong with it
i think iam doing right but the code does not work
anyone please tell me what wrong with it
Last edited: