492KB

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-500124-E-11
F²MC-8FX FAMILY
8-BIT MICROCONTROLLER
MB95F430H SERIES
CAPACITANCE TOUCH SENSOR
USE TSC2_DEMO_434.LIB
APPLICATION NOTE
USE TSC2_Demo_434.LIB V1.1.0
Revision History
Revision History
Version
Date
Updated by
Approved by
Modifications
1.0.0
2011-06-03
Ivan Xiao
Jacky Zhou
First Draft
1.1.0
2011-08-01
Lee Song
Jacky Zhou
1 Update template to the latest version
2 Modify API name and function description
based on new TSC.lib
3 Add new sample code, include UART and Key
service functions
This manual contains 36 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 © 2011 Fujitsu Semiconductor Design (Chengdu) Co., Ltd. All rights reserved.
MCU-AN-500124-E-11 – Page 2
USE TSC2_Demo_434.LIB V1.1.0
Contents
Contents
REVISION HISTORY ............................................................................................................ 2
CONTENTS .......................................................................................................................... 3
1 INTRODUCTION .............................................................................................................. 5
1.1
Purpose ................................................................................................................... 5
1.2
Definitions, Acronyms and Abbreviations ................................................................ 5
1.3
Document Overview ................................................................................................ 5
2 SOLUTIONS .................................................................................................................... 6
2.1
AD Discharge Solution ............................................................................................ 6
2.2
Relaxation Oscillation Solution ................................................................................ 8
3 LIBRARY ....................................................................................................................... 10
3.1
Library Overview ................................................................................................... 10
3.2
Parameters Setup ................................................................................................. 11
3.3
3.2.1
Structure type define................................................................................ 11
3.2.2
Port and Pin define .................................................................................. 11
3.2.3
Sample parameters setup ........................................................................ 11
3.2.4
Example of Parameters Setup ................................................................. 12
Application Interface .............................................................................................. 13
3.3.1
Initialization Function ............................................................................... 13
3.3.2
Check Sensor Function............................................................................ 13
3.3.3
Get Value Function .................................................................................. 14
3.3.4
Update Threshold Function ...................................................................... 14
3.4
FUJITSU TSC Performance .................................................................................. 15
3.5
How to Add Fujitsu TSC.lib .................................................................................... 16
3.6
3.5.1
Add Fujitsu TSC.lib to User’s Project ....................................................... 16
3.5.2
Include Header File.................................................................................. 18
How to use Fujitsu TSC.lib .................................................................................... 19
4 LIB USAGE NOTICE ..................................................................................................... 21
5 ADDITIONAL INFORMATION ....................................................................................... 23
6 APPENDIX ..................................................................................................................... 24
6.1
List of Figures and Tables ..................................................................................... 24
6.2
Sample code ......................................................................................................... 25
6.2.1
Main Function .......................................................................................... 25
6.2.2
Uart Function ........................................................................................... 29
MCU-AN-500124-E-11 – Page 3
USE TSC2_Demo_434.LIB V1.1.0
Contents
6.2.3
Key_Service Function .............................................................................. 35
MCU-AN-500124-E-11 – Page 4
USE TSC2_Demo_434.LIB V1.1.0
Chapter 1 Introduction
1 Introduction
1.1
Purpose
This application note describes FUJITSU TSC solution, and describes how to use TSC
library and TSC GUI.
1.2
Definitions, Acronyms and Abbreviations
1.3
Document Overview
The rest of document is organized as the following:
Chapter 2 explains the working principles of used solution.
Chapter 3 explains how to use TSC library.
Chapter 4 explains LIB usage notice.
MCU-AN-500124-E-11 – Page 5
USE TSC2_Demo_434.LIB V1.1.0
Chapter 2 Solutions
2 Solutions
This chapter introduces working principles of TSC solutions used in TSC2_EVB_434.LIB.
2.1
AD Discharge 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ғ.
This ΔC will affect the electrode charging-up time.
The AD discharge method detects the touch action by compare the voltage difference at the
same time.
Let V1 is voltage of electrode at time t in finger not touch situation. When finger touching,
speed of electrode discharging will be delayed (because of ΔC). At the same time t, the
voltage is V2 which larger than V1. MCU can detect the touch action by compare this voltage
change.
MCU
ADC-pin
Figure 2-1: AD Discharge method Physical Diagram
V
V2
ΔV
V1
Finger not touch
Finger touching
t
t
Figure 2-2: AD Discharge method Curve Graph
MCU-AN-500124-E-11 – Page 6
USE TSC2_Demo_434.LIB V1.1.0
Chapter 2 Solutions
The AD Discharge method includes the following steps:
1. Set pin to input (high impedance) to charge the pad
2. Set pin to output ‘L’ to discharge the pad
3. Get the ADC value periodically
4. Save ADC value
5. Start next sample
The flowchart shown as below
Start
Charge the pad
Discharge the pad
Wait timer
interrupt
Y
Save ADC value
Figure 2-3: AD Discharge method Check Flowchart
MCU-AN-500124-E-11 – Page 7
USE TSC2_Demo_434.LIB V1.1.0
Chapter 2 Solutions
2.2
Relaxation Oscillation 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ғ.
This ΔC will affect the electrode charging-up time.
The Relaxation Oscillation method detects the touch action by compare the frequency
difference which is dependent upon the time.
A simple relaxation oscillator can be created using the MCU’s on-chip comparator and the
capacitive sensor as the tuning element. Any change in capacitance of the sensor
corresponds to a change in frequency which can be measured using the internal PWC
(Pulse Width Capture) hardware of the MCU.
R
CMP_N
CMP_O
CA
R
CMP_P
VREF
R
Timer Input
TAR
Figure 2-4: Relaxation Oscillation method physical diagram
MCU-AN-500124-E-11 – Page 8
USE TSC2_Demo_434.LIB V1.1.0
Chapter 2 Solutions
Finger not touch
V
Finger touching
t
V
t
Figure 2-5: Relaxation Oscillation method curve graph
The Relaxation Oscillation method includes the following steps:
1. Configure register of Comparator
2. Enable PWC interrupt
3. Clear interrupt flag
4. Get the counter value in interrupt service routine
5. Save counter value
6. Start next sample
The flowchart shown as below
Start
Start Comparator
Enable PWC interrupt
Clear interrupt flag
Wait PWC
interrupt
Y
Save Counter value
Figure 2-6: Relaxation Oscillation method Check Flowchart
MCU-AN-500124-E-11 – Page 9
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3 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
Remark
Key_Const type
TSC Key data structure type define
N/A
TSC_ADKEY
TSC AD data structure array
N/A
TSC_CMPKEY
TSC CMP data structure array
N/A
TSC_ADKeyNum
TSC AD Key Number
N/A
TSC_CMPKeyNum
TSC CMP Key Number
N/A
TSCKEY_ADPORT [1..3]
TSC AD Key IO port
N/A
TSCKEY_ CMPREFDATA
TSC CMP Key REF pin data
N/A
TSCKEY_ CMPREFDIR
TSC CMP Key REF pin direction
N/A
TSCKEY_ADPIN [0..7]
TSC Key IO pin
N/A
TSCKEY_ADSampleNumConst
TSC GPIO Key sample number
N/A
TSCKEY_CMPSampleNumConst
TSC AD Key sample number
N/A
TSC_ADThreshold
TSC GPIO Key Threshold data array
N/A
TSC_CMPThreshold
TSC AD Key Threshold data array
N/A
TSC_TimerData
TSC Key Timer Dare register
N/A
TSC_TimerEn
TSC Key Timer Start/Stop control bit
N/A
Table 3-2: Functions List
Prototype
Function Description
Remark
TSCKey_ADInit
This function initializes the timer used, the data structures of the
library and calculates the initial capacitance of the electrodes.
N/A
TSCKey_ADCheck
This function is used to Check if the charge process are
completed and save the value.
N/A
TSCKey_GetADValue
This function is used to detect the key touched status, and
generate a specific key word.
N/A
TSCKey_CMPInit
This function initializes the timer used, the data structures of the
library and calculates the initial capacitance of the electrodes.
N/A
T00PWC_ISR
This function as the interrupt service routine to capture the
oscillation wave and count the value
N/A
TSCKey_GetGPIOValue
This function is used to detect the key touched status, and
generate a specific key word.
N/A
TSCKey_UpdateThr
This function is used to update the threshold set by the GUI and
refresh the detect difference
N/A
MCU-AN-500124-E-11 – Page 10
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.2
Parameters Setup
3.2.1 Structure type define
Every TSC Key have 4 attributes include: initial status, count value, threshold value and
difference threshold value. User can define new key directly using the following structure.
typedef struct
{
unsigned char InitFlag;
//**< Contains the initial status
unsigned int Value;
//**< Contains the count value
unsigned int Threshold;
//**< Contains the threshold value now
unsigned int DifThreshold;
//**< Contains the threshold temp value
} Key_Const;
All the keys which have been defined can make up a array which length will defined by the
parameter TSC_GPIOKeyNum and TSC_ADKeyNum
3.2.2 Port and Pin define
Parameter TSCKEY_ADPORT[1..3], TSCKEY_CMPPORT are used to configure the TSC
pin. The TSCKEY_ADPORT, TSCKEY_CMPPORT, directly use the register value on the
data sheet, and the TSCKEY_ADPIN[0..7] configure the pin (use the continuous pin in same
port are recommend, because that will be good at the sample speed).
3.2.3 Sample parameters setup
The parametes:
#define TSCKEY_ADSampleNumConst
10
//Sample number
#define TSCKEY_CMPSampleNumConst
20
//Sample number
#define TSCKEY_ADDifThrOffset
130
//Threshold Difference Offset
#define TSCKEY_CMPDifThrOffset
120
//Threshold Difference Offset
#define TSC_TimerData
T00DR
//Timer Data
#define TSC_TimerEn
T00CR1_STA
//Timer Enable
extern unsigned int TSC_ADThreshold[TSC_KeyNum];
extern unsigned int TSC_CMPThreshold[TSC_KeyNum];
used to configure the sample number, threshold, and timer initial value.
MCU-AN-500124-E-11 – Page 11
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.2.4 Example of Parameters Setup
#define TSCKEY_ADSampleNumConst
10
//Sample number
#define TSCKEY_CMPSampleNumConst
20
//Sample number
#define TSCKEY_ADDifThrOffset
130
//Threshold Difference Offset
#define TSCKEY_CMPDifThrOffset
120
//Threshold Difference Offset
#define TSC_ADKeyNum
8
//TSCKey number
#define TSC_CMPKeyNum
1
//TSCKey number
#define TSCKEY_CMPREFDATA
PDR7_P76
//TSCKey pin data
>>P76
#define TSCKEY_CMPREFDIR
DDR7_P76
//TSCKey pin dir
>>P76
#define TSCKEY_ADPORT1
0x0000
//TSCKey port register
>>P0
#define TSCKEY_ADPORT2
0x0018
//TSCKey port register
>>P7
#define TSCKEY_ADPORT3
0x0016
//TSCKey port register
>>P6
#define TSCKEY_ADPIN1
0x01
//TSCKey pin dir & data
>>P00
#define TSCKEY_ADPIN2
0x02
//TSCKey pin dir & data
>>P01
#define TSCKEY_ADPIN3
0x04
//TSCKey pin dir & data
>>P02
#define TSCKEY_ADPIN4
0x20
//TSCKey pin dir & data
>>P04
#define TSCKEY_ADPIN5
0x40
//TSCKey pin dir & data
>>P05
#define TSCKEY_ADPIN6
0x02
//TSCKey pin dir & data
>>P71
#define TSCKEY_ADPIN7
0x04
//TSCKey pin dir & data
>>P72
#define TSCKEY_ADPIN8
0x08
//TSCKey pin dir & data
>>P63
#define TSC_TimerData
T00DR
//Timer Data
#define TSC_TimerEn
T00CR1_STA
//Timer Enable
typedef struct
{
unsigned char InitFlag;
//<Contains the initial status
unsigned int Value;
//<Contains the count value
unsigned int Threshold;
//<Contains the threshold value
unsigned int DifThreshold;
//<Contains the difference threshold
} Key_Const;
extern unsigned int TSC_GPIOThreshold[TSC_KeyNum];
extern unsigned int TSC_ADThreshold[TSC_KeyNum];
extern Key_Const TSC_GPIOKEY[TSC_GPIOKeyNum];
extern Key_Const TSC_ADKEY[TSC_ADKeyNum];
MCU-AN-500124-E-11 – Page 12
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.3
Application Interface
All the functions supplied by the TSC.lib will be introduced below, include the function prototype,
input parameter(s), return value(s), and the function description.
3.3.1 Initialization Function
Table 3-3: Initialization Function Table (AD Method)
Prototype
void TSCKey_ADInit (Key_Const *Key);
Parameter:
Key_Const *
Return
void
Description
This function initializes the timer used, the data structures of the library and calculates the
initial capacitance of the electrodes.
Remark
N/A
Key
Pointer to the TSC Key array
Table 3-4: Initialization Function Table (RO Method)
Prototype
void TSCKey_CMPInit (Key_Const *Key);
Parameter:
Key_Const *
Return
void
Description
This function initializes the timer used, the data structures of the library and calculates the
initial capacitance of the electrodes.
Remark
N/A
Key
Pointer to the TSC Key array
3.3.2 Check Sensor Function
Table 3-5: Check Sensor Function Table (AD Method)
Prototype
unsigned int TSCKey_ADCheck(unsigned char TSC_Port,unsigned char TSC_Pin,unsigned
char TSCKEY_SampleNum)
Parameter:
unsigned char*
TSC_Port
Port to be checked
unsigned char
TSC_Pin
Pin to be checked
unsigned char
TSCKEY_SampleNum
Sample number
Return
unsigned int
Check_count
The counter value
Description
This function is used to Check if the charge process are completed and save the value.
Remark
N/A
Table 3-6: Check Sensor Function Table
Prototype
__interrupt void T00PWC_ISR (void)
Parameter:
void
Return
void
Description
This function as the interrupt service routine to capture the oscillation wave and count the
value
Remark
N/A
MCU-AN-500124-E-11 – Page 13
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.3.3 Get Value Function
Table 3-7: Get Value Function Table (AD Method)
Prototype
unsigned char TSCKey_GetADValue(Key_Const *Key)
Parameter:
Key_Const *
Key
Return
Pointer to the TSC Key array
The Key word for the service function
unsigned char
TSCKeyValue
Single touch mode: Only the latest detected
key will be set with ‘0’
Multi touch mode: All touched keys be set
with ‘0’
Description
This function is used to detect the key touched status, and generate a specific key word.
Remark
N/A
Table 3-8: Get Value Function Table (RO Method)
Prototype
unsigned char TSCKey_GetGPIOValue(Key_Const *Key)
Parameter:
Key_Const *
Key
Return
Pointer to the TSC Key array
The Key word for the service function
unsigned char
TSCKeyValue
Single touch mode: Only the latest detected
key will be set with ‘0’
Multi touch mode: All touched keys be set
with ‘0’
Description
This function is used to detect the key touched status, and generate a specific key word.
Remark
N/A
3.3.4 Update Threshold Function
Table 3-9: Update Threshold Function Table
Prototype
void TSCKey_UpdateThr(Key_Const *Key,unsigned char Key_Num,unsigned int *Key_Thr)
Parameter:
Key_Const *
Key
Pointer to the TSC Key array
unsigned char
Key_Num
Number of TSC Keys
unsigned int *
TSCKEY_SampleNum
Pointer to the TSC Threshold array
Return
void
Description
This function is used to update the threshold set by the GUI and refresh the detect difference
Remark
N/A
MCU-AN-500124-E-11 – Page 14
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.4
FUJITSU TSC Performance
Table 3-10: 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
1
P0
IO Pin
4
P04,P05,P06,P07
Timer
2
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-500124-E-11 – Page 15
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.5
How to Add Fujitsu TSC.lib
3.5.1 Add Fujitsu TSC.lib to User’s Project
1. In Softune, Right click on folder Include Files  select Add member to folder from the
menu select File.
Figure 3-1: Add member to folder
2. Because the default option of file type filters is *.c and * .asm, you can’t found TSC.lib in
dialog box of Add Member.
Figure 3-2: Popup Add Member dialog box
MCU-AN-500124-E-11 – Page 16
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3. In Add Member dialog box, select ‘ALL Files’ from ‘Files of Type’, and then you will find
the TSC.lib
Figure 3-3: Found the lib file
4. Double click TSC.lib, and then you can see it has been added in the folder Include Files
Figure 3-4: Add TSC.lib
MCU-AN-500124-E-11 – Page 17
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.5.2 Include Header File
1. Add "#include"TSC.h "" in C file, such as in "main.c ".
Figure 3-5: Add include statement in C file
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-6: Include header file successfully
MCU-AN-500124-E-11 – Page 18
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
3.6
How to use Fujitsu TSC.lib
After complete above works, we can start use the TSC library now. The operation
categorised by if connect to GUI. Both of two operations need initialize TSC, initialize Timer,
initialize GPIO and initialize interrupt. If connect to GUI, the UART module should also be
initialized.
Start
Disable comparer
Disable system interrupt
Set Oscillator
Set interrupt level
Enable system interrupt
Initialize the GPIO
Initialize the UART
Initialize the timer
End
Figure 3-7: Initialize Flow chart
After all used modules have been initialized, program go into a endless loop, to do below
step circularly:
1. Wait the time interval interrupt is generate, clear the interrupt flag
2. Check the electrodes and save the counter value
3. Judgement if the new value bigger or lower than the threshold, if meet the condition,
generate the key word
4. According to the key word jump to corresponding operation (such as drive LED)
5. Go to another new loop
If connect GUI, in above process, there also have the UART interrupt, MCU need send out
counter value or get new threshold from GUI. The direct of transmission is determined by the
user-defined protocol.
MCU-AN-500124-E-11 – Page 19
USE TSC2_Demo_434.LIB V1.1.0
Chapter 3 Library
Start
Wait time interrupt
Check sensor
Save counter value
N
UART
Communication
Meet
detect condition?
Y
Generate key word
Key service
Figure 3-8: Main loop Flowchart
MCU-AN-500124-E-11 – Page 20
GUI
USE TSC2_Demo_434.LIB V1.1.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” as following:
#include " mb95390.h"
/******************************************************************************
InitIrqLevels()
This function
pre-sets all interrupt control registers. It can be used
to set all interrupt priorities in static applications. If this file
contains assignments to dedicated resources, verify
that the
appropriate controller is used.
******************************************************************************/
void InitIrqLevels(void)
{
#ifdef enableUART
ILR2 = 0xFE;
//
IRQ8:
LIN-UART (transmission)
//
IRQ8:
LIN-UART (transmission)
//
IRQ19: Timebase timer
#else
ILR2 = 0xFF;
#endif
ILR4 = 0x3F;
}
/******************************************************************************
Prototypes
Add your own prototypes here. Each vector definition needs is prototype.
Either do it here or include a header file containing them.
******************************************************************************/
__interrupt void DefaultIRQHandler (void);
#ifdef enableUART
__interrupt void UART_ISR (void);
#endif
__interrupt void TBT_ISR (void);
MCU-AN-500124-E-11 – Page 21
USE TSC2_Demo_434.LIB V1.1.0
Chapter 4 LIB Usage Notice
/******************************************************************************
Vector definition
Use following statements to define vectors.
All resource related vectors are predefined.
Remaining software interrupts can be added hereas well.
******************************************************************************/
#ifdef enableUART
#pragma intvect UART_T
8
//
IRQ8:
LIN-UART (transmission)
8
//
IRQ8:
LIN-UART (transmission)
19
//
IRQ19: Time base timer
#else
#pragma intvect DefaultIRQHandler
#endif
#pragma intvect TBT_ISR
MCU-AN-500124-E-11 – Page 22
USE TSC2_Demo_434.LIB V1.1.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/mb95/application_notes.html
Chinese version address:
http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html
MCU-AN-500124-E-11 – Page 23
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
6 Appendix
6.1
List of Figures and Tables
Table 3-1: Parameters List ................................................................................................... 10
Table 3-2: Functions List ...................................................................................................... 10
Table 3-3: Initialization Function Table (AD Method) ............................................................ 13
Table 3-4: Initialization Function Table (RO Method)............................................................ 13
Table 3-5: Check Sensor Function Table (AD Method) ........................................................ 13
Table 3-6: Check Sensor Function Table ............................................................................. 13
Table 3-7: Get Value Function Table (AD Method) ............................................................... 14
Table 3-8: Get Value Function Table (RO Method) .............................................................. 14
Table 3-9: Update Threshold Function Table ....................................................................... 14
Table 3-10: Performance ..................................................................................................... 15
Figure 2-1: AD Discharge method Physical Diagram.............................................................. 6
Figure 2-2: AD Discharge method Curve Graph ..................................................................... 6
Figure 2-3: AD Discharge method Check Flowchart ............................................................... 7
Figure 2-4: Relaxation Oscillation method physical diagram .................................................. 8
Figure 2-5: Relaxation Oscillation method curve graph .......................................................... 9
Figure 2-6: Relaxation Oscillation method Check Flowchart................................................... 9
Figure 3-1: Add member to folder......................................................................................... 16
Figure 3-2: Popup Add Member dialog box .......................................................................... 16
Figure 3-3: Found the lib file................................................................................................. 17
Figure 3-4: Add TSC.lib........................................................................................................ 17
Figure 3-5: Add include statement in C file ........................................................................... 18
Figure 3-6: Include header file successfully.......................................................................... 18
Figure 3-7: Initialize Flow chart ............................................................................................ 19
Figure 3-8: Main loop Flowchart ........................................................................................... 20
MCU-AN-500124-E-11 – Page 24
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
6.2
Sample code
6.2.1 Main Function
File Name: main.c
Function: Initialize and configure
/********************************************************************************************
-File:
main.c
-Author:
Lee Song
-Date:
20110510
-Function:Initialize and configure
*********************************************************************************************/
#include "Lcd_StateGrid.h"
#include "main.h"
#include "PortDef.h"
#include "HardKey.h"
#include "TSC.h"
extern UCHAR disUpdateFlage;
extern UCHAR HideDataBuff[8];
unsigned char TSCUpdateFlag;
extern void TBT_Init(void);
volatile unsigned int Div_Counter = 0;
//=====================================================================
// Initial GPIO peripheral
//=====================================================================
void GPIO_Init(void)
{
LCDCE1 = 0;
LCDCE1_PICTL = 1;
//Set for use GPIO
//Set for use GPIO
LED1_Off;
LED2_Off;
LEDCtrl_DirOut;
HKEYInput_DirIn;
BeepCtrl_Off;
BeepCtrl_DirOut;
//BEEP_Dir
}
MCU-AN-500124-E-11 – Page 25
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
//==================================================================
// Beeper control function
//==================================================================
void Beep(unsigned char num,unsigned char delay)
{
unsigned int i,j,k;
for(k=0;k<num;k++)
{
BeepCtrl_On;
for(i=0;i<100;i++)
{
for(j=0;j<delay;j++);
}
BeepCtrl_Off;
for(i=0;i<100;i++)
{
for(j=0;j<delay;j++);
}
}
}
//==================================================================
// FunctionName: main
// Description: main function
// Input: None
// Return: None
//==================================================================
void main(void)
{
UCHAR dataBuff[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
unsigned char i = 0;
unsigned char j = 1;
CMR0_VCID = 1;
//Disable CMP input
__DI();
Osc_Setup();
//Setup MCU main oscillator/FLL
InitIrqLevels();
//Initialise Interrupt level register and IRQ vector table
__EI();
//Enable system interrupt now
GPIO_Init();
TBT_Init();
MCU-AN-500124-E-11 – Page 26
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
IIC_Init();
#ifdef enableUART
UART_Init();
#endif
do
{
LED1_On;
LED2_On;
if(TSCUpdateFlag == 1)
{
Div_Counter++;
TSCUpdateFlag = 0;
}
}
while(Div_Counter < 30);
Div_Counter = 0;
LED1_Off;
LED2_Off;
Beep(2,500);
TSCKey_Init(TSCKEY);
while(1)
{
CallUpDateKey();
TSCKey_Service();
if(TSCUpdateFlag == 1)
{
TSCUpdateFlag = 0;
if((Div_Counter % 9) == 0)
{
TSCKey_UpdateThr(TSCKEY,TSC_KeyNum,TSC_Threshold);
}
if(Div_Counter == 360)
{
Div_Counter = 0;
}
Div_Counter++;
}
}
}
MCU-AN-500124-E-11 – Page 27
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
//==================================================================
// Setup MCU main oscillator/FLL
// Internal clock 243KHz. Set FLL for 11MHz Bus frequency
//==================================================================
void Osc_Setup(void)
{
SYSC &=0xbf;
//Set PF0/PF1 as main CR pin,set PG1/PG2 as GPIO
SYCC =0xf0;
WATR =0xf3;
SYCC2 =0xf4;
while(STBC_MRDY == 0);
RESET_WATCHDOG();
}
//==================================================================
// Reset the watch dog timer
//==================================================================
void RESET_WATCHDOG(void)
{
WDTC = 0x35;
}
MCU-AN-500124-E-11 – Page 28
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
6.2.2 Uart Function
File Name: Uart.c
Function: Initialize and configure UART module
/********************************************************************************************
-File:
Uart.c
-Author:
Lee Song
-Date:
20110610
-Function: Initialize and configure UART module
*********************************************************************************************/
#include "mb95390.h"
#include "TSC.h"
#include "Uart.h"
unsigned char UART_Start = 0;
unsigned char UART_Sent = 0;
unsigned char UART_Get = 0;
unsigned char Threshold_N = 0;
unsigned char UART_Setfinish = 0;
unsigned char *pTSC_Threshold = (unsigned char *)TSC_Threshold;
unsigned char UART_TSCValue[UART_DBUFF_LEN] = {0};
unsigned char UART_TSCStatus[UART_SBUFF_LEN] = {0};
unsigned char UART_DBUFF_PTR = 0;
unsigned char UART_SBUFF_PTR = 0;
void UART_Init(void)
{
UART_Dir_IN;
UART_Dir_OUT;
SMC10 = 0x0C; // UART/SIO Serial Mode Control Register 1 (SMC10)
// |||||||+------Operating mode select bit (Clock asynchronous mode (UART))
// |||||++-------
Clock select bit(Dedicated baud rate generator)
// ||||+---------
Character bit length control bits(8 bits)
// |||+----------
Stop bit length control bit(2-bit length)
// ||+-----------
Parity control bit(No parity)
// |+------------
Parity polarity bit(Even parity)
// +-----------sequentially)
Serial data direction control bit(Transmit/receive data from MSB side
MCU-AN-500124-E-11 – Page 29
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
SMC20 = 0x5E;// UART/SIO Serial Mode Control Register 2 (SMC20)
// |||||||+-------
Transmission data register empty interrupt enable bit(Disables
//
transmission data register empty interrupts)
// ||||||+-------
Transmission completion interrupt enable bit(Enables transmission
//
completion interrupts)
// |||||+--------
Reception interrupt enable bit(Enables reception interrupts)
// ||||+---------
Transmission operation enable bit(Enables transmission operation)
// |||+----------
Reception operation enable bit(Enables reception operation)
// ||+-----------
Reception error flag clear bit(Clears the error flags in the SSR0 register)
// |+------------
Serial data output enable bit(Enables serial data output)
// +------------
Serial data output enable bit(Disables serial clock output (usable as
//
a general-purpose port))
PSSR0 = 0x04; // UART/SIO Dedicated Baud Rate Generator Prescaler Select Register
(PSSR0)
// ||||||++-------
Prescaler select bits(1/1)
// |||||+----------
Baud rate clock output enable bit(Enables transmission completion interrupts)
// +++++--------Undefined bit
BRSR0 = 26;
// UART/SIO Dedicated Baud Rate Generator Baud Rate Setting
// Register (BRSR0)
// 2 ~ 255
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////// Sample Asynchronous Transfer Rates by Baud Rate Generator ///////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
Total division ratio
//
(PSS × BRS × 4)
Baud rate
/////////////////////////////////////
(Machine Clock/Total division ratio)////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SSR0 = 0x00;
// UART/SIO Serial Status Register (SSR0)
// |||||||+------
Transmit data register empty flag
//
(0:Transmit data present / 1:Transmit data absent)
// ||||||+-------
Transmission completion flag
// |+------------
Parity polarity bit(Even parity)
// +-----------sequentially)
Serial data direction control bit(Transmit/receive data from MSB side
}
MCU-AN-500124-E-11 – Page 30
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
void UART_Transmit(void)
{
if(UART_Sent == 1)
{
if(UART_DBUFF_PTR < UART_DBUFF_LEN)
//Sent the data
{
TDR0 = UART_TSCValue[UART_DBUFF_PTR++];
}
else if(UART_DBUFF_PTR < (UART_DBUFF_LEN << 1))
//Sent the threshold
{
TDR0 = pTSC_Threshold[UART_DBUFF_PTR - UART_DBUFF_LEN];
UART_DBUFF_PTR++;
}
else if(UART_DBUFF_PTR == (UART_DBUFF_LEN << 1))
{
UART_Sent = 0;
UART_DBUFF_PTR = 0;
}
}
else if(UART_Sent == 2)
//Sent the board status
{
if(UART_SBUFF_PTR < UART_SBUFF_LEN)
{
TDR0 = UART_TSCStatus[UART_SBUFF_PTR++];
}
else
{
UART_Sent = 0;
UART_SBUFF_PTR = 0;
}
}
else
{
SSR0_TCPL = 0;
}
}
MCU-AN-500124-E-11 – Page 31
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
__interrupt void UART_ISR (void)
{
unsigned char UART_Temp;
SMC20_RERC = 0;
if(SSR0_RDRF == 1)
//Receive Data
{
SSR0_RDRF = 0;
if(UART_Get == 0)
{
UART_Temp = RDR0;
switch(UART_Temp)
{
case UART_Connect:
{
TDR0 = UART_Check_OK;
UART_Start = 1;
break;
}
case UART_Getdata:
{
UART_Sent = 1;
SSR0_TCPL = 1;
TDR0 = UART_TSCValue[UART_DBUFF_PTR++];
break;
}
case UART_Getstatus:
{
UART_Sent = 2;
SSR0_TCPL = 1;
TDR0 = UART_TSCStatus[UART_SBUFF_PTR++];
break;
}
case UART_Setdata:
{
TDR0 = UART_SetBack;
Threshold_N = 0;
UART_Get = 1;
break;
}
MCU-AN-500124-E-11 – Page 32
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
case UART_Disconnect:
{
UART_Start = 0;
break;
}
default:
{
TDR0 = UART_Check_Erro;
break;
}
}
}
else
//Set threshold by GUI
{
if(Threshold_N < UART_DBUFF_LEN)
{
pTSC_Threshold[Threshold_N] = RDR0;
TDR0 = UART_SetBack;
Threshold_N++;
}
else if(Threshold_N == UART_DBUFF_LEN)
{
UART_Get = 0;
Threshold_N = 0;
UART_Setfinish = 1;
TSCKey_UpdateThr(TSCKEY,TSC_KeyNum);//,TSC_Threshold);
}
}
}
else if(SSR0_TDRE == 1)
//Sent Data
{
SSR0_TDRE = 0;
if(UART_Get == 0)
UART_Transmit();
}
}
MCU-AN-500124-E-11 – Page 33
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
File Name: Uart.h
Function: Header file of UART module
/********************************************************************************************
-File:
Uart.h
-Function: Header file of UART module
/*********************************************************************************************/
#include "TSC.h"
#define UART_DBUFF_LEN
(TSC_KeyNum<<1)
#define UART_SBUFF_LEN
10
#define UART_Dir_IN
DDR1_P10 = 0
#define UART_Dir_OUT
DDR1_P11 = 1
#define UART_Connect
#define UART_Getdata
0x0F
0x5F
#define UART_Getstatus
0x6F
#define UART_Setdata
0xAF
#define UART_SetBack
0xCF
#define UART_Disconnect
0xBF
#define UART_Check_OK
0xFF
#define UART_Check_Erro
0xEF
extern unsigned char UART_TSCValue[UART_DBUFF_LEN];
extern unsigned char UART_TSCStatus[UART_SBUFF_LEN];
void UART_Init(void);
void UART_Transmit(void);
MCU-AN-500124-E-11 – Page 34
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
6.2.3 Key_Service Function
File Name: Key_Service.c
Function: Key press service function
/********************************************************************************************
-File:
Key_Service.c
-Author:
Lee Song
-Date:
20110610
-Function: Key press service function
*********************************************************************************************/
#include "mb95390.h"
#include "PortDef.h"
#include "TSC.h"
unsigned char TSCKeyCode = 0xFF;
unsigned char mTSCKeyCode = 0xFF;
unsigned int Key_Task_Time=0;
extern unsigned char TSCKeyCode;
extern volatile
unsigned int Now_Time;
void CallUpDateKey(void)
{
unsigned char TmpCode = 0xff;
unsigned char TSCTmpCode = 0xff;
if(Now_Time-Key_Task_Time >= 1)
{
Key_Task_Time = Now_Time;
TSCTmpCode = TSCKey_GetValue(TSCKEY);
if (TSCTmpCode == TSCOldCode)
TSCKeyCode = TSCTmpCode;
else
TSCOldCode = TSCTmpCode;
}
}
MCU-AN-500124-E-11 – Page 35
USE TSC2_Demo_434.LIB V1.1.0
Chapter 6 Appendix
void TSCKey_Service(void)
{
unsigned char i;
if(mTSCKeyCode != TSCKeyCode)
{
if(TSCKeyCode != 0xFF)
{
for(i=0;i<4;i++)
{
if((TSCKeyCode | (1 << i)) == 0xFF)break;
}
Beep(1,500);
}
mTSCKeyCode = TSCKeyCode;
}
}
MCU-AN-500124-E-11 – Page 36