用GPIO点亮一个LED灯
按键按下,led亮,放开则灭,相关代码如下:
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "GPIO_LED_Button.h"
#define LED &MODULE_P20,9
#define BUTTON &MODULE_P22,0
void init_GPIOs(void)
{
IfxPort_setPinMode(LED, IfxPort_Mode_outputPushPullGeneral);
IfxPort_setPinMode(BUTTON, IfxPort_Mode_inputPullUp);
}
void control_LED(void)
{
if(IfxPort_getPinState(BUTTON) == 0)
{
IfxPort_setPinState(LED, IfxPort_State_low);
}
else
{
IfxPort_setPinState(LED, IfxPort_State_high);
}
}
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
void core0_main(void)
{
IfxCpu_enableInterrupts();
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
init_GPIOs();
while(1)
{
control_LED();
}
} |