PC Keyboard question


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default PIC as a Keyboard replacement

    Sorry for the delay, I have been working on trying different things. I am starting the PC with a regular keyboard and then swaping it with the PIC replacement.

    I have tried a 16F627A and I have moved back to the 16F688

    Below is the code I am testing, I am sending the data twice trying to send it both LSB and MSB first. Sometimes I get a beep from the PC when I change the PauseUS delay and other times I do not.

    ' PIC 16F688
    ' PortC.5 - Data
    ' PortC.4 - Clk
    ' PortA.2 - Switch in, normal low, active high
    ' PortA.4 - LED Out, high if switch pressed

    ' Circuit description
    ' 10K pull up on PortC.5 - Data
    ' 10K pull up on PortC.4 - Clk
    ' 10K pull up on /MCLR
    ' 10K pulling down on switch input, PortA.2

    'Goal of program, to send a chracter to the PC keyboard port when switch is pressed
    @ device INTRC_OSC_NOCLKOUT
    INCLUDE "modedefs.bas"
    DEFINE SHIFT_PAUSEUS 25
    DEFINE OSC 8 ' 8 Mhz

    TRISA = %00000100 ' Set PORTA.2 to input, all others are output
    TRISC = %00000000 ' set PORTC to outputs
    CMCON0 = 7 ' turn off comparitors
    ANSEL = %00000000 ' set all as digital ports, analog off
    WPUA = %00000000

    char var word
    breakcode var word

    clkout var portc.4
    switch1 var portA.2
    ledout1 var portA.4
    dataout var portc.5

    'char = %10101101010 ' 'CR' mode 0
    'breakcode = %11000011110 '/F0H mode 0
    char = %01010110101
    breakcode = %01111000011

    '----- Main Loop --------------------------------
    Start: ' loop start
    low ledout1 ' turn off LED
    if switch1 = 1 then ' check switch, if pushed then LED on and Char our
    pause 50
    if switch1 =1 then
    high ledout1 ' LED on
    shiftout dataout,clkout,4,[char\11]
    shiftout dataout,clkout,4,[breakcode\11]
    shiftout dataout,clkout,4,[char\11]
    PAUSE 1
    shiftout dataout,clkout,5,[char\11]
    shiftout dataout,clkout,5,[breakcode\11]
    shiftout dataout,clkout,5,[char\11]
    endif
    endif
    goto start ' restart loop
    '----- Main Loop --------------------------------

    I have tried the character to send and the breakcode both ways, but they respond the same.

    I see the characters and clock on the scope, all six characters come across but nothing on the PC.

    I am driving the keyboard direct from the chip, no transistors. Do you think the open-collector could be an issue with the driving? Could the Clock and the timing be an issue?

    I would think that something would appear with both combinations of send's but i seem to be going in circles.

    USB would be great but it's not an option, I am not talking to a Windows OS. I have to use the PS/2 port to send data to the terminal.

    Any thoughts would be great, my goal is to send about 24 pre-defined single characters on switches to the port. I have been

    Thanks,
    HH

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    2 problems that i can see:

    First, looks like ur clock is too fast. PS2 keyboards generate a clock between 10khz-16khz. I'd be changing the shift pause to:

    DEFINE SHIFT_PAUSEUS 40

    Second, The "mode 0" as you call it is the only one with any chance of working, but "%10101101010" corresponds to a scancode of $AD which as far as i can tell is not a valid scancode.

    Try using these:

    char = %10001110000 '$1C = 'a'
    breakcode = %11000011110 '$F0

    shiftout dataout,clkout,4,[char\11]
    shiftout dataout,clkout,4,[breakcode\11]
    shiftout dataout,clkout,4,[char\11]


    Something else you may want to try is this:

    shiftout dataout,clkout,4,[char\11]
    pauseus 100
    shiftout dataout,clkout,4,[breakcode\11]
    pauseus 100
    shiftout dataout,clkout,4,[char\11]
    pauseus 100

    *edit* Check out this page for all the scancodes: http://www.computer-engineering.org/...cancodes2.html

Similar Threads

  1. PC keyboard to ASCII
    By interak in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 1st October 2009, 18:51
  2. AT/PS2 Keybord - PIC Interface?
    By Kamikaze47 in forum Code Examples
    Replies: 73
    Last Post: - 9th August 2009, 17:10
  3. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 01:04
  4. Question for the PC guru's
    By Bruce in forum Off Topic
    Replies: 24
    Last Post: - 28th January 2008, 22:05
  5. Pic to PC AT keyboard caracters
    By sezgin05 in forum General
    Replies: 5
    Last Post: - 27th March 2007, 11:45

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts