Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Read from Keyboard and show on LCD

Hi Folks,

I'm using the Altera DE2 Development Board and trying to read a character from the keyboard and show the equivalent ascii on the character LCD. Although the code is apparently running, nothing happens when I press the keys on the keyboard.

I researched in the altera university program documentation and in materials I could find through the internet. Unfortunatelly I'm not being able to figure out what's happening... So, I'd like to ask for your help on trying to make this code work.

I'm using the Altera Design Suite 9.0... the code is shown below !

(I'm also sending the system.h as an attach file)

Thank you for the attention !

# include "io.h"# include "altera_avalon_pio_regs.h"# include "string.h"# include "system.h"# include "altera_up_avalon_character_lcd.h"# include "altera_up_avalon_character_lcd_regs.h"# include "altera_up_avalon_rs232.h"# include "altera_up_avalon_rs232_regs.h"# include "altera_up_avalon_ps2.h"# include "altera_up_avalon_ps2_regs.h"# include "altera_up_ps2_keyboard.h"

int main()

{

KB_CODE_TYPE decode_mode;

alt_u8 data;

char ascii;

char *temp;

char *p;

short x = 1, y = 1; //If y start from 0 character will hide on the top of monitor

alt_up_character_lcd_dev * char_lcd_dev;

char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/up_avalon_character_lcd_0");

alt_up_character_lcd_init (char_lcd_dev);

alt_up_character_lcd_cursor_blink_on(char_lcd_dev);

alt_up_ps2_dev *ps2;

ps2 = alt_up_ps2_open_dev("/dev/up_avalon_ps2_0");

alt_up_ps2_init(ps2);

//alt_up_ps2_enable_read_interrupt(ps2);

//alt_up_ps2_clear_fifo(ps2);

//ps2-> device_type==PS2_KEYBOARD;

alt_up_character_lcd_set_cursor_pos(char_lcd_dev, x, y);

while(1){

if (decode_scancode(ps2, &decode_mode, &data, &ascii)==0)

{

if (ps2->device_type == PS2_KEYBOARD){

if (decode_mode == KB_ASCII_MAKE_CODE || decode_mode == KB_BINARY_MAKE_CODE || decode_mode == KB_LONG_BINARY_MAKE_CODE)

{

alt_up_ps2_read_data_byte(ps2, temp);

data=*temp;

translate_make_code(decode_mode, data, p);

}

alt_up_character_lcd_set_cursor_pos(char_lcd_dev, x, y);

alt_up_character_lcd_string(char_lcd_dev, p);

x++;

if (x >= 16 && y==0){

y=1;

x = 1;

}

if (x>=16 && y==1){

y = 0;

x = 1;

}

}

return 0;

}

else{

return -1;

}

}

}

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You should debug your program to see where the problem come from, first of all if you receive something from the keyboard, if yes is it the good data, if yes does the LCD work if you send it characters, etc.