Hallo,

Ik wilde eens experimenteren met een matrix toetsenbord op een µC.
Ik doe dat met bascom maar er is een probleem.
Ik kan niks uitlezen.
Hieronder de code:



Contrast Alias Portb.7
Col1 Alias Portf.7
Col2 Alias Portf.6
Col3 Alias Portf.5
Col4 Alias Portf.4
Row1 Alias Portf.3
Row2 Alias Portf.2
Row3 Alias Portf.1
Row4 Alias Portf.0

Config Portf = &B11110000
Portf = &B11111111

'Display contrast
Cls
Config Contrast = Output
Contrast = 0

Dim Drukknop As Byte


Do

   Cls

   Gosub Leesdrukknop

   Lcd "test  "

   Lcd Drukknop

   Waitms 100

   Drukknop = 0

Loop


Leesdrukknop:


   Col1 = 0
   Col2 = 1
   Col3 = 1
   Col4 = 1
   Waitms 50
   If Row1 = 0 Then
      Drukknop = 1
   Elseif Row2 = 0 Then
      Drukknop = 4
   Elseif Row3 = 0 Then
      Drukknop = 7
   Elseif Row4 = 0 Then
      Drukknop = 14
   End If

   Col1 = 1
   Col2 = 0
   Col3 = 1
   Col4 = 1
   If Row1 = 0 Then
      Drukknop = 2
   Elseif Row2 = 0 Then
      Drukknop = 5
   Elseif Row3 = 0 Then
      Drukknop = 8
   Elseif Row4 = 0 Then
      Drukknop = 0
   End If

   Col1 = 1
   Col2 = 1
   Col3 = 0
   Col4 = 1
   If Row1 = 0 Then
      Drukknop = 3
   Elseif Row2 = 0 Then
      Drukknop = 6
   Elseif Row3 = 0 Then
      Drukknop = 9
   Elseif Row4 = 0 Then
      Drukknop = 16
   End If

   Col1 = 1
   Col2 = 1
   Col3 = 1
   Col4 = 0
   If Row1 = 0 Then
      Drukknop = 10
   Elseif Row2 = 0 Then
      Drukknop = 11
   Elseif Row3 = 0 Then
      Drukknop = 12
   Elseif Row4 = 0 Then
      Drukknop = 13
   End If
   Col2 = 1
   Col3 = 1
   Col4 = 1
   Col1 = 1

   Lcd Drukknop

Return

End                                                         'end program

Ik zit al enkele uren te sukkelen maar geraak er niet wijs uit.
Hardwarematig klopt alles, heb ik al nagemeten. Ook heb ik de jtag al moeten uitschakelen.

Mvg Bart

Kijk eens naar het CONFIG KBD en het GETKBD statement in Bascom, doet precies wat jij wilt.

Edit: Gerwin was me een paar seconden voor.

[Bericht gewijzigd door 2N3055 op (18%)]

Ohnee nu voel ik me enorm dom |:(
Bedankt voor de tip!!!

Mvg Bart

Ach niet doen ik heb ook weken gespendeerd op iets waar een functie voor bestond ;)