Hello friends,
I wrote sample code for SW1(button1) , SW2(button2) , Joystick of SAM7-EX256…My code doesnt seem to work but compiles successfuly…Here is my code snip(If some one needs then I can send them the complete project)…Please help me I am Stuck!!
AT91PS_PIO m_pPioA = AT91C_BASE_PIOA;
AT91PS_PIO m_pPioB = AT91C_BASE_PIOB;
int get_key( void )
{
if( !( ( m_pPioA->PIO_PDSR ) & BIT7 ) ) {
return( LEFT_KEY );
}
if( ! ( ( m_pPioA->PIO_PDSR ) & BIT8 ) ) {
return( DOWN_KEY );
}
if( !( ( m_pPioA->PIO_PDSR ) & BIT9 ) ) {
return( UP_KEY );
}
if( !( ( m_pPioA->PIO_PDSR ) & BIT14 ) ) {
return( RIGHT_KEY );
}
if( !( ( m_pPioA->PIO_PDSR ) & BIT15 ) ) {
return( CENTER_KEY );
}
// check button SW1
if( !( ( m_pPioB->PIO_PDSR ) & BIT24 ) ) {
return( BUTTON1 );
}
// check button SW2
if( !( ( m_pPioB->PIO_PDSR ) & BIT25 ) ) {
return( BUTTON2 );
}
return( NO_KEY );
}
.
.
.
extern void LowLevelInit(void);
int main( void )
{
// Initialize the Atmel AT91SAM7S256 (watchdog, PLL clock, default interrupts, etc.)
LowLevelInit();
// Set up the LED (PA3)
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA; // pointer to PIO data structure
pPIO->PIO_PER = LED_MASK; // PIO Enable Register - allow PIO to control pin PP3
pPIO->PIO_OER = LED_MASK; // PIO Output Enable Register - sets pin P3 to outputs
pPIO->PIO_SODR = LED_MASK; // PIO Set Output Data Register - turns off the LED
// Initialize SPI interface to LCD
InitSpi();
// Init LCD
InitLcd();
// clear the screen
LCDClearScreen();
LCDPutStr(“Starting”, 115, 10, SMALL, BLACK, YELLOW);
int i=0;
int number[0];
while( 1 ) {
number[0]++;
Backlight(0);
if ((number[0]==1600))
{
Backlight(1);
LCDClearScreen();
LCDPutStr(“NUMBER”, 115, 10, SMALL, BLACK, RED);
Delay(1000000);
number[0]=0;
Delay(1000000);
}
switch( GetKey() ) {
LCDClearScreen();
case 0:
LCDPutStr(“LEFT KEY”, 115, 10, SMALL, BLACK, YELLOW);
break;
case 1:
LCDPutStr(“CENTER KEY”, 115, 10, SMALL, BLACK, RED);
break;
case 2:
LCDPutStr(“DOWN KEY”, 115, 10, SMALL, BLACK, YELLOW);
break;
case 3:
LCDPutStr(“UP KEY”, 115, 10, SMALL, BLACK, RED);
break;
case 4:
LCDPutStr(“RIGHT KEY”, 115, 10, SMALL, BLACK, YELLOW);
break;
case 5:
LCDPutStr(“BUTTON1 KEY”, 115, 10, SMALL, BLACK, RED);
break;
case 6:
LCDPutStr(“BUTTON2 KEY”, 115, 10, SMALL, BLACK, YELLOW);
break;
default:
LCDPutStr(“NOthing”, 115, 10, SMALL, BLACK, YELLOW);
break;
}
}