?? dpswtch4.c
字號:
/* File: DPSWTCH4.C */
/****************************************************************************
*
* STK16X.DPSWTCH4
* ===============
*
* Low level routines for reading DIP switch state (digital input)
*
* TQ-Systems GmbH
* ----------------
* Customer: TQ-Components
* Project : STK16XSW
* Tools : uVision 2.05
*
* Rev: Date: Name: Modification:
* ----+---------+----------------+------------------------------------------
* 100 19.01.01 A. Lichte taken over from STK16X.506
*****************************************************************************/
/****************************************************************************
*
* availability summary
*
* available for Starterkit: STK16X STK16XU
* conformed for Starterkit: STK16X STK16XU
* available for Modul : TQM164 TQM165 TQM165U TQM166 TQM167
* TQM167UL TQM167U TQM167LC
*
* conformed for Modul : TQM164 TQM165 TQM165U TQM166 TQM167
* TQM167UL TQM167U TQM167LC
*****************************************************************************/
/*==========================================================================*
* include files (#INCLUDE):
*===========================================================================*/
/*--------------------------------------------------------------------------*
* standard include files:
*---------------------------------------------------------------------------*/
#include <reg167.h> /* special function register */
/*--------------------------------------------------------------------------*
* project specific include files:
*---------------------------------------------------------------------------*/
#include "dpswtch4.h" /* DIP switch functions */
/*==========================================================================*
* module internal definitions (#DEFINE):
*===========================================================================*/
/*==========================================================================*
* module internal type declarations (TYPEDEF):
*===========================================================================*/
/*==========================================================================*
* module internal constants (CONST):
*===========================================================================*/
/*==========================================================================*
* extern available constants (CONST):
*===========================================================================*/
/*==========================================================================*
* modul internal variables:
*===========================================================================*/
/*--------------------------------------------------------------------------*
* SWITCH control lines:
*---------------------------------------------------------------------------*/
sbit sw_1 = SW_1;
sbit sw_1_dir = SW_1_DIR;
sbit sw_2 = SW_2;
sbit sw_2_dir = SW_2_DIR;
sbit sw_3 = SW_3;
sbit sw_3_dir = SW_3_DIR;
sbit sw_4 = SW_4;
sbit sw_4_dir = SW_4_DIR;
/*==========================================================================*
* globale external available variables (EXTERN):
*===========================================================================*/
/*==========================================================================*
* modul internal functions:
*===========================================================================*/
/*--------------------------------------------------------------------------*
* void dpswtch4_init()
*---------------------------------------------------------------------------*
* FT: init port 2 for reading DIP switch
* EP: -
* RW: -
* GP: SW_DIR_IN, sw_1_dir, sw_2_dir, sw_3_dir ,sw_4_dir
*---------------------------------------------------------------------------*/
void dpswtch4_init()
{
/* set port pins as inputs for reading DIP switch: */
sw_1_dir = SW_DIR_IN;
sw_2_dir = SW_DIR_IN;
sw_3_dir = SW_DIR_IN;
sw_4_dir = SW_DIR_IN;
}
/*--------------------------------------------------------------------------*
* BYTE dpswtch4_read()
*---------------------------------------------------------------------------*
* FT: read state of DIP switch
* EP: -
* RW: state of DIP switch: SWITCH 1 = Bit 0
* SWITCH 2 = Bit 1
* SWITCH 3 = Bit 2
* SWITCH 4 0 Bit 3
* GP: sw_1, sw_2, sw_3, sw_4
*---------------------------------------------------------------------------*/
BYTE dpswtch4_read()
{ BYTE state;
state = 0x00 | sw_4; /* save state of SWITCH 4 */
state = (state << 1) | sw_3; /* save state of SWITCH 3 */
state = (state << 1) | sw_2; /* save state of SWITCH 2 */
state = (state << 1) | sw_1; /* save state of SWITCH 1 */
return(state);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -