reading buttons in mini2440

new
Hi
I am using a mini2440 kit and managed to run LED test program using ADS.
Now I want to write a program which will turn on the led when a button has
been pushed. I tried using the port G register configuration to detect the
button but its not working . Can anyone please suggest me hoe to read the
buttons

Thanx

TungPham
are you using linux or winCE,
In linux, you can refer to button_test.c in the examples

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>

int main(void)
{
  int buttons_fd;
  char buttons[6] = {'0', '0', '0', '0', '0', '0'};

  buttons_fd = open("/dev/buttons", 0);
  if (buttons_fd < 0) {
    perror("open device buttons");
    exit(1);
  }

  for (;;) {
    char current_buttons[6];
    int count_of_changed_key;
    int i;
    if (read(buttons_fd, current_buttons, sizeof current_buttons) != sizeof
current_buttons) {
      perror("read buttons:");
      exit(1);
    }

    for (i = 0, count_of_changed_key = 0; i < sizeof buttons / sizeof
buttons[0]; i++) {
      if (buttons[i] != current_buttons[i]) {
        buttons[i] = current_buttons[i];
        printf("%skey %d is %s", count_of_changed_key? ", ": "", i+1,
buttons[i] == '0' ? "up" : "down");
        count_of_changed_key++;
      }
    }
    if (count_of_changed_key) {
      printf("\n");
    }
    
    
  }

  close(buttons_fd);
  return 0;
}

AnatoliyBesplemennov
It's very easy!

Exaple (working):

#define rGPGDAT    (*(volatile unsigned *)0x56000064)  //Port G data




void Main(void)
{
    Buzz(7000, 10);
    Fill_Screen(20);
    Set_Font(1,0xFFFF,20);
    Print_String(70,50, "Knobs test example");    

    Set_Font(0,0xFFFF,20);
    
Again:

    if( (rGPGDAT&(1<< 0)) == 0 )  {Print_String(70,80, "Key 1 pressed"); 
Buzz(1000,100);}
    
    if( (rGPGDAT&(1<< 3)) == 0 )  {Print_String(70,110, "Key 2 pressed"); 
Buzz(2000,100);}

    if( (rGPGDAT&(1<< 5)) == 0 )  {Print_String(70,140, "Key 3 pressed"); 
Buzz(3000,100);}
    
    if( (rGPGDAT&(1<< 6)) == 0 )  {Print_String(70,170, "Key 4 pressed"); 
Buzz(4000,100);}
    
    if( (rGPGDAT&(1<< 7)) == 0 )  {Print_String(70,200, "Key 5 pressed"); 
Buzz(5000,100);}

    if( (rGPGDAT&(1<<11)) == 0 )
    {  Print_String  (70,230, "Key 6 pressed, Bye!");
      Buzz(6000,100);
      Delay(3000);
      Exit();    }
      

    Delay(100);
    goto  Again;

}