PS/2 Keyboard Interface

Questions and Comments on All Tutorials

r1ley
Newbie Pyro
Posts: 2
Joined: Mon Mar 25, 2013 4:30 am

Re: PS/2 Keyboard Interface

Postby r1ley » Wed Apr 03, 2013 2:16 pm

ThePyroElectro wrote:
r1ley wrote:does anyone know how I can configure this to display on a 16-segment display?

and use the other outputs like RB and RC?

any help would be great.

Thanks


You can wire up the 7 wires from the original design to the 16-seg or if you want to use all 16 segments, you would need to redefine the characters in the source code. Remap what output pins are +5v and +0v given which keyboard scan-code is detected.


Here's where I'm stuck. I have to use a 16F877A chip. I'm using the LITE version of compilers and the HI-TECH ANSI C compiler which I use for the 16F877A is not available for the 18F452.

Problem here is that the lite version does not include the <capture.h> library. Is there any other way I can add another library that will perform the same work?

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: PS/2 Keyboard Interface

Postby ThePyroElectro » Tue Apr 09, 2013 7:20 pm

r1ley wrote:
ThePyroElectro wrote:
r1ley wrote:does anyone know how I can configure this to display on a 16-segment display?

and use the other outputs like RB and RC?

any help would be great.

Thanks


You can wire up the 7 wires from the original design to the 16-seg or if you want to use all 16 segments, you would need to redefine the characters in the source code. Remap what output pins are +5v and +0v given which keyboard scan-code is detected.


Here's where I'm stuck. I have to use a 16F877A chip. I'm using the LITE version of compilers and the HI-TECH ANSI C compiler which I use for the 16F877A is not available for the 18F452.

Problem here is that the lite version does not include the <capture.h> library. Is there any other way I can add another library that will perform the same work?


Hi r1ley,

I haven't heard of any other compiler for the 16F series that has those capabilities. Microchip just recently released their XC8 library which is based off of hi-tech. I'm willing to bet that it has capture libraries built into it.

Alternatively you can always pull up the datasheet and setup the hardware CCP modules yourselves for the mode of operation that you need. It's not as painful as it sounds, but it definitely isn't as elegant as using library function calls.

Fayev
Newbie Pyro
Posts: 7
Joined: Mon Apr 21, 2014 1:34 pm

Re: PS/2 Keyboard Interface

Postby Fayev » Mon Apr 21, 2014 1:41 pm

Thank you a lot for this great tutorial! I've tried to implement it, but when I compile it I get the following errors:

Error [1105] symbol 'T1_SOURCE_INT' has not been defined
Error [1203] too few arguments in function call

I'm guessing this has something to do with the timers.h library, but I'm not quite sure how to fix this.

Also, I was wondering, in order to read two digits or two different letters in two separate displays (something like "HI" or "10") would it be enough to add some condition to read a delay between keyboard inputs?

Thank you in advance!

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: PS/2 Keyboard Interface

Postby ThePyroElectro » Tue Apr 22, 2014 6:41 pm

Fayev wrote:Thank you a lot for this great tutorial! I've tried to implement it, but when I compile it I get the following errors:

Error [1105] symbol 'T1_SOURCE_INT' has not been defined
Error [1203] too few arguments in function call

I'm guessing this has something to do with the timers.h library, but I'm not quite sure how to fix this.

Also, I was wondering, in order to read two digits or two different letters in two separate displays (something like "HI" or "10") would it be enough to add some condition to read a delay between keyboard inputs?

Thank you in advance!


It looks like you're probably trying to use a different PIC microcontroller than I used and that your specific PIC microcontroller doesn't have the same type of Timer1 hardware module as the one I used.

A delay is a hacky solution but it should work. What I believe I did in future projects was put characters into a giant shift register.

Since you know how many bits PS/2 will send, you can count them all and then put the character into the shift register and then wait until the next character comes.

Fayev
Newbie Pyro
Posts: 7
Joined: Mon Apr 21, 2014 1:34 pm

Re: PS/2 Keyboard Interface

Postby Fayev » Tue Apr 22, 2014 7:41 pm

Yes, I'm using a P18f26j11, and I've checked the timers.h library and there are two ways of calling Opentimer1, one of them requires only one parameter and the other one requires two parameters, also there is an option for separating the configuration with "and" or with "or", but it won't work either way...

Code: Select all

/* ***** TIMER1 ***** */

/* TIMER1 configuration masks -- to be 'anded' together and passed to the
 * 'open' routine. */
 
#if defined (TMR_V6) || defined (TMR_V7) || defined (TMR_V7_1) || defined (TMR_V7_2)\
 || defined (TMR_V7_3) || defined (TMR_V7_4) || defined (TMR_V7_5)

#ifndef USE_OR_MASKS

#if defined (TMR_V7_4)
#define T1_SOURCE_INTOSC    0b11111111  // Clock source is INTOSC
#endif
#define T1_SOURCE_PINOSC    0b11011111  // Clock source T1OSCEN = 0 Ext clock, T1OSCEN=1 Crystal osc
#define T1_SOURCE_FOSC_4    0b10011111  //Clock source is instruction clock (FOSC/4)
#define T1_SOURCE_FOSC      0b10111111  //Closck source is system clock (FOSC)

#define T1_PS_1_1           0b11100111  // 1:1 prescale value
#define T1_PS_1_2           0b11101111  // 1:2 prescale value
#define T1_PS_1_4           0b11110111  // 1:4 prescale value
#define T1_PS_1_8           0b11111111  // 1:8 prescale value

#define T1_OSC1EN_OFF       0b11111011  // Timer 1 oscilator enable off
#define T1_OSC1EN_ON        0b11111111  // Timer 1 oscilator enable on

#define T1_SYNC_EXT_ON      0b11111101  // Synchronize external clock input
#define T1_SYNC_EXT_OFF     0b11111111  // Do not synchronize external clock input

#define T1_8BIT_RW          0b11111110  //Enables register read/write of Timer1 in two 8-bit operations
#define T1_16BIT_RW         0b11111111  //Enables register read/write of Timer1 in one 16-bit operation

#else

#if defined (TMR_V7_4)
#define T1_SOURCE_INTOSC    0b00000000  // Clock source is INTOSC
#endif
#define T1_SOURCE_PINOSC    0b01000000  // Clock source T1OSCEN = 0 Ext clock, T1OSCEN=1 Crystal osc
#define T1_SOURCE_FOSC_4    0b00000000  //Clock source is instruction clock (FOSC/4)
#define T1_SOURCE_FOSC      0b00100000  //Clock source is system clock (FOSC)
#define   T1_SOURCE_MASK       (~T1_SOURCE_FOSC)   //Mask Timer1 Clock Source Select bits

#define T1_PS_1_1           0b00000000  // 1:1 prescale value
#define T1_PS_1_2           0b00001000  // 1:2 prescale value
#define T1_PS_1_4           0b00010000  // 1:4 prescale value
#define T1_PS_1_8           0b00011000  // 1:8 prescale value
#define T1_PS_MASK          (~T1_PS_1_8)   //Mask Timer1 Input Clock Prescale Select bits

#define T1_OSC1EN_OFF       0b00000000  // Timer 1 oscilator enable off
#define T1_OSC1EN_ON        0b00000100  // Timer 1 oscilator enable on
#define   T1_OSC_MASK          (~T1_OSC1EN_ON)      //Mask Timer1 Oscillator Enable bit

#define T1_SYNC_EXT_ON      0b00000000  // Synchronize external clock input
#define T1_SYNC_EXT_OFF     0b00000010  // Do not synchronize external clock input
#define T1_SYNC_MASK       (~T1_SYNC_EXT_OFF)   // Mask Timer1 External Clock Input Synchronization Select bit

#define T1_8BIT_RW          0b00000000  //Enables register read/write of Timer1 in two 8-bit operations
#define T1_16BIT_RW         0b00000001  //Enables register read/write of Timer1 in one 16-bit operation
#define T1_BIT_RW_MASK       (~T1_16BIT_RW)      // Mask Timer1 16-Bit Read/Write Mode Enable bit

#endif

void OpenTimer1 ( unsigned char config,  unsigned char config1);
void CloseTimer1 (void);
unsigned int ReadTimer1 (void);
void WriteTimer1 ( unsigned int timer1);

#else

#ifndef   USE_OR_MASKS

#define T1_8BIT_RW       0b10111111  //Enables register read/write of Timer1 in two 8-bit operations
#define T1_16BIT_RW      0b11111111  //Enables register read/write of Timer1 in one 16-bit operation
#define T1_PS_1_1        0b11001111  // 1:1 prescale value
#define T1_PS_1_2        0b11011111  // 1:2 prescale value
#define T1_PS_1_4        0b11101111  // 1:4 prescale value
#define T1_PS_1_8        0b11111111  // 1:8 prescale value
#define T1_OSC1EN_OFF    0b11110111  // Timer 1 oscilator enable off
#define T1_OSC1EN_ON     0b11111111  // Timer 1 oscilator enable on
#define T1_SYNC_EXT_ON   0b11111011  // Synchronize external clock input
#define T1_SYNC_EXT_OFF  0b11111111  // Do not synchronize external clock input
#define T1_SOURCE_INT    0b11111101  //Internal instruction cycle clock (CLKO) acts as source of clock
#define T1_SOURCE_EXT    0b11111111  //Transition on TxCKI pin acts as source of clock

#else //!USE_OR_MASKS

#define T1_8BIT_RW       0b00000000  //Enables register read/write of Timer1 in two 8-bit operations
#define T1_16BIT_RW      0b01000000  //Enables register read/write of Timer1 in one 16-bit operation
#define T1_BIT_RW_MASK    (~T1_16BIT_RW)      // Mask Timer1 16-Bit Read/Write Mode Enable bit

