亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? switches.c

?? eaayarm101自制小車源代碼 周立功公司原創
?? C
字號:
//*****************************************************************************
//
// switches.c - Code for the push button.
//
// Copyright (c) 2005-2007 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 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 199 of an01245.
//
//*****************************************************************************

#include "../../hw_gpio.h"
#include "../../hw_memmap.h"
#include "../../hw_nvic.h"
#include "../../hw_types.h"
#include "car.h"
#include "compiler.h"
#include "switches.h"
#include "system.h"

//*****************************************************************************
//
//! \page switches_intro Introduction
//!
//! There is a single momentary push button switch on the car that is used to
//! provide basic control of the car's operation.  The switch does not have any
//! hardware debouncing (such as an RC low pass filter), so it is the
//! responsibility of software to provide debouncing of the switch input.
//!
//! Debouncing is accomplished by sampling the switch at a relatively fast rate
//! (relative to a human's ability to press and release the button).  The
//! sampled state of the switch must match for four consecutive samples before
//! it is assumed to be in the given state.  So, as the switch bounces due to a
//! press or release, it it not sampled in the same state and therefore the
//! bouncing is ignored.
//!
//! The code for handling the switches is contained in <tt>switches.c</tt>,
//! with <tt>switches.h</tt> containing the API definitions for use by the
//! remainder of the application.
//
//*****************************************************************************

//*****************************************************************************
//
//! \defgroup switches_api Definitions
//! @{
//
//*****************************************************************************

//*****************************************************************************
//
//! The GPIO port that contains the pin to which the push button is connected.
//
//*****************************************************************************
#define PUSH_BUTTON_PORT        GPIO_PORTC_BASE

//*****************************************************************************
//
//! The GPIO pin to which the push button is connected.
//
//*****************************************************************************
#define PUSH_BUTTON             (1 << 4)

//*****************************************************************************
//
//! The debounced state of the switch(es).  There is only one switch on the
//! car, so only bit zero it utilized.
//
//*****************************************************************************
ZERO_INIT unsigned long g_ulSwitches;

//*****************************************************************************
//
//! This structure describes the state of the switch debouncer.  The debouncre
//! uses four consecutive samples with the switch in the non-debounced state
//! to detect a change in the state of the switch.  This structure and
//! algorithm allows up to eight switches to be debounced in parallel, though
//! only one is utilized by the car.
//
//*****************************************************************************
typedef struct
{
    //
    //! This is the low order bit of the clock used to count the number of
    //! samples with the switch in the non-debounced state.
    //
    unsigned char ucClockA;

    //
    //! This is the high order bit of the clock used to count the number of
    //! samples with the switch in the non-debounced state.
    //
    unsigned char ucClockB;

    //
    //! This is the count of the number of samples during which the switch has
    //! been pressed; it is used to distinguish a button press from a button
    //! hold.
    //
    unsigned short usCount;
}
tSwitchState;

//*****************************************************************************
//
//! The current state of the switch debouncer.
//
//*****************************************************************************
static ZERO_INIT tSwitchState g_sSwitchState;

//*****************************************************************************
//
//! Handles the SysTick interrupt.
//!
//! This fucntion is called when SysTick generates an interrupt.  The state of
//! the push button will be sampled, debounced, and the appropriate action
//! taken when required.
//!
//! Pressing the button will call the CarStop() function on the button press
//! and the CarRun() function in the button release.  Holding the button for an
//! extended period of time (controlled by #DIAG_HOLD_TIME) will call the
//! CarDiagnostic() function when the timeout period expires (and therefore
//! CarRun() is not called).
//!
//! On every SysTick interrupt, the CarTick() function is called to allow the
//! car to make decisions about how to proceed.
//!
//! \return None.
//
//*****************************************************************************
void
SysTickHandler(void)
{
    unsigned char ucValue, ucDelta;

    //
    // Read the current switch input value.
    //
    ucValue = HWREG(PUSH_BUTTON_PORT + GPIO_O_DATA + (PUSH_BUTTON << 2));

    //
    // Determine the switches that are at a different state than the debounced
    // state.
    //
    ucDelta = ucValue ^ (g_ulSwitches & 0xff);

    //
    // Increment the clocks by one.
    //
    g_sSwitchState.ucClockA ^= g_sSwitchState.ucClockB;
    g_sSwitchState.ucClockB = ~g_sSwitchState.ucClockB;

    //
    // Reset the clocks corresponding to switches that have not changed state.
    //
    g_sSwitchState.ucClockA &= ucDelta;
    g_sSwitchState.ucClockB &= ucDelta;

    //
    // Get the new debounced switch state.
    //
    g_ulSwitches &= (g_sSwitchState.ucClockA | g_sSwitchState.ucClockB);
    g_ulSwitches |= ((~(g_sSwitchState.ucClockA | g_sSwitchState.ucClockB)) &
                     ucValue);

    //
    // Determine the switches that just changed debounced state.
    //
    ucDelta ^= (g_sSwitchState.ucClockA | g_sSwitchState.ucClockB);

    //
    // See if the push button just changed state.
    //
    if(ucDelta & PUSH_BUTTON)
    {
        //
        // See if the push button was just pressed or released.
        //
        if(!(g_ulSwitches & PUSH_BUTTON))
        {
            //
            // The button was just pressed, so reset the hold time counter.
            //
            g_sSwitchState.usCount = 0;

            //
            // If currently in run mode, switch to stop mode immediately.
            //
            CarStop();
        }
        else
        {
            //
            // The button was just released, so see if it was held less than
            // the diag mode hold time.
            //
            if(g_sSwitchState.usCount < (DIAG_HOLD_TIME * SYSTICK_CLOCK))
            {
                //
                // If currently in stop mode, switch to run mode.
                //
                CarRun();
            }
        }
    }

    //
    // See if the push button is currently pressed.
    //
    if(!(g_ulSwitches & PUSH_BUTTON))
    {
        //
        // Increment the hold counter if it is not maxed out.
        //
        if(g_sSwitchState.usCount < 65535)
        {
            g_sSwitchState.usCount++;
        }

        //
        // See if the button has pressed for 5 seconds.
        //
        if(g_sSwitchState.usCount == (DIAG_HOLD_TIME * SYSTICK_CLOCK))
        {
            //
            // Switch to diag mode.
            //
            CarDiagnostic();
        }
    }

    //
    // Call the car's tick handler.
    //
    CarTick();
}

//*****************************************************************************
//
//! Configures the switch input.
//!
//! This function prepares the push button switch for normal operation.  The
//! corresponding pin is configured as an input and the SysTick counter is
//! configured to generate periodic interrupts.
//!
//! The default debounced state of the switch is taken to be the state of the
//! switch during initialization.  If the switch is being pressed or released
//! during initialization, the default debounced state may end up incorrect.
//! In this case, the debouncing of the switch will quickly rectify the
//! situation, though a spurious press or release event may result.
//!
//! \return None.
//
//*****************************************************************************
void
SwitchesInit(void)
{
    //
    // Make the push button pin be an input.
    //
    HWREG(PUSH_BUTTON_PORT + GPIO_O_DIR) &= ~(PUSH_BUTTON);

    //
    // Read the current switch input values.  This becomes the default
    // debounced switch state.
    //
    g_ulSwitches = HWREG(PUSH_BUTTON_PORT + GPIO_O_DATA + (PUSH_BUTTON << 2));

    //
    // Setup SysTick to interrupt at the appropriate rate.
    //
    HWREG(NVIC_ST_RELOAD) = (SYSTEM_CLOCK / SYSTICK_CLOCK) - 1;
    HWREG(NVIC_ST_CTRL) = (NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_INTEN |
                           NVIC_ST_CTRL_ENABLE);
}

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区中文字幕电影| 91亚洲大成网污www| 国产成人综合在线观看| 91一区二区三区在线观看| 欧美精品在线一区二区三区| 久久精品日产第一区二区三区高清版 | 久久久影视传媒| 亚洲国产视频在线| 国产盗摄女厕一区二区三区| 欧美美女直播网站| 国产三级一区二区| 婷婷久久综合九色国产成人 | 日韩制服丝袜先锋影音| 成人久久18免费网站麻豆 | 亚洲444eee在线观看| 国产成人8x视频一区二区| 欧美日韩一级二级三级| 国产精品美女久久福利网站| 免费观看成人av| 欧美日韩视频在线第一区 | 九九精品视频在线看| 欧美在线高清视频| 日韩码欧中文字| 国产成人在线视频网址| 日韩免费观看2025年上映的电影| 亚洲精品伦理在线| a级高清视频欧美日韩| 欧美精品一区男女天堂| 男男gaygay亚洲| 欧美精三区欧美精三区| 亚洲已满18点击进入久久| www.99精品| 国产精品情趣视频| 欧美三级在线播放| 亚洲乱码一区二区三区在线观看| 国产成人免费9x9x人网站视频| 精品理论电影在线| 美女尤物国产一区| 日韩视频一区在线观看| 日韩电影免费一区| 欧美一级久久久| 亚洲成av人**亚洲成av**| 欧洲精品中文字幕| 亚洲成在线观看| 7777女厕盗摄久久久| 亚洲444eee在线观看| 欧美人妖巨大在线| 免费在线成人网| 精品国产一区二区三区久久久蜜月 | 国产麻豆成人传媒免费观看| 久久精品人人做| 国产91精品精华液一区二区三区 | 亚洲国产欧美在线人成| 欧美日韩久久久| 日韩高清一区在线| 精品精品国产高清a毛片牛牛| 老司机精品视频在线| 国产亚洲污的网站| 99在线热播精品免费| 亚洲精品国产视频| 91麻豆精品国产91久久久久 | 91精品国产综合久久福利软件| 日韩电影在线一区二区三区| 欧美成人福利视频| 丁香六月综合激情| 亚洲国产综合人成综合网站| 在线不卡一区二区| 国产乱子伦一区二区三区国色天香| 国产欧美日韩一区二区三区在线观看| 成人av一区二区三区| 一区二区三区资源| 欧美电影免费观看高清完整版在| 国产精品羞羞答答xxdd| 一区二区日韩av| 久久视频一区二区| 色婷婷av一区二区三区大白胸 | 91蜜桃婷婷狠狠久久综合9色| 亚洲午夜在线视频| 欧美高清在线视频| 欧美区一区二区三区| 成人久久视频在线观看| 手机精品视频在线观看| 国产精品久久久久婷婷二区次| 欧美日韩专区在线| 国产麻豆91精品| 亚洲一区二区在线观看视频| 久久在线免费观看| 在线视频一区二区三| 国产91色综合久久免费分享| 视频一区视频二区在线观看| 国产精品三级视频| 日韩一区二区免费在线观看| 91在线国产观看| 精品一区二区三区蜜桃| 亚洲午夜久久久久| 亚洲国产精品传媒在线观看| 欧美一区二区久久久| 99久久婷婷国产综合精品电影| 麻豆成人91精品二区三区| 亚洲精品乱码久久久久久| 国产亚洲一区二区三区| 日韩欧美亚洲国产精品字幕久久久| 91视频国产观看| 风流少妇一区二区| 理论电影国产精品| 日韩精品亚洲一区| 亚洲激情在线激情| 中文字幕一区二区在线播放| 久久精品视频一区| 26uuu亚洲| 精品国产青草久久久久福利| 91精品国产福利在线观看| 欧美视频一区二区三区四区| 色中色一区二区| 日本高清不卡视频| 一本一本久久a久久精品综合麻豆| 国产成人在线免费观看| 国产精品18久久久久久久久| 国产精一区二区三区| 国产麻豆视频精品| 国产91丝袜在线播放九色| 国产成人精品影院| av在线这里只有精品| www.亚洲精品| 91麻豆精品秘密| 欧美伊人精品成人久久综合97 | 欧美网站一区二区| 97se亚洲国产综合自在线| 成人av免费观看| 粉嫩在线一区二区三区视频| 国产真实乱偷精品视频免| 日韩av电影天堂| 狠狠色丁香婷综合久久| 日本欧美肥老太交大片| 日一区二区三区| 天天色天天操综合| 精品在线播放免费| 精品制服美女丁香| 美女视频黄a大片欧美| 日韩国产一区二| 视频一区国产视频| 全国精品久久少妇| 日本视频免费一区| 麻豆精品在线播放| 蜜桃久久av一区| 国产91精品露脸国语对白| 成人高清视频在线| 99久久99久久久精品齐齐| 极品少妇xxxx偷拍精品少妇| 成人免费毛片app| 色综合天天综合网天天狠天天| 成人免费av资源| 色婷婷av一区| 欧美亚一区二区| 精品福利视频一区二区三区| 久久久午夜精品| 亚洲欧美综合色| 亚洲综合色视频| 国内一区二区在线| 成人性生交大片免费看在线播放| 成人app软件下载大全免费| 91在线视频免费观看| 日韩视频免费观看高清完整版在线观看 | 一区二区三区中文在线观看| 亚洲曰韩产成在线| 日韩精品国产精品| 国产一区二区导航在线播放| 精彩视频一区二区三区| 色天天综合久久久久综合片| 欧美日韩在线不卡| 亚洲精品一区二区精华| 中文字幕第一页久久| 奇米色一区二区| 高清成人免费视频| 色婷婷综合久色| 337p粉嫩大胆噜噜噜噜噜91av| 一区二区三区高清在线| 激情综合网激情| 99国产精品久久久久| 欧美三级欧美一级| 久久色.com| 蜜桃一区二区三区四区| av午夜一区麻豆| 欧美大片一区二区| 国产精品国模大尺度视频| 国内外成人在线视频| eeuss国产一区二区三区| 日本高清成人免费播放| 久久久久久久久99精品| 亚洲国产人成综合网站| 色国产综合视频| 久久久国际精品| 日本麻豆一区二区三区视频| jlzzjlzz国产精品久久| 日本一区二区三区免费乱视频| 日韩精品一级二级| 色婷婷av一区二区三区软件| 久久精品人人做人人综合| 国产一区二区三区四区五区美女| 欧美日韩一区精品|