No more posts here...but hope to find help!
I try to build this device ; on pushing on different button - having one different result !
But...nothing happens... Something's wrong ! Any advice ? Thanks !
Code:@ DEVICE pic16F628A, INTRC_OSC, WDT_OFF, PWRT_OFF, BOD_OFF, MCLR_ON, LVP_OFF, CPD_OFF, PROTECT_OFF Include "modedefs.bas" ' Serial Protocol Define OSC 4 ' 4MHz crystal used CMCON = 7 ' Disable on-chip comparator, PORTA in digital mode '// Define port pins as inputs and outputs ... TRISA = %00001000 TRISB = %00001100 '// Declare Variables... Col_A VAR PORTB.1 Col_B VAR PORTA.2 Row_A VAR PORTA.3 Row_B VAR PORTB.3 Row_C VAR PORTB.2 Buzzer VAR PORTB.5 Scan_Col VAR BYTE ' Counter - denoting current col in scan Key_Press VAR BYTE ' Contains value of key (0-9) & * + # Key_Down VAR BYTE ' Flag set true when key is depressed Allow_Key VAR BYTE ' Flag - disallow multiple keys being pressed I VAR byte ' General working var Scan_Keypad: '// Scan cols @ incf _Scan_Col, 1 ' Inc col pos... SELECT CASE Scan_Col ' Col (1-2) CASE 1 Col_A = 0 ' Switch on col (active low) Col_B = 1 ' Col off '// 3 Key IF Row_A = 0 THEN ' Key down? ... IF Allow_Key = 0 THEN ' Any other key down? Key_Press = 3 ' Load var w/value of key Allow_Key = 1 ' Disallow other keys ENDIF ENDIF '// 6 Key IF Row_B = 0 THEN IF Allow_Key = 0 THEN Key_Press = 6 Allow_Key = 1 ENDIF ENDIF '// 9 Key IF Row_C = 0 THEN IF Allow_Key = 0 THEN Key_Press = 9 Allow_Key = 1 ENDIF ENDIF CASE 2 Col_A = 1 Col_B = 0 '// 2 Key IF Row_A = 0 THEN IF Allow_Key = 0 THEN Key_Press = 2 Allow_Key = 1 ENDIF ENDIF '// 5 Key IF Row_B = 0 THEN IF Allow_Key = 0 THEN Key_Press = 5 Allow_Key = 1 ENDIF ENDIF '// 8 Key IF Row_C = 0 THEN IF Allow_Key = 0 THEN Key_Press = 8 Allow_Key = 1 ENDIF ENDIF Scan_Col = 0 END SELECT '// Ouput key IF Key_Down <> Key_Press THEN ' Key already been sent? IF Key_Press <> 255 THEN ' 255 denotes no key press IF Key_Press = 42 OR Key_Press = 35 THEN ' Numerical key? '// Brief chrip of the piezo & flash of the LED for i = 0 to 20 toggle buzzer pause 5 next gosub result_key ENDIF Key_Down = Key_Press ' Copy of key just sent Buzzer = 0 ' Make sure LED is off ENDIF endif '// Check for key release, all cols on (active low) ... Col_A = 0 Col_B = 0 '// Reset flags allowing other keys to be processed if no keys are depressed IF Row_A = 1 THEN IF Row_B = 1 THEN IF Row_C = 1 THEN Allow_Key = 0 Key_Down = 0 Key_Press = 255 ENDIF ENDIF ENDIF GOTO Scan_Keypad ' Loop back Result_key : SELECT CASE key_press case 3 high buzzer pause 1000 low buzzer case 6 high buzzer pause 2000 low buzzer case 9 high buzzer pause 3000 low buzzer end select return


!
... Something's wrong ! Any advice ? Thanks !


Bookmarks