#define T1_PS_1_1        0b00000000  // 1:1 prescale value
#define T1_PS_1_2        0b00010000  // 1:2 prescale value
#define T1_PS_1_4        0b00100000  // 1:4 prescale value
#define T1_PS_1_8        0b00110000  // 1:8 prescale value
#define T1_PS_MASK       (~T1_PS_1_8)      //Mask Timer1 Input Clock Prescale Select bits
   
#define T1_OSC1EN_OFF    0b00000000  // Timer 1 oscilator enable off
#define T1_OSC1EN_ON     0b00001000  // Timer 1 oscilator enable on
#define   T1_OSC_MASK       (~T1_OSC1EN_ON)   //Mask Timer1 Oscillator Enable bit

#define T1_SYNC_EXT_ON   0b00000000  // Synchronize external clock input
#define T1_SYNC_EXT_OFF  0b00000100  // Do not synchronize external clock input
#define T1_SYNC_MASK    (~T1_SYNC_EXT_OFF)   // Mask Timer1 External Clock Input Synchronization Select bit

#define T1_SOURCE_INT    0b00000000  //Internal instruction cycle clock (CLKO) acts as source of clock
#define T1_SOURCE_EXT    0b00000010  //Transition on TxCKI pin acts as source of clock
#define   T1_SOURCE_MASK    (~T1_SOURCE_EXT)   //Mask Timer1 Clock Source Select bits

#endif //USE_OR_MASKS

void OpenTimer1 ( unsigned char config);
void CloseTimer1 (void);
unsigned int ReadTimer1 (void);
void WriteTimer1 ( unsigned int timer1);
#endif


Anyway I'll check how to handle timers on this PIC, and i'll try the shift registers as well.

Thank you!

Fayev
Newbie Pyro
Posts: 7
Joined: Mon Apr 21, 2014 1:34 pm

Re: PS/2 Keyboard Interface

Postby Fayev » Mon Apr 28, 2014 10:27 pm

It won't recognize the T1_SOURCE_INT by any method... I've compiled the program without this statement, like this:

Code: Select all

T1CONbits.TMR1ON=1;

T1CONbits.RD16=1;

T1CONbits.T1CKPS1=0;

T1CONbits.T1CKPS0=0;

T1CONbits.TMR1CS1=1;

T1CONbits.TMR1CS0=0;

PIE1bits.TMR1IE=1;


(Sorry I'm totally new at timers) And it won't work.. Also, is there a problem if I connect the Data from the PS2 to the SDI input of my PIC? (RC4 for the p18f26j11) and I've wired the clock to the SCK pin (RC3)... Could this be what is making it not to work?

I've now connected DATA from PS/2 to RB2 and the clock to RB1. Still not working :(

Thank you and sorry for troubling you!

ThePyroElectro
PyroElectro Admin
Posts: 1181
Joined: Mon Nov 12, 2007 9:24 pm
Location: Earth
Contact:

Re: PS/2 Keyboard Interface

Postby ThePyroElectro » Tue Apr 29, 2014 4:16 pm

Fayev wrote:It won't recognize the T1_SOURCE_INT by any method... I've compiled the program without this statement, like this:

Code: Select all

T1CONbits.TMR1ON=1;

T1CONbits.RD16=1;

T1CONbits.T1CKPS1=0;

T1CONbits.T1CKPS0=0;

T1CONbits.TMR1CS1=1;

T1CONbits.TMR1CS0=0;

PIE1bits.TMR1IE=1;


(Sorry I'm totally new at timers) And it won't work.. Also, is there a problem if I connect the Data from the PS2 to the SDI input of my PIC? (RC4 for the p18f26j11) and I've wired the clock to the SCK pin (RC3)... Could this be what is making it not to work?

I've now connected DATA from PS/2 to RB2 and the clock to RB1. Still not working :(

Thank you and sorry for troubling you!


Due to my lack of experience with the specific version of PIC that you are using, I can't give any concrete answers, only conjecture.

SCK on RC3 should work fine as long as it is set as an input and you can verify that the input works.

I would connect an oscilloscope to the SCK/SDI lines to verify signals are being sent across them that the microcontroller can catch.

Fayev
Newbie Pyro
Posts: 7
Joined: Mon Apr 21, 2014 1:34 pm

Re: PS/2 Keyboard Interface

Postby Fayev » Tue Aug 05, 2014 8:25 pm

Hi again!

Thank you for your reply, I did it :D ! Shifting for two digits and all... There's only one thing, the circuit must be connected to the power source with the keyboard plugged, otherwise if the PIC is powered on first and then the keyboard is plugged it just won't do a thing. Is there anything you can recommend me to solve this?


Thank you!


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 3 guests