did i say ioc pin change is a bad way to do keys
try this and compare results
Code:
#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_ON
__config _CONFIG5, _CP_OFF & _CPD_OFF
#ENDCONFIG
DEFINE OSC 32
define CCP4_REG PORTD ' PWM Pulse out to LCD contrast
DEFINE CCP4_BIT 2 ' 2N2907 PNP with 1K on base
define CCP3_REG PORTD ' PWM Pulse out to LCD backlight
DEFINE CCP3_BIT 3 ' 2N2222A NPN with 1K on base
define CCP5_REG 0
DEFINE CCP5_BIT 0
ANSELA = 0
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
WPUC = % 00100000
WPUB = % 00110000
TRISA = % 00001111
TRISB = % 11111111
TRISC = % 11111111
TRISD = % 11110011
IOCBN = % 00100000
PushSwitchA VAR PortC.5 ;sw2
PushSwitchB VAR Portb.4 ;sw1
PushSwitchC VAR Portb.5
InterruptLED VAR Lata.4
anotherLED VAR Lata.5
polLED VAR Lata.6
notherLED VAR Lata.7
ButtonWasPressed VAR WORD[2]
lc var byte
Pause 500 ' Let PIC stabilize
InterruptLED = 0
anotherLED = 0
HPWM 3,250,1953 ' Pulse Contrast
HPWM 4,150,1953 ' Pulse Backlight
Mainloop:
lc=lc+1
if lc==50 then
polLED = !polLED
lc=0
endif
ButtonWasPressed[0] = (ButtonWasPressed[0]<<1) + PushSwitcha
ButtonWasPressed[1] = (ButtonWasPressed[1]<<1) + PushSwitchb
if ButtonWasPressed[0] = $f then ' Check flag
anotherLED = !anotherLED
endif
if ButtonWasPressed[1] = $f then ' Check flag
notherLED = !notherLED
endif
if IOCBF then
InterruptLED = !InterruptLED
IOCBF = 0
endif
pause 10
goto mainloop
pps , my way works fine even with no capacitor on the switches
Bookmarks