be80be
Well-Known Member
I been trying to get a keypad to work on porta because I need portb for pwm. The reading of the keys work. But I've been trying to save how many keys was pressed and can't for the life of me get it to. What I'm trying to do
is count to see if key8 was pressed 4 times in a row. thanks for any help

is count to see if key8 was pressed 4 times in a row. thanks for any help
Code:
Device = 18F1220
Clock = 8
Config OSC = INTIO2
Config MCLRE = OFF
Include "INTOSC8.bas"
Dim counter As Word
Dim key1 As Bit
Dim key2 As Bit
Dim key3 As Bit
Dim key4 As Bit
Dim key5 As Bit
Dim key6 As Bit
Dim key7 As Bit
Dim key8 As Bit
Dim key9 As Bit
Dim key10 As Bit
Dim key11 As Bit
Dim key12 As Bit
Dim col1 As PORTA.0
Dim col2 As PORTA.1
Dim col3 As PORTA.2
Dim roll1 As PORTA.3
Dim roll2 As PORTA.4
Dim roll3 As PORTA.6
Dim roll4 As PORTA.7
Dim out0 As PORTB.0
Dim out1 As PORTB.1
SetAllDigital
Input (roll1)
Input (roll2)
Input (roll3)
Input (roll4)
Output (col1)
Output (col2)
Output (col3)
Output (PORTB.1)
Output (PORTB.0)
counter = 0
While true
High (col1) Low (col2) Low (col3) // col 1 this scans keys
If col1 = 1 And col2 =0 And col3 = 0 And roll1 = 1 Then
key1 = 1
Else
key1 =0
EndIf
High (col1) Low (col2) Low (col3)
If col1 = 1 And col2 =0 And col3 = 0 And roll2 = 1 Then
key2 = 1
Else
key2 = 0
EndIf
High (col1) Low (col2) Low (col3)
If col1 = 1 And col2 =0 And col3 = 0 And roll3 = 1 Then
key3 = 1
Else
key3 = 0
EndIf
High (col1) Low (col2) Low (col3)
If col1 = 1 And col2 =0 And col3 = 0 And roll4 = 1 Then
key4 = 1
Else
key4 = 0
EndIf
Low (col1) High (col2) Low (col3) // col 2
If col2 = 1 And col1 =0 And col3 = 0 And roll1 = 1 Then
key5 = 1
Else
key5 = 0
EndIf
Low (col1) High (col2) Low (col3)
If col2 = 1 And col1 =0 And col3 = 0 And roll2 = 1 Then
key6 = 1
Else
key6 = 0
EndIf
Low (col1) High (col2) Low (col3)
If col2 = 1 And col1 =0 And col3 = 0 And roll3 = 1 Then
key7 = 1
Else
key7 =0
EndIf
Low (col1) High (col2) Low (col3)
If col2 = 1 And col1 = 0 And col3 = 0 And roll4 = 1 Then
key8 = 1
Else
key8 = 0
EndIf
Low (col1) Low(col2) High (col3) // col 3
If col3 = 1 And col1 =0 And col1 = 0 And roll1 = 1 Then
key9 = 1
Else
key9 = 0
EndIf
Low (col1) Low (col2) High (col3)
If col3 = 1 And col2 =0 And col1 = 0 And roll2 = 1 Then
key10 = 1
Else
key10 = 0
EndIf
Low (col1) Low (col2) High (col3)
If col3 = 1 And col2 =0 And col1 = 0 And roll3 = 1 Then
key11 = 1
Else
key11 = 0
EndIf
Low (col1) Low (col2) High (col3)
If col3 = 1 And col2 =0 And col1 = 0 And roll4 = 1 Then
key12 = 1
Else
key12 = 0
EndIf
Low (out1)
Low (out0)
If key8 = 1 Then // lights a led if key8 is pressed
Toggle (out0) //
EndIf
If key8 = 1 And out0 = 1 And counter < 0 Then // this is what I can't get to work
Inc (counter) // the counter dosn't change value
EndIf
If counter = 4 Then // should hit 4 and turn on the led
High (out1)
EndIf
Wend