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 (Shanghai) Co., Ltd. Application Note MCU-AN-500084-E-10 F²MC-8FX FAMILY 8-BIT MICROCONTROLLER MB95200H/210H SERIES CAPACITANCE TOUCH SENSOR APPLICATION NOTE Capacitance Touch Sensor V1.0 Revision History Revision History Date 2010-04-14 Author Ivan. Xiao Change of Records V1.0, First draft This manual contains 42 pages. 1. The products described in this manual and the specifications thereof may be changed without prior notice. To obtain up-to-date information and/or specifications, contact your Fujitsu sales representative or Fujitsu authorized dealer. 2. Fujitsu will not be liable for infringement of copyright, industrial property right, or other rights of a third party caused by the use of information or drawings described in this manual. 3. The contents of this manual may not be transferred or copied without the express permission of Fujitsu. 4. The products contained in this manual are not intended for use with equipments which require extremely high reliability such as aerospace equipments, undersea repeaters, nuclear control systems or medical equipments for life support. 5. Some of the products described in this manual may be strategic materials (or special technology) as defined by the Foreign Exchange and Foreign Trade Control Law. In such cases, the products or portions thereof must not be exported without permission as defined under the law. © 2010 Fujitsu Semiconductor (Shanghai) Co., Ltd. MCU-AN- 500084-E-10 – Page 2 Capacitance Touch Sensor V1.0 CONTENTS CONTENTS REVISION HISTORY .............................................................................................................. 2 CONTENTS ............................................................................................................................ 3 1 INTRODUCTION ................................................................................................................ 5 2 FUJITSU CAPACITANCE TOUCH SENSOR SOLUTION ................................................ 6 3 LIBRARY ........................................................................................................................... 8 3.1 Library Functions....................................................................................................... 8 3.2 FUJITSU TSC Performance.................................................................................... 12 3.3 How to Add Fujitsu TSC.lib ..................................................................................... 13 3.3.1 Add Fujitsu TSC.lib to User’s Project ........................................................ 13 3.3.2 Add "#include ‘TSC.h’" in c File ................................................................. 16 3.4 How to use Fujitsu TSC.lib ...................................................................................... 17 4 LIB USAGE NOTICE ....................................................................................................... 19 5 TSC GUI ........................................................................................................................... 21 5.1 Overview ................................................................................................................. 21 5.2 Open Software ........................................................................................................ 22 5.3 Check Threshold ..................................................................................................... 23 5.3.1 Overview ................................................................................................... 23 5.3.2 Check Start ............................................................................................... 24 5.3.3 Checking ................................................................................................... 25 5.3.4 Check Stop................................................................................................ 26 5.3.5 Calculate Threshold .................................................................................. 27 5.4 Test Threshold ........................................................................................................ 28 5.4.1 Overview ................................................................................................... 28 5.4.2 Test Start................................................................................................... 29 5.4.3 Testing ...................................................................................................... 30 5.4.4 Test Stop ................................................................................................... 31 5.5 Graph ...................................................................................................................... 32 5.5.1 Overview ................................................................................................... 32 5.5.2 Graph ........................................................................................................ 32 6 ADDITIONAL INFORMATION ......................................................................................... 33 7 APPENDIX ....................................................................................................................... 34 7.1 Index of Figures ...................................................................................................... 34 7.2 Index of Table ......................................................................................................... 34 MCU-AN- 500084-E-10 – Page 3 Capacitance Touch Sensor V1.0 CONTENTS 7.3 Sample Code .......................................................................................................... 36 MCU-AN- 500084-E-10 – Page 4 Capacitance Touch Sensor V1.0 Chapter 1 Introduction 1 Introduction This application note describes FUJITSU TSC solution, and describes how to use TSC library and TSC GUI. Chapter 2 explains the working principles of TSC solution. Chapter 3 explains how to use TSC library. Chapter 4 explains LIB usage notice. Chapter 5 explains how to use TSC GUI. MCU-AN- 500084-E-10 – Page 5 Capacitance Touch Sensor V1.0 Chapter 2 FUJITSU Capacitance Touch Sensor Solution 2 FUJITSU Capacitance Touch Sensor Solution This chapter introduces working principles of TSC solution. The theory of capacitance touch sensor is to check capacitance increment. As follows, when finger not touch the C = Cp, when touching the C = Cp +Cғ, and the increment is ΔC = Cғ. Figure 2-1: Capacitance Touch Sensor Theory According to the characteristics of capacitor, the deposited charge of capacitor increases along with the increase of capacitance. FUJITSU uses A/D+GPIO method to check the capacitance change. The method includes the following steps: GPIO output ‘H’, duration 20us, then GPIO input and A/D sampling. Start GPIO output ‘H’ Delay 20us GPIO input Switch to A/D and sampling Figure 2-2: Operation Flowchart MCU-AN- 500084-E-10 – Page 6 Capacitance Touch Sensor V1.0 Chapter 2 FUJITSU Capacitance Touch Sensor Solution Figure 2-3: Hardware Connection During GPIO input, the voltage when C sensor is touched is higher than the case when it is not touched. Figure 2-4: Sketch Map MCU-AN- 500084-E-10 – Page 7 Capacitance Touch Sensor V1.0 Chapter 3 Library 3 Library This chapter introduces how to use TSC library. Basing on MB95F204K, FUJITSU designs a 4-buttons TSC solution which provides a library for user to use and a TSC GUI to test. 3.1 Library Functions The library has 12 functions which are listed as follow. Table 3-1: Functions Function Name Function void TSC_init(void) Initialize TSC void button1_init(unsigned int threshold) Set button1 threshold void button2_init(unsigned int threshold) Set button2 threshold void button3_init(unsigned int threshold) Set button3 threshold void button4_init(unsigned int threshold) Set button4 threshold void UART_init(void) Initialize and start serial port void TBT_init(void) Initialize and start Timebase Timer unsigned char Get_Data(void) Get check data void Transmit(void) Transmit data unsigned char get_mode(void) Get sensor mode void set_mode(unsigned char set_mode) Set sensor mode void clear_check_data(void) Clear check data MCU-AN- 500084-E-10 – Page 8 Capacitance Touch Sensor V1.0 Chapter 3 Library void TSC_init(void) Table 3-2: TSC_init Function Name TSC_init Description Initialize IO which connect sensor, and initialize A/D. Input None Return None void button1_init(unsigned int threshold) Table 3-3: button1_init Function Name button1_init Description Set button1 threshold Input threshold: threshold value, and the type data from 1000 to 1120 Return None void button2_init(unsigned int threshold) Table 3-4: button2_init Function Name button2_init Description Set button2 threshold Input threshold: threshold value, and the type data from 1000 to 1120 Return None void button3_init(unsigned int threshold) Table 3-5: button3_init Function Name button3_init Description Set button3 threshold Input threshold: threshold value, and the type data from 1000 to 1120 Return None void button4_init(unsigned int threshold) Table 3-6: button4_init Function Name button4_init Description Set button4 threshold Input threshold: threshold value, and the normal value from 1000 to 1120 Return None MCU-AN- 500084-E-10 – Page 9 Capacitance Touch Sensor V1.0 Chapter 3 Library void UART_init(void) Table 3-7: UART_init Function Name UART_init Description Initialize and start serial port, the data length is 8-bit, stop bit length is 1-bit, parity is even parity, and the baud rate is 115200. Input None Return None void TBT_init(void) Table 3-8: TBT_init Function Name TBT_init Description Initialize and start Timebase Timer, the interval time is 2¹² x 1/FCRH Input None Return None void Transmit(void) Table 3-9: Transmit Function Name Transmit Description Transmit check data to TSC GUI Input None Return None unsigned char get_mode(void) Table 3-10: get_mode Function Name get_mode Description Get current check mode Input None Return Return check mode: 0: highest mode, this mode only returns sensor number which the maximum increment of voltage and over threshold. 1: normal mode, this mode return all over threshold sensor. 2: slippage mode, this mode checks slippage direction, right or left. MCU-AN- 500084-E-10 – Page 10 Capacitance Touch Sensor V1.0 Chapter 3 Library unsigned char Get_Data(void) Table 3-11: Get_Data Function Name Get_Data Description Get check data Input None Return Return sensor number or slippage direction. The returned value varies with the mode. highest mode: 1->button1, 2->button2, 3->button3, 4->button4, 0-> no button. normal mode: bit0-> button1, bit1-> button2, bit2-> button3, bit3-> button4, 1: touching, 0: not touch. slippage mode: 1: right, 2: left, 0: checking. void set_mode(unsigned char set_mode) Table 3-12: set_mode Function Name set_mode Description Set current check mode Input Set mode: 0: highest mode, this mode only returns sensor number which the maximum increment of voltage and over threshold. 1: normal mode, this mode return all over threshold sensor. 2: slippage mode, this mode checks slippage direction, right or left. Return None MCU-AN- 500084-E-10 – Page 11 Capacitance Touch Sensor V1.0 Chapter 3 Library void clear_check_data(void) Table 3-13: clear_check_data Function Name clear_check_data Description Clear check data when checking Input None Return None 3.2 FUJITSU TSC Performance Table 3-14: Performance Resource Amount ROM 1272 Byte Description ROM space: If just need support 1 sensor, ROM of lib can be reduced to: 300 Byte If just need support 2 sensors, ROM of lib can be reduced to: 960 Byte If just need support 3 sensors, ROM of lib can be reduced to: 1120 Byte If need support 4 sensors, ROM of Lib is: 1272 Byte RAM 36 Byte RAM space: If just need support 1 sensor, RAM of lib can be reduced to: 11 Byte If just need support 2 sensors, RAM of lib can be reduced to: 26 Byte If just need support 3 sensors, RAM of lib can be reduced to: 31 Byte If need support 4 sensors, RAM of Lib is: 36 Byte IO Port 4 P00~P02,P03 A/D 4 Channel 1,2,3,6(P00~P02,P03) Timer 1 Timebase Timer Serial Port 1 Serial Port(P04,P05),only use in check threshold mode Machine Clock >=8M Scan 1 Key 2 ms MCU-AN- 500084-E-10 – Page 12 Capacitance Touch Sensor V1.0 Chapter 3 Library 3.3 How to Add Fujitsu TSC.lib 3.3.1 Add Fujitsu TSC.lib to User’s Project 1. In Softune, right click Include Files and select Add member to folder > File from the shortcut menu. Figure 3-1: Select File MCU-AN- 500084-E-10 – Page 13 Capacitance Touch Sensor V1.0 Chapter 3 Library 2. The TSC.lib can’t be found in window of Add Member. Figure 3-2: open Add Member Window 3. In Add Member window, select ALL Files from Files of Type, and then you will find the TSC.lib. Figure 3-3: Select File Type MCU-AN- 500084-E-10 – Page 14 Capacitance Touch Sensor V1.0 Chapter 3 Library 4. Then the TSC.lib could be found. Figure 3-4: Show TSC.lib 5. Double click TSC.lib, and the TSC.lib will be added to Source Files. Figure 3-5: Add TSC.lib MCU-AN- 500084-E-10 – Page 15 Capacitance Touch Sensor V1.0 Chapter 3 Library 3.3.2 Add "#include ‘TSC.h’" in c File 1. Add "#include ‘TSC.h’" in c file, such as in "main.c ". Figure 3-6: Add “#include “TSC.h "” in “main.c” 2. Compile the whole project, "TSC.h" will link TSC.lib to c file, so that user program can use API functions in TSC.lib. Figure 3-7: ‘#include ‘TSC.h’’ is Added Successfully MCU-AN- 500084-E-10 – Page 16 Capacitance Touch Sensor V1.0 Chapter 3 Library 3.4 How to use Fujitsu TSC.lib Using the library needs following step. First, initialize TSC main function, threshold and Timebase Timer. If need to get the threshold, the UART needs to be initialized. Second, use function “Get_data()” to get the check data. Timebase Timer interrupt checks sensor function, and UART transmits the check data to TSC GUI. Connect TSC GUI software flowchart Start Initialization ( TSC_init(), button1_init(threshold), button2_init(threshold), button3_init(threshold), button4_init(threshold), UART_init(), TBT_init()) UART interrupt Transmit sampling data to TSC GUI Timebase Timer interrupt Get check value (Get_Data()) and main function Interrupt end Interrupt end End Figure 3-8: Get Threshold with GUI Flowchart MCU-AN- 500084-E-10 – Page 17 Check which sensor is being touched Capacitance Touch Sensor V1.0 Chapter 3 Library Not connect TSC GUI software flowchart Start Initialization ( TSC_init(), button1_init(threshold), button2_init(threshold), button3_init(threshold), button4_init(threshold), TBT_init()) Timebase Timer interrupt Get check value (Get_Data()) and main function Interrupt end End Figure 3-9: Working Flowchart MCU-AN- 500084-E-10 – Page 18 Check which sensor is being touched Capacitance Touch Sensor V1.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 This solution needs to use Timebase Timer interrupt to check sensor, and the interval time is 512us. It is unnecessary to use UART if the threshold is not gotten or tested with TSC GUI, and the interrupt setting in “vector.c” is as following: #include "mb95200.h" #include "TSC.h" … void InitIrqLevels(void) { … #ifdef enableUART ILR2 = 0xfd; // IRQ8: LIN-UART (transmission) // IRQ9: 8/16-bit PPG ch1 (lower) | UART/SIO ch1 // IRQ10: 8/16-bit PPG ch1 (upper) | I2C ch1 // IRQ11: 16-bit reload timer ch0 #else ILR2 = 0xff; // IRQ8: LIN-UART (transmission) // IRQ9: 8/16-bit PPG ch1 (lower) | UART/SIO ch1 // IRQ10: 8/16-bit PPG ch1 (upper) | I2C ch1 // IRQ11: 16-bit reload timer ch0 #endif … ILR4 = 0xbf; // IRQ16: 16-bit reload timer ch1 | I2C ch0 // IRQ17: 16-bit PPG ch1 // IRQ18: 10-biat A/D-converter // IRQ19: Timebase timer .. } … #ifdef enableUART __interrupt void UART_T (void); #endif MCU-AN- 500084-E-10 – Page 19 Capacitance Touch Sensor V1.0 Chapter 4 LIB Usage Notice __interrupt void TBT (void); .. #ifdef enableUART #pragma intvect UART_T 8 // IRQ8: LIN-UART (transmission) #else #pragma intvect DefaultIRQHandler 8 // IRQ8: LIN-UART (transmission) #endif… #pragma intvect TBT 19 // IRQ19: Timebase timer … Mode When slippage mode is selected, the check data will be cleared during checking. Use “clear_check_data” function to clear check data. Button number The corresponding relationship between button number and pins are as follows. Button1-P00, Button2-P01, Button3-P02, Button4-P05, Sample code For more operation please refer to Appendix: Sample Code. MCU-AN- 500084-E-10 – Page 20 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5 TSC GUI This chapter introduces how to use TSC library. 5.1 Overview The hardware needs to use Serial Port to connect PC with TSC board, as follows: PC Serial port TSC board Figure 5-1: GUI Connects TSC Board TSC GUI is used to get and test threshold. It includes four files, as shown in Figure 5-2. Figure 5-2: GUI Software MCU-AN- 500084-E-10 – Page 21 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.2 Open Software Double click TSC GUI.exe to open the software, and the software includes 4 parts, Menu Bar, Check module, Test module and Graph module, as following: Menu Bar: this module ‘FileÆexit’, ‘ToolsÆlanguage’, ‘HelpÆhelp’; ‘HelpÆabout’. Check: this module includes ‘Button Select’, ‘Mode’, ‘Max/Min Data’, ‘Check Status’, ‘Current Data’ and ‘Start’ Button. Test: this module includes ‘Mode’, ‘Threshold’, ‘Test Result’, ‘Test Status’, ‘Current Data’, and ‘Start’ Button. Graph: this module includes ‘Button Select’ and graph display area. The main interface is shown as follow: Figure 5-3: TSC GUI Interface MCU-AN- 500084-E-10 – Page 22 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.3 Check Threshold 5.3.1 Overview 1. Button Select: This item is used to select which button to check. It has 16 options: “button 1” to “button 16”. 2. Mode: This item is used to set current check mode, it include 2 modes, “Not Touch”, “Touching”. 3. Current Data: This item displays current data. 4. Check Status: This item displays current status, “checking” or “stop”. 5. Max/Min Data: This item displays max data and min data when check is stopped. 6. Get Threshold: Get the threshold. 7. Start/Stop: Clicking this item can start or stop check. 1 ○ 3 ○ 2 ○ 5 ○ 6 ○ 4 ○ 7 ○ Figure 5-4: Check Main Interface MCU-AN- 500084-E-10 – Page 23 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.3.2 Check Start Select the button to be checked from Button Select field and select the right mode from Mode field. Click Start, and the button text changes to Stop. The button will be checked for a moment. 1 ○ 2 ○ 7 ○ Figure 5-5: Check Start MCU-AN- 500084-E-10 – Page 24 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.3.3 Checking In this status, all the fields in GUI Check Module cannot be operated except ‘Stop’. If Touching is selected in Mode, the sensor should be kept in touching state. Figure 5-6: Checking MCU-AN- 500084-E-10 – Page 25 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.3.4 Check Stop Click Stop button to stop check, and the button text changes to Start. The max data and min data are generated in Max/Min Data field. Figure 5-7: Check Stop MCU-AN- 500084-E-10 – Page 26 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.3.5 Calculate Threshold When Not Touch and Touching statuses are all checked, click Get Threshold button to calculate the threshold. 6 ○ Figure 5-8: Calculate Threshold MCU-AN- 500084-E-10 – Page 27 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.4 Test Threshold 5.4.1 Overview 1. Mode: This item is used to set current test mode, it include 3 modes, “Not Touch”, “Touching”. 2. Test Status: This item displays current status, “checking” or “stop”. 3. Threshold: This item sets the threshold to be tested. 4. Current Data: This item displays current data. 5. Test Result: This item displays test result, “pass” and “not pass”. 6. More Information: Display more information on test. 7. Start/Stop: Clicking this item can start or stop test. 1 ○ 4 ○ 3 ○ 5 ○ 6 ○ 2 ○ 7 ○ Figure 5-9: Test Main Interface MCU-AN- 500084-E-10 – Page 28 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.4.2 Test Start Select a mode from Mode field, select the button to be tested in Current Data field, and input the threshold in Threshold field. If the threshold is already gotten in check module, it will be automatically displayed in Threshold field. Click OK to submit the threshold. 1 ○ 4 ○ 3 ○ 7 ○ Figure 5-10: Test Start MCU-AN- 500084-E-10 – Page 29 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.4.3 Testing Figure 5-11: Testing MCU-AN- 500084-E-10 – Page 30 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.4.4 Test Stop Click Stop to stop test, and the current button test result will be displayed in Test Result. Click More Information to display all button test results. 6 ○ Figure 5-12: Test Result MCU-AN- 500084-E-10 – Page 31 Capacitance Touch Sensor V1.0 Chapter 5 TSC GUI 5.5 Graph 5.5.1 Overview 1. Button Select: This item is used to select which button to display. It has 16 items, “button 1” to “button 16”. 5.5.2 Graph This module displays A/D sampling data graph. Select the button to be displayed from Button Select field. Figure 5-13: Graph MCU-AN- 500084-E-10 – Page 32 Capacitance Touch Sensor V1.0 Chapter 6 Additional Information 6 Additional Information For more information about FUJITSU SEMICONDUCTOR products, visit the following website. English version: http://www.fujitsu.com/cn/fsp/services/mcu/mb95/application_notes.html Simplified Chinese Version: http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html MCU-AN- 500084-E-10 – Page 33 Capacitance Touch Sensor V1.0 Chapter 7 Appendix 7 Appendix 7.1 Index of Figures Figure 2-1: Capacitance Touch Sensor Theory ....................................................................... 6 Figure 2-2: Operation Flowchart .............................................................................................. 6 Figure 2-3: Hardware Connection ............................................................................................ 7 Figure 2-4: Sketch Map ............................................................................................................ 7 Figure 3-1: Select File ............................................................................................................ 13 Figure 3-2: open Add Member Window ................................................................................. 14 Figure 3-3: Select File Type ................................................................................................... 14 Figure 3-4: Show TSC.lib ....................................................................................................... 15 Figure 3-5: Add TSC.lib ......................................................................................................... 15 Figure 3-6: Add “#include “TSC.h "” in “main.c” ..................................................................... 16 Figure 3-7: ‘#include ‘TSC.h’’ is Added Successfully ............................................................. 16 Figure 3-8: Get Threshold with GUI Flowchart ...................................................................... 17 Figure 3-9: Working Flowchart ............................................................................................... 18 Figure 5-1: GUI Connects TSC Board ................................................................................... 21 Figure 5-2: GUI Software ....................................................................................................... 21 Figure 5-3: TSC GUI Interface ............................................................................................... 22 Figure 5-4: Check Main Interface ........................................................................................... 23 Figure 5-5: Check Start .......................................................................................................... 24 Figure 5-6: Checking .............................................................................................................. 25 Figure 5-7: Check Stop .......................................................................................................... 26 Figure 5-8: Calculate Threshold ............................................................................................. 27 Figure 5-9: Test Main Interface .............................................................................................. 28 Figure 5-10: Test Start ........................................................................................................... 29 Figure 5-11: Testing ............................................................................................................... 30 Figure 5-12: Test Result ........................................................................................................ 31 Figure 5-13: Graph ................................................................................................................. 32 7.2 Index of Table Table 3-1: Functions ................................................................................................................ 8 Table 3-2: TSC_init .................................................................................................................. 9 Table 3-3: button1_init ............................................................................................................. 9 Table 3-4: button2_init ............................................................................................................. 9 Table 3-5: button3_init ............................................................................................................. 9 Table 3-6: button4_init ............................................................................................................. 9 Table 3-7: UART_init ............................................................................................................. 10 MCU-AN- 500084-E-10 – Page 34 Capacitance Touch Sensor V1.0 Chapter 7 Appendix Table 3-8: TBT_init ................................................................................................................ 10 Table 3-9: Transmit ................................................................................................................ 10 Table 3-10: get_mode ............................................................................................................ 10 Table 3-11: Get_Data ............................................................................................................ 11 Table 3-12: set_mode ............................................................................................................ 11 Table 3-13: clear_check_data ................................................................................................ 12 Table 3-14: Performance ....................................................................................................... 12 MCU-AN- 500084-E-10 – Page 35 Capacitance Touch Sensor V1.0 Chapter 7 Appendix 7.3 Sample Code Project Name: TSC Function: TSC /******************************************************************************************** -File: main.c -Author: Ivan Xiao -Date: 20100408 -Function: For TSC *********************************************************************************************/ #include "mb95200.h" #include "TSC.h" unsigned char led = 0; /******************************************************************************************** -FunctionName: init -Description: initialization system and -Input: None -Return: None *********************************************************************************************/ void init (void) { SYCC = 0; EIC30 = 0x50; //machine frequence is 8M //external interrupt 7 DDR1 = 0xff; PDR1 = 0xFF; DDR6 = 0xff; PDR6 = 0xFF; Button1_init(1077); //button1 threshold initialization Button2_init(1080); //button2 threshold initialization Button3_init(1086); //button3 threshold initialization Button4_init(1080); //button4 threshold initialization TSC_init (); //TSC initialization #ifdef enableUART UART_init(); //use serial port and initialization #endif TBT_init(); //Timebase Timer initialization } MCU-AN- 500084-E-10 – Page 36 Capacitance Touch Sensor V1.0 Chapter 7 Appendix /******************************************************************************************** -FunctionName: main -Description: main function -Input: None -Return: None *********************************************************************************************/ void main(void) { unsigned char temp; init (); InitIrqLevels(); __EI(); while(1) { if(get_mode() == Highest_Mode) //judge current mode { switch(Get_Data()) //get check result { case HighestMode_Button1: PDR6 = 0xf7; //button1 touching temp = PDR0; temp |= 0x40; PDR0 = temp; PDR1 = 0xff; break; case HighestMode_Button2: PDR6 = 0xef; //button2 touching temp = PDR0; temp |= 0x40; PDR0 = temp; PDR1 = 0xff; break; MCU-AN- 500084-E-10 – Page 37 Capacitance Touch Sensor V1.0 Chapter 7 Appendix case HighestMode_Button3: PDR6 = 0xff; //button3 touching temp = PDR0; temp &= 0xbf; PDR0 = temp; PDR1 = 0xff; break; case HighestMode_Button4: PDR6 = 0xff; //button4 touching temp = PDR0; temp |= 0x40; PDR0 = temp; PDR1 = 0x00; break; case Checking: PDR6 = 0xff; //no button touch temp = PDR0; temp |= 0x40; PDR0 = temp; PDR1 = 0xFF;break; } } else if(get_mode() ==Normal_Mode) //judge current mode { if((Get_Data() & BIT00_Button1)== NormalMode_Button1) //judge button1 touching? { temp = PDR6; temp &= 0xf7; PDR6 = temp; } else { temp = PDR6; temp |= 0x08; MCU-AN- 500084-E-10 – Page 38 Capacitance Touch Sensor V1.0 Chapter 7 Appendix PDR6 = temp; } if((Get_Data() & BIT01_Button2) == NormalMode_Button2) //judge button1 touching? { temp = PDR6; temp &= 0xef; PDR6 = temp; } else { temp = PDR6; temp |= 0x10; PDR6 = temp; } if((Get_Data() & BIT02_Button3) == NormalMode_Button3) //judge button1 touching? { temp = PDR0; temp &= 0xbf; PDR0 = temp; } else { temp = PDR0; temp |= 0x40; PDR0 = temp; } if((Get_Data() & BIT03_Button4) == NormalMode_Button4) //judge button1 touching? { PDR1 = 0x00; } else { PDR1 = 0xff; } } MCU-AN- 500084-E-10 – Page 39 Capacitance Touch Sensor V1.0 Chapter 7 Appendix else if(get_mode() == Slippage_Mode) //judge current mode { if(Get_Data() == SlippageMode_Add) //judge slippage bearing { led++; if(led>4) led =4; clear_check_data(); //clear check data } else if(Get_Data() == SlippageMode_Sub) //judge slippage bearing { if(led !=0) led--; clear_check_data(); } switch(led) { case 0: //open 0 led temp = PDR6; temp |= 0x18; PDR6 = temp; temp = PDR0; temp |= 0x40; PDR0 = temp; PDR1 = 0xff; break; case 1: //open 1 led temp = PDR6; temp |= 0x10; temp &= 0xF7; PDR6 = temp; temp = PDR0; temp |= 0x40; MCU-AN- 500084-E-10 – Page 40 Capacitance Touch Sensor V1.0 Chapter 7 Appendix PDR0 = temp; PDR1 = 0xff; break; case 2: //open 2 leds temp = PDR6; temp &= 0xE7; PDR6 = temp; temp = PDR0; temp |= 0x40; PDR0 = temp; PDR1 = 0xff; break; case 3: //open 3 leds temp = PDR6; temp &= 0xE7; PDR6 = temp; temp = PDR0; temp &= 0xBF; PDR0 = temp; PDR1 = 0xff; break; case 4: //open 4 leds temp = PDR6; temp &= 0xE7; PDR6 = temp; temp = PDR0; temp &= 0xBF; PDR0 = temp; PDR1 = 0x00; break; } } } } MCU-AN- 500084-E-10 – Page 41 Capacitance Touch Sensor V1.0 Chapter 7 Appendix /******************************************************************************************** -FunctionName: E_INT -Description: external interrupt process, change mode by hard key. -Input: None -Return: None *********************************************************************************************/ __interrupt void E_INT (void) { unsigned char temp; if(get_mode() == Highest_Mode) //judge current mode to change mode set_mode(Normal_Mode); else if(get_mode() == Normal_Mode) { set_mode(Slippage_Mode); } else if(get_mode() == Slippage_Mode) set_mode(Highest_Mode); temp = EIC30; temp &= 0x7f; EIC30 = temp; } /******************************************************************************************** -FunctionName: UART_T -Description: serial port transmit interrupt -Input: None -Return: None *********************************************************************************************/ #ifdef enableUART __interrupt void UART_T (void) { Transmit(); //transmit check data to TSC GUI } #endif MCU-AN- 500084-E-10 – Page 42