ps/2 Tastatur am Atmega8

sebo1989

Neues Mitglied
25. Nov. 2009
39
0
0
Sprachen
Hallo,

nachdem mein Glcd endlich läuft habe ich mich jetzt mal dran gesetzt, eine Pc-Tastatur einzusetzen um einfach ins Display reinzuschreiben.

Für die Testzwecke nutze ich erstmal ein Standart 16*2 Lcd.

Nun gut ich habe viel rumgesucht aber bin noch nicht so richtig an
Informationen gekommen.

Das Beispiel aus Bascom tut es ihrgentwie nicht.
Code:
Config Keyboard = Pinb.2 , Data = Pinb.4 , Keydata = Keydata



'Dim some used variables

Dim S As String * 12

Dim B As Byte , Test As Single
Test = 222111



'In this example we use SERIAL(COM) INPUT redirection

$serialinput = Kbdinput



'Show the program is running

Locate 1 , 1
Lcd Test
Waitms 800
Cls


Do

'The following code is remarked but show how to use the GetATKBD() function

' B = Getatkbd()     'get a byte and store it into byte variable

'When no real key is pressed the result is 0

'So test if the result was > 0

' If B > 0 Then

'    Print B ; Chr(b)

' End If



'The purpose of this sample was how to use a PC AT keyboard

'The input that normally comes from the serial port is redirected to the

'external keyboard so you use it to type

Input "Name " , S

'and show the result

Locate 1 , 1
Lcd S

'now wait for the F1 key , we defined the number 200 for F1 in the table

Do

   B = Getatkbd()
   Locate 2 , 1
   Lcd B
   Waitms 200
Loop Until B <> 0

Locate 2 , 1
Lcd B


Loop

End



'Since we do a redirection we call the routine from the redirection routine

'

Kbdinput:

'we come here when input is required from the COM port

'So we pass the key into R24 with the GetATkbd function

' We need some ASM code to save the registers used by the function

$asm

push r16           ; save used register

push r25

push r26

push r27



Kbdinput1:

rCall _getatkbd   ; call the function

tst r24           ; check for zero

breq Kbdinput1     ; yes so try again

pop r27           ; we got a valid key so restore registers

pop r26

pop r25

pop r16

$end Asm

'just return

Return



'The tricky part is that you MUST include a normal call to the routine

'otherwise you get an error

'This is no clean solution and will be changed

B = Getatkbd()



'This is the key translation table



Keydata:

'normal keys lower case

Data 0 , 0 , 0 , 0 , 0 , 200 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , &H5E , 0

Data 0 , 0 , 0 , 0 , 0 , 113 , 49 , 0 , 0 , 0 , 122 , 115 , 97 , 119 , 50 , 0

Data 0 , 99 , 120 , 100 , 101 , 52 , 51 , 0 , 0 , 32 , 118 , 102 , 116 , 114 , 53 , 0

Data 0 , 110 , 98 , 104 , 103 , 121 , 54 , 7 , 8 , 44 , 109 , 106 , 117 , 55 , 56 , 0

Data 0 , 44 , 107 , 105 , 111 , 48 , 57 , 0 , 0 , 46 , 45 , 108 , 48 , 112 , 43 , 0

Data 0 , 0 , 0 , 0 , 0 , 92 , 0 , 0 , 0 , 0 , 13 , 0 , 0 , 92 , 0 , 0

Data 0 , 60 , 0 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0

Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0



'shifted keys UPPER case

Data 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0

Data 0 , 0 , 0 , 0 , 0 , 81 , 33 , 0 , 0 , 0 , 90 , 83 , 65 , 87 , 34 , 0

Data 0 , 67 , 88 , 68 , 69 , 0 , 35 , 0 , 0 , 32 , 86 , 70 , 84 , 82 , 37 , 0

Data 0 , 78 , 66 , 72 , 71 , 89 , 38 , 0 , 0 , 76 , 77 , 74 , 85 , 47 , 40 , 0

Data 0 , 59 , 75 , 73 , 79 , 61 , 41 , 0 , 0 , 58 , 95 , 76 , 48 , 80 , 63 , 0

Data 0 , 0 , 0 , 0 , 0 , 96 , 0 , 0 , 0 , 0 , 13 , 94 , 0 , 42 , 0 , 0

Data 0 , 62 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0 , 0

Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0
Clock liegt an Pinb.2 und Data an Pinb.4.

Hat einer von euch schonmal etwas ähnliches ausprobiert und kann mir helfen?


Gruß
Sebastian
 
hallo sebastian,

ich habe mich gerade daran erinnert, dass ich mit diesen routinen auch probleme hatte.
hier mal ein kleiner quelltext, mit dem ich damals erfolg hatte.
vielleichts hieft bes dir ja mal als ansatz.

Code:
$regfile = "m32def.dat"
$crystal = 16000000
$baud = 38400


Config Keyboard = Pind.2 , Data = Pind.3 , Keydata = Keydata


Config Int0 = Low Level                                    
On Int0 Isr0                                                
Enable Int0
Enable Interrupts


Dim Aktualkey As Byte




Do
 Print Aktualkey


Waitms 300



Loop


Isr0:
Aktualkey = Getatkbdraw()
Return
Keydata:                                                    ' needed as dummy for config keyboard


gruss klaus
 
hallo sebastian,

freut mich, dass es klappt.

was da bei bascom an beispiel dabei ist, hat bei mir auch nicht gefunzt und durch rumprobieren kam ich dann auf diese merkwürdige lösung.

gruss klaus
 

Über uns

  • Makerconnect ist ein Forum, welches wir ausschließlich für einen Gedankenaustausch und als Diskussionsplattform für Interessierte bereitstellen, welche sich privat, durch das Studium oder beruflich mit Mikrocontroller- und Kleinstrechnersystemen beschäftigen wollen oder müssen ;-)
  • Dirk
  • Du bist noch kein Mitglied in unserer freundlichen Community? Werde Teil von uns und registriere dich in unserem Forum.
  •  Registriere dich

User Menu

 Kaffeezeit

  • Wir arbeiten hart daran sicherzustellen, dass unser Forum permanent online und schnell erreichbar ist, unsere Forensoftware auf dem aktuellsten Stand ist und der Server regelmäßig gewartet wird. Auch die Themen Datensicherheit und Datenschutz sind uns wichtig und hier sind wir auch ständig aktiv. Alles in allem, sorgen wir uns darum, dass alles Drumherum stimmt :-)

    Dir gefällt das Forum und unsere Arbeit und du möchtest uns unterstützen? Unterstütze uns durch deine Premium-Mitgliedschaft!
    Wir freuen uns auch über eine Spende für unsere Kaffeekasse :-)
    Vielen Dank! :ciao:


     Spende uns! (Paypal)