void LED_Config(void)
{
// The first step is to turn on the GPIO peripheral clock power. Only when it is turned on can the related GPIO registers be operated .
Chip_GPIO_Init(LPC_GPIO); //Peripheral clock power
//The second step is to set the GPIO pin to normal GPIO function.
Chip_IOCON_PinMux(LPC_IOCON, 2, 0, IOCON_MODE_INACT, IOCON_FUNC0);
//IOCON_FUNC0 sets P2.0 to GPIO function, IOCON_MODE_INACT (turn off the pull-up and pull-down functions)
Chip_IOCON_PinMux(LPC_IOCON, 2, 1, IOCON_MODE_INACT, IOCON_FUNC0); //IOCON_FUNC0 sets P2.1 to GPIO function
Chip_IOCON_PinMux(LPC_IOCON, 2, 2, IOCON_MODE_INACT, IOCON_FUNC0);
Chip_IOCON_PinMux(LPC_IOCON, 2, 3, IOCON_MODE_INACT, IOCON_FUNC0);
Chip_IOCON_PinMux(LPC_IOCON, 2, 4, IOCON_MODE_INACT,
Chip_IOCON_PinMux(LPC_IOCON, 2, 5, IOCON_MODE_INACT, IOCON_FUNC0);
Chip_IOCON_PinMux(LPC_IOCON, 2, 6, IOCON_MODE_INACT, IOCON_FUNC0);
Chip_IOCON_PinMux(LPC_IOCON, 2, 7, IOCON_MODE_INACT, IOCON_FUNC0); //Set P2.7 to GPIO function //The third step is
to set the output mode, because it is to control peripheral devices, set it to output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 0, true); //Set P2.0 output mode true, output mode false input mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 1, true);//Set output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 2, true);//Set output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 3, true);//Set output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 4, true);//Set output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 5, true);//Set output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 6, true);//Set output mode
Chip_GPIO_SetPinDIR(LPC_GPIO,2, 7, true);//Set output mode
//The fourth step is to set the output low level P2.0~P2.7.
Chip_GPIO_SetPortValue(LPC_GPIO,2,0XFFFFFF00);//Set the output low level P2.0~P2.7
}
The following two functions are bit manipulation functions that control the output high and low levels. They have the same effect as the Chip_GPIO_SetPortValue() function.
Chip_GPIO_SetPinOutHigh(LPC_GPIO,2,0)//Set P2.0 output high level
Chip_GPIO_SetPinOutLow(LPC_GPIO,2,0)//Set P2.0 output low level
【01】LPC1768_LED实验.rar
(241.61 KB, downloads: 17)
This content is originally created by EEWORLD forum user cxmdz . If you need to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source