Hi i am working with this code(button sample) but only responds with pins DIO nº1,3,5,7 when they are shorted to earth by pin DIO nº2. Why 9,11,13,15 does not work?
#include<unistd.h> #include<sys/types.h> #include<sys/mman.h> #include<stdio.h> #include<fcntl.h> #include<string.h>
#define DIOBASE 0xE8000000 int main(int argc, char **argv) { volatile unsigned int *PBDR, *PBDDR, *GPIOBDB;
int i; unsigned char state; unsigned char *start; int fd = open("/dev/mem", O_RDWR|O_SYNC);
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, DIOBASE);
PBDR = (unsigned int *)(start + 0x04); //port b //starting address of DIO read, E8000000 + 4 = E80000004 PBDDR = (unsigned int *)(start + 0x14); //port b direction
GPIOBDB = (unsigned int *)(start + 0xC4); // debounce on port b
*PBDDR = 0xf0; //upper nibble output, lower nibble input *GPIOBDB = 0x01; //enable debounce on bit 0 state = *PBDR; // read initial state
printf ("Press buttons on DIO inputs. Ctrl-C to Quit.\n");
int count = 0; unsigned char oldstate = (unsigned char)0; while (1) //(state & 0x01) { state = *PBDR; // remember bit 0 is pulled up with 4.7k ohm if (oldstate != state) { printf ("State:%x\n", state); oldstate = state; } usleep(1000); count++; } printf ("\nDONE\n"); close(fd); return 0; }
Charlas más divertidas con el nuevo Windows Live Messenger
__._,_.___
__,_._,___
|
|