Help me out..


Closed Thread
Results 1 to 5 of 5

Thread: Help me out..

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    to read a PS2 keyboard, you need something like...
    Code:
                    '
                    '   PS2 Keypad signal
                    '   -----------------
            DEFINE  PS2_SCLK        PORTC
            DEFINE  PS2_SCLK_BIT        1
            DEFINE  PS2_SDATA       PORTC
            DEFINE  PS2_SDATA_BIT       0
    
            '   
            '       Variables definition
            '       ====================
            KeyPS2      var BYTE                ' Store pressed key
    
    
        ' some code here
    
    
                    '
                    '       Keypad scan routine
                    '       ===================
    ReadPS2:        '
                    '       data is packed in a 11 Bit format
                    '           Start, 8 bit data(LSB first), 1 parity, 1 stop.
                    '
                    '       data is available on the falling edge of the clk
                    '
            gotsync=0                           ' No synch received
    
        ScanIt:    
            ASM
                CHK?RP  PS2_SCLK
                CALL    SkipPulse               ; Skip the start bit
                CLRF    _BitCounter             ; clear bit counter
    
        ReadLoop
                BTFSC   PS2_SCLK,PS2_SCLK_BIT   ; wait for clk falling edge
                GOTO    $-1                     ;
                ENDASM
            
            @   MOVE?TB PS2_SDATA,PS2_SDATA_BIT,_SDATA
            KeyPS2.0[BitCounter]=SDATA          ; Save current bit value
            
            ASM
                BTFSS   PS2_SCLK,PS2_SCLK_BIT   ; wait for clk falling edge   
                GOTO    $-1                     ;
                
                INCF    _BitCounter,F           ; increment bit counter
                
                MOVLW   8                       ;
                XORWF   _BitCounter,W           ; check if = 8 (end)
                BTFSS   STATUS,Z                ;
                GOTO    ReadLoop                ; if not read again
    
                CALL    SkipPulse               ; skip parity
                CALL    SkipPulse               ; skip stop bit
                GOTO    GetOut                  ; get out of here to test the 
                                                ;     actual result
        
        SkipPulse
                BTFSC   PS2_SCLK,PS2_SCLK_BIT   ; wait for falling edge
                GOTO    $-1                     ;
                
                BTFSS   PS2_SCLK,PS2_SCLK_BIT   ; wait for rising edge
                GOTO    $-1                     ;
                
                RETURN                          ; Bye bye!
                
        GetOut            
            ENDASM
    Then, you need to build a HUGE lookup table and + conditions to fit the PS2 ScanCode which is store in KeyPS2 variable.

    The above don't check the parity, don't check the validity of the Start bit... it's just a plain and starter version.... sorry if it's mostly in ASM..

    In PBP it should be something close to...
    Code:
    ReadPS2:
            FOR COUNTERBIT=0 TO 10
                WaitFallingEdge: if sclk then waitfallingedge
                KEY.0[COUNTERBit]=SDATA
                WaitRisingEdge: if sclk=0 then waitrisingedge
                NEXT
            KEY=(KEY>>1)&$ff          
            return
    there's few other example here and there in the forum. Melanie also draw the whole PC ScanCode table.

    at least
    http://www.picbasic.co.uk/forum/show...ghlight=ps2%2A
    http://www.picbasic.co.uk/forum/show...ight=scan+code
    Last edited by mister_e; - 22nd February 2007 at 22:40.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Apr 2006
    Posts
    21


    Did you find this post helpful? Yes | No

    Default Thanks

    Thank you Steve, for your concern i will give it a try and get back to you, mostly to use ps2 keyboard is good for the moving sign display as it serves as stand alone with out pc,when you plug the key board you just hit any funtion key like f1 to enter data,f2 to delete,and f3 to store the data etc, that will be fine for me .

  3. #3
    Join Date
    Apr 2006
    Posts
    21


    Did you find this post helpful? Yes | No

    Default hello

    hello steve ,
    i have try it without success.
    anymore idea.

  4. #4
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by Joann View Post
    hello steve ,
    i have try it without success.
    anymore idea.
    Perhaps you could post a schematic of what you have done? This may help others in helping you since the suggested code you have been offered is to be known as working.

    Best Regards,

    Trent Jackson

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