682KB

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-500133-E-10
F²MC-8FXFAMILY
8-BIT MICROCONTROLLER
MB95410H/470H SERIES
TSC_GPIO.LIB
APPLICATION NOTE
TSC_GPIO.LIB V1.0.0
Revision History
Revision History
Version
Date
Updated by
Approved by
Modifications
1.0.0
2012-2-23
Lee Song
Jacky Zhou
First Draft
This manual contains 23 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 © 2011Fujitsu Semiconductor Design (Chengdu) Co., Ltd. All rights reserved.
MCU-AN-500133-E-10 – Page 2
TSC_GPIO.LIBV1.0.0
Contents
Contents
REVISION HISTORY ............................................................................................................ 2
CONTENTS .......................................................................................................................... 3
1 INTRODUCTION .............................................................................................................. 4
1.1
Purpose ................................................................................................................... 4
1.2
Document Overview ................................................................................................ 4
2 GPIO SOLUTION ............................................................................................................. 5
3 LIBRARY ......................................................................................................................... 7
3.1
Library Overview ..................................................................................................... 7
3.2
Parameters Setup ................................................................................................... 8
3.3
3.2.1
Port and Pin define .................................................................................... 8
3.2.2
Sample Parameters setup ......................................................................... 9
3.2.3
Structure Type Define .............................................................................. 10
Application Interface .............................................................................................. 11
3.3.1
TSCKey_Init ............................................................................................ 11
3.3.2
TSCKey_SampleUnit ............................................................................... 11
3.3.3
TSCKey_Filter ......................................................................................... 11
3.3.4
TSCKey_GetValue .................................................................................. 11
3.4
FUJITSU TSC Performance .................................................................................. 12
3.5
How to Add Fujitsu TSC_GPIO.lib ......................................................................... 13
3.6
3.5.1
Add Fujitsu TSC_GPIO.lib to User’s Project ............................................ 13
3.5.2
Include Header File.................................................................................. 15
How to use Fujitsu TSC_GPIO.lib ......................................................................... 16
4 LIB USAGE NOTICE ..................................................................................................... 18
5 ADDITIONAL INFORMATION ....................................................................................... 20
1 APPENDIX ..................................................................................................................... 21
1.1
List of Figures and Tables ..................................................................................... 21
1.2
Sample Code ........................................................................................................ 22
1.2.1
Main Function .......................................................................................... 22
MCU-AN-500133-E-10 – Page 3
TSC_GPIO.LIB V1.0.0
Chapter 1 Introduction
1 Introduction
1.1
Purpose
This application note describes FUJITSU TSC_GPIO library, which is based on latest
Capacitance Touch Sensor (TSC) GPIO algorithm. Added to that is the descriptions of how
to use TSC_GPIO library and some notices.
1.2
Document Overview
The rest of document is organized as the following:
Chapter 2 explains the working principles of GPIO solution.
Chapter 3 explains how to use TSC library.
Chapter4 explains LIB usage notice.
MCU-AN-500133-E-10 – Page 4
TSC_GPIO.LIBV1.0.0
Chapter 2 GPIO Solution
2 GPIO Solution
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-500133-E-10 – Page 5
TSC_GPIO.LIB V1.0.0
Chapter 2 GPIO Solution
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-500133-E-10 – Page 6
TSC_GPIO.LIBV1.0.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
Remarks
TSCKEY_Buttonx_Used
Decide if TSCKEY Button x be Used
N/A
TSCKEY_IndividualKeyUsed
Decide if Individual Key will be Used
N/A
TSCKEY_SlideKeyUsed
Decide if Slide Key will be Used
N/A
TSCKEY_MinificationEnable
Decide if need minification of baseline value
N/A
TSCKEY_InterpolationEnable
Decide if need interpolation of slide position
N/A
TSCKEY_KeyNum
Total GPIO TSCKey number
N/A
TSCKEY_SlideKeyNum
TSCKey GPIO slide key number
N/A
TSCKEY_IIRShiftConstLx
Shift Const Level x for IIR filter
N/A
TSCKEY_IIRNumConstLx
Number of Shift Times Const Level x for IIR filter
N/A
TSCKEY_OffsetLx
Offset Const Level x for individual keys
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
Baseline value minificateconst
N/A
TSCKEY_BalnUpdateConst
Basline update couterconst
N/A
TSCKEY_AmpShiftConst
Aamplify shift const
N/A
TSCKEY_DebounceConst
Debounceconst
N/A
TSCKEY_DebounceMinuConst
Debounceconst
N/A
Table 3-2: Functions List
Prototype
Function Description
void TSCKey_Init
(unsigned char Key_Num)
Initialize TSC module
Remarks
N/A
void TSCKey_SampleUnit
(unsigned char TSCKEY_SampleNum)
Bottom layer sample unit of TSC.
N/A
void TSCKey_Filter
(unsigned char Key_Num, unsigned char Order_Shift)
Filter function of TSC sample value
N/A
unsigned int TSCKey_GetValue
(unsigned char Key_Num)
Judgment touch status and coding key
value
N/A
MCU-AN-500133-E-10 – Page 7
TSC_GPIO.LIB V1.0.0
Chapter 3 Library
3.2
Parameters Setup
3.2.1 Port and Pin define
The driver layer function composed by assembly language, so the related ports and pins
defined based on assembly language.
#pragma asm
/* \brief TSCKEY Data Port Define */
TSCKEY_Button0_Data
.equ
0x0000
/* TSCKey pin data
>> Port 5 */
TSCKEY_Button1_Data
.equ
0x0000
/* TSCKey pin data
>> Port 0 */
TSCKEY_Button2_Data
.equ
0x0000
/* TSCKey pin data
>> Port 0 */
TSCKEY_Button3_Data
.equ
0x0000
/* TSCKey pin data
>> Port 0 */
/* \brief TSCKEY Direction Port Define */
TSCKEY_Button0_Dir
.equ
0x0001
/* TSCKey pin dir
>> Port 5 */
TSCKEY_Button1_Dir
.equ
0x0001
/* TSCKey pin dir
>> Port 0 */
TSCKEY_Button2_Dir
.equ
0x0001
/* TSCKey pin dir
>> Port 0 */
TSCKEY_Button3_Dir
.equ
0x0001
/* TSCKey pin dir
>> Port 0 */
/* \brief TSCKEY Sample Pin Define */
TSCKEY_Button0_Bit
.equ
0
/* TSCKey pin
>> P52 */
TSCKEY_Button1_Bit
.equ
1
/* TSCKey pin
>> P00 */
TSCKEY_Button2_Bit
.equ
2
/* TSCKey pin
>> P01 */
TSCKEY_Button3_Bit
.equ
3
/* TSCKey pin
>> P02 */
/* \brief Timer used Define */
TSC_TimerDataUp
.equ
0xf94
TSC_TimerDataLow
.equ
0xf95
TSC_TimerEn
.equ
0x37:7
#pragma endasm
MCU-AN-500133-E-10 – Page 8
TSC_GPIO.LIBV1.0.0
Chapter 3 Library
3.2.2 Sample Parameters setup
The parameters:
#define TSCKEY_IndividualKeyUsed
TRUE
/* Use Individual Key or not */
#define TSCKEY_SlideKeyUsed
FALSE
/* Use Slide Key or not */
#define TSCKEY_MinificationEnable
FALSE
/* Compression of baseline value */
#define TSCKEY_InterpolationEnable
FALSE
/* Interpolation of slide pos*/
#define TSCKEY_KeyNum
4
/* Total GPIO TSCKey number */
#define TSCKEY_SlideKeyNum
0
/* TSCKey GPIO slide key number */
#define TSCKEY_IIRShiftConstL1
1
/* IIR filter Shift Level 1 */
#define TSCKEY_IIRShiftConstL2
2
/* IIR filter Shift Level 2 */
#define TSCKEY_IIRShiftConstL3
3
/* IIR filter Shift Level 3 */
#defineTSCKEY_IIRShiftConstL4
5
/* IIR filter Shift Level 4 */
/* IIR filter Approximating Const Level 1 */
#define TSCKEY_IIRNumConstL1
2<<TSCKEY_IIRShiftConstL1
/* IIR filter Approximating Const Level 2 */
#define TSCKEY_IIRNumConstL2
2<<TSCKEY_IIRShiftConstL2
/* IIR filter Approximating Const Level 3 */
#define TSCKEY_IIRNumConstL3
2<<TSCKEY_IIRShiftConstL3
/* IIR filter Approximating Const Level 4 */
#define TSCKEY_IIRNumConstL4
2<<TSCKEY_IIRShiftConstL4
#define TSCKEY_OffsetL0
40
/* Offset Const Level 0 */
#define TSCKEY_OffsetL1
100
/* Offset Const Level 0 */
#define TSCKEY_OffsetL2
170
/* Offset Const Level 0 */
#define TSCKEY_OffsetL3
200
/* Offset Const Level 0 */
#define TSCKEY_OffsetL4
300
/* Offset Const Level 0 */
#define TSCKEY_SubAvgShiftConst
1
/* Average shift const */
#define TSCKEY_NoiseOffsetConst
100
/* Offset const of noise */
#define TSCKEY_DeltaBucketThrConst
50
/* Delta value threshold const */
#define TSCKEY_PercentSumConst
180
/* Percent sum const */
#define TSCKEY_MinificationConst
3
/* Baseline compression const */
#define TSCKEY_BalnUpdateConst
1
/* Baseline update counter const */
#define TSCKEY_AmpShiftConst
0
/* Amplify shiftconst */
Used to configure the sample number, threshold, and timer initial value.
MCU-AN-500133-E-10 – Page 9
TSC_GPIO.LIB V1.0.0
Chapter 3 Library
3.2.3 Structure Type Define
Each TSC Key has 4 attributes: original value, filtered value, noise threshold and difference
percent value.
typedefstruct
{
unsignedintOriginValue;
/* Contains the original value */
unsignedintValue;
/* Contains the filtered value */
unsignedintNoiseThreshold;
/* Contains the noise threshold */
unsignedintPercent;
/* Contains the value percent */
} Key_Const;
User can define new key directly using the following structure.
typedefstruct
{
unsignedintValue;
/* Contains the current baseline value */
signedintDeltaBucket;
/* Contains the key threshold level */
} Basline_Const;
MCU-AN-500133-E-10 – Page 10
TSC_GPIO.LIBV1.0.0
Chapter 3 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
Prototype
void TSCKey_Init(unsigned char Key_Num)
Parameter:
unsigned
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
char
Indicate the number of touch keys need initialization
3.3.2 TSCKey_SampleUnit
Prototype
void TSCKey_SampleUnit(unsigned char TSCKEY_SampleNum)
Parameter:
unsigned char TSCKEY_SampleNum
Return
void
Description
Bottom layer sample unit of TSC.
Remark
N/A
Indicate sample number
3.3.3 TSCKey_Filter
Prototype
void TSCKey_Filter(unsigned char Key_Num, unsigned char Order_Shift)
unsigned char Key_Num
Parameter:
unsigned char Order_Shift
Indicate the number of touch keys need filter
Indicate the shift number of order for filter
Return
void
Description
Filter function of TSC sample value
Remark
N/A
3.3.4 TSCKey_GetValue
Prototype
void TSCKey_GetValue(unsigned char Key_Num)
Parameter:
unsigned char 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
Indicate the number of touch keys need filter
MCU-AN-500133-E-10 – Page 11
TSC_GPIO.LIB V1.0.0
Chapter 3 Library
3.4
FUJITSU TSC Performance
Table 3-3: 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
Time base Timer
Serial Port
1
Serial Port(P04,P05),only use in check threshold mode
Machine Clock
>=8M
Scan 1 Key
2 ms
MCU-AN-500133-E-10 – Page 12
TSC_GPIO.LIBV1.0.0
Chapter 3 Library
3.5
How to Add Fujitsu TSC_GPIO.lib
3.5.1 Add Fujitsu TSC_GPIO.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-500133-E-10 – Page 13
TSC_GPIO.LIB V1.0.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-500133-E-10 – Page 14
TSC_GPIO.LIBV1.0.0
Chapter 3 Library
3.5.2 Include Header File
1. Add "#include "TSC_ConfigInfo.h "" in header file, such as in "main.h ".
Figure 3-5: Add include statement in C file
2. Compile the whole project, "TSC_ConfigInfo.h" will link TSC_GPIO.lib to c file, so that
user program can use API functions in TSC_GPIO.lib.
Figure 3-6: Include header file successfully
MCU-AN-500133-E-10 – Page 15
TSC_GPIO.LIB V1.0.0
Chapter 3 Library
3.6
How to use Fujitsu TSC_GPIO.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
Disablecomparer
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 goes 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-500133-E-10 – Page 16
TSC_GPIO.LIBV1.0.0
Chapter 3 Library
Start
Osc_Setup
GPIO Initialization
LCD Initialization
TBT Initialization
TSCKey Initialization
Peripherals Self-checking
TSCKeySample
TSCKey Filter
Get hard key value
MECHkey service
Get TSCKey value
TSCKey service


