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> CompilerAnother method of waking the PIC is an external one, a change onone of the port pins. We will examine more closely the use of an externalsource.There are two main ways of waking the PIC using an external source.One is a change on bits 4..7 of PortB. Another is a change on bit-0 ofPortB. We shall first look at the wake up on change of PortB,bits-4..7.As its name suggests, any change on these pins either high to low orlow to high will wake the PIC. However, to setup this mode of operationseveral bits within registers INTCON and OPTION_REG need tobe manipulated. One of the first things required is to enable the weakPortB pull-up resistors. This is accomplished by clearing the RBPU bitof OPTION_REG (OPTION_REG.7). If this was not done, then thepins would be floating and random input states would occur wakingthe PIC up prematurely.Although technically we are enabling a form of interrupt, we are not interestedin actually running an interrupt handler. Therefore, we mustmake sure that GLOBAL interrupts are disabled, or the PIC will jumpto an interrupt handler every time a change occurs on PortB. This isdone by clearing the GIE bit of INTCON (INTCON.7).The interrupt we are concerned with is the RB port change type. Thisis enabled by setting the RBIE bit of the INTCON register (INT-CON.3). All this will do is set a flag whenever a change occurs (and ofcourse wake up the PIC). The flag in question is RBIF, which is bit-0of the INTCON register. For now we are not particularly interested inthis flag, however, if global interrupts were enabled, this flag could beexamined to see if it was the cause of the interrupt. The RBIF flag isnot cleared by hardware so before entering SLEEP it should becleared. It must also be cleared before an interrupt handler is exited.The SLEEP command itself is then used. Upon a change of PortB,bits 4..7 the PIC will wake up and perform the next instruction (orcommand) after the SLEEP command was used.A second external source for waking the PIC is a pulse applied toPortB.0. This interrupt is triggered by the edge of the pulse, high tolow or low to high. The INTEDG bit of OPTION_REG (OP-TION_REG.6) determines what type of pulse will trigger the interrupt.If it is set, then a low to high pulse will trigger it, and if it is clearedthen a high to low pulse will trigger it.To allow the PortB.0 interrupt to wake the PIC the INTE bit must beset, this is bit-4 of the INTCON register. This will allow the flag INTF(INTCON.1) to be set when a pulse with the right edge is sensed.126Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!