Other Parts Discussed in Thread: EK-TM4C123GXL
EDIT by moderator (Questions were in Title):
Q1:When I run the code below,it always goes into exit.c (void abort(void)) , if I add a while(1) in the end ,it won't goes into exit.c Q2:I made this project to test ButtonPoll() below,I copied it from http://www.ti.com/lit/zip/tidcb5
/**
* main.c
*/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
uint8_t ButtonsPoll(uint8_t *, uint8_t *);
static uint8_t g_ui8ButtonStates = GPIO_PIN_0|GPIO_PIN_4; //两个按键状态,初始化为高,按下
uint8_t *pui8Delta = 0;
uint8_t *pui8RawState = 0;
uint8_t ui8Buttons = 0;
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01;
HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0;
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, (GPIO_PIN_1 + GPIO_PIN_2 + GPIO_PIN_3));
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, (GPIO_PIN_0 + GPIO_PIN_4));
GPIODirModeSet( GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4, GPIO_DIR_MODE_IN);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4,
GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
g_ui8ButtonStates = GPIOPinRead( GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);
// while(1)
// {
// SysCtlDelay(SysCtlClockGet()/3000);
// ui8Buttons = ButtonsPoll(pui8Delta, pui8RawState);
// }
}
uint8_t ButtonsPoll(uint8_t *pui8Delta, uint8_t *pui8RawState)
{
uint32_t ui32Delta;
uint32_t ui32Data;
static uint8_t ui8SwitchClockA = 0;
static uint8_t ui8SwitchClockB = 0;
//
// Read the raw state of the push buttons. Save the raw state
// (inverting the bit sense) if the caller supplied storage for the
// raw value.
//
ui32Data = (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4));
if(pui8RawState) //指针非空
{
*pui8RawState = (uint8_t)~ui32Data;//现在的状态取反得到原来的状态
}
//
// Determine the switches that are at a different state than the debounced(抖动)
// state.
//
ui32Delta = ui32Data ^ g_ui8ButtonStates;
//
// Increment the clocks by one.
//
ui8SwitchClockA ^= ui8SwitchClockB;
ui8SwitchClockB = ~ui8SwitchClockB;
//
// Reset the clocks corresponding to switches that have not changed state.
//
ui8SwitchClockA &= ui32Delta;
ui8SwitchClockB &= ui32Delta;
//
// Get the new debounced switch state.
//
g_ui8ButtonStates &= ui8SwitchClockA | ui8SwitchClockB;
g_ui8ButtonStates |= (~(ui8SwitchClockA | ui8SwitchClockB)) & ui32Data;
//
// Determine the switches that just changed debounced state.
//
ui32Delta ^= (ui8SwitchClockA | ui8SwitchClockB);
//
// Store the bit mask for the buttons that have changed for return to
// caller.
//
if(pui8Delta)
{
*pui8Delta = (uint8_t)ui32Delta;
}
//
// Return the debounced buttons states to the caller. Invert the bit
// sense so that a '1' indicates the button is pressed, which is a
// sensible way to interpret the return value.
//
return(~g_ui8ButtonStates);
}