二、程序設(shè)計(jì)
要注意的是ARM系列微控制器GPIO口在使用時(shí)的問題,特別要注意每次輸出0和輸出1,使用的都是不同的寄存器。而且,GPIO口的功能每次也都需要設(shè)定它是做輸入,輸出還是做準(zhǔn)雙向口或者開漏模式。這一點(diǎn)很重要,與單片機(jī)不同,所以如果這里編程時(shí)序不注意會(huì)導(dǎo)致失敗。
編程過程中,我使用了符合CMSIS標(biāo)準(zhǔn)的ARM Cortex微控制器標(biāo)準(zhǔn)API函數(shù)庫(kù)來調(diào)用GPIO口操作函數(shù),主要用到的有:
(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: