ME Labs, Inc. 719-520-5323 |
ME Labs, Inc. | 1-719-520-5323 | Example Program - ASMINT.pbpPICBASIC PRO program to demonstrate interrupts in assembly language. Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off. Program waits .5 seconds and turns LED back on.' Name : ASMINT.pbp ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : PM or MPASM ' Target PIC : Any PIC16F types ' Hardware : Non specific ' Oscillator : internal or external ' Keywords : ASSEMBLY INTERRUPTS ' Description : PICBASIC PRO program to demonstrate interrupts in ' assembly language. Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off. ' Program waits .5 seconds and turns LED back on. ' led Var PORTB.7 wsave Var byte $20 system 'wsave1 Var byte $a0 system ' Necessary for devices with RAM in bank1 'wsave2 Var byte $120 system ' Necessary for devices with RAM in bank2 'wsave3 Var byte $1a0 system ' Necessary for devices with RAM in bank3 ssave Var byte bank0 system psave Var byte bank0 system Goto start ' Skip around interrupt handler ' Define interrupt handler define INTHAND myint ' Assembly language interrupt handler Asm ; Save W, STATUS and PCLATH registers, if not done previously myint movwf wsave swapf STATUS, W clrf STATUS movwf ssave movf PCLATH, W movwf psave ; Insert interrupt code here ; Save and restore FSR and any other registers used bcf _led ; If interrupt, turn off LED bcf INTCON, 1 ; Clear interrupt flag ; Restore saved registers movf psave, W movwf PCLATH swapf ssave, W movwf STATUS swapf wsave, F swapf wsave, W retfie ; Return from interrupt Endasm start: TRISB = $7f ' LED out, rest in OPTION_REG = $7f ' Enable PORTB pullups INTCON = $90 ' Enable INTE interrupt led = 1 ' Turn LED on waitloop: If led = 1 Then waitloop ' Wait here while LED is still on ' If we get here, LED is off Pause 500 ' Wait .5 seconds Goto start ' Start over (turn LED back on) End Download the program file. |
Copyright 2019 ME Labs, Inc. PO Box 8250 Asheville NC 28814 (719) 520-5323 (719) 520-1867 fax email: support@melabs.com |
|