tmr0 register
This is a replay to a PM that the user worte me. My answer was long and im sure some others whould want to read my explanation, so i posted it here
Hi,
First of all, if you think that i helped, then in the window where i wrote my answer any maybe in this one there is a buttom with
Helped me writen on it. Please click that, so i will know that you did appritiate my help.
Regarding your questions:
what bits do i set within the INTCON register?
Ok, If you will look at the PIC16F87XA.pdf the you will see in
FIGURE 14-10: INTERRUPT LOGIC the table what you need to enable inorder to get your interupt.
Also go to
2.2.2.3 INTCON Register and there you will see what bits you need to set on ( =1 ) and what you need to see off (=0 ).
also,if i want to use the 4MHz crystal i am currently using and trigger the timer using the internal instruction cycle=1us or 1mHz(if im not mistaken),how do i go about getting the clock to work as desired
If you will look at
FIGURE 5-1: BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER in the data sheet then you will see what you need to turn ON or OFF for the clock to work from the internal 4MHz. BUT, you need to remember this. The internal clock needs to be divided by 4 { each instruction will be 1/( 4MHz / 4MHz ) }.
So lets say you will use the prescaler at max, thats 1:256 and using the internal clock at 4MHz then will get this timing:
4MHz/4MHz = 1MHz = (1 / 1MHz ) = 0.000001 Sec.
The TMR0 will incrament every prescaler * 1MHz = 256 * 0.000001 = 0.000256 Sec
To find out when you will get an interupt if you will load 0x30 to TMR0 register:
TMR0 max register - Var = 0xFF - 0x30 = 0xCF
Interupt = 0xCF * 0.000256 = 0.052992 Sec.
So, if you will load this settings, you will get an interupt every 0.052992 of the second when using the OSC of 4MHz.
Good luck.