?? switch_wait_timeoutl.c
字號:
/*--------------------------------------------------------------------*-
Switch_Wait_TimeoutL.C(v1.00)
----------------------------------------------------------------------
Simple library for processing a switch input
(Made more reliable by means of a ~10-second timeout)
-*------------------------------------------------------------------*/
#include "Main.H"
#include "Port.H"
#include "Switch_Wait_TimeoutL.H"
#include "Delay_T0.H"
#include "TimeoutL.H"
/*------------------------------------------------------------------*-
SWITCH_Init()
Initialisation function for the switch library
-*-----------------------------------------------------------------*/
void SWITCH_Init(void){
Switch_pin = 1 ; //Use this pin for input
}
/*------------------------------------------------------------------*-
SWITCH_Get_Input()
Reads and debounces a mechanical switch as follows:
1.If switch is not pressed ,return SWITCH_NOT_PRESSED
2.If switch is pressed,wait for DEBOUNCE_PERIOD (in ms)
a. If switch is not pressed ,return SWITCH_NOT_PRESSED
b. If switch is pressed,wait(with timeout) for switch to be released.If it
times out ,then return SWITCH_NOT_PRESSED ; otherwise ,return SWITCH_PRESSED
See Switch_Wait.H for details of return values;
-*-------------------------------------------------------------------*/
bit SWITCH_Get_Input(const tByte DEBOUNCE_PERIOD){
tByte Return_value= SWITCH_NOT_PRESSED;
tLong Timeout_loop= LOOP_TIMEOUT_INIT_10000ms;
if(Switch_pin == 0){
//Switch is pressed
//Debounce - just wait
Delay_T0_Wait(DEBOUNCE_PERIOD);
//Check switch again
if(Switch_pin ==0 ){
//Wait until the switch is released
//(With TIMEOUT LOOP - 10 seconds)
while((Switch_pin == 0) && (++Timeout_loop != 0));
//Check for timeout
if (Timeout_loop == 0)
Return_value = SWITCH_NOT_PRESSED;
else
Return_value = SWITCH_PRESSED;
}
}
//Now finally return switch value
return Return_value;
}
/*-----------------------------------------------------------------*-
---------------------END OF FILE -----------------------------------
-*-------------------------------------------------------------------*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -