The PCs keyboard.docx
《The PCs keyboard.docx》由会员分享,可在线阅读,更多相关《The PCs keyboard.docx(12页珍藏版)》请在冰豆网上搜索。
ThePCskeyboard
The PC's keyboard.
WhywouldyouwanttointerfacetheKeyboard?
TheIBMkeyboardcanbeacheapalternativetoakeyboardonaMicroprocessordevelopmentsystem.Ormaybeyouwantaremoteterminal,justcoupleitwithaLCDModule.
MaybeyouhaveaRS-232BarcodeScannerorotherinputdevices,whichyouwanttousewithexistingsoftwarewhichonlyallowsyoutokeyinnumbersorletters.YoucoulddesignyourselfalittleboxtoconvertRS-232intoaKeyboardTransmission,makingittransparenttothesoftware.
Aninterfacingexampleisgivenshowingthekeyboard'sprotocolsinaction.Thisinterfacingexampleusesa68HC705J1AMCUtodecodeanIBMATkeyboardandoutputtheASCIIequivalentofthekeypressedat9600BPS.
NotethatthispageonlydealswithATKeyboards.IfyouhaveanyXTkeyboards,youwishtointerface,considerplacingtheminamuseum.Wewillnotdealwiththistypeofkeyboardinthisdocument.XTKeyboardsuseadifferentprotocolcomparedtotheAT,thuscodecontainedonthispagewillbeincompatible.
PCKeyboardTheory
TheIBMkeyboardyoumostprobablyhavesittinginfrontofyou,sendsscancodestoyourcomputer.ThescancodestellyourKeyboardBios,whatkeysyouhavepressedorreleased.Takeforexamplethe'A'Key.The'A'keyhasascancodeof1C(hex).Whenyoupressthe'A'key,yourkeyboardwillsend1Cdownit'sserialline.Ifyouarestillholdingitdown,forlongerthanit'stypematicdelay,another1Cwillbesent.Thiskeepsoccurringuntilanotherkeyhasbeenpressed,orifthe'A'keyhasbeenreleased.
Howeveryourkeyboardwillalsosendanothercodewhenthekeyhasbeenreleased.Taketheexampleofthe'A'keyagain,whenreleased,thekeyboardwillsendF0(hex)totellyouthatthekeywiththeproceedingscancodehasbeenreleased.Itwillthensend1C,soyouknowwhichkeyhasbeenreleased.
Yourkeyboardonlyhasonecodeforeachkey.Itdoesn'tcareittheshiftkeyhasbeenpressed.Itwillstillsendyouthesamecode.It'suptoyourkeyboardBIOStodeterminethisandtaketheappropriateaction.Yourkeyboarddoesn'tevenprocesstheNumLock,CapsLockandScrollLock.WhenyoupresstheCapsLockforexample,thekeyboardwillsendthescancodeforthecaplocks.ItisthenuptoyourkeyboardBIOStosendacodetothekeyboardtoturnontheCapslockLED.
Nowthere's101keysand8bitsmake256differentcombinations,thusyouonlyneedtosendonebyteperkey,right?
Nop.Unfortunatelyahandfulofthekeysfoundonyourkeyboardareextendedkeys,andthusrequiretwoscancode.ThesekeysareprecededbyaE0(hex).Butitdoesn'tstopattwoscancodeseither.HowaboutE1,14,77,E1,F0,14,F0,77!
Nowthatcan'tbeavalidscancode?
Wrongagain.It'shappenstobesentwhenyoupressthePause/breakkey.Don'taskmewhytheyhavetomakeitsolong!
Maybetheywerehavingabaddayorsomething?
Whenanextendedkeyhasbeenreleased,itwouldbeexpectthatF0wouldbesenttotellyouthatakeyhasbeenreleased.ThenyouwouldexpectE0,tellingyouitwasanextendedkeyfollowedbythescancodeforthekeypressed.Howeverthisisnotthecase.E0issentfirst,followedbyF0,whenanextendedkeyhasbeenreleased.
KeyboardCommands
BesidesScancodes,commandscanalsobesenttoandfromthekeyboard.Thefollowingsectiondetailsthefunctionofthesecommands.Bynomeansisthisacompletelist.Theseareonlysomeofthemorecommoncommands.
HostCommands
ThesecommandsaresentbytheHosttotheKeyboard.Themostcommoncommandwouldbethesetting/resettingoftheStatusIndicators(i.e.theNumlock,CapsLock&ScrollLockLEDs).Themorecommonandusefulcommandsareshownbelow.
ED
SetStatusLED's-ThiscommandcanbeusedtoturnonandofftheNumLock,CapsLock&ScrollLockLED's.AfterSendingED,keyboardwillreplywithACK(FA)andwaitforanotherbytewhichdeterminestheirStatus.Bit0controlstheScrollLock,Bit1theNumLockandBit2theCapslock.Bits3to7areignored.
EE
Echo-UponsendingaEchocommandtotheKeyboard,thekeyboardshouldreplywithaEcho(EE)
F0
SetScanCodeSet.UponSendingF0,keyboardwillreplywithACK(FA)andwaitforanotherbyte,01-03whichdeterminestheScanCodeUsed.Sending00asthesecondbytewillreturntheScanCodeSetcurrentlyinUse
F3
SetTypematicRepeatRate.KeyboardwillAcknowledgecommandwithFAandwaitforsecondbyte,whichdeterminestheTypematicRepeatRate.
F4
KeyboardEnable-Clearsthekeyboardsoutputbuffer,enablesKeyboardScanningandreturnsanAcknowledgment.
F5
KeyboardDisable-Resetsthekeyboard,disablesKeyboardScanningandreturnsanAcknowledgment.
FE
Resend-Uponreceiptoftheresendcommandthekeyboardwillre-transmitthelastbytesent.
FF
Reset-ResetstheKeyboard.
Command