Hi all,
I am having some trouble getting a simple program using the Interrupt on change function.
Here is my hardware setup:
PIC18F2550, 4MHz Crystal. LEDs attached on PORTA<0:3>, push button on PORTB.4. I am using the EasyPIC6 dev board from Mikro Electronika so all of the connections are definately correct.
The software is written in Picbasic Pro using Microcode Studio and includes the use of Darrell Taylors Instant Interrupts.
The program is ultimately very simple:
Turn on LED on A.1
Initialise the USB connection
Turn on LED on A.0 (and off on A.1)
Enter a loop in which the USB connecton is serviced approximately every 5ms and set LED on A.3 to status of B.4 (this is to confirm to me that the program is still running)
When the interrupt on change on PORTB is detected it sets A.2 LED to the status of B.4.
However the program for some reason does not function correctly. One of two things happens when the button is pressed: Either A.2 stays off (but A.3 follows the button press so the program is running correctly but the interrupt does not seem to be firing.) or all the LEDs turn off and don't come back at all until the device is reset.
I just cannot figure this out at all! If anyone can help it could be greatly appreciated.
Since im certain this is a code issue I have attached it below:
I am having some trouble getting a simple program using the Interrupt on change function.
Here is my hardware setup:
PIC18F2550, 4MHz Crystal. LEDs attached on PORTA<0:3>, push button on PORTB.4. I am using the EasyPIC6 dev board from Mikro Electronika so all of the connections are definately correct.
The software is written in Picbasic Pro using Microcode Studio and includes the use of Darrell Taylors Instant Interrupts.
The program is ultimately very simple:
Turn on LED on A.1
Initialise the USB connection
Turn on LED on A.0 (and off on A.1)
Enter a loop in which the USB connecton is serviced approximately every 5ms and set LED on A.3 to status of B.4 (this is to confirm to me that the program is still running)
When the interrupt on change on PORTB is detected it sets A.2 LED to the status of B.4.
However the program for some reason does not function correctly. One of two things happens when the button is pressed: Either A.2 stays off (but A.3 follows the button press so the program is running correctly but the interrupt does not seem to be firing.) or all the LEDs turn off and don't come back at all until the device is reset.
I just cannot figure this out at all! If anyone can help it could be greatly appreciated.
Since im certain this is a code issue I have attached it below:
Rich (BB code):
==============================================================================
' PIC Configuration Bits
' ==============================================================================
asm
__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
; ; ; USB clock source comes from the 96 MHz PLL divided by 2
; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2]
; No prescale (4 MHz oscillator input drives PLL directly)
__CONFIG _CONFIG1H, _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
; ; ; Oscillator Switchover mode disabled
; ; Fail-Safe Clock Monitor disabled
; XT oscillator, PLL enabled, XT used by USB
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_OFF_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L ;& _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
endasm
DEFINE OSC 48
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
' ==============================================================================
' Constants and Variables Definition
' ==============================================================================
USBBufferSizeMax con 3 ' maximum buffer size
USBBufferSizeTX con 3 ' input
USBBufferSizeRX con 3 ' output
' the USB buffer...
USBBuffer Var Byte[USBBufferSizeMax]
USBBufferCount Var Byte
' Used by USB initialisation:
usb_device_state var byte EXT
CONFIGURED_STATE CON EXT
' Used in USB Comms
IDLEIF VAR UIR.4
SOFIF VAR UIR.6
Plugged VAR BIT
InputPin VAR PORTB.4 ' the Input on which edges are detected
InputStatusLED var PORTA.2 ' the status of InputPin is mirrored here
StatusLED_Pin1 var PORTA.0 ' Bicolour Device Status LED pin1
StatusLED_Pin2 var PORTA.1 ' Bicolour Device Status LED pin2
tempbyte var byte
temp var bit
==============================================================================
' Hardware configuration
' ==============================================================================
TRISA = 0 ' all outputs
TRISB = %00010000' only RB4 as input so others are excluded from IOC
TRISC = 0 ' all outputs
PORTA = 0 ' set all LEDs off at startup
PORTB = 0
' ==============================================================================
' A/D converter
' ==============================================================================
'
ADCON0 = %00000000 ' A/D converter module disabled
ADCON1 = %00001111 ' PORTA all digital signals
' ==============================================================================
' USB module
' ==============================================================================
ucfg = %00010100 ' enable internal USB pull-up, Full speed USB
' ==============================================================================
' ASSEMBLER MACROS
' ==============================================================================
'
' HIGH Priority Interrupt processor macro
'
' Change on PORTB interrupt to transmit input status only on change
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RBC_INT, _ChangeOnPortB, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
endasm
==============================================================================
' MAIN PROGRAM
' ==============================================================================
StatusLED_Pin2 = 1
StatusLED_Pin1 = 0
gosub InitialiseUSB ' Initialise the USB
StatusLED_Pin2 = 0
StatusLED_Pin1 = 1
@ INT_ENABLE RBC_INT ; Enable the RBC Interrupt
ProgramStart:
' Sit in a loop waiting for interrupts to occur
USBSERVICE
pause 5
PORTA.3 = InputPin
goto ProgramStart
' ==============================================================================
' ROUTINES ==========================================================
' ==============================================================================
ChangeOnPortB:
@ INT_DISABLE RBC_INT
tempbyte = PORTB ' read portb to update the change latch
InputStatusLED = InputPin
@ INT_ENABLE RBC_INT
@ INT_RETURN
InitialiseUSB:
pause 500
usbinit ' initialise USB...
repeat ' kick-start it by performing a tight loop of servicing until the USB
' state is CONFIGURED (Darrell Taylors method)
usbservice
until usb_device_state = CONFIGURED_STATE
return
Last edited: