'On Interrupt - Interrupts in BASIC
'Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off.
'Program waits .5 seconds and turns LED back on.
Symbol led = PORTB.7 'reasigno nombre al portb.7
ANSEL = %00000000 'los pin I/O digitales, % en bin
CMCON = 0x07 'comparador a off, 0x en hex
OSCCON = 0x7e 'set intrc To 8mhz, se usara reloj interno a 8Mhz
TRISB.7 = 0 'declaro portb.7 como salida
TRISB.0 = 1 'declaro portb.0 como entrada, 0-1 activa interrupcion
OPTION_REG = 0x7f 'Enable PORTB pullups
INTCON = 0x90 'Enable INTE interrupt
loop:
High led 'Turn LED on
Goto loop 'Do it forever
End
'Interrupt handler
On Interrupt 'Define interrupt handler, desactiva interrupciones
Low led 'If we get here, turn LED off
WaitMs 500 'Wait .5 seconds
INTCON.1 = 0 'Clear interrupt flag
Resume 'Return to main program, activa interrupciones
En el caso que sigas teniendo problemas, adjunta el .hex y lo simulo en el PSI y asi salimos de dudas.
Código: [Seleccionar]OSCCON = 0x7e 'set intrc To 8mhz, se usara reloj interno a 8Mhz
Hola :
Un coentario sobre las interrupciones en pbp: si tenemos necesidad de atender una interrupción ,el pbp lo hace cuando termina de ejecutar la instrucción en curso.
Ejemplo :si estamos ejecutando una instruccin pause 5000 y en el momento que comenzó esta pausa se genera la interrupción (por cualquier tipo de interrupción) ,recién el pbp va a ejecutar la rutina de interrupción cuando termine la instrucción pause.-
En cambio ,por lo que simule en picsimuladoride ,este atiendo las interrupciones cuando se generan.-
Espero me hayan entendido
Jorge
'PROGRAMA PARA PRACTICAR CON INTERRUPCIONES EXTERIORES DEL PIN RB0
'On Interrupt - Interrupts in BASIC
'Turn LED on. Interrupt on PORTB.0 (INTE) turns LED off.
'Program waits .5 seconds and turns LED back on.
'-------------------------------------------------------------------
'Define SIMULATION_WAITMS_VALUE = 1 'ignora los Waitms
'-------------------------------------------------------------------
Symbol led = PORTB.7 'reasigno nombre al portb.7
ANSEL = %00000000 'los pin I/O digitales
CMCON = 0x07 'comparador a off
OSCCON = 0x7e 'set intrc To 8mhz, se usara reloj interno a 8Mhz
TRISB.7 = 0 'declaro portb.7 como salida
TRISB.0 = 1 'declaro portb.0 como entrada
OPTION_REG = 0x7f 'Enable PORTB pullups
INTCON = 0x90 'Enable INTE interrupt
'-------------------------------------------------------------------
main:
High led 'Turn LED on
Goto main 'Do it forever
End
'Interrupt handler
On Interrupt 'Define interrupt handler, disable interrupt
Low led 'If we get here, turn LED off
WaitMs 500 'Wait 0.5 Seconds
INTCON.1 = 0 'Clear interrupt flag
Resume 'Return to main program, enable interrupt