Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic based AT keyboard

Status
Not open for further replies.
You should put some effort into your question.

To send characters to the computer by PIC, you must first create the Universe.
 
i am a student from computer field not from electronics field. I want make a remote controlled car which can be controlled from my desktop. IS it possible?
if yes then please give me some idea so that i do it. Plz explain every problem related to this project
THANKS
 
Yes, of course it's possible. However, you need to explain yourself a lot more. we can't possibly help you very much if we don't know how much you know.

question 1: do you know how to program and use PICs?
if you don't, you need to get used to that before you even think about trying to interface with a keyboard, and there is plenty of information on this forum about that, so if you need to get started, please refer to all of that existing available information.

question 2: do you understand the keyboard communication protocol?
**broken link removed** offers essentially everything you need to know to interface with a PS/2 keyboard, and has information on the AT keyboards as well, so it should be everything you need for AT as well.

Once you know all that stuff, then you can ask more specific questions that people can reasonably answer. If you don't already know all of it, then you shouldn't expect to be able to complete this project without doing a lot of learning first. It sounds to me like a pretty reasonable project; someone with familiarity with keyboard interfacing, PICs, and most likely using serial radio wireless modules, it could be made to work in a day. If you are willing to spend the time learning about all the various things involved, then you can most likely do it as well, it will just take longer.
 
Last edited:
If your BASIC compiler does not include pre-made routines for generating these codes (which it sounds like it doesn't) then you would have to make your own.
Making a routine like that involves simple bit manipulation and a bunch of delay loops, to time all the pulses correctly. Compilers are often very inefficient, and I'm sure a BASIC compiler is no different... making it often challenging or impossible to get short, reliable delay loops. I can't help you much from this point, because I've never used a PIC BASIC compiler. If your compiler supports adding inline assembly code then your problem might be pretty reasonable... if it does not, I don't think it's going to be a lot of fun. At the very least, I would expect you would have to hook the pic up to an oscilloscope and spend a lot of time writing code, checking the output waveform, changing the code, checking the waveform, etc etc.
 
Here is a snippet of ASM that reads a code from a PC keyboard.

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;Waits for Keypress, returns KeyCode in W
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DataPin equ 0x06 ;PIC Pin
ClockPin equ 0x07 ;PIC Pin
Char equ 0x35 ;buffer
BitCounter equ 0x36 ;number of bits to read

GetScanCode
bsf STATUS, RP0 ;select bank 1
bsf TRISB, DataPin ;set pins as input
bsf TRISB, ClockPin
bcf OPTION_REG, NOT_RBPU ;pull-ups are enabled
bcf STATUS, RP0 ;select bank 0

call ClockWait ;wait for Pull up to take effect and
;keyboard to pull clock low

;--- Read Data Bits ----

ReadKey
clrf Char
movlw .8 ;bits to read
movwf BitCounter

ReadChar
rrf Char
bcf Char, 7 ;default value is 0
call ClockWait ;wait for clock to go high then low

btfss PORTB, DataPin ;read Data
goto Next
bsf Char, 7 ;Data is High
Next decfsz BitCounter
goto ReadChar ;read next Data Bit


call ClockWait ;Parity Bit

call ClockWait ;Stop Bit

;--- Pull Clock Line Low (keyboard will buffer any further keystrokes)

bsf STATUS, RP0 ;select bank 1
bcf TRISB, ClockPin ;set clock line as output
bcf STATUS, RP0 ;select bank 0
bcf PORTB, ClockPin ;set clock line low


movf Char, W
return


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ClockWait
;wait for clock to go high
btfss PORTB, ClockPin
goto ClockWait

ClockWait2
;wait for clock to go low
btfsc PORTB, ClockPin
goto ClockWait2

return
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Go to Radioshack and buy a ps/2 extension cable, cut of the male end and use the female end to connect to the PIC. I use a 4 pin header (power, ground, clock and data). You can search for the PS/2 pinout's on the net and connect accordingly. PC keyboards use 'make' and 'break' codes to signify a keypress and keyrelease. So you'll need to filter these and convert your scancode to a keycode. Heres a simple subroutine to convert. I think these are for the AT, I cant remember, I wrote this over a year ago. Call this routine with the scan code in W and it will return the ASCII code.

CharTable
addwf PCL
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;00-0F
dt 0,0,0,0,0,'Q','1',0,0,0,'Z','S','A','W','2',0 ;10-1F
dt 0,'C','X','D','E','4','3',0,0,' ','V','F','T','R','5',0 ;20-2F
dt 0,'N','B','H','G','Y','6',0,0,0,'M','J','U','7','8',0 ;30-3F
dt 0,0,'K','I','O','0','9',0,0,0,0,'L',0,'P',0,0 ;40-4F
dt 0,0,0,0,0,0,0,0,0,0,.13,0,0,0,0,0 ;50-5F
dt 0,0,0,0,0,0,.8,0,0,0,0,0,0,0,0,0 ;60-6F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;70-7F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;80-8F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;90-9F
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;A0-AF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;B0-BF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;C0-CF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;D0-DF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;E0-EF
dt 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;F0-FF
 
shouldn't be hard to figure it out, you can see from:
Code:
DataPin equ 0x06 ;PIC Pin
ClockPin equ 0x07 ;PIC Pin
...
bsf TRISB, DataPin ;set pins as input
bsf TRISB, ClockPin
that the ps/2 data and clock pins are bits 6 and 7 of port B. a PS/2 connector pinout diagram will tell you the appropriate pins to connect (plus power and ground to the PS/2 connector, of course), and the rest is just your typical PIC circuit; power/ground, decoupling cap(s), oscillator if needed, etc.
 
i use this code but then i compile occurs some errors
help me with erros in lines please

i use picsimulator ide / assembler to test

errors:

rrf Char Invalid argument

goto Next Invalid argument of the instruction

Next decfsz BitCounter Unrecognized instruction
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top