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> Compiler5.42. ON_INTERRUPTSyntax :Overview :Operators :Example :ON_INTERRUPT LabelJump to a subroutine when a Hardware interrupt occursLabel is a valid identifier‘ Flash an LED attached to PortB.0 at a different rate to the‘ LED attached to PortB.1DEVICE 16F84ON_INTERRUPT Flash‘ Assign some Interrupt associated aliasesSYMBOL T0IE INTCON.5 ' TMR0 Overflow Interrupt EnableSYMBOL T0IF INTCON.2 ' TMR0 Overflow Interrupt FlagSYMBOL GIE INTCON.7 ' Global Interrupt EnableSYMBOL PS0 OPTION_REG.0 ' Prescaler ratio bit-0SYMBOL PS1 OPTION_REG.1 ' Prescaler ratio bit-1SYMBOL PS2 OPTION_REG.2 ' Prescaler ratio bit-2' Prescaler Assignment (1=assigned to WDT 0=assigned to oscillator)SYMBOL PSA OPTION_REG.3' Timer0 Clock Source Select (0=Internal clock 1=External PORTA.4)SYMBOL T0CS OPTION_REG.5SYMBOL LED PORTB.1GOTO Over_interrupt ‘ Jump over the interrupt subroutine‘ Interrupt routine starts hereFlash: CONTEXT SAVE ‘ Save the registers' XOR PortB with 1, Which will turn on with one interrupt' and turn off with the next the LED connected to PortB.0PORTB = PORTB ^ 1T0IF = 0' Clear the TMR0 overflow flagCONTEXT RESTORE ‘ Restore the registers and exitOver_interrupt : TRISB = %00000000PORTB = 0‘ Initiate the interruptGIE = 0PSA = 0PS0 = 1PS1 = 1PS2 = 1T0CS = 0TMR0 = 0T0IE = 1GIE = 1' Configure PortB as outputs‘ Clear PortB' Turn off global interrupts' Assign the prescaler to external oscillator' Set the prescaler' to increment TMR0' every 256th instruction cycle' Assign TMR0 clock to internal source' Clear TMR0 initially' Enable TMR0 overflow interrupt' Enable global interrupts79Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!