248KB

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-500037-E-10
F²MC-8FX FAMILY
8-BIT MICROCONTROLLER
MB95200 SERIES
KEYBOARD DEVELOPMENT
USING AD
APPLICATION NOTE
Keyboard Development Using AD V1.0
Revision History
Revision History
Version
Date
Updated by
Modifications
1.0
2/24/2009
Benjamin. Yang
First draft
This manual contains 15 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 document are not intended for use with equipment which require extremely
high reliability such as aerospace equipment, undersea repeaters, nuclear control systems or medical
equipment 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 theory
must not be exported without permission as defined under the law.
© 2009 Fujitsu Semiconductor (Shanghai) Co., Ltd.
MCU-AN-500037-E-10 – Page 2
Keyboard Development Using AD V1.0
Contents
CONTENTS
REVISION HISTORY .............................................................................................................. 2 CONTENTS ............................................................................................................................ 2 1 INTRODUCTION ................................................................................................................ 4 2 INTRODUCTION TO AD FUNCTION ................................................................................ 5 2.1 Function of AD Conversion ....................................................................................... 5 2.2 Jittering Elimination in Keyboard ............................................................................... 5 3 HARDWARE DESIGN ....................................................................................................... 6 3.1 Hardware Circuit ....................................................................................................... 6 3.2 Relationship between Key Status and Input Voltage ................................................ 6 4 RESOURCE USAGE ......................................................................................................... 7 4.1 8/10-bit A/D Converter Control Register 1 (ADC1) ................................................... 7 4.2 8/10-bit A/D Converter Control Register 2 (ADC2) ................................................... 8 4.3 8/10-bit A/D Converter Data Registers Upper/Lower (ADDH, ADDL) ....................... 9 4.4 AD Converter Process ............................................................................................ 10 5 SOFTWARE DESIGN ...................................................................................................... 11 6 SAMPLE CODE ............................................................................................................... 12 7 APPENDIX ....................................................................................................................... 15 7.1 Tables ..................................................................................................................... 15 7.2 Figures .................................................................................................................... 15 MCU-AN-500037-E-10 – Page 3
Keyboard Development Using AD V1.0
Chapter 1 Introduction
1 Introduction
There are three methods to develop a keyboard by MB95200 series MCU: external interrupt,
AD conversion and matrix.
This document describes how to use the AD Conversion to design the keyboard.
This document also describes the realization theories of AD conversion by examples.
MCU-AN-500037-E-10 – Page 4
Keyboard Development Using AD V1.0
Chapter 2 Introduction to AD Function
2 Introduction to AD Function
This chapter introduces the functions of using AD Conversion to realize the keyboard.
2.1
Function of AD Conversion
The function of AD Convertor is to convert an analog voltage (input voltage) value on an
analog input pin to a 10-bit digital value. The MCU of MB95200 series has at least 2 analog
input pins. When AD convertor is enabled, the analog input signal on the selected channel
will be sampled and compared inside the AD convertor and finally converted to a digital
value stored into the A/D converter data register (ADDH, ADDL).
2.2
Jittering Elimination in Keyboard
Jittering elimination has been one of important problems in keyboard design. In hardware
circuit design, add a capacitor to the analog input pin to weaken the jittering, while in
software design, re-confirm the data to avoid jittering occurred on a real keyboard.
MCU-AN-500037-E-10 – Page 5
Keyboard Development Using AD V1.0
Chapter 3 Hardware Design
3 Hardware Design
This chapter introduces the hardware design to develop keyboard using AD Conversion.
3.1
Hardware Circuit
The resistors in the following hardware circuit are designed to divide voltage. And the analog
input pin will get a different voltage from the circuit. The following circuit is for your reference:
Figure 3-1: Hardware Design for Keyboard Using AD
3.2
Relationship between Key Status and Input Voltage
Table 3-1: Relationship between Key Status and Input Voltage
Pressed key
AN00 Voltage
ADDL value
Virtual value
SW1
0V
0x00
Area
0x00>=ADDL<=0x05
SW2
2.5 V
0x7F
0x79>=ADDL<=0x85
SW3
3.3 V
0xAA
0xA1>=ADDL<=0xB2
0xBF
0xB5>=ADDL<=0xC8
SW4
3.75 V
MCU-AN-500037-E-10 – Page 6
Keyboard Development Using AD V1.0
Chapter 4 Resource Usage
4 Resource Usage
This chapter introduces the resource usage of AD Conversion.
Please refer to Chapter 17 of MB95200 Series Hardware Manual for detailed register setting.
4.1
8/10-bit A/D Converter Control Register 1 (ADC1)
The 8/10-bit A/D converter control register 1 (ADC1) is used to enable and disable individual
functions of the 8/10-bit A/D converter, select an analog input pin and check the status of the
converter.
Figure 4-1: ADC1 Register
MCU-AN-500037-E-10 – Page 7
Keyboard Development Using AD V1.0
Chapter 4 Resource Usage
4.2
8/10-bit A/D Converter Control Register 2 (ADC2)
The 8/10-bit A/D converter control register 2 (ADC2) is used to control different functions of
the 8/10-bit A/D converter, select the input clock, and enable and disable interrupts.
Figure 4-2: ADC2 Register
MCU-AN-500037-E-10 – Page 8
Keyboard Development Using AD V1.0
Chapter 4 Resource Usage
4.3
8/10-bit A/D Converter Data Registers Upper/Lower (ADDH, ADDL)
The 8/10-bit A/D converter data registers upper/lower (ADDH, ADDL) store the results of 10bit A/D conversion during 10-bit A/D conversion. The upper two bits of 10-bit data are stored
in the ADDH register and the lower eight bits the ADDL register.
Figure 4-3: AD Data Registers
The upper two bits of 10-bit A/D data correspond to bit1 and bit0 in the ADDH register and
the lower eight bits bit15 to bit8 in the ADDL register.
If the AD8 bit in ADC2 register is set to "1", 8-bit precision is selected. Reading the ADDL
register can obtain 8-bit data.
MCU-AN-500037-E-10 – Page 9
Keyboard Development Using AD V1.0
Chapter 4 Resource Usage
4.4
AD Converter Process
After the conversion time according to the register settings elapses, the results of conversion
are finalized and stored in the ADDH and ADDL registers. After A/D conversion is completed
and before the next A/D conversion is started, it's required to read A/D data registers
(conversion results) and clear ADI flag bit (bit 3) in the ADC1 register.
MCU-AN-500037-E-10 – Page 10
Keyboard Development Using AD V1.0
Chapter 5 Software Design
5 Software Design
This chapter introduces the software design to develop keyboard using AD conversion.
Once the AD convertor is enabled, it will capture the status information of keyboard. If the
value (Distem0) belongs to the key-value, restored it, if not, the AD Convertor continues to
sample. After this, stop the AD Convertor and make the system wait for about 20ms, then
restart the AD Convertor and get a sample value (Distem1) again. Finally, judge this value to
see if it is equal to Distem0. If it is different from Distem0, it is regarded that jittering happens;
otherwise, judge which key has been pressed.
Below is the flow chart of this software design.
Figure 5-1: Software Design Flow Chart for Keyboard Development
MCU-AN-500037-E-10 – Page 11
Keyboard Development Using AD V1.0
Chapter 6 Sample Code
6 Sample Code
This chapter illustrates keyboard development using AD Conversion.
The following example shows how to use the AD Conversion input pin AN00 to design a 4key keyboard.
As discussed in chapter 5, if using AD Conversion to design a keyboard system, initialize the
AD Conversion first, then AD conversion starts sampling, and gets an sample value, read
this value and judge that if it belongs to the key-value. if does not, system continues to
sample; if does, stop the AD Conversion and let the system waits for about 20 ms, and then
restart AD Conversion, get an another sample value. If the two sample values are the same,
it shows that one of the keys has been pressed; if not, it shows only a jittering happens.
.
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS.
/* FUJITSU SEMICONDUCTOR ACCEPTS NO RESPONSIBILITY OR LIABILITY
/* FOR ANY ERRORS OR ELIGIBILITY FOR ANY PURPOSES.
/* (C) Fujitsu Semiconductor (Shanghai) Co., LTD.
/*-------------------------------------------------------------------#include "../MB95200_IO/mb95200.h". . .
void clock_Select(void)
// Main clock initialize
{
SYCC = 0x00;
WATR = 0x00;
STBC = 0x01;
SYCC2= 0xF4;
}
void syinit(void)
{
DDR0_P00 = 0;
//P00 input enable
ADC1 = 0x01;
//AN00 as input
ADC2 = 0x80;
//8-bit resolution,1×MCLK
ADC1_AD = 1;
//start A/D converter
DDR0 = 0xF0;
//P4~P7 as output pin
PUL0 = 0x00;
AIDRL = 0xFE;
}
void timer_init(void)
{
TMCR0 = 0x10;
// 16-bit
T00CR0 = 0x81;
// interval timer with continuous mode
T00CR1 = 0xA0;
// disable output, start timer
T01DR = 0x27;
// 10000us
T00DR = 0x10;
while(STBC_MRDY);
}
__interrupt void Timer_Interrupt (void)
{
T00CR1_IF = 0;
T00CR1_IE = 0;
timer_counter++;
if(timer_counter==1) // Read and store ADDL in value 1
{
AD_Sample();
}
MCU-AN-500037-E-10 – Page 12
*/
*/
*/
*/
*/
Keyboard Development Using AD V1.0
Chapter 6 Sample Code
if(timer_counter==2)
// Read and store ADDL in value 2 and
compare value and value 2
{
key_judge();
}
if(timer_counter>=3)
{
timer_counter=0;
}
/Timer_counter restart
}
void AD_Sample(void)
{
if(ADC1_ADI==1)
{
while(!ADC1_ADI);
Distem0 = ADD_ADDL; // Read AD Sample value 1
}
ADC1_AD=1;
// Start AD again
}
void key_judge(void)
{
if(ADC1_ADI==1)
// Read and store ADDL in value 2
{
while(!ADC1_ADI);
Distem1 = ADD_ADDL;
}
if(Distem1==Distem0)
// Judge if value 1 and value 2 equality
{
if(Distem1 == Range_value0) // Key process
{
DDR0_P04 = 1;
PDR0_P04 = 0;
}
if((Distem1 >= Range_value1)&&(Distem1 <= Range_value2))
{
DDR0_P05 = 1;
PDR0_P05 = 0;
}
if((Distem1 >= Range_value3)&&(Distem1 <= Range_value4))
{
DDR0_P06 = 1;
PDR0_P06 = 0;
}
if((Distem1 >= Range_value5)&&(Distem1 <= Range_value6))
{
DDR0_P07 = 1;
PDR0_P07 = 0;
}
}
}
void main(void)
{
InitIrqLevels();
//initialise Interrupt level and IRQ vector table
__EI();
// global interrupt enable
clock_Select();
while(1)
{
syinit();
timer_init();
}
}
MCU-AN-500037-E-10 – Page 13
Keyboard Development Using AD V1.0
Chapter 6 Sample Code
Please note, this sample project is based on our starter-kit MB2146-410A. The target MCU
is MB95F304K. AN0 is used as an analog input pin, and LED1 to LED4 an indicator. If
keyboard hardware circuit as shown in chapter 3.1 is not provided, stop a jumper and
connect VR3 to MCU so that VR3 can be used as an analog input. Then observe how LED
changes in adjusting VR3.
MCU-AN-500037-E-10 – Page 14
Keyboard Development Using AD V1.0
Chapter 7 Appendix
7 Appendix
7.1
Tables
Table 3-1: Relationship between Key Status and Input Voltage .............................................. 6 7.2
Figures
Figure 3-1: Hardware Design for Keyboard Using AD ............................................................. 6 Figure 4-1: ADC1 Register ....................................................................................................... 7 Figure 4-2: ADC2 Register ....................................................................................................... 8 Figure 4-3: AD Data Registers ................................................................................................. 9 Figure 5-1: Software Design Flow Chart for Keyboard Development .................................... 11 MCU-AN-500037-E-10 – Page 15