11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> CompilerThere is however, another way TMR0 may be incremented. By settingthe T0CS bit of the OPTION_REG (OPTION_REG.5) a rising or fallingtransition on PortA.0 will also increment TMR0. Setting T0CS will attachTMR0 to PortA.0 and clearing TOCS will attach it to the oscillators.If PortA.0 is chosen then an associated bit, T0SE (OP-TION_REG.4) must be set or cleared. Clearing T0SE will incrementTMR0 with a low to high transition, while setting T0SE will incrementTMR0 with a high to low transition.The prescaler’s ratio is still valid when PortA.0 is chosen as thesource, so that every n th transition on PortA.0 will increment TMR0.Where n is the prescaler ratio.Before the interrupt is enabled, TMR0 itself should be assigned avalue, as any variable should be when first starting a program. Inmost cases clearing TMR0 will suffice. This is necessary because,when the PIC is first powered up the value of TMR0 could be anythingfrom 0 to 255We are now ready to allow TMR0 to trigger an interrupt. This is accomplishedby setting the T0IE bit of INTCON (INTCON.5). Settingthis bit will not cause a global interrupt to occur just yet, but will informthe PIC that when global interrupts are enabled, TMR0 will be onepossible cause. When TMR0 overflows (rolls over from 255 to 0) theT0IF (INTCON.2) flag is set. This is not important yet but will becomecrucial in the interrupt handler subroutine.The final act is to enable global interrupts by setting the GIE bit of theINTCON register (INTCON.7).Format of the interrupt handler.The interrupt handler subroutine must always follow a fixed pattern.First, the contents of the STATUS, PCLATH, FSR, and Working registermust be saved, this is termed context saving. A command hasbeen added that does this automatically named CONTEXT SAVE.Variable space is automatically allocated for the registers.When the interrupt handler was called the GIE bit was automaticallycleared by hardware, disabling any more interrupts. If this were notthe case, another interrupt might occur while the interrupt handler wasprocessing the first one, which would lead to disaster.Now the T0IF (TMR0 overflow) flag becomes important. Because, beforeexiting the interrupt handler it must be cleared to signal that wehave finished with the interrupt and are ready for another one.T0IF = 0' Clear the TMR0 overflow flag81Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!