Key1 pressed: Turn on LED1; Display “①”in LCD
Key2 pressed: Turn on LED2; Display “②”in LCD



Play Key touched: if display loop paused will continue play
Pause Key touched:if display loop is playing will be paused
Pre Key touched:switch topre display item and begin play

Next Key touched: switch tonext display item and begin play
LCD Display Loop
LCD_PageDisplay
PERL_LED
Figure 3-8: Main loop Flowchart
MCU-AN-500133-E-10 – Page 17
TSC_GPIO.LIB 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
This solution needs to use Time base 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 “vectors.c” as following:
#include "mb95410.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.
******************************************************************************/
voidInitIrqLevels(void)
{
#ifdefenableUART
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 voidDefaultIRQHandler (void);
#ifdefenableUART
__interrupt void UART_ISR (void);
#endif
__interrupt void TBT_ISR (void);
MCU-AN-500133-E-10 – Page 18
TSC_GPIO.LIBV1.0.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.
******************************************************************************/
#ifdefenableUART
#pragmaintvect UART_T
8
//
IRQ8:
LIN-UART (transmission)
#else
#pragmaintvectDefaultIRQHandler
8
//
IRQ8:
LIN-UART (transmission)
#endif
#pragmaintvect TBT_ISR
19
//
IRQ19: Timebase timer
MCU-AN-500133-E-10 – Page 19
TSC_GPIO.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/mb95/application_notes.html
Chinese version address:
http://www.fujitsu.com/cn/fss/services/mcu/mb95/application_notes.html
MCU-AN-500133-E-10 – Page 20
TSC_GPIO.LIBV1.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 ........................................................................................................ 7
Table 3-3: Performance ....................................................................................................... 12
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......................................................................................... 13
Figure 3-2: Popup Add Member dialog box .......................................................................... 13
Figure 3-3: Found the lib file................................................................................................. 14
Figure 3-4: Add TSC.lib........................................................................................................ 14
Figure 3-5: Add include statement in C file ........................................................................... 15
Figure 3-6: Include header file successfully.......................................................................... 15
Figure 3-7: Initialize Flow chart ............................................................................................ 16
Figure 3-8: Main loop Flowchart ........................................................................................... 17
MCU-AN-500133-E-10 – Page 21
TSC_GPIO.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
/*!
******************************************************************************
**
** \file main.c
**
** $Id: main.c V2.0.0 2012.2.20 14:50 PM Lee.Song $
**
** \brief .
**
** Add here more detailed description if needed ...
**
** (C) Copyright 200x-201x by Fujitsu Semiconductor Ltd. Asia
**
*/
/*---------------------------------------------------------------------------*/
/* include files
*/
/*---------------------------------------------------------------------------*/
#include "main.h"
/*---------------------------------------------------------------------------*/
/* constants and macros
*/
/*---------------------------------------------------------------------------*/
volatile unsigned int LCD_DispTaskTime = 0;
RUN_FLAG run_flag;
/*---------------------------------------------------------------------------*/
/* local functions
*/
/*---------------------------------------------------------------------------*/
void Osc_Setup(void)
{
#if EXClock_Used
SYSC = 0xBF;
SYCC = 0xF0;
WATR = 0xF3;
SYCC2 = 0xF4;
#else
SYCC = 0xF0;
SYCC2 = 0xE5;
CRTH_CRSEL0 = 1;
CRTH_CRSEL1 = 0;
#endif
while(STBC_MRDY == 0);
}
/*---------------------------------------------------------------------------*/
/* local functions
*/
/*---------------------------------------------------------------------------*/
void RESET_WATCHDOG(void)
{
WDTC = 0x35;
}
void main(void)
{
unsigned char LoopIndex;
CMR0_VCID = 1;
/* Set for use GPIO Disable CMP input */
__DI();
Osc_Setup();
/* Setup MCU main oscillator/FLL */
InitIrqLevels();
/* Initialise Interrupt level and IRQ vector table */
__EI();
/* Enable system interrupt now */
MCU-AN-500133-E-10 – Page 22
TSC_GPIO.LIBV1.0.0
Chapter 1 Appendix
/* Module initialization */
GPIO_Init();
LCD_Init();
/* LCD module initialization */
TBT_Init();
/* Time Base Timer module initialization */
TSCKey_Init(TSCKEY_KeyNum);
/* TSC Key module initialization */
/* Load initial value */
LCD_DispTaskTime = Now_Time;
/* Initial LCD display task time */
run_flag.TSC_Play = TRUE;
/* Initial flag as TRUE */
run_flag.LCD_PlayFirstLoop = TRUE;/* Initial first play flag as TRUE */
run_flag.RunStatusLEDFilp = TRUE; /* Initial LED flip flag as TRUE */
/* LCD display for check */
LCD_AllDisplay(LCD_BUFF_LEN);/* Test the LCD hardware */
/* LED display for check */
LED1_On;
LED2_On;
/* Hold on display period of time for check */
while((Now_Time - LCD_DispTaskTime) < LCD_DispTimeInterval);
LCD_DispTaskTime = Now_Time;
/* LCD shut down */
LCD_PageDisplay();
/* LED shut down */
LED1_Off;
LED2_Off;
/* Beep ringing twice */
PERL_Beep(2,300);
/* Load loop display value to temp buffer */
for(LoopIndex=0;LoopIndex<8;LoopIndex++)
{
LCD_DispBuffTemp[LoopIndex] = LCD_LoopDispBuff[LoopIndex];
}
/* Endless loop */
while(1)
{
/* TSC key sample unit */
TSCKey_SampleUnit(TSCKEY_SampleNumConst);
/* TSC key fiter function */
TSCKey_Filter(TSCKEY_KeyNum,TSCKEY_IIRShiftConstL4);
/* Machanical key fiter function */
MECHKey_Filter();
/* Machanical key service */
MECHKey_Service();
/* TSC key service */
TSCKey_Service();
/* LCD display loop judgement */
if(Now_Time - LCD_DispTaskTime >= LCD_DispTimeInterval)
{
LCD_DispTaskTime = Now_Time;
if(run_flag.TSC_Play == TRUE)
{LCD_StepElectrovalency(((LCD_LoopIndex/LOGO_BUFF_LEN)
+ 1),1);
LCD_DispLoop(LCD_DispBuffTemp);
}
/* System run status indication LED */
if(run_flag.RunStatusLEDFilp == TRUE)
{
run_flag.RunStatusLEDFilp = FALSE;
PERL_LED(1,LED_On);
PERL_LED(2,LED_Off);
}
else
{
run_flag.RunStatusLEDFilp = TRUE;
PERL_LED(1,LED_Off);
PERL_LED(2,LED_On);
}
}
/* LCD display */
LCD_PageDisplay(); /* Display various data page on LCD screen */
}
}
MCU-AN-500133-E-10 – Page 23