this program is based on the PS/2 keyboard library and the LCD library, the lcd display whatever input is coming from the PS/2 keyboard.

Dependencies:   TextLCD mbed

Committer:
edwinb
Date:
Sun Jan 30 15:05:39 2011 +0000
Revision:
0:3774ff2f9a59
Child:
1:2178724f96f1

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edwinb 0:3774ff2f9a59 1 /* This is my first project with the mbed. I have just collected libraries together
edwinb 0:3774ff2f9a59 2 and came up with the mash up below. The keyboard input is received by both the
edwinb 0:3774ff2f9a59 3 terminal and the LCD connected to the mbed.
edwinb 0:3774ff2f9a59 4 the PS/2 wiring is as follows
edwinb 0:3774ff2f9a59 5 ====p22 clock, white===========
edwinb 0:3774ff2f9a59 6 ====p21 signal, green==========
edwinb 0:3774ff2f9a59 7 ====yellow, orange +/- voltage=
edwinb 0:3774ff2f9a59 8 */
edwinb 0:3774ff2f9a59 9 #include "mbed.h"
edwinb 0:3774ff2f9a59 10 #include "PS2ASCII.h"
edwinb 0:3774ff2f9a59 11 #include "TextLCD.h"
edwinb 0:3774ff2f9a59 12
edwinb 0:3774ff2f9a59 13 TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
edwinb 0:3774ff2f9a59 14 PS2ASCII myKeyboard(p22, p21);
edwinb 0:3774ff2f9a59 15 DigitalOut mLED(LED1);
edwinb 0:3774ff2f9a59 16 DigitalOut mLED2(LED2);// not needed for now
edwinb 0:3774ff2f9a59 17 int i=0;
edwinb 0:3774ff2f9a59 18 char *buffer;
edwinb 0:3774ff2f9a59 19 int main() {
edwinb 0:3774ff2f9a59 20 printf("the program has started");
edwinb 0:3774ff2f9a59 21 printf("=========================================\n ");
edwinb 0:3774ff2f9a59 22 while (1) {
edwinb 0:3774ff2f9a59 23 unsigned char symbol = myKeyboard.getChar();
edwinb 0:3774ff2f9a59 24 if (myKeyboard.E0flag() == true) { //is the make code one or two bytes long?
edwinb 0:3774ff2f9a59 25 printf(" E0 ");
edwinb 0:3774ff2f9a59 26 mLED2=1;
edwinb 0:3774ff2f9a59 27 } else {
edwinb 0:3774ff2f9a59 28 wait(0.2);
edwinb 0:3774ff2f9a59 29 printf("%c", symbol);
edwinb 0:3774ff2f9a59 30 lcd.locate(0,0);
edwinb 0:3774ff2f9a59 31 lcd.printf("Keyboard: \n");
edwinb 0:3774ff2f9a59 32
edwinb 0:3774ff2f9a59 33 if (symbol) {
edwinb 0:3774ff2f9a59 34
edwinb 0:3774ff2f9a59 35 i++;
edwinb 0:3774ff2f9a59 36 buffer = new char[16]; //create a char array to hold 16 char
edwinb 0:3774ff2f9a59 37 buffer[i]= symbol; //traverse the array one step at a time
edwinb 0:3774ff2f9a59 38 //lcd.cls();
edwinb 0:3774ff2f9a59 39 lcd.locate(i,1);
edwinb 0:3774ff2f9a59 40 lcd.printf("%c", buffer[i]); //print the char array
edwinb 0:3774ff2f9a59 41 printf(" \t");
edwinb 0:3774ff2f9a59 42 //wait(0.9);
edwinb 0:3774ff2f9a59 43 if (i==16) {
edwinb 0:3774ff2f9a59 44 lcd.cls();
edwinb 0:3774ff2f9a59 45 i=0;
edwinb 0:3774ff2f9a59 46 delete [] buffer;
edwinb 0:3774ff2f9a59 47
edwinb 0:3774ff2f9a59 48 x
edwinb 0:3774ff2f9a59 49 }
edwinb 0:3774ff2f9a59 50 //anytime a key is pressed one of LEDs light up
edwinb 0:3774ff2f9a59 51 mLED=1;
edwinb 0:3774ff2f9a59 52 wait(0.04);
edwinb 0:3774ff2f9a59 53 mLED=0;
edwinb 0:3774ff2f9a59 54 }
edwinb 0:3774ff2f9a59 55 }
edwinb 0:3774ff2f9a59 56 }
edwinb 0:3774ff2f9a59 57 }