You are not logged in

Log in into our community

Log in so you acess some hidden content

* Fields are required.

Register into our community!

Sign up now for some good content

* Fields are required.

Lost something?

Enter your username or email to reset your password.

* Fields are required.

Joystick

Posted on : Sun , 02 2014 by : virusi

LPC1768 Joystick Application :


In this tutorial will take a look how we can work with a joystick using NXP LPC1768 microcontroller.

JoyStickApplication
Fig.1 Joystick Application

Ok so let’s take a look at the program.

AT INITIALIZATION :

1. Initialize system clock

 /* initialize clocks */
SystemInit();  
 

2. Configure PIN’s where joystick is connected as input.

 /* Configure P 1.25 ... P 1.29 as input	*/
LPC_GPIO1->FIODIR &= ~(SET_PIN_1_25|SET_PIN_1_26
                      |SET_PIN_1_27|SET_PIN_1_28
                      |SET_PIN_1_29);

3. Configure PIN’s where led’s are connected output.

/* Configure P 2.00... P 2.07 as output */
LPC_GPIO2->FIODIR |= (SET_LED_0|SET_LED_1|
                     SET_LED_2|SET_LED_3|
                     SET_LED_4|SET_LED_5|
                     SET_LED_6|SET_LED_7) ; 

AT RUNTIME :

1. Read Joystick PIN’s

 JSval = (~((LPC_GPIO1->FIOPIN>>25)&0x1F))&0x1F; 

2. Check which button was pressed

 /* Joystick select was pressed */
if( JSval == JS_SEL )
{
    LPC_GPIO2->FIOPIN = SET_LED_0;
    Delay(100);		
    LPC_GPIO2->FIOPIN = RESET_LEDS;
}
/* Joystick down was pressed */
else if( JSval == JS_DOWN )
{
    LPC_GPIO2->FIOPIN = SET_LED_1;	
    Delay(100);		
    LPC_GPIO2->FIOPIN = RESET_LEDS;
}
/* Joystick left was pressed */
else if( JSval == JS_LEFT )
{
    LPC_GPIO2->FIOPIN = SET_LED_2;	
    Delay(100);		
    LPC_GPIO2->FIOPIN = RESET_LEDS;
} 
/* Joystick right was pressed */
else if( JSval == JS_RIGHT )
{
    LPC_GPIO2->FIOPIN = SET_LED_3;	
    Delay(100);		
    LPC_GPIO2->FIOPIN = RESET_LEDS;
} 
/* Joystick up was pressed */
else if( JSval == JS_UP ) 
{
    LPC_GPIO2->FIOPIN = SET_LED_4;
    Delay(100);		
    LPC_GPIO2->FIOPIN = RESET_LEDS;
}

DOWNLOAD :


If you are interested in the full example then download JoyStick example.
Last updated on Mon , 03 2014
SHARE THIS PAGE :

This page is waiting for your comment.

Share and Leave a comment.

You must be logged in to post a comment.

Back to Top