?? qs_dk-lm3s102.c
字號:
HWREGBITW(&g_ulFlags, FLAG_UNMUTE) ^= 1;
}
}
}
else
{
//
// Reset the debounce counter.
//
g_ulDebounceCounter = 0;
}
//
// Decrement the click rate counter.
//
g_ulClickRateCount--;
//
// If the count is one then the piezo needs to be turned on.
//
if(g_ulClickRateCount == 1)
{
if(HWREGBITW(&g_ulFlags, FLAG_UNMUTE))
{
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0);
}
}
//
// If the count is zero then the piezo needs to be turned off.
//
if(g_ulClickRateCount == 0)
{
//
// Turn off the piezo.
//
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);
//
// Reset the count to the click rate.
//
g_ulClickRateCount = g_ulClickRate;
}
}
//*****************************************************************************
//
// Quick start demo application.
//
//*****************************************************************************
int
main(void)
{
unsigned long ulCount;
char pcBuffer[4];
//
// Set the clocking to run directly from the crystal. Get and store the
// system clock frequency.
//
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ);
//
// Enable the peripherals used by this example.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Enable processor interrupts.
//
IntMasterEnable();
//
// Configure SysTick for a 100Hz interrupt.
//
SysTickPeriodSet(SysCtlClockGet() / 100);
SysTickEnable();
SysTickIntEnable();
//
// Set A0 and A1 as peripheral function for the UART. This is used to
// output a data log of the captured samples.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Set GPIO B0 as an output. This drives the buzzer on the board.
//
GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_DIR_MODE_OUT);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, 0);
//
// Set GPIO B4 as an analog comparator input.
//
GPIOPinTypeComparator(GPIO_PORTB_BASE, GPIO_PIN_4);
//
// Set GPIO B5 as an input. It is connected to the push button on the
// board.
//
GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_DIR_MODE_IN);
//
// Configure the comparator to use the internal reference voltage.
//
ComparatorConfigure(COMP_BASE, COMPARATOR_ID, COMP_ASRCP_REF);
//
// Set the initial internal reference voltage generator value to the first
// in the list of values to use.
//
ComparatorRefSet(COMP_BASE, g_pulCompLevels[0]);
//
// Configure the UART.
//
UARTConfigSet(UART0_BASE, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//
// Initialize the peripheral device controller/LCD.
//
PDCInit();
PDCLCDInit();
PDCLCDBacklightOn();
//
// Create new character glyphs for the LMI logo. The glyphs are as
// follows:
//
// ...XX ..XXX XXX.. .....
// ...XX ..XXX XXXXX .....
// ...XX ..XX. .XXXX .....
// ...XX ..XX. .XX.. X....
// ...XX ..XX. .XX.. X....
// ...XX ..XX. .XX.. XX...
// ...XX ..XX. .XX.. XX...
// ...XX ..XX. .XX.. XX...
//
// ...XX ..XX. .XX.. XX...
// ...XX ..XX. .XX.. XX...
// ...XX ...X. .XX.. XX...
// ....X ...X. .XX.. XX...
// ....X ..... ..... XX...
// ..... XX... ..... XX...
// ..... XXXXX XXXXX XX...
// ..... ..XXX XXXXX XX...
//
PDCLCDCreateChar(0, "\003\003\003\003\003\003\003\003");
PDCLCDCreateChar(1, "\007\007\006\006\006\006\006\006");
PDCLCDCreateChar(2, "\034\037\017\014\014\014\014\014");
PDCLCDCreateChar(3, "\000\000\000\020\020\030\030\030");
PDCLCDCreateChar(4, "\003\003\003\001\001\000\000\000");
PDCLCDCreateChar(5, "\006\006\002\002\000\030\037\007");
PDCLCDCreateChar(6, "\014\014\014\014\000\000\037\037");
PDCLCDCreateChar(7, "\030\030\030\030\030\030\030\030");
//
// Write the splash screen to the LCD.
//
PDCLCDSetPos(0, 0);
PDCLCDWrite(" \000\001\002\003 Luminary", 14);
PDCLCDSetPos(0, 1);
PDCLCDWrite(" \004\005\006\007 Micro", 11);
//
// Delay for five seconds while the splash screen is displayed.
//
for(ulCount = 0; ulCount < (100 * 5); ulCount++)
{
//
// Wait until a SysTick interrupt has occurred.
//
while(!HWREGBITW(&g_ulFlags, FLAG_SYSTICK))
{
}
//
// Clear the SysTick interrupt flag.
//
HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 0;
}
//
// Clear the screen and write the main display.
//
PDCLCDClear();
PDCLCDSetPos(0, 0);
PDCLCDWrite("Turn the Pot -->", 16);
PDCLCDSetPos(0, 1);
PDCLCDWrite("Value:", 6);
//
// Set the global variables to their initial state. The click rate
// defaults to the slowest rate and the piezo is not muted.
//
g_ulCompIdx = 0;
g_ulCompAccum = 0;
g_ulPotSetting = 0;
g_ulClickRate = 48;
g_ulClickRateCount = 48;
HWREGBITW(&g_ulFlags, FLAG_UNMUTE) = 1;
//
// Loop forever while the LED tracks the comparator value.
//
while(1)
{
//
// See if there is a new potentiometer result.
//
if(HWREGBITW(&g_ulFlags, FLAG_RESULTS))
{
//
// Put the new pot value into the string for the LCD.
//
if(g_ulPotSetting > 9)
{
pcBuffer[0] = '1';
}
else
{
pcBuffer[0] = ' ';
}
pcBuffer[1] = '0' + (g_ulPotSetting % 10);
//
// Write the new pot value to the UART.
//
UARTCharPut(UART0_BASE, pcBuffer[0]);
UARTCharPut(UART0_BASE, pcBuffer[1]);
UARTCharPut(UART0_BASE, '\r');
UARTCharPut(UART0_BASE, '\n');
//
// Write the string to the LCD.
//
PDCLCDSetPos(7, 1);
PDCLCDWrite(pcBuffer, 2);
//
// Clear the flag indicating a new result.
//
HWREGBITW(&g_ulFlags, 1) = 0;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -