What I do wrong ?!
I adapted "keypad.bas" to my hw :
and I wrote this pice of code :Code:KB_ROW = 3 ; 3 ROW keypad KB_ROW_PORT = PORTB ; Keypad ROW on PORTB KB_ROW_BIT = 3 ; ROW0 = PORTB.3 KB_COL = 3 ; 3 COL keypad KB_COL_PORT = PORTB ; Keypad Col on PORTB KB_COL_BIT = 0 ; COL0 = PORTB.0 DebounceDelay = 0x80 ; debounce delay 41mSec SINGLE_SCAN = 0 ; Scan ;till a key is pressed KEYPAD_AUTOREPEAT = 1
..but no change in porta.0 or porta.1 state ...Code:@ DEVICE pic16F628A, XT_OSC, WDT_OFF, PWRT_ON, BOD_OFF, MCLR_ON, LVP_OFF Define OSC 4 ' 4MHz CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode include "alldigital.pbp" include "C:\PBP\enc_KEY.BAS" TrisA = %00000000 PortA = %00000000 PortB = %00111000 TrisB = %00011000 oldState VAR BYTE newState VAR BYTE Q_Count VAR WORD DIR VAR BIT UP CON 1 DN CON 0 Main_Loop: newState = (PortB & %00111000) portb.5 = 1 gosub encoder portb.5 = 0 if dir = up then porta.0 = 0 porta.1 = 1 endif if dir = dn then porta.0 = 1 porta.1 = 0 endif goto Main_Loop encoder: If newState <> 0 THEN If newState <> oldState THEN ' Changed from last time? Select Case oldState Case 32 If NewState = 128 THEN ' Was 1 now 4 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 1 now 2 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 64 If NewState = 32 THEN ' Was 2 now 1 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 2 now 4 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF Case 128 If NewState = 64 THEN ' Was 4 now 2 = Up Q_Count = Q_Count + 1 DIR = UP ELSE ' Was 4 now 1 = Down Q_Count = Q_Count - 1 DIR = DN ENDIF END SELECT oldState = NewState ENDIF ENDIF Return




Bookmarks