Tuesday, July 04, 2006

Blinky Hack

A quick hack of blinky and I now have the code below which polls pin 1 on Port 0 of the GPIO and if it goes low (by me clicking it) it sends pin 1 on Port 1 high.

The problem with this is my button simulation is more like a switch. I have to click the pin to turn it low and click again to turn it high. That isn't really what the LogStick "button" is all about. I need to find a more realistic button emulation. Hmmm...


/* Example program to detect a Pin
attached to GPIO going low which
represents button press */

...

#define PINMASK 0x00000001

/* IF masked pin number is low THEN button pressed */
#define BUTTON_PRESSED ((IOPIN0 & PINMASK)== 0)

void wait (void) {int d; for (d = 0; d < 1000000; d++);}


int main (void) {
/* GPIO Port 0 is input (default after reset anyway) */
IODIR0 = 0x00000000;

/* GPIO P0.1 defined as Output */
IODIR1 = 0x00000001;
while (1) {
/* IF button pressed, toggle an output pin*/
if (BUTTON_PRESSED) {
IOSET1 = 1;
wait();
IOCLR1 = 1;
}
}
...

0 Comments:

Post a Comment

<< Home