简体   繁体   中英

setting pins on various ports in gpio LM3SD96

I want to set a few pins in GPIO ports PA, PD, and PF on a Stellaris LM3S9D96.

I know the bit operation procedures needed to that, but I am confused on how to select different pins in ports PA, PD, etc. and AND them with appropriate masks. Could someone explain these operations to me?

The ports on the Stellaris chips are pin addressable. This made really easy if you use the StellarisWare Driver Library .

The User Guide has a pretty good example of how to use the GPIO Library functions. From page 142-143:

9.3 Programming Example

The following example shows how to use the GPIO API to initialize the GPIO, enable interrupts, read data from pins, and write data to pins.

 int iVal; // // Register the port-level interrupt handler. This handler is the first // level interrupt handler for all the pin interrupts. // GPIOPortIntRegister(GPIO_PORTA_BASE, PortAIntHandler); // // Initialize the GPIO pin configuration. // // Set pins 2, 4, and 5 as input, SW controlled. // GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5); // // Set pins 0 and 3 as output, SW controlled. // GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_3); // // Make pins 2 and 4 rising edge triggered interrupts. // GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4, GPIO_RISING_EDGE); // // Make pin 5 high level triggered interrupts. // GPIOIntTypeSet(GPIO_PORTA_BASE, GPIO_PIN_5, GPIO_HIGH_LEVEL); // // Read some pins. // iVal = GPIOPinRead(GPIO_PORTA_BASE, (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5)); // // Write some pins. Even though pins 2, 4, and 5 are specified, those pins // are unaffected by this write because they are configured as inputs. At // the end of this write, pin 0 will be a 0, and pin 3 will be a 1. // GPIOPinWrite(GPIO_PORTA_BASE, (GPIO_PIN_0 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5), 0xF8); // // Enable the pin interrupts. // GPIOPinIntEnable(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_4 | GPIO_PIN_5); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM