在gpio LM3SD96的各个端口上设置引脚

时间:2013-12-06 07:37:59

标签: embedded arm gpio

我想在Stellaris LM3S9D96上的GPIO端口PA,PD和PF中设置几个引脚。

我知道所需的位操作程序,但我对如何在端口PA,PD等中选择不同的引脚以及使用适当的掩码AND它们感到困惑。有人可以向我解释这些操作吗?

1 个答案:

答案 0 :(得分:0)

Stellaris芯片上的端口是引脚可寻址的。如果您使用StellarisWare Driver Library,这非常容易。

User Guide是如何使用GPIO库函数的一个很好的例子。从第142-143页开始:

  

9.3编程示例

     

以下示例说明如何使用GPIO API初始化GPIO,启用中断,从引脚读取数据以及将数据写入引脚。

     
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);