The following document contains information on Cypress products. Colophon The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for any use that includes fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for any use where chance of failure is intolerable (i.e., submersible repeater and artificial satellite). Please note that Spansion will not be liable to you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. If any products described in this document represent goods or technologies subject to certain restrictions on export under the Foreign Exchange and Foreign Trade Law of Japan, the US Export Administration Regulations or the applicable laws of any other country, the prior authorization by the respective government entity will be required for export of those products. Trademarks and Notice The contents of this document are subject to change without notice. This document may contain information on a Spansion product under development by Spansion. Spansion reserves the right to change or discontinue work on any product without notice. The information in this document is provided as is without warranty or guarantee of any kind as to its accuracy, completeness, operability, fitness for particular purpose, merchantability, non-infringement of third-party rights, or any other warranty, express, implied, or statutory. Spansion assumes no liability for any damages of any kind arising out of the use of the information in this document. ® ® ® TM Copyright © 2013 Spansion Inc. All rights reserved. Spansion , the Spansion logo, MirrorBit , MirrorBit Eclipse , TM ORNAND and combinations thereof, are trademarks and registered trademarks of Spansion LLC in the United States and other countries. Other names used are for informational purposes only and may be trademarks of their respective owners. Fujitsu Semiconductor Design (Chengdu) Co., Ltd. Application Note MCU-AN-510121-E-10 32-BIT MICROCONTROLLER MB9AA30N SERIES BLUEMOON-EVB_TSC.LIB APPLICATION NOTE ARM and Cortex-M3 are the trademarks of ARM Limited in the EU and other countries. Bluemoon-EVB_TSC.LIB V1.0.0 Revision History Revision History Version Date Updated by 1.0.0 2012-10-30 Abel Ma Approved by Modifications First Draft This manual contains 22 pages. Specifications are subject to change without notice. For further information please contact each office. All Rights Reserved. The contents of this document are subject to change without notice. Customers are advised to consult with sales representatives before ordering. The information, such as descriptions of function and application circuit examples, in this document are presented solely for the purpose of reference to show examples of operations and uses of FUJITSU SEMICONDUCTOR device; FUJITSU SEMICONDUCTOR does not warrant proper operation of the device with respect to use based on such information. When you develop equipment incorporating the device based on such information, you must assume any responsibility arising out of such use of the information. FUJITSU SEMICONDUCTOR assumes no liability for any damages whatsoever arising out of the use of the information. Any information in this document, including descriptions of function and schematic diagrams, shall not be construed as license of the use or exercise of any intellectual property right, such as patent right or copyright, or any other right of FUJITSU SEMICONDUCTOR or any third party or does FUJITSU SEMICONDUCTOR warrant non-infringement of any third-party's intellectual property right or other right by using such information. FUJITSU SEMICONDUCTOR assumes no liability for any infringement of the intellectual property rights or other rights of third parties which would result from the use of information contained herein. The products described in this document are designed, developed and manufactured as contemplated for general use, including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for use accompanying fatal risks or dangers that, unless extremely high safety is secured, could have a serious effect to the public, and could lead directly to death, personal injury, severe physical damage or other loss (i.e., nuclear reaction control in nuclear facility, aircraft flight control, air traffic control, mass transport control, medical life support system, missile launch control in weapon system), or (2) for use requiring extremely high reliability (i.e., submersible repeater and artificial satellite). Please note that FUJITSU SEMICONDUCTOR will not be liable against you and/or any third party for any claims or damages arising in connection with above-mentioned uses of the products. Any semiconductor devices have an inherent chance of failure. You must protect against injury, damage or loss from such failures by incorporating safety design measures into your facility and equipment such as redundancy, fire protection, and prevention of over-current levels and other abnormal operating conditions. Exportation/release of any products described in this document may require necessary procedures in accordance with the regulations of the Foreign Exchange and Foreign Trade Control Law of Japan and/or US export control laws. The company names and brand names herein are the trademarks or registered trademarks of their respective owners. Copyright © 2012 Fujitsu Semiconductor Design (Chengdu) Co., Ltd. All rights reserved. MCU-AN-510121-E-10 – Page 2 Bluemoon-EVB_TSC V1.0.0 Contents Contents REVISION HISTORY ............................................................................................................ 2 CONTENTS .......................................................................................................................... 3 1 INTRODUCTION .............................................................................................................. 4 1.1 Purpose ................................................................................................................... 4 1.2 Document Overview ................................................................................................ 4 2 TSC PRINCIPLE .............................................................................................................. 5 3 TSC LIBRARY ................................................................................................................. 7 3.1 Library Overview ..................................................................................................... 7 3.2 Parameters Setup ................................................................................................... 9 3.3 3.4 3.2.1 Port and Pin define .................................................................................... 9 3.2.2 Sample Parameters setup ....................................................................... 10 3.2.3 Structure Type Define .............................................................................. 11 Application Interface .............................................................................................. 12 3.3.1 TSCKey_Init(uint8_t) ............................................................................... 12 3.3.2 TSCKey_SampleUnit(uint32_t) ................................................................ 12 3.3.3 TSCKey_Filter(uint8_t, uint8_t) ................................................................ 12 3.3.4 uint32_t TSCKey_GetValue(uint8_t) ....................................................... 12 3.3.5 uint8_t TSCKey_UpdateBaseline(uint8_t) ............................................... 13 How to Add Fujitsu TSC_LIB.a .............................................................................. 14 3.4.1 Add Fujitsu TSC_GPIO.lib to User’s Project ............................................ 14 3.4.2 Include Header File.................................................................................. 16 4 LIB USAGE NOTICE ..................................................................................................... 17 5 ADDITIONAL INFORMATION ....................................................................................... 18 1 APPENDIX ..................................................................................................................... 19 1.1 List of Figures and Tables ..................................................................................... 19 1.2 Sample Code ........................................................................................................ 20 1.2.1 Main Function .......................................................................................... 20 MCU-AN-510121-E-10 – Page 3 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 1 Introduction 1 Introduction 1.1 Purpose This application note describes FUJITSU TSC_LIB library, which is based on latest Capacitance Touch Sensor (TSC) GPIO algorithm. Added to that is the descriptions of how to use TSC_LIB library and some notices. This TSC_LIB.a library is used in IAR development environment. 1.2 Document Overview The rest of document is organized as the following: Chapter 2 describes TSC Principle. Chapter 3 describes TSC Library. Chapter 4 describes LIB Usage Notice. MCU-AN-510121-E-10 – Page 4 Bluemoon-EVB_TSC V1.0.0 Chapter 2 TSC Principle 2 TSC Principle This chapter introduces working principles of GPIO solution. The theory of capacitance touch sensor is to check capacitance increment. As follows, when finger not touch the (2.1) While the pad is touching, equation become (2.2) Where the increment is ΔC = CF. Finger CF CP Figure 2-1: Diagram of Capacitance Touch Sensor Theory According to the characteristics of capacitor, the deposited charge of capacitor increases along with the increase of capacitance. FUJITSU uses GPIO method to check the capacitance change. VCC Pull up resistor MCU Filter resistor GPIO-pin Figure 2-2: Diagram of GPIO algorithm MCU-AN-510121-E-10 – Page 5 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 2 TSC Principle The method includes the following steps: 1. Set pin to high impedance to charge the pad; 2. Begin counter accumulation; 3. Wait until the pad is charged; 4. Set pin to ‘L’ to discharge the pad; 5. Wait until the pad is discharged; 6. Save counter value; 7. Sample number decrease; 8. If sample number isn’t zero, start next sample loop; 9. If sample number is zero, calculate sum of counter, finish sample; Flowchart and hardware connection are shown in Figure 2-3 and Figure 2-4. Start Charge the pad Counter accumulation Wait padcharged N Y Discharge the pad Counter accumulation Wait paddischarged N Y Sample number decrease N If sampling number is zero? Y Calculate sum of counter End Figure 2-3: Check Flowchart Figure 2-4: Hardware Connection MCU-AN-510121-E-10 – Page 6 Bluemoon-EVB_TSC V1.0.0 Chapter 3 TSC Library 3 TSC Library This chapter introduces how to use TSC library. 3.1 Library Overview There are parameters which user need to setup, and 4 functions as API for user’s situations. All the parameters and functions are introduced as follow. Table 3-1: Parameters List Name Description Remarks TSCKEY_KEYNUM Total TSC key number N/A TSCKEY_SampleNumConst Sample number N/A TSCKEY_BUTTONX_USED Decide if TSC key Button X will be Used N/A TSCKEY_BUTTONX_DATA_IN TSC key X pin data in N/A TSCKEY_BUTTONX_DATA_OUT TSC key X pin data out N/A TSCKEY_BUTTONX_DIR TSC key X pin dir in N/A TSCKEY_BUTTONX_PULL_UP TSC key X pin pull up N/A TSCKEY_BUTTONX_PFR TSC key X pin PFR N/A TSCKEY_BUTTONX_PORT TSC key X port N/A TSCKEY_BUTTONX_PIN TSC key X pin N/A TSCKEY_OffsetLX Offset Const Level X for individual keys N/A TSC_TIMER_INITITAL_VALUE Timer load value register N/A TSC_TIMER_COUNT_VALUE Timer current value register N/A TSC_TIMER_START Enable timer N/A TSC_TIMER_STOP Disable time N/A Basline_Const Used TSC baseline update N/A Key_Const TSC key information N/A TSC_KeyOffset Each individual key offset const N/A TSC_Baseline Each key current baseline information N/A TSCKEY_SubAvgShiftConst Sub driver layer average shift const N/A TSCKEY_AvoidErrorConst Avoid mistake in initialize process N/A TSCKEY_NoiseOffsetConst Avoid mistake in initialize process N/A TSCKEY_DeltaBucketThrConst Delta value threshold const N/A TSCKEY_PercentSumConst Sum const of all keys N/A TSCKEY_MinificationConst Base line value minificate const N/A TSCKEY_BalnUpdateConst Base line update counter const N/A TSCKEY_AmpShiftConst Amplify shift const N/A MCU-AN-510121-E-10 – Page 7 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 3 TSC Library Table 3-2: Functions List Prototype Function Description Remarks void TSCKey_Init(uint8_t Key_Num) Initialize TSC module N/A void TSCKey_SampleUnit(uint32_t TSCKEY_SampleNum) Bottom layer sample unit of TSC. N/A void TSCKey_Filter(uint8_t Key_Num, uint8_t Order_Shift) Filter function of TSC sample value N/A uint32_t TSCKey_GetValue(uint8_t Key_Num) Judgment touch status and coding key value N/A uint8_t TSCKey_UpdateBaseline(uint8_t Key_Num) TSC key update baseline N/A MCU-AN-510121-E-10 – Page 8 Bluemoon-EVB_TSC V1.0.0 Chapter 3 TSC Library 3.2 Parameters Setup 3.2.1 Port and Pin define The related hardware define: #define TSCKEY_BUTTON0_USED Used */ TRUE /* Decide if TSCKEY Button0 will be #define TSCKEY_BUTTON1_USED Used */ FALSE /* Decide if TSCKEY Button1 will be #define TSCKEY_BUTTON2_USED Used */ FALSE /* Decide if TSCKEY Button2 will be #define TSCKEY_BUTTON3_USED Used */ FALSE /* Decide if TSCKEY Button3 will be #define TSCKEY_BUTTON0_DATA_IN bFM3_GPIO_PDIR1_P5/* TSC Key pin data in*/ #define TSCKEY_BUTTON1_DATA_IN bFM3_GPIO_PDIR4_P6/* TSC Key pin data in*/ #define TSCKEY_BUTTON2_DATA_IN bFM3_GPIO_PDIR3_PF/* TSC Key pin data in*/ #define TSCKEY_BUTTON3_DATA_IN bFM3_GPIO_PDIR3_PE/* TSC Key pin data in*/ #define TSCKEY_BUTTON0_DATA_OUT bFM3_GPIO_PDOR1_P5 /* TSC Key pin data out*/ #define TSCKEY_BUTTON1_DATA_OUT bFM3_GPIO_PDOR4_P6 /* TSC Key pin data out*/ #define TSCKEY_BUTTON2_DATA_OUT bFM3_GPIO_PDOR3_PF/* TSC Key pin data out*/ #define TSCKEY_BUTTON3_DATA_OUT bFM3_GPIO_PDOR3_PE /* TSC Key pin data out*/ #define TSCKEY_BUTTON0_DIR in*/ bFM3_GPIO_DDR1_P5 /* TSC Key pin dir #define TSCKEY_BUTTON1_DIR in*/ bFM3_GPIO_DDR4_P6 /* TSC Key pin dir #define TSCKEY_BUTTON2_DIR in*/ bFM3_GPIO_DDR3_PF /* TSC Key pin dir #define TSCKEY_BUTTON3_DIR in*/ bFM3_GPIO_DDR3_PE /* TSC Key pin dir #define TSCKEY_BUTTON0_PULL_UP bFM3_GPIO_PCR1_P5 /* TSC Key pin pull up*/ #define TSCKEY_BUTTON1_PULL_UP bFM3_GPIO_PCR4_P6 /* TSC Key pin pull up*/ #define TSCKEY_BUTTON2_PULL_UP bFM3_GPIO_PCR3_PF /* TSC Key pin pull up*/ #define TSCKEY_BUTTON3_PULL_UP bFM3_GPIO_PCR3_PE /* TSC Key pin pull up*/ #define TSCKEY_BUTTON0_PFR bFM3_GPIO_PFR1_P5 /* TSC Key pin PFR*/ #define TSCKEY_BUTTON1_PFR bFM3_GPIO_PFR4_P6 /* TSC Key pin PFR*/ #define TSCKEY_BUTTON2_PFR bFM3_GPIO_PFR3_PF /* TSC Key pin PFR*/ #define TSCKEY_BUTTON3_PFR bFM3_GPIO_PFR3_PE /* TSC Key pin PFR*/ #define TSCKEY_BUTTON0_PORT PORT_1 /* TSC Key port*/ #define TSCKEY_BUTTON1_PORT PORT_4 /* TSC Key port*/ #define TSCKEY_BUTTON2_PORT PORT_3 /* TSC Key port*/ #define TSCKEY_BUTTON3_PORT PORT_3 /* TSCKey port*/ #define TSCKEY_BUTTON0_PIN PIN_5 /* TSC Key pin */ #define TSCKEY_BUTTON1_PIN PIN_6 /* TSC Key pin */ #define TSCKEY_BUTTON2_PIN PIN_15 /* TSC Key pin */ #define TSCKEY_BUTTON3_PIN PIN_14 /* TSC Key pin */ MCU-AN-510121-E-10 – Page 9 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 3 TSC Library 3.2.2 Sample Parameters setup The parameters: #define TSC_TIMER_INITITAL_VALUE FM3_BT3_RT->PCSR // Timer load value register #define TSC_TIMER_COUNT_VALUE FM3_BT3_RT->TMR // Timer current value register #define TSC_TIMER_TMCR FM3_BT3_RT->TMCR // Timer control1 register #define TSC_TIMER_TMCR2 FM3_BT3_RT->TMCR2 // Timer control2 register #define TSC_TIMER_STC FM3_BT3_RT->STC // Timer status control register #define TSC_TIMER_CTR TSC_TIMER_TMCR // Timer load value register #define TSC_TIMER_START #define TSC_TIMER_STOP #define TSCTIMEINITVAL (TSC_TIMER_CTR | (3)) (TSC_TIMER_CTR & (~3)) // Enable Timer // Disable Timer 0xFFFF #define TSCKEY_MinificationEnable FALSE //Decide if need minification of baseline value #define TSCKEY_IIRShiftConstL1 1 // Shift Const Level 0 for IIR filter #define TSCKEY_IIRNumConstL1 2 << TSCKEY_IIRShiftConstL1 // Number of Shift Times Const Level 0 for IIR filter #define TSCKEY_IIRShiftConstL2 2 // Shift Const Level 1 for IIR filter #define TSCKEY_IIRNumConstL2 2 << TSCKEY_IIRShiftConstL2 // Number of Shift Times Const Level 1 for IIR filter #define TSCKEY_IIRShiftConstL3 3 //Shift Const Level 2 for IIR filter #define TSCKEY_IIRNumConstL3 2 << TSCKEY_IIRShiftConstL3 // Number of Shift Times Const Level 2 for IIR filter #define TSCKEY_IIRShiftConstL4 5 #define TSCKEY_IIRNumConstL4 2 << TSCKEY_IIRShiftConstL4 // Shift Const Level 3 for IIR filter // Number of Shift Times Const Level 3 for IIR filter #define TSCKEY_OffsetL0 10 // Offset Const Level 0 for individual keys #define TSCKEY_OffsetL1 10 // Offset Const Level 1 for individual keys #define TSCKEY_OffsetL2 10 // Offset Const Level 2 for individual keys #define TSCKEY_OffsetL3 10 // Offset Const Level 3 for individual keys #define TSCKEY_SubAvgShiftConst 1 //Sub driver layer average shift const #define TSCKEY_AvoidErrorConst 300 // Avoid mistake in initialize process #define TSCKEY_NoiseOffsetConst 100 // Avoid mistake in initialize process #define TSCKEY_DeltaBucketThrConst 50 // Delta value threshold const #define TSCKEY_PercentSumConst // Sum const of all keys 400 #define TSCKEY_MinificationConst 3 // Baseline value minificate const #define TSCKEY_BalnUpdateConst 1 // Baseline update counter const #define TSCKEY_AmpShiftConst 1 // Amplify shift const Used to configure the sample number, threshold, and timer initial value. MCU-AN-510121-E-10 – Page 10 Bluemoon-EVB_TSC V1.0.0 Chapter 3 TSC Library 3.2.3 Structure Type Define Each TSC Key has 4 attributes: original value, filtered value, noise threshold and difference percent value. typedef struct { uint32_t OriginValue; /* Contains the original value */ uint32_t Value; /* Contains the count value */ uint32_t NoiseThreshold; /* Contains the key threshold level */ uint32_t Percent; /* Contains the value percent */ } Key_Const; User can define new key directly using the following structure. typedef struct { uint32_t Value; /* Contains the current baseline value */ int32_t DeltaBucket; /* Contains the key threshold level */ } Basline_Const; MCU-AN-510121-E-10 – Page 11 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 3 TSC Library 3.3 Application Interface All the functions supplied by the TSC_GPIO.lib will be introduced below, include the function prototype, input parameter(s), return value(s), and the function description. 3.3.1 TSCKey_Init(uint8_t) Prototype void TSCKey_Init(uint8_t Key_Num) Parameter: Key_Num: Return void Description Initialize LCD module 1. Disables analog function of TSC pin. 2. Initialize counter 3. Initialize pin status to discharge TSC pad 4. Get baseline and noise threshold 5. Initialize used flag N/A Remark Indication the number of touch keys need initialization 3.3.2 TSCKey_SampleUnit(uint32_t) Prototype void TSCKey_SampleUnit(uint32_t TSCKEY_SampleNum) Parameter: TSCKEY_SampleNum: Return void Description Bottom layer sample unit of TSC. Remark N/A Indication sample number 3.3.3 TSCKey_Filter(uint8_t, uint8_t) Prototype Parameter: void TSCKey_Filter(uint8_t Key_Num, uint8_t Order_Shift) Key_Num: Indication the number of touch keys need filter Return Order_Shift: void Indication the shift number of order for filter Description Filter function of TSC sample value Remark N/A 3.3.4 uint32_t TSCKey_GetValue(uint8_t) Prototype uint32_t TSCKey_GetValue(uint8_t Key_Num) Parameter: Key_Num: Return Key word of individual keys in lower byte; Slide position of slider in upper byte Description Judgment touch status and coding key value Remark N/A Indication the number of touch keys need filter MCU-AN-510121-E-10 – Page 12 Bluemoon-EVB_TSC V1.0.0 Chapter 3 TSC Library 3.3.5 uint8_t TSCKey_UpdateBaseline(uint8_t) Prototype uint8_t TSCKey_UpdateBaseline(uint8_t Key_Num) Parameter: Key_Num: Return Runs status Description TSC key update baseline Remark N/A Indication the number of touch keys need filter MCU-AN-510121-E-10 – Page 13 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 3 TSC Library 3.4 How to Add Fujitsu TSC_LIB.a 3.4.1 Add Fujitsu TSC_GPIO.lib to User’s Project 1. In IAR project, Right click on workspace select Add Files from the menu Add. Figure 3-1: Add member to folder 2. In Add Member dialog box, select ‘ALL Files’ from ‘Files of Type’, and then you will find the TSC_LIB.a Figure 3-2: Found the lib file MCU-AN-510121-E-10 – Page 14 Bluemoon-EVB_TSC V1.0.0 Chapter 3 TSC Library 3. Double click TSC_LIB.a, and then you can see it has been added in the folder Include Files Figure 3-3: Add TSC.lib MCU-AN-510121-E-10 – Page 15 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 3 TSC Library 3.4.2 Include Header File 1. Add "#include "tsc.h "" in header file, such as in "main.h ". Figure 3-4: Add include statement in C file 2. Compile the whole project, "tsc.h" will link TSC_LIB.a to c file, so that user program can use API functions in TSC_LIB.a. MCU-AN-510121-E-10 – Page 16 Bluemoon-EVB_TSC V1.0.0 Chapter 4 LIB Usage Notice 4 LIB Usage Notice This chapter introduces LIB usage notice. Machine clock The machine clock should be set to 8M or above. If the machine clock is less than 8M, the sensor response is slow. Interrupt When calling TSC_LIB.a library API functions, the all MCU interrupt will disable. After calling these functions, the MCU will resume all interrupt as ago. #define DisAllInterrupt() __asm("CPSID I") //Disable all interrupt #define EnAllInterrupt() __asm("CPSIE I") //Enable all interrupt TSC initialization When initialization the TSC (i.e., when calling the TSCKey_Init function), user can’t touch the TSC key. MCU-AN-510121-E-10 – Page 17 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 5 Additional Information 5 Additional Information For more Information on FUJITSU semiconductor products, visit the following websites: English version address: http://www.fujitsu.com/cn/fsp/services/mcu/32bit/fm3/an.html Chinese version address: http://www.fujitsu.com/cn/fss/services/mcu/32bit/fm3/an.html MCU-AN-510121-E-10 – Page 18 Bluemoon-EVB_TSC V1.0.0 Chapter 1 Appendix 1 Appendix 1.1 List of Figures and Tables Table 3-1: Parameters List ..................................................................................................... 7 Table 3-2: Functions List ........................................................................................................ 8 Figure 2-1: Diagram of Capacitance Touch Sensor Theory .................................................... 5 Figure 2-2: Diagram of GPIO algorithm .................................................................................. 5 Figure 2-3: Check Flowchart .................................................................................................. 6 Figure 2-4: Hardware Connection .......................................................................................... 6 Figure 3-1: Add member to folder......................................................................................... 14 Figure 3-2: Found the lib file................................................................................................. 14 Figure 3-3: Add TSC.lib........................................................................................................ 15 Figure 3-4: Add include statement in C file ........................................................................... 16 MCU-AN-510121-E-10 – Page 19 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 1 Appendix 1.2 Sample Code 1.2.1 Main Function Name: Main Function Function: Initialize and configure. main.c //************************************************************************************************************************* // FUNCTION: // Init the system // PARAMETERS: // RETURN: // none: //************************************************************************************************************************* void Sys_Init(void) { SetAllGpioOutH(); // Set the not used GPIO H level to reduce the power consume in normal mode InitRTC(0x0); // Initialize RTC Lvd_Init(); // LVD initialization, detection voltage 4V, LVD interrupt CommonDvc_Int(); // Init common device, eg: LCD backlight, Beep, LED BT0ReloadTimer_Init(); // Init and start BT0 //Test-self the device BeepOn(); LcdBackOn(); LedTscOn(); LedWorkOn(); Delay_ms(20); LCD_Init(); // Init LCD ShowPage1(); Delay_ms(400); BeepOff(); LedTscOff(); LedWorkOff(); InitADC(); // Initialize ADC gMon_1SecFlag = 0; gMon_CurTemp = 0; gMon_CaliStep = 0; ADC12_ScanStart(ADCUnit, ADC12_SCAN_MODE_CONTINUE); // Start ADC for first temperature sampling Delay_ms(2500); TSCKey_Init(TSCKEY_KEYNUM); // Initialise TSC Key } MCU-AN-510121-E-10 – Page 20 Bluemoon-EVB_TSC V1.0.0 Chapter 1 Appendix /** ****************************************************************************** ** \brief Main function of project for MB9AA30 series. ** ** \param none ** \return uint32_t return value, if needed ******************************************************************************/ int32_t main(void) { Sys_Init(); // Init the system while(1) { StatusServeRun(); // Led indication the system run status KeyScanf(); // Scan the key and Joystick KeyTouchServe(); // Have a key, Led and Beep indication DispModeServe(); // LCD display, normal mode and key down mode if ( (MechKeyId == 0x1) && (TscKeyId == 0x1) && (JoyKeyId != JoyNot) ) // Enter min system test mode { MinSysCurTest(); } if ((MechKeyId == 0x1) && (JoyKeyId == JoyOk) && (TscKeyId == 0x0)) { RtcModeSet(); // Setting time & date mode } if ((TscKeyId == 0x1) && (MechKeyId == 0x1) && (JoyKeyId == JoyNot)) { EnterLowerPowerModeProcess(); // Enter standby stop mode } if (((LastJoyKeyId != JoyNot) && (JoyKeyId != JoyNot)) || (TscKeyId == 0x1)) // Normal mode, has a key? { KeyDown = 0x1; // Beep and led indication KeyDownCnt = 0x0; // Clean the counter DisplayMode = 0x1; // Enter key display mode TouchModeCnt = 0x0; // Clean the counter TscKeyId = 0x0; } TscKeyScanf(); // Judging has a TSC key TSCKey_UpdateBaseline(TSCKEY_KEYNUM); // Update the TSC base line if(TempSmplFinished == 1) // Temperature sample finishes? { TempSmplFinished = 0; GetCurTemp(&gMon_CurTemp); gMon_CaliStep = CaliProcess(gMon_CurTemp); } MCU-AN-510121-E-10 – Page 21 Bluemoon-EVB_TSC.LIB V1.0.0 Chapter 1 Appendix if ( PowerSupplyCnt >= POWER_SUPPLY_TIME ) // Power judging, different supply voltage { PowerSupply = 0x1; PowerSupplyCnt = 0x0; Lvd_Init(); // LVD initialization, detection voltage 4V, LVD interrupt Delay_ms(5); if ( PowerSupplyLast != PowerSupply ) { LCD_Init(); // Supply power chagned, then Init LCD } } } } MCU-AN-510121-E-10 – Page 22