Bala,
Glad to be of help and that you have it working as you wanted.
I am a little curious about your statements and reported observations though.
Your posted code does indeed create a ~1Hz blinking led (~.5sec on / ~.5sec off).
It does this by creating a TMR0 Overflow Interrupt that fires every 1.024ms and your T0Count tests for 512 counts which makes LED2 toggle every ~524ms.
TMR0 Overflow = (1 / [4000000/4]) * 4 * 256 = 0.001024 seconds (You are setting the Prescaler to 1:4 as "OPTION_REG = OPTION_REG & $80 | 1" does)
BTW, I guess the comments have not be updated in the posted code for the above OPTION_REG line? ("Set TMR0 Prescaler to 256")
LED2 Toggle = TMR0 Overflow * 512 = 0.001024 * 512 = 0.524288 seconds
This creates a ~0.5sec On / ~0.5sec Off rate for ~1Hz.
You state that my suggestion of setting the TMR0 Prescaler to 1:32 and T0Count test to 61, blinks the light at 0.5Hz (1 second On, 1 second Off).
And you then set the Prescaler to 1:16 and then LED2 blinks at 1Hz.
Well, setting up the configuration as I suggested here on my end does create a blinking led at ~1Hz.
TMR0 Overflow = (1 / [4000000/4]) * 32 * 256 = 0.008192 seconds
LED2 Toggle = TMR0 Overflow * 61 = 0.008192 * 61 = 0.499712 seconds (~0.5sec On / ~0.5sec Off).
I have verified your code with my suggested settings added via the simulator (do not have the 16F88 IC) and it blinks at ~1Hz.
I also verified your posted code as is via the simulator and have the same ~1Hz blinking rate as would be expected from the calculations.
If you set the Prescaler to 1:16 and leave the T0Count test to 61 then the result would be different.
TMR0 Overflow = (1 / [4000000/4]) * 16 * 256 = 0.004096 seconds
LED2 Toggle = TMR0 Overflow * 61 = 0.004096 * 61 = 0.249856 seconds
Which would cause LED2 to blink at ~2Hz (~.250sec On / ~.250sec Off)
Perhaps your setting of the OPTION_REG register was not quite right when you tested the suggestions?
To set the PORTB Pullups enabled and TMR0 Prescaler to 1:32, OPTION_REG = $84 %10000100.
To set the PORTB Pullups enabled and TMR0 Prescaler to 1:16, OPTION_REG = $83 %10000011.
Again, just curious about your observations...
Bookmarks