Very basic library problem I need help with

11 Nov 2009 . Edited: 11 Nov 2009

Hi all,

I work in the live event industry but I've started to use the mBed to code for my dissertation. I don't have any prior coding experience but I've got a lot of experience with electronics.

I'm trying to get my 16x2 Text LCD to display key presses from a PS2 keyboard, using some of the code from the Cookbook.

This is my code:

#include "mbed.h"
#include "TextLCD.h"                       
DigitalIn ps2clk(p21);
DigitalIn ps2din(p22);
TextLCD lcd(p24, p25, p26, p27, p28, p29, p30);        

static const unsigned char ps2KeyMap[] = {
//   0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '`', ' ', // 00-0F
' ', ' ', ' ', ' ', ' ', 'Q', '1', ' ', ' ', ' ', 'Z', 'S', 'A', 'W', '2', ' ', // 10-1F
' ', 'C', 'X', 'D', 'E', '4', '3', ' ', ' ', ' ', 'V', 'F', 'T', 'R', '5', ' ', // 20-2F
' ', 'N', 'B', 'H', 'G', 'Y', '6', ' ', ' ', ' ', 'M', 'J', 'U', '7', '8', ' ', // 30-3F
' ', ',', 'K', 'I', 'O', '0', '9', ' ', ' ', '.', '/', 'L', ';', 'P', '-', ' ', // 40-4F
' ', ' ','\'', ' ', '[', '=', ' ', ' ', ' ', ' ', ' ', ']', ' ','\\', ' ', ' ', // 50-5F
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 60-6F
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 70-7F
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 80-8F
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // 90-9F
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // A0-AF
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // B0-BF
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // C0-CF
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // D0-DF
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // E0-EF
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', // F0-FF

};  

unsigned char ps2GetKey(void)
{
unsigned int buf;
int i;
buf = 0;
ps2clk = 0;                               // first error
ps2din.direction(0);                  // second error
ps2clk.direction(0);
for(i=0;i<11;i++) {
while(ps2clk);
while(!ps2clk);
buf = buf >> 1;
buf |= ps2din ? 512 : 0;
}
ps2clk.direction(1);
buf &= 0xFF;
return (unsigned char)buf;
}

int main(void)
{
printf("\n\rPS2 Keyboard:");
while(1) {
unsigned char c;
skip_break:
c = ps2GetKey();
if(c == 0xF0) {
c = ps2GetKey();
goto skip_break;
}
lcd.printf("%c", ps2KeyMap[c]);
}
return 0;
}

 

And in the compiler output I get the following warnings:

1st - No operator "=" matches these operands

2nd Class mbed::DigitalIn has no member "direction"

Can anybody tell me where I'm going wrong please? Would really appreciate it.

 

Simon Pettitt

11 Nov 2009

Just use:

PS2ASCII myKeyboard(21, 23);
Just use this page for reference:

11 Nov 2009

Ok thanks Vlad, I'll give that a go now.

11 Nov 2009 . Edited: 11 Nov 2009

There s a PS2ASCII class now so it is much easyer to use./

Make sure you use:

#include "PS2Kbd.h"

To include the class in your bin.

Let me know if there is anything else you need.

11 Nov 2009

Thanks so much Vlad. Here is my new code:

 

#include "mbed.h"
#include "PS2Kbd.h"
#include "TextLCD.h"
#include "PS2ASCII.h"
//----------------------//
TextLCD lcd(p24, p25, p26, p27, p28, p29, p30);
PS2ASCII myKeyboard(21, 22);
DigitalOut LED(LED1);
int main() {
lcd.cls();                                  //clear screen

while (1) {
unsigned char symbol = myKeyboard.getChar();
if (symbol == 0x1B) {                       //clear screen function
lcd.cls();
continue;
}
if (myKeyboard.E0flag() == true) {          //is the make code one or two bytes long?
lcd.printf(" E0 ");
lcd.printf("%c ", symbol);
continue;
}
lcd.printf("%c", symbol);
}
}

 

But the compiler output says "Cannot open source input file "LPC2300.h":no such file or directory." It has this 7 times, 4 times referencing the PS2Keyboard library and 3 times referencing the PS2ASCII library...however I can't seem to find this other header file to make it happy...

Thanks for your help

11 Nov 2009 . Edited: 11 Nov 2009

Try starting with a clean new program it seems like your class files are not there.

I will try to replicate your example when I get home.

12 Nov 2009

Great, thanks a lot. I'll give that a go.

12 Nov 2009 . Edited: 12 Nov 2009

Hi SimonP, Vlad,

I just had a look at the cookbook example you are discussing, and noticed it was done by someone who obviously had the older beta module and library. It therefore needs a little work to get working, and can also take advantage of some of the library improvements.

So I imported it, and just did a version to bring it up to date. This updated test version can be found at:

The main changes were to change the pin names from int to PinName, and to use the new DigitalInOut class to support the bi-directional pin requirement. And that is about it really.

As I haven't got it wired up, I've only compiled it to test the changes I made have no basic problems, so you might have to do some final changes. Anyway, importing this project is probably a good starting point to get something working.

Simon

12 Nov 2009

Fantastic, I'll try that.

Thanks Simon.