二、程序设计
要注意的是ARM系列微控制器GPIO口在使用时的问题,特别要注意每次输出0和输出1,使用的都是不同的寄存器。而且,GPIO口的功能每次也都需要设定它是做输入,输出还是做准双向口或者开漏模式。这一点很重要,与单片机不同,所以如果这里编程时序不注意会导致失败。
编程过程中,我使用了符合CMSIS标准的ARM Cortex微控制器标准API函数库来调用GPIO口操作函数,主要用到的有:
(1)DrvGPIO_Open
Prototype
void DrvGPIO_Open ( E_DRVGPIO_PORT port, E_DRVGPIO_PIN pin, E_DRVGPIO_IO IOMode ) Description
Set the specified GPIO pin to the specified GPIO operation mode.
Parameter
port [in] E_DRVGPIO_PORT, specify GPIO port.
It could be E_PORT0, E_PORT1, E_PORT2, E_PORT3 and E_PORT4.
pin [in]
Specify pin of the GPIO port. It could be E_PIN0, E_PIN2 ... ~ E_PIN7.
IOMode [in]
E_DRVGPIO_IO, set the specified GPIO pin to be E_IO_INPUT, E_IO_OUTPUT, E_IO_OPENDRAIN or E_IO_QUASI mode.
Include
Driver/DrvGPIO.h
Return Value
None
Example:
(2)DrvGPIO_SetBit
Prototype
int32_t DrvGPIO_SetBit (E_DRVGPIO_PORT port, E_DRVGPIO_PIN pin)
Description
Set the specified GPIO pin to 1.
Parameter
port [in]
E_DRVGPIO_PORT, specify GPIO port.
It could be E_PORT0, E_PORT1, E_PORT2, E_PORT3 and E_PORT4.
pin [in]
Specify pin of the GPIO port. It could be E_PIN0, E_PIN2 ... ~ E_PIN7.
Include
Driver/DrvGPIO.h
Return Value
E_SUCCESS: Operation successful
Example:
DrvGPIO_Open (E_PORT0, E_PIN0, E_IO_OUTPUT);
DrvGPIO_SetBit (E_PORT0, E_PIN0);
(3)DrvGPIO_ClrBit
Prototype
int32_t DrvGPIO_ClrBit (E_DRVGPIO_PORT port, E_DRVGPIO_PIN pin)
Description
Set the specified GPIO pin to 0.
Parameter
port [in]
E_DRVGPIO_PORT, specify GPIO port.
It could be E_PORT0, E_PORT1, E_PORT2, E_PORT3 and E_PORT4.
pin [in]
Specify pin of the GPIO port. It could be E_PIN0, E_PIN2 ... ~ E_PIN7.
Include
Driver/DrvGPIO.h
Return Value
E_SUCCESS: Operation successful
Example:
DrvGPIO_Open (E_PORT0, E_PIN0, E_IO_OUTPUT);
DrvGPIO_ClrBit (E_PORT0, E_PIN0);
(4)DrvGPIO_SetPortBits
Prototype
int32_tDrvGPIO_SetPortBits (E_DRVGPIO_PORT port, int32_t i32PortValue)
Description
Set the output port value to the specified GPIO port.
Parameter
port [in]
E_DRVGPIO_PORT, specify GPIO port.
It could be E_PORT0, E_PORT1, E_PORT2, E_PORT3 and E_PORT4.
i32PortValue [in]
The data output value. It could be 0~0xFF.
Include
Driver/DrvGPIO.h
Return Value
E_SUCCESS: Operation successful
Example: