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
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