This Code Gives the Interfacing of AVR Micro Controller With PS2 Keyboard

3
This code gives the interfacing of AVR microcontroller with PS2 keyboard. The keyboard has 2 wires for data transfer, in which one is data line and the other is clock line. For more details about the PC keyboard please check this link http://www.8051projects.info/exp8.asp In this experiment the keyboard is interface with the AVR microcontroller and the typed character is displayed over the LCD display. Circuit Diagram Bascom Code $regfile = "m32def.dat" $crystal = 4000000 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , Rs = Porta.0 , E = Porta.1 Config Keyboard = Pind.2 , Data = Pind.4 , Keydata = Keydata Dim Text As String * 20 Dim I As Byte Dim L As Byte $serialinput = Kbdinput $serialinput2lcd

Transcript of This Code Gives the Interfacing of AVR Micro Controller With PS2 Keyboard

Page 1: This Code Gives the Interfacing of AVR Micro Controller With PS2 Keyboard

This code gives the interfacing of AVR microcontroller with PS2 keyboard. The keyboard has 2 wires for data transfer, in which one is data line and the other is clock line. For more details about the PC keyboard please check this link http://www.8051projects.info/exp8.asp

In this experiment the keyboard is interface with the AVR microcontroller and the typed character is displayed over the LCD display.

Circuit Diagram

Bascom Code

$regfile = "m32def.dat"$crystal = 4000000

Config Lcd = 16 * 2Config Lcdpin = Pin , Db4 = Porta.2 , Db5 = Porta.3 , Db6 = Porta.4 , Db7 = Porta.5 , Rs = Porta.0 , E = Porta.1Config Keyboard = Pind.2 , Data = Pind.4 , Keydata = Keydata

Dim Text As String * 20Dim I As ByteDim L As Byte

$serialinput = Kbdinput$serialinput2lcd

Text = "This is a Test!"L = Len(text)Cursor OffClsPrint TextWait 1For I = 1 To 16 Shiftlcd Right Wait 1

Page 2: This Code Gives the Interfacing of AVR Micro Controller With PS2 Keyboard

Next I

For I = 1 To L Shiftlcd Left Wait 1Next I

Do

ClsCursor BlinkCursor OnPrint "Enter Text :"Locate 2 , 1Input TextL = Len(text)Cursor NoblinkCursor OffClsPrint TextFor I = 1 To 16 Shiftlcd Right 'Wait 1Next IWait 1L = L + 16For I = 1 To L Shiftlcd Left Wait 1Next ILoop

End

Kbdinput:

$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

Return

I = Getatkbd()

Keydata:

Page 3: This Code Gives the Interfacing of AVR Micro Controller With PS2 Keyboard

'normal keys lower caseData 0 , 0 , 0 , 0 , 0 , 200 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , &H5E , 0Data 0 , 0 , 0 , 0 , 0 , 113 , 49 , 0 , 0 , 0 , 122 , 115 , 97 , 119 , 50 , 0Data 0 , 99 , 120 , 100 , 101 , 52 , 51 , 0 , 0 , 32 , 118 , 102 , 116 , 114 , 53 , 0Data 0 , 110 , 98 , 104 , 103 , 121 , 54 , 7 , 8 , 44 , 109 , 106 , 117 , 55 , 56 , 0Data 0 , 44 , 107 , 105 , 111 , 48 , 57 , 0 , 0 , 46 , 45 , 108 , 48 , 112 , 43 , 0Data 0 , 0 , 0 , 0 , 0 , 92 , 0 , 0 , 0 , 0 , 13 , 0 , 0 , 92 , 0 , 0Data 0 , 60 , 0 , 0 , 0 , 0 , 8 , 0 , 0 , 49 , 0 , 52 , 55 , 0 , 0 , 0Data 48 , 44 , 50 , 53 , 54 , 56 , 0 , 0 , 0 , 43 , 51 , 45 , 42 , 57 , 0 , 0'shifted keys UPPER caseData 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0Data 0 , 0 , 0 , 0 , 0 , 81 , 33 , 0 , 0 , 0 , 90 , 83 , 65 , 87 , 34 , 0Data 0 , 67 , 88 , 68 , 69 , 0 , 35 , 0 , 0 , 32 , 86 , 70 , 84 , 82 , 37 , 0Data 0 , 78 , 66 , 72 , 71 , 89 , 38 , 0 , 0 , 76 , 77 , 74 , 85 , 47 , 40 , 0Data 0 , 59 , 75 , 73 , 79 , 61 , 41 , 0 , 0 , 58 , 95 , 76 , 48 , 80 , 63 , 0Data 0 , 0 , 0 , 0 , 0 , 96 , 0 , 0 , 0 , 0 , 13 , 94 , 0 , 42 , 0 , 0Data 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 -->