Hello,
I have some problems about switch,
1. I'm using TM4C1231H6PMI with IAR Embedded Workbench IDE. I'm trying to use SW PB1 to change the LED mode which has on, off and flash. If I press the SW first time, the LED will turn on, second time will turn off, third time will flash every 1 second by timer. How can I do without interrupt ?
2. Now I'm learning about switch, I don't understand why when I run the code, at the first time while loop the value of
MAP_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_1) is 2, and GPIO_PIN_1 has no value. Then MAP_GPIOPinRead will be 0, and after I press the switch it still be 0. I don't know where is the problem.
My code as follow,
int
main(void)
{
MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
//
HWREG(GPIO_PORTF_BASE + 0x520) = 0x4C4F434B;
HWREG(GPIO_PORTF_BASE + 0x524) = 0x00FF;
HWREG(GPIO_PORTF_BASE + 0x420) = 0x0000;
HWREG(GPIO_PORTF_BASE + 0x51C) = 0x001F;
//
MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4);
MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_1 | GPIO_PIN_0);
//
MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
// Key
MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_1);
uint32_t Key1status;
while(1)
{
Key1status = MAP_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_1);
if (Key1status == GPIO_PIN_1)
{
MAP_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, GPIO_PIN_4);
}
else
{
MAP_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0);
}
}
}
