Any idea what's going on?
I removed the KHz variable and kept only MHz, but it still does the same thing:
- sometimes it triggers once,
- sometimes it triggers twice (IOC on positive edge is OFF),
- no pattern (that I could see),
16F18877
Code:
@ ERRORLEVEL -306 ; turn off crossing page boundary message
include "C:\PBP Includes\DT_INTS-14_16F1885x-7x.bas"
include "C:\PBP Includes\ReEnterPBP.bas"
ASM
INT_LIST macro ;IntSource, Label, Type, ResetFlag?
INT_Handler IOC_INT, _IOCinterrupts, PBP, yes ;IOCC.3
endm
INT_CREATE ;Creates the interrupt processor
ENDASM
#CONFIG
__config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
__config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
__config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
__config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
__config _CONFIG5, _CP_OFF & _CPD_OFF
#ENDCONFIG
DEFINE OSC 32
' LCD is used for debugging
DEFINE LCD_DREG PORTD ' Set LCD data port
DEFINE LCD_DBIT 4 ' Set starting data bit
DEFINE LCD_RSREG PORTD ' Set LCD register select port
DEFINE LCD_RSBIT 1 ' Set LCD register select bit
DEFINE LCD_EREG PORTD ' Set LCD enable port
DEFINE LCD_EBIT 0 ' Set LCD enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size
DEFINE LCD_LINES 4 ' Set number of lines on LCD
DEFINE LCD_COM1MANDUS 1000 ' Set COM1mand delay time in microseconds
DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds
' CCPx is used to control Contrast and Blacklight on LCD
define CCP3_REG PORTD ' PWM Pulse out to LCD contrast
DEFINE CCP3_BIT 2 ' 2N2907 PNP with 1K on base
define CCP4_REG PORTD ' PWM Pulse out to LCD backlight
DEFINE CCP4_BIT 3 ' 2N2222A NPN with 1K on base
IOCBP = %00000000 ;IOC Interrupt, Positive Edge, low-to-high
IOCBN = %00000100 ;IOC Interrupt, Negative Edge, from high-to-low
WPUB = %00000100 ; Pull-up resistor on pin B2
' PPS is used to move CCP functions to other pins
PinD2 CON $1A ' Datasheet table 13-2
PinD3 CON $1B
CCP3PPS = PinD2 ' CCP3 Peripheral input selection
CCP4PPS = PinD3 ' CCP4 Peripheral input selection
PeripheralCCP3 CON $0B ' Datasheet table 13-3
PeripheralCCP4 CON $0C
RD2PPS = PeripheralCCP3 ' Pin D2 output source selection
RD3PPS = PeripheralCCP4 ' Pin D3 output source selection
RB0PPS = 0 ' Disable CCP3 (moved to D2)
RB5PPS = 0 ' Disable CCP4 (moved to D3)
ANSELA = %00000000 ' No analog operations
ANSELB = %00000000
ANSELC = %00000000
ANSELD = %00000000
ANSELE = %00000000
TRISA = %00000000
TRISB = %00000100 ' Only pin B2 is Input
TRISC = %00000000
TRISD = %00000000
TRISE = %00000000
IOC_NAV2_Swap_flag var IOCBF.2 ' IOC flag on pin B2 change
NAV2_Swap_ON VAR BYTE
NAV2_MHz_Standby VAr BYTE
NAV2_MHz_Active VAr BYTE
SwapFrequency var WORD ' Temporary variable used for Swapping frequencies
Pause 500 ' Let PIC and LCD stabilize
NAV2_MHz_Standby = 111 : NAV2_MHz_Active = 222
HPWM 3,250,1953 ' Contrast
HPWM 4,150,1953 ' Backlight
IOCBF = %00000000 ' Clear all interrupt flags
NAV2_Swap_ON = 0 ' Clear Swap button is waiting for processing
goto Start
;--- Subroutines ---------------------------------------------------------------
IOCinterrupts:
if IOC_NAV2_Swap_flag = 1 then ' Swap frequencies
NAV2_Swap_ON = 1
IOC_NAV2_Swap_flag = 0
endif
@ INT_RETURN
Start:
LCDOUT $FE, 1 : Pauseus 1
LCDOUT $FE, $80, "COM/NAV ENCODER TEST" : Pauseus 1
@ INT_ENABLE IOC_INT
PAUSE 500
Mainloop:
if NAV2_Swap_ON = 1 then ' Swap button has been pressed
SwapFrequency = NAV2_MHz_Standby ' Swap MHz frequency
NAV2_MHz_Standby = NAV2_MHz_Active
NAV2_MHz_Active = SwapFrequency
NAV2_Swap_ON = 0 ' Turn OFF swap flag
endif
LCDOUT $FE, $D4, "NAV2:", dec3 NAV2_MHz_Standby,_
" ", dec3 NAV2_MHz_Active : Pauseus 1
goto mainloop
end
Gutted code and left only LCD for my observations.
Bookmarks