Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12606 Discussions

Read from Keyboard and show on LCD

Altera_Forum
Honored Contributor II
1,080 Views

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; 

}  

}
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
294 Views

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.

0 Kudos
Reply