⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qs_dk-lm3s811.c

📁 Stellaris公司推出1美元ARM,这是Stellaris驱动库源程序
💻 C
📖 第 1 页 / 共 2 页
字号:
            HWREGBITW(&g_ulFlags, FLAG_BUTTON) ^= 1;

            //
            // If the push button was just pushed, then toggle the mute flag.
            //
            if(!HWREGBITW(&g_ulFlags, FLAG_BUTTON))
            {
                //
                // Toggle the mute flag.
                //
                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 10 then the piezo needs to be turned on.
    //
    if(g_ulClickRateCount == 10)
    {
        //
        // Set the PWM period according to the desired tone frequency.  The
        // pulse width is set to half to give 50% duty cycle.  Only turn it on
        // if unmuted.
        //
        if(HWREGBITW(&g_ulFlags, FLAG_UNMUTE))
        {
            PWMGenPeriodSet(PWM_BASE, PWM_GEN_1,
                            g_ulSystemClock / g_ulToneFreq);
            PWMPulseWidthSet(PWM_BASE, PWM_OUT_2,
                             (g_ulSystemClock / 2) / g_ulToneFreq);

            //
            // Enable the PWM output so the tone will sound.
            //
            PWMOutputState(PWM_BASE, PWM_OUT_2_BIT, true);
        }
    }

    //
    // If the count is zero then the tone needs to be turned off.
    //
    if(g_ulClickRateCount == 0)
    {
        //
        // Turn off the PWM output.
        //
        PWMOutputState(PWM_BASE, PWM_OUT_2_BIT, false);

        //
        // 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);
    g_ulSystemClock = SysCtlClockGet();

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_COMP0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC);
    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 B0 as peripheral function PWM2 for output to piezo buzzer.
    //
    GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_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]);

    //
    // ADC0 is used for light sensor input.  Configure it to use sequence 0,
    // take one sample and stop.
    //
    ADCSequenceConfigure(ADC_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC_BASE, 0, 0, ADC_CTL_CH0 | ADC_CTL_END);
    ADCSequenceEnable(ADC_BASE, 0);

    //
    // Trigger the initial acquisition, so that a result will be available.
    //
    ADCProcessorTrigger(ADC_BASE, 0);

    //
    // Configure and enable the PWM generator.
    //
    PWMGenConfigure(PWM_BASE, PWM_GEN_1,
                    PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
    PWMGenEnable(PWM_BASE, PWM_GEN_1);

    //
    // 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);

            //
            // Add the note name to the string.
            //
            pcBuffer[2] = ' ';
            pcBuffer[3] = g_chNote;

            //
            // Write the new pot value to the UART.
            //
            UARTCharPut(UART0_BASE, pcBuffer[0]);
            UARTCharPut(UART0_BASE, pcBuffer[1]);
            UARTCharPut(UART0_BASE, pcBuffer[2]);
            UARTCharPut(UART0_BASE, pcBuffer[3]);
            UARTCharPut(UART0_BASE, '\r');
            UARTCharPut(UART0_BASE, '\n');

            //
            // Write the string to the LCD.
            //
            PDCLCDSetPos(7, 1);
            PDCLCDWrite(pcBuffer, 4);

            //
            // Clear the flag indicating a new result.
            //
            HWREGBITW(&g_ulFlags, 1) = 0;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -