T218电容触摸
单片机源程序如下:
- //=============================================================================
- // Touch.c
- //-----------------------------------------------------------------------------
- // Copyright (C) 2016. ABOV Semiconductor Limited, All rights reserved.
- //-----------------------------------------------------------------------------
- // Program Description:
- //
- // Source file for Touch key firmware.
- //
- //-----------------------------------------------------------------------------
- // Target: A96T218_EFT
- // Tool chain: Keil C51 V8.05a
- // ABOV Semiconductor T/M8051 OCD debugger(MCS51_OCD_FX2(FT083))
- //
- // Project Name: A96T218_EFT
- //
- //-----------------------------------------------------------------------------
- // Release 1.0
- //
- //=============================================================================
- #include <intrins.h>
- #include <math.h>
- #include <limits.h>
- #include "T218App.h"
- #include "Debug.h"
- #include "A96T218.h"
- #include "Touch.h"
- #include "LEDSegment.h"
- #include "Timer.h"
- #include "Buzzer.h"
- #ifdef TUNING_MODE
- #include "Tuner.h"
- #endif
- //=============================================================================
- //=============================================================================
- unsigned int noiseHold;
- unsigned int TouchedCnt;
- unsigned char Max1stIndex;
- unsigned char StartUpFlg;
- tc_state state;
- __TOUCH_VAR TD;
- //=============================================================================
- unsigned char xdata mActivKey;
- unsigned char xdata TouchTmpFlg;
- //==============================================================================
- // Enable Touch Port
- //==============================================================================
- unsigned char SKO;
- //=============================================================================
- //=============================================================================
- unsigned int code TouchThLow[] = {_KEY_TH_L00,_KEY_TH_L01,_KEY_TH_L02,_KEY_TH_L03,_KEY_TH_L04,_KEY_TH_L05,_KEY_TH_L06,_KEY_TH_L07,
- _KEY_TH_L08,_KEY_TH_L09,_KEY_TH_L10,_KEY_TH_L11,_KEY_TH_L12,_KEY_TH_L13,_KEY_TH_L14,_KEY_TH_L15,
- _KEY_TH_L16,_KEY_TH_L17,_KEY_TH_L18,_KEY_TH_L19,_KEY_TH_L20,_KEY_TH_L21,_KEY_TH_L22,_KEY_TH_L23};
-
- unsigned int code TouchThHigh[] = {_KEY_TH_H00,_KEY_TH_H01,_KEY_TH_H02,_KEY_TH_H03,_KEY_TH_H04,_KEY_TH_H05,_KEY_TH_H06,_KEY_TH_H07,
- _KEY_TH_H08,_KEY_TH_H09,_KEY_TH_H10,_KEY_TH_H11,_KEY_TH_H12,_KEY_TH_H13,_KEY_TH_H14,_KEY_TH_H15,
- _KEY_TH_H16,_KEY_TH_H17,_KEY_TH_H18,_KEY_TH_H19,_KEY_TH_H20,_KEY_TH_H21,_KEY_TH_H22,_KEY_TH_H23};
- unsigned int code TouchThRelease[] = {_KEY_TH_R00,_KEY_TH_R01,_KEY_TH_R02,_KEY_TH_R03,_KEY_TH_R04,_KEY_TH_R05,_KEY_TH_R06,_KEY_TH_R07,
- _KEY_TH_R08,_KEY_TH_R09,_KEY_TH_R10,_KEY_TH_R11,_KEY_TH_R12,_KEY_TH_R13,_KEY_TH_R14,_KEY_TH_R15,
- _KEY_TH_R16,_KEY_TH_R17,_KEY_TH_R18,_KEY_TH_R19,_KEY_TH_R20,_KEY_TH_R21,_KEY_TH_R22,_KEY_TH_R23};
-
- unsigned int code defaultNoiseTh[] = {_NOISE_TH_P00,_NOISE_TH_P01,_NOISE_TH_P02,_NOISE_TH_P03,_NOISE_TH_P04,_NOISE_TH_P05,_NOISE_TH_P06,_NOISE_TH_P07,
- _NOISE_TH_P08,_NOISE_TH_P09,_NOISE_TH_P10,_NOISE_TH_P11,_NOISE_TH_P12,_NOISE_TH_P13,_NOISE_TH_P14,_NOISE_TH_P15,
- _NOISE_TH_P16,_NOISE_TH_P17,_NOISE_TH_P18,_NOISE_TH_P19,_NOISE_TH_P20,_NOISE_TH_P21,_NOISE_TH_P22,_NOISE_TH_P23};
- unsigned char code DKSMRBit[24] = {_DKSMR_00,_DKSMR_01,_DKSMR_02,_DKSMR_03,_DKSMR_04,_DKSMR_05,_DKSMR_06,_DKSMR_07,
- _DKSMR_08,_DKSMR_09,_DKSMR_10,_DKSMR_11,_DKSMR_12,_DKSMR_13,_DKSMR_14,_DKSMR_15,
- _DKSMR_16,_DKSMR_17,_DKSMR_18,_DKSMR_19,_DKSMR_20,_DKSMR_21,_DKSMR_22,_DKSMR_23};
- unsigned char code DSetBit[24] = {_DSetBit_00,_DSetBit_01,_DSetBit_02,_DSetBit_03,_DSetBit_04,_DSetBit_05,_DSetBit_06,_DSetBit_07,
- _DSetBit_08,_DSetBit_09,_DSetBit_10,_DSetBit_11,_DSetBit_12,_DSetBit_13,_DSetBit_14,_DSetBit_15,
- _DSetBit_16,_DSetBit_17,_DSetBit_18,_DSetBit_19,_DSetBit_20,_DSetBit_21,_DSetBit_22,_DSetBit_23};
- unsigned char code DResetBit[24] = {_DResetBit_00,_DResetBit_01,_DResetBit_02,_DResetBit_03,_DResetBit_04,_DResetBit_05,_DResetBit_06,_DResetBit_07,
- _DResetBit_08,_DResetBit_09,_DResetBit_10,_DResetBit_11,_DResetBit_12,_DResetBit_13,_DResetBit_14,_DResetBit_15,
- _DResetBit_16,_DResetBit_17,_DResetBit_18,_DResetBit_19,_DResetBit_20,_DResetBit_21,_DResetBit_22,_DResetBit_23};
- unsigned char code DPortSel[24] = {_DPortSel_00,_DPortSel_01,_DPortSel_02,_DPortSel_03,_DPortSel_04,_DPortSel_05,_DPortSel_06,_DPortSel_07,
- _DPortSel_08,_DPortSel_09,_DPortSel_10,_DPortSel_11,_DPortSel_12,_DPortSel_13,_DPortSel_14,_DPortSel_15,
- _DPortSel_16,_DPortSel_17,_DPortSel_18,_DPortSel_19,_DPortSel_20,_DPortSel_21,_DPortSel_22,_DPortSel_23};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DVCAL[HOPP_MAX][24] = {{_DVCAL00_00,_DVCAL00_01,_DVCAL00_02,_DVCAL00_03,_DVCAL00_04,_DVCAL00_05,_DVCAL00_06,_DVCAL00_07,
- _DVCAL00_08,_DVCAL00_09,_DVCAL00_10,_DVCAL00_11,_DVCAL00_12,_DVCAL00_13,_DVCAL00_14,_DVCAL00_15,
- _DVCAL00_16,_DVCAL00_17,_DVCAL00_18,_DVCAL00_19,_DVCAL00_20,_DVCAL00_21,_DVCAL00_22,_DVCAL00_23},
- {_DVCAL01_00,_DVCAL01_01,_DVCAL01_02,_DVCAL01_03,_DVCAL01_04,_DVCAL01_05,_DVCAL01_06,_DVCAL01_07,
- _DVCAL01_08,_DVCAL01_09,_DVCAL01_10,_DVCAL01_11,_DVCAL01_12,_DVCAL01_13,_DVCAL01_14,_DVCAL01_15,
- _DVCAL01_16,_DVCAL01_17,_DVCAL01_18,_DVCAL01_19,_DVCAL01_20,_DVCAL01_21,_DVCAL01_22,_DVCAL01_23},
- {_DVCAL02_00,_DVCAL02_01,_DVCAL02_02,_DVCAL02_03,_DVCAL02_04,_DVCAL02_05,_DVCAL02_06,_DVCAL02_07,
- _DVCAL02_08,_DVCAL02_09,_DVCAL02_10,_DVCAL02_11,_DVCAL02_12,_DVCAL02_13,_DVCAL02_14,_DVCAL02_15,
- _DVCAL02_16,_DVCAL02_17,_DVCAL02_18,_DVCAL02_19,_DVCAL02_20,_DVCAL02_21,_DVCAL02_22,_DVCAL02_23}};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DNFS[HOPP_MAX][24] = {{_DNFS00_00,_DNFS00_01,_DNFS00_02,_DNFS00_03,_DNFS00_04,_DNFS00_05,_DNFS00_06,_DNFS00_07,
- _DNFS00_08,_DNFS00_09,_DNFS00_10,_DNFS00_11,_DNFS00_12,_DNFS00_13,_DNFS00_14,_DNFS00_15,
- _DNFS00_16,_DNFS00_17,_DNFS00_18,_DNFS00_19,_DNFS00_20,_DNFS00_21,_DNFS00_22,_DNFS00_23},
- {_DNFS01_00,_DNFS01_01,_DNFS01_02,_DNFS01_03,_DNFS01_04,_DNFS01_05,_DNFS01_06,_DNFS01_07,
- _DNFS01_08,_DNFS01_09,_DNFS01_10,_DNFS01_11,_DNFS01_12,_DNFS01_13,_DNFS01_14,_DNFS01_15,
- _DNFS01_16,_DNFS01_17,_DNFS01_18,_DNFS01_19,_DNFS01_20,_DNFS01_21,_DNFS01_22,_DNFS01_23},
- {_DNFS02_00,_DNFS02_01,_DNFS02_02,_DNFS02_03,_DNFS02_04,_DNFS02_05,_DNFS02_06,_DNFS02_07,
- _DNFS02_08,_DNFS02_09,_DNFS02_10,_DNFS02_11,_DNFS02_12,_DNFS02_13,_DNFS02_14,_DNFS02_15,
- _DNFS02_16,_DNFS02_17,_DNFS02_18,_DNFS02_19,_DNFS02_20,_DNFS02_21,_DNFS02_22,_DNFS02_23}};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DRSD[HOPP_MAX][24] = {{_DRSD00_00,_DRSD00_01,_DRSD00_02,_DRSD00_03,_DRSD00_04,_DRSD00_05,_DRSD00_06,_DRSD00_07,
- _DRSD00_08,_DRSD00_09,_DRSD00_10,_DRSD00_11,_DRSD00_12,_DRSD00_13,_DRSD00_14,_DRSD00_15,
- _DRSD00_16,_DRSD00_17,_DRSD00_18,_DRSD00_19,_DRSD00_20,_DRSD00_21,_DRSD00_22,_DRSD00_23},
- {_DRSD01_00,_DRSD01_01,_DRSD01_02,_DRSD01_03,_DRSD01_04,_DRSD01_05,_DRSD01_06,_DRSD01_07,
- _DRSD01_08,_DRSD01_09,_DRSD01_10,_DRSD01_11,_DRSD01_12,_DRSD01_13,_DRSD01_14,_DRSD01_15,
- _DRSD01_16,_DRSD01_17,_DRSD01_18,_DRSD01_19,_DRSD01_20,_DRSD01_21,_DRSD01_22,_DRSD01_23},
- {_DRSD02_00,_DRSD02_01,_DRSD02_02,_DRSD02_03,_DRSD02_04,_DRSD02_05,_DRSD02_06,_DRSD02_07,
- _DRSD02_08,_DRSD02_09,_DRSD02_10,_DRSD02_11,_DRSD02_12,_DRSD02_13,_DRSD02_14,_DRSD02_15,
- _DRSD02_16,_DRSD02_17,_DRSD02_18,_DRSD02_19,_DRSD02_20,_DRSD02_21,_DRSD02_22,_DRSD02_23}};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DCMPCTL[HOPP_MAX][24] = {{_DCMPCTL00_00,_DCMPCTL00_01,_DCMPCTL00_02,_DCMPCTL00_03,_DCMPCTL00_04,_DCMPCTL00_05,_DCMPCTL00_06,_DCMPCTL00_07,
- _DCMPCTL00_08,_DCMPCTL00_09,_DCMPCTL00_10,_DCMPCTL00_11,_DCMPCTL00_12,_DCMPCTL00_13,_DCMPCTL00_14,_DCMPCTL00_15,
- _DCMPCTL00_16,_DCMPCTL00_17,_DCMPCTL00_18,_DCMPCTL00_19,_DCMPCTL00_20,_DCMPCTL00_21,_DCMPCTL00_22,_DCMPCTL00_23},
- {_DCMPCTL01_00,_DCMPCTL01_01,_DCMPCTL01_02,_DCMPCTL01_03,_DCMPCTL01_04,_DCMPCTL01_05,_DCMPCTL01_06,_DCMPCTL01_07,
- _DCMPCTL01_08,_DCMPCTL01_09,_DCMPCTL01_10,_DCMPCTL01_11,_DCMPCTL01_12,_DCMPCTL01_13,_DCMPCTL01_14,_DCMPCTL01_15,
- _DCMPCTL01_16,_DCMPCTL01_17,_DCMPCTL01_18,_DCMPCTL01_19,_DCMPCTL01_20,_DCMPCTL01_21,_DCMPCTL01_22,_DCMPCTL01_23},
- {_DCMPCTL02_00,_DCMPCTL02_01,_DCMPCTL02_02,_DCMPCTL02_03,_DCMPCTL02_04,_DCMPCTL02_05,_DCMPCTL02_06,_DCMPCTL02_07,
- _DCMPCTL02_08,_DCMPCTL02_09,_DCMPCTL02_10,_DCMPCTL02_11,_DCMPCTL02_12,_DCMPCTL02_13,_DCMPCTL02_14,_DCMPCTL02_15,
- _DCMPCTL02_16,_DCMPCTL02_17,_DCMPCTL02_18,_DCMPCTL02_19,_DCMPCTL02_20,_DCMPCTL02_21,_DCMPCTL02_22,_DCMPCTL02_23}};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DTTDHL[HOPP_MAX][24] = {{_DTTDHL00_00,_DTTDHL00_01,_DTTDHL00_02,_DTTDHL00_03,_DTTDHL00_04,_DTTDHL00_05,_DTTDHL00_06,_DTTDHL00_07,
- _DTTDHL00_08,_DTTDHL00_09,_DTTDHL00_10,_DTTDHL00_11,_DTTDHL00_12,_DTTDHL00_13,_DTTDHL00_14,_DTTDHL00_15,
- _DTTDHL00_16,_DTTDHL00_17,_DTTDHL00_18,_DTTDHL00_19,_DTTDHL00_20,_DTTDHL00_21,_DTTDHL00_22,_DTTDHL00_23},
- {_DTTDHL01_00,_DTTDHL01_01,_DTTDHL01_02,_DTTDHL01_03,_DTTDHL01_04,_DTTDHL01_05,_DTTDHL01_06,_DTTDHL01_07,
- _DTTDHL01_08,_DTTDHL01_09,_DTTDHL01_10,_DTTDHL01_11,_DTTDHL01_12,_DTTDHL01_13,_DTTDHL01_14,_DTTDHL01_15,
- _DTTDHL01_16,_DTTDHL01_17,_DTTDHL01_18,_DTTDHL01_19,_DTTDHL01_20,_DTTDHL01_21,_DTTDHL01_22,_DTTDHL01_23},
- {_DTTDHL02_00,_DTTDHL02_01,_DTTDHL02_02,_DTTDHL02_03,_DTTDHL02_04,_DTTDHL02_05,_DTTDHL02_06,_DTTDHL02_07,
- _DTTDHL02_08,_DTTDHL02_09,_DTTDHL02_10,_DTTDHL02_11,_DTTDHL02_12,_DTTDHL02_13,_DTTDHL02_14,_DTTDHL02_15,
- _DTTDHL02_16,_DTTDHL02_17,_DTTDHL02_18,_DTTDHL02_19,_DTTDHL02_20,_DTTDHL02_21,_DTTDHL02_22,_DTTDHL02_23}};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DTTDHH[HOPP_MAX][24] = {{_DTTDHH00_00,_DTTDHH00_01,_DTTDHH00_02,_DTTDHH00_03,_DTTDHH00_04,_DTTDHH00_05,_DTTDHH00_06,_DTTDHH00_07,
- _DTTDHH00_08,_DTTDHH00_09,_DTTDHH00_10,_DTTDHH00_11,_DTTDHH00_12,_DTTDHH00_13,_DTTDHH00_14,_DTTDHH00_15,
- _DTTDHH00_16,_DTTDHH00_17,_DTTDHH00_18,_DTTDHH00_19,_DTTDHH00_20,_DTTDHH00_21,_DTTDHH00_22,_DTTDHH00_23},
- {_DTTDHH01_00,_DTTDHH01_01,_DTTDHH01_02,_DTTDHH01_03,_DTTDHH01_04,_DTTDHH01_05,_DTTDHH01_06,_DTTDHH01_07,
- _DTTDHH01_08,_DTTDHH01_09,_DTTDHH01_10,_DTTDHH01_11,_DTTDHH01_12,_DTTDHH01_13,_DTTDHH01_14,_DTTDHH01_15,
- _DTTDHH01_16,_DTTDHH01_17,_DTTDHH01_18,_DTTDHH01_19,_DTTDHH01_20,_DTTDHH01_21,_DTTDHH01_22,_DTTDHH01_23},
- {_DTTDHH02_00,_DTTDHH02_01,_DTTDHH02_02,_DTTDHH02_03,_DTTDHH02_04,_DTTDHH02_05,_DTTDHH02_06,_DTTDHH02_07,
- _DTTDHH02_08,_DTTDHH02_09,_DTTDHH02_10,_DTTDHH02_11,_DTTDHH02_12,_DTTDHH02_13,_DTTDHH02_14,_DTTDHH02_15,
- _DTTDHH02_16,_DTTDHH02_17,_DTTDHH02_18,_DTTDHH02_19,_DTTDHH02_20,_DTTDHH02_21,_DTTDHH02_22,_DTTDHH02_23}};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code DTTMR[HOPP_MAX] = {_DTTMR00,_DTTMR01,_DTTMR02};
- unsigned char code DTSCTL0[HOPP_MAX] = {_DTSCTL0_00,_DTSCTL0_01,_DTSCTL0_02};
- unsigned char code DTSCTL1[HOPP_MAX] = {_DTSCTL1_00,_DTSCTL1_01,_DTSCTL1_02};
- unsigned char code DFPCAL[HOPP_MAX] = {_DFPCAL00,_DFPCAL01,_DFPCAL02};
- unsigned char code DKSMR[HOPP_MAX] = {_DKSMR00,_DKSMR01,_DKSMR02};
- unsigned char code DCCAL[HOPP_MAX] = {_DCCAL00,_DCCAL01,_DCCAL02};
- unsigned char code DTTDLL[HOPP_MAX] = {_DTTDLL00,_DTTDLL01,_DTTDLL02};
- unsigned char code DTTDLH[HOPP_MAX] = {_DTTDLH00,_DTTDLH01,_DTTDLH02};
- //------------------------------------------------------------------------------------------------------------------------------------------
- unsigned char code ScanKeyOrder[] = {_DKEYOD_00,_DKEYOD_01,_DKEYOD_02,_DKEYOD_03,_DKEYOD_04,_DKEYOD_05,_DKEYOD_06,_DKEYOD_07,
- _DKEYOD_08,_DKEYOD_09,_DKEYOD_10,_DKEYOD_11,_DKEYOD_12,_DKEYOD_13,_DKEYOD_14,_DKEYOD_15,
- _DKEYOD_16,_DKEYOD_17,_DKEYOD_18,_DKEYOD_19,_DKEYOD_20,_DKEYOD_21,_DKEYOD_22,_DKEYOD_23};
- unsigned char code LEDEnBit[] = {0xFC,0xE7,0x33};
- //------------------------------------------------------------------------------------------------------------------------------------------
- //##############################################################################
- //##############################################################################
- // Initialization
- //##############################################################################
- //##############################################################################
- //==============================================================================
- //==============================================================================
- //==============================================================================
- // Enable Touch Port
- //==============================================================================
- unsigned char SelectChannel(void);
- void InitTouchPort(void)
- {
- #ifdef TUNING_MODE
- unsigned char ii;
- #endif
- //-------------------------------------------------------------------------
- //-------------------------------------------------------------------------
- mActivKey = TOUCHKEY;
- #ifdef TUNING_MODE
- for(ii = 0;ii < 24;ii++)TN.KeyAsign[ii] = _NOT_USE;
-
- for(ii = 0;ii < mActivKey;ii++)
- {
- TN.KeyAsign[ScanKeyOrder[ii]] = ii;
- }
- #endif
- }
- //#define tmpTTDHH 0x03
- //#define tmpTTDHH 0x0A
- #define tmpTTDHL 0x0A
- #define tmpTTDHH 0x01
- unsigned char SelectChannel(void)
- {
- // unsigned char kk,cnt;
-
- SKO = ScanKeyOrder[TD.SensOrderCnt];
- P0IO = P1IO = P2IO = P3IO = 0xFF;
- P0 = 0xFF;
- P1 = 0xFF;
- P2 = 0xFF;
- P3 = 0xFF;
- PSR0 = PSR2 = PSR3 = 0x00;
- P0FT = P2FT = P3FT = 0x00;
- TTMR = 0;
-
-
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
T218_SNWPCB_IH_Cooker_CS.zip
(1.11 MB, 下载次数: 10)
|