khatus
Member level 3
This is the code for generating a delay of 1ms by using PIC18F4550 Timer0 Interrupt Service Routine.My question is
why these two lines
have been used once inside the function void Interrupt()
and again inside the function void InitTimer0()?
I know these are value to be loaded to the timer. But What is the reason for writing in two places?
This line would have been written only once in the function.
Here is y complete code
why these two lines
Code:
TMR0H = 0xFF; /* Load count for generating delay of 1ms */
TMR0L = 0xB2;
and again inside the function void InitTimer0()?
I know these are value to be loaded to the timer. But What is the reason for writing in two places?
Code:
TMR0H = 0xFF; /* Load count for generating delay of 1ms */
TMR0L = 0xB2;
Here is y complete code
Code:
//**Generating a delay of 1ms by using PIC18F2550 Timer0 Interrupt Service Routine**//
#define Pulse LATB
void InitTimer0();
void main()
{
OSCCON = 0b00000000; /* Configure oscillator frequency to 20MHz */
TRISB = 0x00; /* Set as output Port */
Pulse = 0xff; /* Send high on PortB */
InitTimer0();
while(1);
}
/***************Interrupt Service Routine for Timer0******************/
void Interrupt()
{
if (TMR0IF_bit)
{
TMR0H = 0xFF; /* Load count for generating delay of 1ms */
TMR0L = 0xB2;
TMR0IF_bit =0; /* Make Timer0 Overflow Flag to '0' */
//Enter your code here
Pulse =~ Pulse; /* Toggle PortB at of 500 Hz */
}
}
void InitTimer0()
{
/* Enable 16-bit TMR0 register,pre-scaler=64,External clock=20MHz,timer OFF */
T0CON = 0b00000101; /*Configure TIMER0 control register*/
TMR0H = 0xFF; /* Load Count for generating delay of 1ms */
TMR0L = 0xB2;
GIE_bit =1; /* Enable Global Interrupt */
PEIE_bit =1; /* Enable Peripheral Interrupt */
TMR0IE_bit =1; /* Enable Timer0 Overflow Interrupt */
TMR0IF_bit = 0; /* clear Timer0 interrupt flag bit */
TMR0ON_bit = 1; /* Turn ON Timer0 */
}