在线时间2 小时
UID4001071
注册时间2024-7-6
NXP金币45
该用户从未签到
新手上路
- 积分
- 20
- 最后登录
- 2024-7-12
|
void Kbi_Init()
{
CONFIG_PIN_AS_GPIO(PTE,PTE0,INPUT); /* Configure SW1 (PTD0) as an input */
CONFIG_PIN_AS_GPIO(PTE,PTE1,INPUT); /* Configure SW2 (PTD1) as an input */
CONFIG_PIN_AS_GPIO(PTE,PTE2,INPUT); /* Configure SW1 (PTD0) as an input */
CONFIG_PIN_AS_GPIO(PTE,PTE3,INPUT); /* Configure SW2 (PTD1) as an input */
CONFIG_PIN_AS_GPIO(PTE,PTE4,INPUT); /* Configure SW2 (PTD1) as an input */
ENABLE_INPUT(PTE,PTE0); /* Enable input SW1*/
ENABLE_INPUT(PTE,PTE1); /* Enable input SW2*/
ENABLE_INPUT(PTE,PTE2); /* Enable input SW1*/
ENABLE_INPUT(PTE,PTE3); /* Enable input SW2*/
ENABLE_INPUT(PTE,PTE4); /* Enable input SW2*/
ENABLE_PULLUP(PTE,PTE0); /* 配置内部上拉电阻 */
ENABLE_PULLUP(PTE,PTE1); /* 配置内部上拉电阻 */
ENABLE_PULLUP(PTE,PTE2); /* 配置内部上拉电阻 */
ENABLE_PULLUP(PTE,PTE3); /* 配置内部上拉电阻 */
ENABLE_PULLUP(PTE,PTE4); /* 配置内部上拉电阻 */
SIM_SCGC |= SIM_SCGC_KBI1_MASK; /* Enable bus clock on KBI0 */
KBI1_SC = 0; /* Clearing mechanism */
KBI1_ES |= KBI_ES_KBEDG(0x00); /* Polarity setting, falling edge low level,PTE0 */
KBI1_PE |= KBI_PE_KBIPE(0x00); /* Enable KBI1 channel 0 , PTE0 */
KBI1_ES |= KBI_ES_KBEDG(0x00); /* Polarity setting, falling edge low level,PTE0 */
KBI1_PE |= KBI_PE_KBIPE(0x01); /* Enable KBI1 channel 1 , PTE1 */
KBI1_ES |= KBI_ES_KBEDG(0x00); /* Polarity setting, falling edge low level,PTE0 */
KBI1_PE |= KBI_PE_KBIPE(0x02); /* Enable KBI1 channel 0 , PTE0 */
KBI1_ES |= KBI_ES_KBEDG(0x00); /* Polarity setting, falling edge low level,PTE0 */
KBI1_PE |= KBI_PE_KBIPE(0x03); /* Enable KBI1 channel 1 , PTE1 */
KBI1_ES |= KBI_ES_KBEDG(0x00); /* Polarity setting, falling edge low level,PTE0 */
KBI1_PE |= KBI_PE_KBIPE(0x04); /* Enable KBI1 channel 0 , PTE0 */
KBI1_SC = 0; /* Clearing flags*/
KBI1_SC |=KBI_SC_RSTKBSP_MASK; /* Clearing RSTKBSP bit*/
KBI1_SC |= KBI_SC_KBIE_MASK; /* Enable KBI1 Interrupts */
KBI_SetCallback(KBI1,KBI1_IRQHandler); /* Set the KBI callback function to be called on each button press */
NVIC_EnableIRQ(KBI1_IRQn); /* Enable KBI1 Interrupt */
}
void KBI1_IRQHandler()
{
KBI_Interrupt();
}
void KBI_Interrupt()
{
KBI1_SC |= KBI_SC_KBACK_MASK; /*Clear flag*/
power_on;
Uart_SendChar(KBI1_SP);//Uart_SendChar(KBI1_SP);
if((KBI1_SP & KBI_SP_SP(0x00))>>0) /* If SW1 has been pressed */
{row=1;
power_on;}
else if((KBI1_SP & KBI_SP_SP(0x01))>>1) /* If SW2 has been pressed */
{row=2;power_down;
}
else if((KBI1_SP & KBI_SP_SP(0x02))>>2) /* If SW2 has been pressed */
{row=3;
power_on;}
else if((KBI1_SP & KBI_SP_SP(0x03))>>3) /* If SW2 has been pressed */
{row=4;power_down;
}
else if((KBI1_SP & KBI_SP_SP(0x04))>>4) /* If SW2 has been pressed */
row=5;
}
|
|