?? qs_dk-lm3s102.c
字號:
//*****************************************************************************
//
// qs_dk-lm3s102.c - A quick start sample application to demo chip features
//
// Copyright (c) 2006 Luminary Micro, Inc. All rights reserved.
//
// Software License Agreement
//
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
// exclusively on LMI's Stellaris Family of microcontroller products.
//
// The software is owned by LMI and/or its suppliers, and is protected under
// applicable copyright laws. All rights are reserved. Any use in violation
// of the foregoing restrictions may subject the user to criminal sanctions
// under applicable laws, as well as to civil liability for the breach of the
// terms and conditions of this license.
//
// THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 920 of the Stellaris Driver Library.
//
//*****************************************************************************
#include "../../hw_memmap.h"
#include "../../hw_types.h"
#include "../../src/comp.h"
#include "../../src/debug.h"
#include "../../src/gpio.h"
#include "../../src/interrupt.h"
#include "../../src/sysctl.h"
#include "../../src/systick.h"
#include "../../src/pwm.h"
#include "../../src/adc.h"
#include "../../src/uart.h"
#include "../pdc.h"
//*****************************************************************************
//
// Define I/O configuration.
//
//*****************************************************************************
#define COMPARATOR_ID 0
#define GPIO_PIN_MUTE GPIO_PIN_5
//*****************************************************************************
//
//! \addtogroup dk_lm3sxxx_list
//! <h1>DK-LM3S102 Quickstart Application (qs_dk-lm3s102)</h1>
//!
//! This example uses the photocell on the development board to create a geiger
//! counter for visible light. In bright light, the click rate (i.e. the
//! count) increases; in low light it decreases. The light reading is also
//! displayed on the LCD, and a log of the readings is output on the UART at
//! 115,200, 8-n-1. The push button can be used to turn off the clicking noise
//! on and off; when off the LCD and UART still provide the light reading.
//!
//! In the default jumper configuration of the development board, this example
//! actually samples the potentiometer and the push button will not work. In
//! order for this example to fully work, the following jumper wire connections
//! must be made: JP3 pin 1 to JP5 pin 2 (requiring the removal of the jumper
//! on JP5) and JP19 pin 2 to J6 pin 6.
//
//*****************************************************************************
//*****************************************************************************
//
// The voltage levels of the internal voltage reference to use for comparison
// to the photocell input.
//
//*****************************************************************************
static const unsigned long g_pulCompLevels[] =
{
COMP_REF_0_1375V, COMP_REF_0_275V, COMP_REF_0_4125V, COMP_REF_0_55V,
COMP_REF_0_6875V, COMP_REF_0_825V, COMP_REF_0_9625V, COMP_REF_1_1V,
COMP_REF_1_2375V, COMP_REF_1_375V, COMP_REF_1_5125V, COMP_REF_1_65V,
COMP_REF_1_7875V, COMP_REF_1_925V, COMP_REF_2_0625V
};
//*****************************************************************************
//
// The current index into the internal voltage reference array.
//
//*****************************************************************************
static unsigned long g_ulCompIdx;
//*****************************************************************************
//
// The current accumulation of results from the comparator.
//
//*****************************************************************************
static unsigned long g_ulCompAccum;
//*****************************************************************************
//
// The most recent setting of the potentiometer.
//
//*****************************************************************************
static unsigned long g_ulPotSetting;
//*****************************************************************************
//
// The number of SysTick counts between clicks of the piezo.
//
//*****************************************************************************
static unsigned long g_ulClickRate;
//*****************************************************************************
//
// Counts SysTick events. Used to determine when the piezo should make a
// sound.
//
//*****************************************************************************
static unsigned long g_ulClickRateCount;
//*****************************************************************************
//
// The counter of the number of consecutive times that the push button has a
// value different than the currently debounced state.
//
//*****************************************************************************
static unsigned long g_ulDebounceCounter;
//*****************************************************************************
//
// A set of flags. The flag bits are defined as follows:
//
// 0 -> The mute flag; when clear, the piezo will not be clicked and the
// comparator results will only be available on the LCD and over the
// UART. When set, the piezo will click.
// 1 -> An indicator from the SysTick interrupt handler to the main code
// that new comparator results are available.
// 2 -> The current debounced state of the push button.
// 3 -> An indicator that a SysTick interrupt has occurred.
//
//*****************************************************************************
#define FLAG_UNMUTE 0
#define FLAG_RESULTS 1
#define FLAG_BUTTON 2
#define FLAG_SYSTICK 3
static volatile unsigned long g_ulFlags;
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
//*****************************************************************************
//
// The interrupt handler for the SysTick interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
//
// Indicate that a SysTick interrupt has occurred.
//
HWREGBITW(&g_ulFlags, FLAG_SYSTICK) = 1;
//
// Determine the tick rate. Get the current comparator value. Increment
// the accumulator if it is one.
//
if(ComparatorValueGet(COMP_BASE, COMPARATOR_ID))
{
g_ulCompAccum++;
}
//
// Increment the internal reference voltage array index and see if the end
// has been reached.
//
g_ulCompIdx++;
if(g_ulCompIdx == (sizeof(g_pulCompLevels) / sizeof(g_pulCompLevels[0])))
{
//
// Go back to the beginning of the array.
//
g_ulCompIdx = 0;
//
// Save the comparison results and reset the accumulator.
//
g_ulPotSetting = g_ulCompAccum;
g_ulCompAccum = 0;
//
// Set the bit in g_ulFlags indicating that new results are available.
//
HWREGBITW(&g_ulFlags, FLAG_RESULTS) = 1;
//
// Compute the new rate at which to click the piezo.
//
g_ulClickRate = ((15 - g_ulPotSetting) + 3) * 5;
//
// If the current count is greater than the click rate then set the
// count to the click rate so that the click will happen sooner.
//
if(g_ulClickRateCount > g_ulClickRate)
{
g_ulClickRateCount = g_ulClickRate;
}
}
//
// Set the internal reference voltage to the next comparison value.
//
ComparatorRefSet(COMP_BASE, g_pulCompLevels[g_ulCompIdx]);
//
// Determine if the piezo should be muted. See if the push button is in a
// different state than the currently debounced state.
//
if((GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_MUTE) ? 1 : 0) !=
HWREGBITW(&g_ulFlags, FLAG_BUTTON))
{
//
// Increment the number of counts with the push button in a different
// state.
//
g_ulDebounceCounter++;
//
// If four consecutive counts have had the push button in a different
// state then the state has changed.
//
if(g_ulDebounceCounter == 4)
{
//
// Toggle the debounced state of the push button.
//
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.
//
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -