Professional Documents
Culture Documents
Product
Specification
DOC. VERSION 2.5
Trademark Acknowledgments:
IBM is a registered trademark and PS/2 is a trademark of IBM
Windows is a trademark of Microsoft Corporation
ELAN and ELAN logo
Hong Kong:
USA:
Elan Information
Technology Group
Europe:
Shenzhen:
Shanghai:
Elan Microelectronics
Shenzhen, Ltd.
Elan Microelectronics
Shanghai Corporation, Ltd.
Siewerdtstrasse 105
8050 Zurich, SWITZERLAND
Tel: +41 43 299-4060
Fax: +41 43 299-4079
http://www.elan-europe.com
Contents
Contents
1
Features ..................................................................................................................... 2
2.1 MCU Features.................................................................................................... 2
2.2 Peripheral........................................................................................................... 3
2.3 Internal Specification.......................................................................................... 3
Pin Description.......................................................................................................... 7
Code Option............................................................................................................... 8
7.2
7.3
7.7
7.8
Flowchart...........................................................................................................19
Code Examples .................................................................................................20
Interrupt............................................................................................................ 21
7.5.1
7.5.2
7.5.3
7.5.4
7.5.5
7.5.6
7.6
7.5
7.4
iii
Contents
7.9
Peripherals............................................................................................................... 41
8.1 Timer 0 (16 Bits Timer with Capture and Event Counter Functions)............. 41
8.1.1
8.1.2
8.1.3
8.1.4
8.2
Timer 1 (8 Bits)................................................................................................. 46
8.3
Timer 2 (8 Bits)................................................................................................. 49
8.2.1
8.3.1
8.3.2
8.4
8.5
8.6
iv
Contents
8.7
8.8
8.9
10
11
12
Instruction Set:........................................................................................................ 97
13
14
Package.................................................................................................................. 108
Contents
2.0
2.1
2.2
2.3
2.4
2.5
vi
Revision Description
1. Added Code option: melody/speech interrupt and
prescaler
2. Added Code option: interrupt priority change
3. Added Code option: current D/A reference option
4. Added function: melody/speech interrupt and
prescaler
5. Modified the affected INC and DEC Status.
6. Added 128-pin QFP package Diagram.
7. Added Power Consumption & Soldering
Temperature Electrical Characteristic.
8. Modified the Operating temperature range:
10 ~ +70C.
9. Added the EXTMEM bit description.
Modified the Current D/A reference source, Melody
interrupt & Interrupt priority description.
1. Modified the EPG3231 remark PM board version
for code option.
2. Provided selection for UART standard baud rate:
9.83MHz or 14.745MHz.
1. Added CPU change operation mode example.
2. Added External ROM speed setting example &
formula.
3. Modified the SPI clock source from PLL/2 only.
4. Added I/O pin type circuit diagrams.
Added 64-pin 7x7mm LQFP package diagram.
1. Added a Note about Sleep and Idle mode.
2. Modified PLLC capacitor range.
3. Modified A/D converter samlpe rate max value
4. Modified 10MHz supply current max value
5. Modified the A/D conversion operation mode.
Date
2003/12/26
2004/02/23
2004/05/17
2004/07/19
2004/12/13
2005/11/08
ePG3231
RISC II-2G Series Microcontroller
General Description
The ePG3231 is an 8-bit RISC MCU which has an embedded 10 bits SAR A/D
converter with touch screen controller, two 8-bit timers and one 16-bit general timer
with capture and event counter functions, IR generator, watchdog timer, SPI, UART,
four melody timers, a PWM and a current D/A. Furthermore, the EPG3231 has an
embedded large size user RAM and program memory with supporting external memory
in system programming (ISP) function. It is suitable for educational learning tools
application requiring high performance and low cost solution.
The MCU core is ELANs second generation RISC based MCU, namely RISCII (RII).
The core was designed for low power and portable devices. It supports FAST mode,
SLOW mode, IDLE mode and SLEEP mode for low power applications.
IMPORTANT NOTES
Do not use Register BSR (05h) Bit7 ~ Bit5.
Do not use Register BSR1 (07h) Bit7 ~ Bit5.
Do not use Special Register (2Ah).
Don not use Special Register (4Fh).
Do not use Registers JDNZ & JINZ at FSR1 (09h) special register.
Port J & K are ideal for keyboard matrix application due to its low output current (see
DC Electrical Characteristics in Chapter 9).
Before going into SLEEP mode or IDLE mode, Ports D, E, & F must be set as Output
port and output high. At the same time, Ports G & H must be set as Input port and
enable pull-high.
1.2 Applications
Electronic book
ePG3231
RISC II-2G Series Microcontroller
Features
2.1 MCU Features
Processor mode, MCU mode and Extended MCU mode selection through the PMD
pin
Look-up Table function is fast and highly efficient when teamed up with REPEAT
instruction
ePG3231
RISC II-2G Series Microcontroller
2.2 Peripheral
One input port (Port A) and ten general I/O ports. (Port B ~ Port K)
8-bit IR generator
8-bit PWM and a current D/A for melody and speech application
10-bit resolution SAR A/D converter with 6 channels general analog input and 2
channels for touch panel application
MCU modes: SLEEP mode, IDLE mode, SLOW mode, and FAST mode
PLL is turned on during FAST mode, and controlled by PEN bit when MCU is in
SLOW or IDLE mode.
MCU Wake-up function includes Input wake-up, Timer 1 wake-up, Touch Panel
wake-up, SPI wake-up, and A/D wake-up.
MCU interrupt function includes Input Port interrupt, Touch Panel interrupt, Capture
interrupt, Speech Timer interrupt, Timer interrupt (Timers 0~2), A/D interrupt, SPI
interrupt, and UART interrupt.
MCU reset function includes Power-on reset, RSTB Pin reset, and Watchdog
Timer reset.
ePG3231
RISC II-2G Series Microcontroller
Block Diagram
RSTB
TEST
VDD
AVDD
OSCI
OSCO
PMD
8*8 Mul
ALU
PRODH PRODL
Shifter
Addressing
D/A , PWM
Key IO
Port K
Port J
SPI
ROM
External memory
interface
RAM
Music/Speech
Synthesizer
PLLC/
HOSCI
HOSCO
Control Unit
SAR A/D
VREX
Timing Generator
UART IR generator
I/O control
8
8
VSS AVSS
ePG3231
RISC II-2G Series Microcontroller
ePG3231AQ
NC
NC
NC
PI.3
PI.2
PI.1
PI.0
PJ.0
PJ.1
PJ.2
PJ.3
PJ.4
PJ.5
PJ.6
PJ.7
PK.0
PK.1
PK.2
PK.3
PK.4
PK.5
PK.6
PK.7
TEST
OSCI
OSCO
RSTB
AVSS
HOSCI
HOSCO
PMD
PA.0
PA.1
PA.2
PA.3
PA.4
NC
NC
NC
NC
NC
NC
NC
NC
PG.4
PG.5
PG.6
PG.7
PH.0
PH.1
PH.2
PH.3
PH.4
PH.5
PH.6
PH.7
PI.7
PI.6
PI.5
PI.4
NC
NC
NC
NC
NC
NC
NC
NC
NC
PC.3
PC.2
PC.1
PC.0
PB.7
PB.6
PB.5
PB.4
PB.3
PB.2
VSS
PB.1
PB.0
VDD
PA.7
PA.6
PA.5
NC
NC
NC
NC
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
NC
NC
NC
PG.3
PG.2
PG.1
PG.0
PF.0
PF.1
PF.2
PF.3
PF.4
PF.5
PF.6
PF.7
PE.0
PE.1
PE.2
PE.3
PE.4
PE.5
PE.6
PE.7
PD.0
PD.1
PD.2
PD.3
PD.4
PD.5
PD.6
PD.7
AVDD
VREX
PC.7
PC.6
PC.5
PC.4
NC
102
101
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
PJ.1
PJ.0
PI.4
PI.5
PI.6
PI.7
PH.7
PH.6
PH.5
PH.4
PH.3
PH.2
PH.1
PH.0
PF.0
PF.1
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
PJ.2
PJ.3
PJ.4
PJ.5
PJ.6
PJ.7
TEST
OSCI
OSCO
RSTB
AVSS
PLLC
PMD
PA.0
PA.1
PA.2
ePG3231BQ
LQFP 64 pins
PF.2
PF.3
PF.4
PF.5
PF.6
PF.7
PE.0
PE.1
PE.2
PE.3
PE.4
PE.5
PE.6
PE.7
PD.6
AVDD
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
PA.3
PA.4
PA.5
PA.6
VDD
PB.1
VSS
PB.2
PB.5
PB.6
PB.7
PC.0
PC.1
PC.2
PC.3
VREX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ePG3231
RISC II-2G Series Microcontroller
126
127
128
ePG3231
(top view)
123
AQ BQ
No. No.
ePG3231
Pin Name
AQ BQ
No. No.
ePG3231
Pin Name
AQ BQ
No. No.
ePG3231
Pin Name
N.C.
33
15
PA.1
65
N.C.
N.C.
34
16
PA.2
66
N.C.
35
17
PA.3
67
PI.3
36
18
PA.4
68
PI.2
37
N.C.
PI.1
38
N.C.
PI.0
39
63
PJ.0 (Strobe 0)
40
64
PJ.1 (Strobe 1)
41
10
PJ.2 (Strobe 2)
42
AQ BQ
No. No.
ePG3231
Pin Name
97
PG.1 (D1)
PC.4 (ADIN4/YP)
98
PG.2 (D2)
PC.5 (ADIN3/XP)
99
PG.3 (D3)
PC.6 (YN)
100
N.C.
69
PC.7 (XN)
101
N.C.
70
32
VREX
102
N.C.
N.C.
71
33
AVDD
103
N.C.
N.C.
72
PD.7 (OEB)
104
N.C.
N.C.
73
34
PD.6 (WEB)
105
N.C.
N.C.
74
PD.5 (A21)
106
N.C.
11
PJ.3 (Strobe 3)
43
19
PA.5
75
PD.4 (A20)
107
N.C.
12
PJ.4 (Strobe 4)
44
20
PA.6 (Rref)
76
PD.3 (A19)
108
N.C.
13
PJ.5 (Strobe 5)
45
PA.7
77
PD.2 (A18)
109
PG.4 (D4)
VDD
78
PD.1 (A17)
110
PG.5 (D5)
PB.0 (VO2)
79
PD.0 (A16)
111
PG.6 (D6)
PB.1 (VO1/DAO)
80
35
PE.7 (A15)
112
PG.7 (D7)
14
PJ.6 (Strobe 6)
46
21
15
PJ.7 (Strobe 7)
47
16
PK.0 (Strobe 8)
48
22
17
PK.1 (Strobe 9)
49
23
VSS
81
36
PE.6 (A14)
113 51
PH.0 (D8)
18
50
24
PB.2 (IROT)
82
37
PE.5 (A13)
114 52
PH.1 (D9)
19
51
PB.3
83
38
PE.4 (A12)
115 53
PH.2 (D10)
20
52
PB.4
84
39
PE.3 (A11)
116 54
PH.3 (D11)
21
53
25
PB.5 (EVIN/CPIN)
85
40
PE.2 (A10)
117 55
PH.4 (D12)
22
54
26
PB.6 (UTXD)
86
41
PE.1 (A9)
118 56
PH.5 (D13)
23
55
27
PB.7 (URXD)
87
42
PE.0 (A8)
119 57
PH.6 (D14)
24
TEST
56
28
PC.0 (ADIN8)
88
43
PF.7 (A7)
120 58
PH.7 (D15)
25
OSCI
57
29
PC.1 (ADIN7)
89
44
PF.6 (A6)
121 59
PI.7 (SPISDI)
26
OSCO
58
30
PC.2 (ADIN6)
90
45
PF.5 (A5)
122 60
PI.6 (SPISDO)
27
10
RSTB
59
31
PC.3 (ADIN5)
91
46
PF.4 (A4)
123 61
PI.5 (SPISCK)
28
11
AVSS
60
N.C.
92
47
PF.3 (A3)
124 62
PI.4 (/SPISS)
29
12
HOSCI /PLLC
61
N.C.
93
48
PF.2 (A2)
125
N.C.
30
HOSCO
62
N.C.
94
49
PF.1 (A1)
126
N.C.
31
13
PMD
63
N.C.
95
50
PF.0 (A0)
127
N.C.
32
14 PA.0
64
N.C.
96
PG.0 (D0)
128
N.C.
ePG3231
RISC II-2G Series Microcontroller
Pin Description
Name
VDD
VSS
AVDD
AVSS
RSTB
TEST
OSCI/RC
OSCO
I/O/Power
Function
P
P
I
HOSCI/PLLC
I
I
O
I/O
I
HOSCO
PMD
VREX
I/O
Port A
Port E
I
I
I/O
I
O
I
O
O
O
I/O
O
O
I
I
I
I
I
I
I/O
O
I/O
O
O
Port F
Port B
Port C
Port D
Description
Digital power supply. The range is from 2.2V to 3.6V. Connect VSS through a
capacitor (0.1F).
Analog power supply. The range is from 2.2V to 3.6V. Connect AVSS through a
capacitor (0.1F).
System reset. Input with built-in pull up resistor (100K ohms typical).
Low: RESET asserted
High: RESET released
Normally connected to VSS. Reserved for testing purposes.
RC or Crystal oscillator selection is by Code Option.
32768 Hz oscillator pin. Should be connected to VSS through a capacitor (20pF).
RC oscillator connector pin. Should be connected to VDD through resistor (2M).
Crystal or PLL selection is by Code Option.
PLL capacitor connector pin. Should be connected to VSS through 0.01~0.047F
capacitor.
High frequency Chrystal oscillator pin. Should be connected to VSS through a
capacitor (20pF).
Processor mode and MCU/Extended MCU mode selection pin. Connect to VDD or
VSS through a resistor (100K).
0: MCU mode / Extended MCU mode
1: Processor mode
External or internal reference voltage for A/D converter. Connect to VSS through a
0.1F capacitor.
General input port for special functions, i.e., Wake-up, Interrupt, & Key matrix input.
Bit 6: D/A reference resistor
General Input/Output port
Bit 7: UART Rx pin
Bit 6: UART Tx pin
Bit 5: Event counter/Capture input pin
Bit 2: IR output pin
Bit 1: PWM or Current D/A output pin
Bit 0: PWM output pin
General Input/Output port
Bit 7: Touch screen X direction negative pin
Bit 6: Touch screen Y direction negative pin
Bit 5: Touch screen X direction positive pin & A/D input Channel 3
Bit 4: Touch screen Y direction positive pin & A/D input Channel 4
Bit 3: A/D input Channel 5
Bit 2: A/D input Channel 6
Bit 1: A/D input Channel 7
Bit 0: A/D input Channel 8
General Input/Output port
Bit 7: Extended PROM/DROM low active output enable
Bit 6: External memory interface write enable pin
Bit 5~0: Processor mode or External memory interface address [A21:A16]
General Input/Output port
Bit 7~0: Extended MCU mode/Processor mode or External memory interface
address [A15:A8].
General Input/Output port.
Bit 7~0: Extended MCU mode/Processor mode or External memory interface
address [A7:A0].
ePG3231
RISC II-2G Series Microcontroller
Name
I/O/Power
Function
Port G
I
I/O
Port H
I
I/O
Port I
I/O
I
O
I/O
I
O
I/O
O
I/O
O
Port J
Port K
Description
General Input/Output port
Bit 7~0: Extended MCU mode/Processor mode data bus [D7:D0]
Bit 7~0: External memory interface data [D7:D0]
General Input/Output port
Bit 7~0: Extended MCU mode/Processor mode data bus [D15:D8]
Bit 7~0: External memory interface data [D15:D8]
General Input/Output port
Bit 7: Serial data input pin
Bit 6: Serial data output pin
Bit 5: Serial clock input/output pin
Bit 4: /Slave Select pin
Bit 3~0: High drive output pins
General Input/Output port
Bit 7~0: Key Strobe 7 ~ 0 pins
General Input/Output port
Bit 7~0: Key Strobe 15 ~ 8 pins
Code Option
ePG3231
RISC II-2G Series Microcontroller
64KW
128KW
Port E:Port F
Port D[0]:Port E:Port F
Port D[5:0]
Port D[5:1]
256KW
512KW
Port D[5:2]
Port D[5:3]
1MW
2MW
Port D[5:4]
Port D[5]
4MW
ePG3231
RISC II-2G Series Microcontroller
Function Description
7.1 Reset Function
A RESET can be triggered by:
WDT timeout
/Chip reset
+
0.1uF
RSTB
WDT reset
VDD
RSTB
Tpwr
OSC
Twup1
Twup
CPU work
Characteristics
Oscillator start up time
CPU warm up time
CPU reset time
Min.
Typical
Max.
Unit
100
260
18
226
340
22
300
550
44
ms
ms
ms
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
/TO
/PD
SGE
SLE
OV
DC
Bit 0 (C):
Zero flag
Bit 3 (OV): Overflow flag. Use in signed operation when Bit 6 carry into or borrow
from signed bit (Bit7).
Bit 4 (SLE): Computation result is less than or equal to zero (Negative value) after
signed arithmetic. Only affected by HEX arithmetic instruction.
Bit 5 (SGE):Computation result is greater than or equal to zero (positive value) after
signed arithmetic. Only affected by HEX arithmetic instruction.
NOTE
1. When OV=1 after signed arithmetic, you can check SGE bit and SLE bit to verify
whether overflow (carry into sign bit) or underflow (borrow from sign bit) occurred.
If OV=1 and SGE=1 overflow occurred.
If OV=1 and SLE=1 underflow occurred.
2. When overflow took place, you should clear the MSB of Accumulator to get the
correct value.
When underflow took place, you should set the MSB of accumulator to get the
correct value.
Example 1: ADD positive value with a positive value, and the ACC signed bit will be
affected.
MOV
ACC, #60h
ADD
ACC, #70h
11
ePG3231
RISC II-2G Series Microcontroller
Example 2: SUB positive value from negative value, and ACC signed bit will be
affected.
MOV
ACC, #50h
SUB
ACC, #90h
SLE=1,
OV=1,
7.1.3
Bit 6 (/PD)
0
1
0
1
Event
WDT time out reset from SLEEP mode
WDT time out reset (not SLEEP mode)
Reserved.
Power up or RSTB pin low condition
12
Addr.
NAME
Initial Value
00h
01h
02h
03h
04h
05h
06h
07h
08h
09h
0Ah
0Bh
0Ch
0Dh
0Eh
0Fh
INDF0
FSR0
PCL
PCM
PCH
BSR
STKPTR
BSR1
INDF1
FSR1
ACC
TABPTRL
TABPTRM
TABPTRH
CPUCON
STATUS
0000 0000
0000 0000
0000 0000
00
0 0000
0000 0000
0 0000
1000 0000
xxxx xxxx
0000 0000
0000 0000
0000 0000
00 000c
cu
Addr.
10h
11h
12h
13h
14h
15h
16h
17h
18h
19h
1Ah
1Bh
1Ch
1Dh
1Eh
1Fh
NAME
TRL2
PRODL
PRODH
ADOTL
ADOTH
UARTTX
UARTRX
PORT A
PORT B
PORT C
PORT D
PORT E
PORT F
PORT G
PORT H
PORT I
Initial Value
uuuu uuuu
uuuu uuuu
uuuu uuuu
000 0uu
uuuu uuuu
ePG3231
RISC II-2G Series Microcontroller
Control Register:
Addr.
NAME
Initial Value
Addr.
20h
21h
22h
23h
24h
25h
26h
27h
28h
29h
2Ah
2Bh
2Ch
2Dh
2Eh
2Fh
30h
31h
32h
33h
34h
35h
36h
37h
PFS
STBCON
INTCON
INTSTA
TRL0L
TRL0H
TRL1
TR01CON
TR2CON
TRLIR
(Reserved)
POST_ID
ADCON
PAINTEN
PAINTSTA
PAWAKE
UARTCON
UARTSTA
PORTJ
PORTK
DCRB
DCRC
DCRDE
DCRFG
0010 0000
38h
39h
3Ah
3Bh
3Ch
3Dh
3Eh
3Fh
40h
41h
42h
43h
44h
45h
46h
47h
48h
49h
4Ah
4Bh
4Ch
4Dh
4Eh
4Fh
Legend: x = unknown
u = unchanged,
0100 0000
0000 0000
0000 0000
uuuu uuuu
uuuu uuuu
uuuu uuuu
0000 0000
0000 0000
uuuu uuuu
111 000
0101 0000
0000 0000
0000 0000
0000 0000
0000 0010
0000 0000
1111 1111
1111 1111
0011 0011
0011 0011
NAME
Initial Value
DCRHI
0011 0011
DCRJK
0011 0011
PBCON
0000 0000
PCCON
0000 0000
PLLF
T0CL
0000 0000
T0CH
0000 0000
SPICON
0000 0000
SPISTA
0-00 0000
SPRL
SPRM
SPRH
SFCR
0000 0000
ADDL1~ADDL4
ADDM1~ADDM4
ADDH1~ADDH4
ENV1~4 / SPHDR
0000 0000 / 0000 0000
MTCON1~4 / SPHTCON 0000 0000 / 0000 0000
MTRL1~4 / SPHTRL
0000 0000 / 0000 0000
VOCON
0000 0111
TR1C
1111 1111
TR2C
1111 1111
ADCF
uuuu uuuu
(Reserved)
= unimplemented read as 0
c = value depends on actual condition
Bit 0 (MS0) of RE (CPUCON) is reloaded from INIM bit of code option when MCU resets.
If it is a power-on reset or RSTB pin is at low condition, the /TO bit and /PD bit of RF (STATUS)
are set to 1. If it is a WDT time out reset, the /TO bit is cleared and /PD bit remains
unchanged.
13
ePG3231
RISC II-2G Series Microcontroller
32.8kHz
RC/X'tal
OSC.
PLL
PLLC/
HOSCI
HOSCO
Fsys
FPLL
OSCSEL
of code option
PEN
0
1
HFSEL
MS0
of code option
FSS
0
High Freq.
OSC.
FA/D
1
FPLL
Fper
0
HFSEL
of code option
32.8kHz RC oscillator
14
ePG3231
RISC II-2G Series Microcontroller
HOSCI
HOSCO
PFS (R20h):
Factual (Hz)
Fosch
Fosch/2 / PFS
Reserved
15
ePG3231
RISC II-2G Series Microcontroller
7.2.2.2 Phase Locked Loop (PLL)
PLLC/
HOSCI
0.01uF ~
0.047uF
HOSCO
PLL Oscillator
Fig. 7-5 Hi-Frequency PLL Oscillator Circuit Diagram
PLLF (R3Ch): Stores the actual PLL frequency value. It is used to verify whether
the PLL frequency is stable or not.
PFS (R20h):
Ftarget (MHz)
PFS Register
Ftarget (MHz)
0~14
N.A. 1
15
31
46
61
76
0.983
2.032
3.015
3.998
4.981
92
107
122
137
150
153
255
6.029
7.012
7.995
8.978
9.83 2
10.027
16.712
When UART is enabled, system clock should be 9.83MHz (PFS=150) or 14.745MHz (PFS=225)
The table is based on 32.768kHz oscillator frequency. The Maximum range of PLL is
from 983kHz ~ 16.712MHz.
16
ePG3231
RISC II-2G Series Microcontroller
Reset
MS1=0 &
SLEP
32K OSC.:oscillating
PLL:turned on
MS1=0 &
SLEP
MS0=1
FAST
MODE
Reset
32K OSC.:oscillating
PEN=0->PLL: stopped
PEN=1->PLL turned on
MS0=0
RESET
operation
Reset Release
Reset
Reset Release
Reset
SLOW
M ODE
MS1=1 &
SLEP
wakeup
& MS0=1
IDLE
M ODE
(CPU stops)
MS1=1 &
SLEP
Wakeup
& MS0=0
32K OSC.:Oscillating
PEN=0->PLL stopped
PEN=1->PLL turned on
The following table shows the available functions for each type of MCU Mode:
Mode
Device
OSC (32768Hz)
Fsys
PLL
A/D conversion
Timers 0~2, IR generator
INT
SPI
UART
Melody Synthesizer
PWM, current D/A
SLEEP
1
(slave)
IDLE
SLOW
From OSC
(slave)
FAST
From PLL
Interrupt flag will be recorded but not executed until the MCU wakes up.
It is recommended to operate the A/D converter in IDLE mode to lower the noise couple from
the MCU clock.
17
ePG3231
RISC II-2G Series Microcontroller
T im e
Ts
0m s
MS0
SLO W
MODE
System
clock
FA ST M O D E
T arget
32.768K
T im e
0m s
0.244m s
Ts
NOTE
Slow mode will switch to Fast mode at Time=0ms
The System clock will switch into FPLL after 8 oscillations clocks, and frequency
will then increase to about hundreds of kHz.
The PLL frequency will be stable (5%) at Time=Ts (around 2ms~5ms).
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
SLOW MODE: When the MS0 bit (Bit 0) is set to 0, the MCU will enter into SLOW
mode.
FAST MODE: When the MS0 bit (Bit 0) is set to 1, the MCU will into enter FAST
mode.
SLEEP MODE: When the MS1 bit (Bit 1) is set to 0 and SLEP instruction is
executed, the MCU will enter into SLEEP mode.
IDLE MODE:
18
ePG3231
RISC II-2G Series Microcontroller
PEN: High Frequency enable bit. This bit is only effective when MCU is in IDLE or
SLOW mode.
MCU Mode
SLEEP
IDLE/SLOW
FAST
PEN Bit
PLL On/Off
0
1
Off
Off
On
On
SLEEP
(Slave)
IDLE
(Slave)
SLOW
FAST
7.4.1 Flowchart
C h a n g e P L L F re q u e n c y
BS
CPUCON, PEN
T u rn o n th e P L L
BC
CPUCON, MS0
C h a n g e C P U t o S lo w m o d e
MOV
MOV
SCALL
A ,# 1 2 2
P F S ,A
C h a n g e P L L fre q u e n c y to
8M Hz
DLY3m s
D e la y f o r 3 m s t o w a it f o r
P L L t o b e s t a b le
BS
CPUCON, MS0
C h a n g e C P U to F a s t m o d e
BC
CPUCON, PEN
T u rn o ff th e P L L
G o t o M a in R o u t in e
19
ePG3231
RISC II-2G Series Microcontroller
BC
CPUCON,MS0
CLR
DCRDE
BS
CPUCON,PE
MOV
A, # 11110000B
MOV
,#122
MOV
DCRFG, A
MOV
PFS,A
MOV
A, # 00001111B
;8MHz
Delay 3msec
OR
DCRHI, A
BS
CPUCON,MS0
MOV
A, # 11111111B
BC
CPUCON,PE
MOV
PORTD, A
MOV
PORTE, A
MOV
PORTF, A
BC
CPUCON, MS0
BS
CPUCON, MS1
CPUCON,MS0
SLEP
NOP
DCRDE
MOV
A, # 11110000B
MOV
DCRFG, A
MOV
A, # 00001111B
OR
DCRHI, A
MOV
A, # 11111111B
MOV
PORTD, A
MOV
PORTE, A
MOV
PORTF, A
BC
CPUCON, MS0
BC
CPUCON, MS1
SLEP
NOP
IMPORTANT !
Before going into SLEEP mode or IDLE mode, Ports D, E, & F must be set as output
port and output high. At the same time, Ports G & H must be set as Input port and
enable pull-high. Otherwise, higher power consumption problem will result during
SLEEP and IDLE modes.
20
ePG3231
RISC II-2G Series Microcontroller
7.5 Interrupt
When interrupt occurs, the GLINT bit (Bit 2) of CPUCON register is reset to 0. It
disables all interrupts, including LEVEL1 ~ LEVEL5 (~ LEVEL6 for Mode 2). Setting
this bit to 1 will enable all un-mask interrupts.
The interrupt priority has two different sequences (Melody interrupts and Interrupt
priority) that are selected by code option.
Mode 1: Disable melody interrupt function and Interrupt priority
(External > Capture > Speech > Timers 0 ~ 2 > Peripheral).
Interrupt Level
Interrupt Source
Start Address
Remarks
RESET
0x00000
Level 1
Input Port A
0x00002
PAINT, PIRQB
Level 2
Capture
0x00004
CPIF
Level 3
Speech Timer
0x00006
SPHTI
Level 4
Timers 0~2
0x00008
Level 5
Peripheral
0x0000A
Interrupt Source
Start Address
Remarks
RESET
0x00000
Level 1
Timer 0
0x00008
TMR0I
Level 2
0x00004
CPIF
Level 3
Capture
Speech &
melody Timer
0x00006
SPHTI (MTI)
Level 4
Input Port A
0x00002
PAINT, PIRQB
Level 5
Timer 1, 2
0x00008
TMR1I, TMR2I
Level 6
Peripheral
0x0000A
Code Example:
; *****
Reset program
ResetSEG CSEG 0X00
LJMP MSTART
LJMP INPTINT
LJMP CAPINT
LJMP SPHINT
LJMP TIMERINT
LJMP PERIPH
PgmSEG
CSEG 0X20
MOVRP
MOV
RETI
Status,StatusBuf
A,AccBuf
21
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === Input Port and Touch Panel Interrupt
INPTINT:
S0CALL PUSH
JBC
ADCON,PIRQB,toTPINT
TEST
PAINTSTA
JBC
STATUS,F_Z,toPAINT
SJMP
POP
PAINTSTA
POP
22
ePG3231
RISC II-2G Series Microcontroller
23
ePG3231
RISC II-2G Series Microcontroller
4. URXI Interrupt:
24
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === Peripheral Interrupt
PERIPH:
S0CALL PUSH
JBS
INTSTA,ADIF,toADINT
JBS
INTSTA,UERRI,toUERRINT
JBS
INTSTA,UTXI,toUTXINT
JBS
INTSTA,URXI,toURXINT
JBS
SPISTA,SRBFI,toSPINT
SJMP
POP
; -- A/D interrupt
toADINT:
BC
INTSTA,ADIF
:
SJMP
POP
; --- UART Receiving Error Interrupt
toUERRINT:
BC
INTSTA,UERRI
:
SJMP
POP
; --- UART Tx Buffer Full Interrupt
toUTXINT:
BC
INTSTA,UTXI
:
SJMP
POP
; --- UART Rx Buffer Full Interrupt
toURXINT:
BC
INTSTA,URXI
:
SJMP
POP
; --- SPI interrupt
toSPINT:
BC
SPISTA,SRBFI
:
SJMP
POP
25
ePG3231
RISC II-2G Series Microcontroller
Extended MCU mode: Both internal PROM / external DROM are available
(PMD=0, add an external memory)
MCU MODE
(PMD=0, No external memory)
00000h
Interrupt vector
Code Option
Test
Program
00020h
On-chip
Program
Memory
7FFFh
ON-CHIP
Processor Mode
(PMD=1, Add external memory)
00000h
Interrupt vector
Code Option
Test
Program
00020h
On-chip
Program
Memory
7FFFh
OFF-CHIP
FFFFh
10000h
3FFFFh
Reserved
3FFFFh
040000h
ExternalProgram
Memory
(192KW)
ON-CHIP
ON-CHIP
External Data
Memory
000000h
ExternalProgram
Memory
(192KW)
02FFFFh
External Data
Memory
3FFFFFh
(256KW)
3FFFFFh
OFF-CHIP
OFF-CHIP
26
ePG3231
RISC II-2G Series Microcontroller
t cycle
OSCI
t ad
t ad
A0 ~ A21
D0 ~ D15
t ds
t dh
t cycle
t ad
t ds
t dh
Characteristics
Min.
Typ.
Max.
Unit
62.5*
10*
10*
80*
-
ns
ns
ns
ns
Processor mode
Fig. 7-10 MCU Mode, Extended MCU Mode and Processor Mode Circuit Diagrams
Product Specification (V2.5) 11.08 2005
(This specification is subject to change without further notice)
27
ePG3231
RISC II-2G Series Microcontroller
PMD=1
(Processor mode):
0000h
|
000Bh
28
Segment
Addr.
Segment
Addr.
Segment
0000h
|
000Bh
Interrupt
Vector
(12 words)
000Ch
|
000Fh
Code
Option
(4 words)
0010h
|
001Fh
Test
Program
(16 words)
0020h
|
3FFFh
Segment 0
|
Segment 1
4000h
|
7FFFh
Segment 2
|
Segment 3
24000h
|
27FFFh
8000h
|
BFFFh
Not
Implement
C000h
|
FFFFh
10000h
|
13FFFh
14000h
|
17FFFh
18000h
|
1BFFFh
1C000h
|
1FFFFh
20000h
Segment 16
23FFFh
Segment 17
Addr.
Segment
20000h
Segment 16
23FFFh
Segment 17
Interrupt
Vector
(12 words)
000Ch
|
000Fh
Code
Option
(4 words)
0010h
|
001Fh
Test
Program
(16 words)
0020h
|
3FFFh
Segment 0
|
Segment 1
Segment 18
|
Segment 19
4000h
|
7FFFh
Segment 2
|
Segment 3
24000h
|
27FFFh
Segment 18
|
Segment 19
28000h
|
2BFFFh
Segment 20
|
Segment 21
8000h
|
BFFFh
Segment 4
|
Segment 5
28000h
|
2BFFFh
Segment 20
|
Segment 21
Not
Implement
2C000h
|
2FFFFh
Segment 22
|
Segment 23
C000h
|
FFFFh
Segment 6
|
Segment 7
2C000h
|
2FFFFh
Segment 22
|
Segment 23
Segment 8
|
Segment 9
Segment 10
|
Segment 11
Segment 12
|
Segment 13
Segment 14
|
Segment 15
30000h
|
33FFFh
34000h
|
37FFFh
38000h
|
3BFFFh
3C000h
|
3FFFFh
Segment 24
|
Segment 25
Segment 26
|
Segment 27
Segment 28
|
Segment 29
Segment 30
|
Segment 31
10000h
|
13FFFh
14000h
|
17FFFh
18000h
|
1BFFFh
1C000h
|
1FFFFh
Segment 8
|
Segment 9
Segment 10
|
Segment 11
Segment 12
|
Segment 13
Segment 14
|
Segment 15
30000h
|
33FFFh
34000h
|
37FFFh
38000h
|
3BFFFh
3C000h
|
3FFFFh
Segment 24
|
Segment 25
Segment 26
|
Segment 27
Segment 28
|
Segment 29
Segment 30
|
Segment 31
ePG3231
RISC II-2G Series Microcontroller
INDF0
FSR0
PCL
PCM
PCH
BSR
STKPTR
BSR1
INDF1
FSR1
ACC
TABPTRL
TABPTRM
TABPTRH
CPUCON
STATUS
10
TRL2
11
PRODL
12
PRODH
13
ADOTL
14
ADOTH
1
2
Bit 7
W = Writable bit
= unimplemented, read as 0
Bit 6
Bit 5
R/W
PC7
R/W
PC15
R/W
PC6
R/W
PC14
R/W
Indirect Addressing Pointer 0
R/W
File Select Register 0 for INDF0
R/W
R/W
R/W
R/W
PC5
PC4
PC3
PC2
R/W
R/W
R/W
R/W
PC13
PC12
PC11
PC10
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
R/W
PC1
R/W
PC9
R/W
PC17
R/W
PC0
R/W
PC8
R/W
PC16
R/W
Bank Select Register for INDF0 & General RAM
R/W
Stack Pointer
R/W
Bank Select Register 1 for INDF1
R/W
Indirect Addressing Pointer 1
R
R/W
1
File Select Register 1 for INDF1
R/W
Accumulator
R/W
Table Pointer Low
R/W
Table Pointer Middle
R/W
Table Pointer High
R/W
R/W
R/W
R/W
R/W
R/W
PEN
SMCAND SMIER
GLINT
MS1
MS0
R
R
R/W
R/W
R/W
R/W
R/W
R/W
/TO
/PD
SGE
SLE
OV
Z
DC
C
R/W
Timer 2 Reload Register
R/W
Multiplier Product Low
R/W
Multiplier Product High
R/W
R/W
R/W
R/W
R
R
WDTEN EXTMEM ADWKEN
FSS
ADOT1
ADOT0
R
R
R
R
R
R
R
R
ADOT9
ADOT8
ADOT7
ADOT6
ADOT5
ADOT4
ADOT3
ADOT2
Do not use BSR (05h) Bit 7 ~ Bit 5 and BSR 1 (07h) Bit 7 ~ Bit 5
Do not use JDNZ & JINZ at FSR1 (09h) special register
29
ePG3231
RISC II-2G Series Microcontroller
15
UARTTX
16
UARTRX
17
PORT A
18
PORT B
19
PORT C
1A
PORT D
1B
PORT E
1C
PORT F
1D
PORT G
1E
PORT H
1F
PORTI
20
PFS
21
STBCON
22
INTCON
23
INTSTA
24
TRL0L
25
TRL0H
26
TRL1
27
TR01CON
28
TR2CON
29
TRLIR
2A
(Reserved)
2B
POST_ID
2C
ADCON
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
W
TB7
R
RB7
R
A.7
R/W
B.7
R/W
C.7
R/W
D.7
R/W
E.7
R/W
F.7
R/W
G.7
R/W
H.7
R/W
I.7
W
TB6
R
RB6
R
A.6
R/W
B.6
R/W
C.6
R/W
D.6
R/W
E.6
R/W
F.6
R/W
G.6
R/W
H.6
R/W
I.6
W
TB5
R
RB5
R
A.5
R/W
B.5
R/W
C.5
R/W
D.5
R/W
E.5
R/W
F.5
R/W
G.5
R/W
H.5
R/W
I.5
W
TB4
R
RB4
R
A.4
R/W
B.4
R/W
C.4
R/W
D.4
R/W
E.4
R/W
F.4
R/W
G.4
R/W
H.4
R/W
I.4
W
TB3
R
RB3
R
A.3
R/W
B.3
R/W
C.3
R/W
D.3
R/W
E.3
R/W
F.3
R/W
G.3
R/W
H.3
R/W
I.3
W
TB2
R
RB2
R
A.2
R/W
B.2
R/W
C.2
R/W
D.2
R/W
E.2
R/W
F.2
R/W
G.2
R/W
H.2
R/W
I.2
W
TB1
R
RB1
R
A.1
R/W
B.1
R/W
C.1
R/W
D.1
R/W
E.1
R/W
F.1
R/W
G.1
R/W
H.1
R/W
I.1
W
TB0
R
RB0
R
A.0
R/W
B.0
R/W
C.0
R/W
D.0
R/W
E.0
R/W
F.0
R/W
G.0
R/W
H.0
R/W
I.0
R/W
Target PLL Frequency Selection Register
R/W
R/W
R/W
R/W
R/W
R/W
R/W
UINVEN
/REN
BitST
ALL
STB3
STB2
STB1
R/W
R/W
R/W
R/W
R/W
R/W
R/W
CPIE
ADIE
URXIE
UTXIE
UERRIE TMR2IE TMR1IE
R/W
R/W
R/W
R/W
R/W
R/W
R/W
CPIF
ADIF
URXI
UTXI
UERRI
TMR2I
TMR1I
R/W
Timer 0 Reload Low Byte Register
R/W
Timer 0 Reload High Byte Register
R/W
Timer 1 Reload Register
R/W
R/W
R/W
R/W
R/W
R/W
R/W
T1WKEN
T1EN
T1PSR1 T1PSR0
IREN
T0CS
T0PSR1
R/W
R/W
R/W
R/W
R/W
R/W
R/W
IRPSR1 IRPSR0 T0FNEN1 T0FNEN0 T2EN
T2CS
T2PSR1
R/W
IR Reload Register
3
R/W
STB0
R/W
TMR0IE
R/W
TMR0I
R/W
T0PSR0
R/W
T2PSR0
R/W
EM_ID
R/W
DET
R/W
VRS
R/W
R/W
FSR1_ID FSR0_ID
R/W
R
ADEN
PIROB
R/W
EMPE
R/W
S/DB
R/W
CHS2
R/W
R/W
FSR1PE FSR0PE
R/W
R/W
CHS1
CHS0
30
ePG3231
RISC II-2G Series Microcontroller
2D
PAINTEN
2E
PAINTSTA
2F
PAWAKE
30
UARTCON
31
UARTSTA
32
PORT J
33
PORT K
34
DCRB
35
DCRC
36
DCRDE
37
DCRFG
38
DCRHI
39
DCRJK
3A
PBCON
3B
PCCON
3C
PLLF
3D
TOCL
3E
TOCH
3F
SPICON
40
SPISTA
41
SPRL
42
SPRM
43
SPRH
44
SFCR
Bit 7
Bit 6
Bit 5
R/W
R/W
R/W
PA7IE
PA6IE
PA5IE
R/W
R/W
R/W
PA7I
PA6I
PA5I
R/W
R/W
R/W
WKEN7 WKEN6 WKEN5
W
R/W
R/W
TB8
UMODE1 UMODE0
R
R/W
R/W
RB8
EVEN
PRE
R/W
R/W
R/W
J.7
J.6
J.5
R/W
R/W
R/W
K.7
K.6
K.5
R/W
R/W
R/W
Bit7DC
Bit6DC
Bit5DC
R/W
R/W
R/W
Bit7DC
Bit6DC
Bit5DC
R/W
R/W
R/W
EHNPU ELNPU EHNDC
R/W
R/W
R/W
GHNPU GLNPU GHNDC
R/W
R/W
R/W
IHNPU
ILNPU
IHNDC
R/W
R/W
R/W
KHNPU KLNPU KHNDC
R/W
R/W
R/W
Bit7PU
Bit6PU
Bit5PU
R/W
R/W
R/W
Bit7PU
Bit6PU
Bit5PU
Bit 4
Bit 3
Bit 2
R/W
R/W
R/W
PA4IE
PA3IE
PA2IE
R/W
R/W
R/W
PA4I
PA3I
PA2I
R/W
R/W
R/W
WKEN4 WKEN3 WKEN2
R/W
R/W
R/W
BRATE2 BRATE1 BRATE0
R/W
R/W
R/W
PRERR OVERR FMERR
R/W
R/W
R/W
J.4
J.3
J.2
R/W
R/W
R/W
K.4
K.3
K.2
R/W
R/W
R/W
Bit4DC
Bit3DC
Bit2DC
R/W
R/W
R/W
Bit4DC
Bit3DC
Bit2DC
R/W
R/W
R/W
ELNDC DHNPU DLNPU
R/W
R/W
R/W
GLNDC FHNPU
FLNPU
R/W
R/W
R/W
ILNDC
HHNPU HLNPU
R/W
R/W
R/W
KLNDC
JHNPU
JLNPU
R/W
R/W
R/W
Bit4PU
Bit3PU
Bit2PU
R/W
R/W
R/W
Bit4PU
Bit3PU
Bit2PU
R
Actual PLL Frequency Value Register
Bit 1
Bit 0
R/W
PA1IE
R/W
PA1I
R/W
WKEN1
R
UTBE
R
URBF
R/W
J.1
R/W
K.1
R/W
Bit1DC
R/W
Bit1DC
R/W
DHNDC
R/W
FHNDC
R/W
HHNDC
R/W
JHNDC
R/W
Bit1PU
R/W
Bit1PU
R/W
PA0IE
R/W
PA0I
R/W
WKEN0
R/W
TXE
R/W
RXE
R/W
J.0
R/W
K.0
R/W
Bit0DC
R/W
Bit0DC
R/W
DLNDC
R/W
FLNDC
R/W
HLNDC
R/W
JLNDC
R/W
Bit0PU
R/W
Bit0PU
R/W
TLS1
R/W
WEN
R/W
TLS0
R/W
AGMD2
R/W
AGMD1
R/W
SE
R
RBF
R/W
CSB0
31
ePG3231
RISC II-2G Series Microcontroller
ADDL
46
ADDM
47
ADDH
48
ENV/SPHDR
49
MTCON/
SPHTCON
4A
MTRL/SPHTRL
R/W
VOEN
4B
VOCON
4C
TR1C
4D
TR2C
4E
ADCF
4F
(Reserved)
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
R/W
Melody Channels 1~4 Address Low Byte Register
R/W
Melody Channels 1~4 Address Middle Byte Register
R/W
Melody Channels 1~4 Address High Byte Register
R/W
Melody Channels 1~4 Envelope Register/Speech Data Register
R/W
Melody Channels 1~4 Control Register/Speech Control Register
45
Bit 7
R/W
VOL0
Address
Un-Banked
50h
|
7Fh
Address
80h
|
FFh
32
Bank 0
Bank 1
Bank 2
Bank 3
..
Bank 31
General
Purpose
RAM
General
Purpose
RAM
General
Purpose
RAM
General
Purpose
RAM
..
General
Purpose
RAM
ePG3231
RISC II-2G Series Microcontroller
7.9
7.9.2 PCL, PCM, PCH (R02h, R03h, R04h): Program Counter Register
Bit17 Bit16 Bit15 Bit14 Bit13 Bit12 Bit11 Bit10 Bit9 Bit8 Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
PCH
PCM
PCL
Indirect_JUMP:
MOV
A,number
ADD
A,ACC
; A<-- 2*A
; PCL<-- PCL+A
ADD
PCL,A
function_table:
LJMP function_address_1 ; number=0
LJMP function_address_2 ; number=1
LJMP function_address_3 ; number=2
LJMP function_address_4 ; number=3
LJMP function_address_5 ; number=4
LJMP function_address_6 ; number=5
LJMP function_address_7 ; number=6
.........
function_address_1:
.........
; Function 1 operation
.........
RET
33
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
EM_ID
FSR1_ID
FSR0_ID
EMPE
FSR1PE
FSR0PE
Bit 0 (FSR0PE): Enable FSR0 post increase/decrease function. FSR0 will NOT carry
into nor borrow from BSR.
Bit 1 (FSR1PE): Enable FSR1 post increase/decrease function. FSR1 will carry into
or borrow from BSR1.
Bit 4 FSR0_ID): Set to 1 means auto increase. Reset to 0 means auto decrease of
FSR0.
Bit 5 (FSR1_ID): Set to 1 means auto increase. Reset to 0 means auto decrease of
FSR1.
34
ePG3231
RISC II-2G Series Microcontroller
The linear address capabilities of INDF1 are as shown in the following diagram:
Auto Increase on FSR1
(Set FSR1PE=1,FSR1 ID=1)
Instruction
BSR1
FSR1
INDF1
ACC
03
FF
AA
00
04
80
BB
AA
04
81
CC
BB
04
82
DD
CC
M OV A,INDF1
M OV A,INDF1
File Register
M OV A,INDF1
BANK 3
BANK 4
81h
BB
CC
82h
DD
80h
:
:
FDh
FEh
FFh
88
99
AA
:
:
Instruction
BSR1
FSR1
INDF1
ACC
04
80
BB
00
03
FF
AA
BB
03
FE
99
AA
03
FD
88
99
M OV A,INDF1
M OV A,INDF1
M OV A,INDF1
:
Code Example:
;*******************************************
;*
Const => Working bank setting
;*
REG => Save or Recall register
;*******************************************
; ***** RAM stack macro
; *** Initial RAM stack
IniRAMsk MACRO
#Const
MOV
A,#Const
MOV
BSR1,A
CLR
FSR1
BS
POST_ID,FSR1PE
ENDM
; *** Push RAM stack
PushRAM MACRO
REG
BS
POST_ID,FSR1_ID
MOVRP
INDF1,REG
ENDM
; *** Pop RAM stack
PopRAM MACRO
REG
BC
POST_ID,FSR1_ID
MOVPR
REG,INDF1
ENDM
Product Specification (V2.5) 11.08 2005
(This specification is subject to change without further notice)
ePG3231
RISC II-2G Series Microcontroller
Bit 23
TABPTRH
Bit 16 Bit15
Bit 8 Bit 7
TABPTRM
Bit 0
TABPTRL
INCLUDE "DROM_E.hdr"
:
:
TBPTH
#(PROMTabB*2)/10000H
TBPTM
#(PROMTabB*2)/100H
TBPTL
#PROMTabB*2
:
:
TBRD
0,ACC ;no change
TBRD
1,ACC ;auto-increase
TBRD
2,ACC ;auto-decrease
:
:
; *** Program ROM data
PROMTabB:
DB
0x00,0x01,0x02,0x03,0x04,0x05
DB
0x10,0x11,0x12,0x13,0x14,0x15
DB
0x20,0x21,0x22,0x23,0x24,0x25
36
;to ROMConverter
:
:
TBPTL #_Data_l
TBPTM #_Data_m
TBPTH #_Data_h
BS
TABPTRH,7
:
:
TBRD
0,ACC
;no change
TBRD
1,ACC
;auto-increase
TBRD
2,ACC
;auto-decrease
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
Bit 3 (SMIER):
MUL
A,# 88
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
UINVEN
/REN
BitST
ALL
STB3
STB2
STB1
STB0
37
ePG3231
RISC II-2G Series Microcontroller
DCRB, DCRC (R34h, R35h): Port B & Port C Direction Control Registers
Bit 7 ~ Bit 0 (Bit 7DC ~ Bit 0DC): 0 : Set to output pin
1 : Set to input pin
PBCON, PCCON (R3Ah, R3Bh): Port B & Port C Pull-up Resistor Control
Registers
Bit 7 ~ Bit 0 (Bit 7PU ~ Bit 0PU): 0 : Disable the pull-up resistor
1 : Enable the pull-up resistor
DCRDE (R36h): Port D & Port E Direction Control & Pull-up Resistor Control
Register
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
EHNPU
ELNPU
EHNDC
ELNDC
DHNPU
DLNPU
DHNDC
DLNDC
DCRFG (R37h): Port F & Port G Direction Control & Pull-up Resistor Control
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
GHNPU
GLNPU
GHNDC
GLNDC
FHNPU
FLNPU
FHNDC
FLNDC
38
ePG3231
RISC II-2G Series Microcontroller
7.9.12 Port H, Port I (R1Eh, R38h): External Memory Data Bus and
General I/O Registers
DCRHI (R38h): Port H & Port I Direction Control & Pull-up Resistor Control
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
IHNPU
ILNPU
IHNDC
ILNDC
HHNPU
HLNPU
HHNDC
HLNDC
DCRJK (R39h): Port J & Port K Direction Control & Pull-up Resistor Control
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
KHNPU
KLNPU
KHNDC
KLNDC
JHNPU
JLNPU
JHNDC
JLNDC
39
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; *** Port A function
; --- Port A interrupt
INPTINT:
PUSH
MOV
; --- Port A interrupt
JBS
MOV
Q_PAINT:
POP
RETI
; --- Port H output
CLR
; --- Port A pull-up enable
BC
CLR
MOV
; --- Port A interrupt
MOV
; --- Port A wakeup
MOV
BS
; --- Sleep mode
BC
SLEP
NOP
:
:
40
A,PAINTSTA
STATUS,F_Z,Q_PAINT
PORTH,A
DCRHI
STBCON,REN
PAINTSTA
A,#11111111B
PAINTEN,A
PAWAKE,A
CPUCON,GLINT
CPUCON,MS1
ePG3231
RISC II-2G Series Microcontroller
Peripherals
8.1 Timer 0 (16 Bits Timer with Capture and Event Counter
Functions)
Fosc
Fper /2
TRL0H:TRL0L
T0PSR1~0 T0FNEN1~0
T0CS
Comparator
Fcs
Prescaler
Function
Enable
Selector
Schmit
Trigger
Timer 0
reset
(16 bit counter) Counting
Selector
value
AGMD2~0
T0FNEN1~0
EVIN/
CPIN
Edge
Detector
Timer 0 INT
T0CH:T0CL
CPIF
T=
1
Pr escaler (TRL0 H : TRL0 L + 1)
Fcs
Timer 0 Frequency:
Clock Source
Fper / 2
TRL0H:TRL0L
Prescaler
Timer 0 Freq.
FFFFh
1:64
128Hz
Fpll (8MHz)
4MHz
00FFh
1:1
15.6kHz
Fosch (16MHz)
8MHz
00FFh
1:1
31.2kHz
Fosc (32.768kHz)
41
ePG3231
RISC II-2G Series Microcontroller
T=
1
Pr escaler [(T 0CH : T 0CL )NEW (T 0CH : T 0CL )OLD ]
Fcs
10
000
001
010
011
100
101
CPIN
Timer 0 P1 P2 P3 P4 P5 P6 P7 P8 P9 P10P11P12P13 P14P15P16 P17P18P19P20 P21P22P23P24P25P26P27P28 P29
P30P31P32P33
CPIF
T0CH:T0CL
P2
P3
P6
P7
P9
P11
P13
P15
P17
P21
P22
42
ePG3231
RISC II-2G Series Microcontroller
Event Counter Mode Example:
T0FN EN 1~0
00
11
010
AG M D 2~0
011
E V IN
T im e r 0
P0
P1
P2
P3
P4
P5
T 0 C H :T 0 C L
P0
P1
P2
P3
P4
P5
Bit 7
T1WKEN
Bit 6
T1EN
Bit 5
T1PSR1
Bit 4
T1PSR0
Bit 3
IREN
Bit 2
T0CS
Bit 1
T0PSR1
Bit 0
T0PSR0
Prescaler Value
00
01
10
11
1:1
1:4
1:16
1:64
Bit 6
IRPSR1
IRPSR0
Bit 5
Bit 4
T0FNEN1 T0FNEN0
Bit 3
Bit 2
Bit 1
Bit 0
T2EN
T2CS
T2PSR1
T2PSR0
Bit 5 ~ Bit 4 (T0FNEN1 ~ T0FNEN0): Timer 0, Capture, and event counter modes
selection bits
43
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
AGMD2
AGMD1
AGMD0
Bit 4
Bit 3
WDTPSR1 WDTPSR0
Bit 2
Bit 1
Bit 0
SPHSB
CSB1
CSB0
Bit 7 ~ Bit 5 (AGMD2 ~ AGMD0): Capture and Event Counter functions edge detector
selection bits
T0FNEN 1 ~ 0
00
01
10
Mode
Disable
Timer 0
Capture
AGMD 2~0
000
001
010
011
100
101
Event Counter
010
011
11
Edge Mode
1st Rising edge, 2nd falling edge and so on
1st Falling edge, 2nd rising edge and so on
Every rising edge
Every falling edge
Every 4th rising edge
Every 16th rising edge
Every rising edge
Every falling edge
Note: 1. Disable the Timer 0 before changing from one mode to another.
2. To avoid error, setup T0FNEN1 and T0FNEN0 simultaneously.
Bit 6
-
Bit 5
-
Bit 4
SMCAND
Bit 3
SMIER
Bit 2
GLINT
Bit 1
MS1
Bit 0
MS0
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIE
ADIE
URXIE
UTXIE
UERRIE
TMR2IE
TMR1IE
TMR0IE
Bit 2
TMR2I
Bit 1
TMR1I
Bit 0
TMR0I
Bit 6
ADIF
Bit 5
URXI
Bit 4
UTXI
Bit 3
UERRI
Bit 0 (TMR0I): Set to 1 when Timer 0 is larger than TRL0H ~ TRL0L value
Clear to 0 by software or disable Timer 0
Bit 7 (CPIF):
44
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === Timer 0 interrupt
TIMERINT:
CAPINT:
PUSH
PUSH
JBC
INTSTA,TMR0I,Q_Time
JBS
INTSTA,CPIF,Q_ICAP
BC
INTSTA,TMR0I
BC
INTSTA,CPIF
BTG
PORTC,3
BTG
PORTC,3
BS
INTFLAG,F_ICAP
Q_Time:
POP
Q_ICAP:
RETI
POP
RETI
;
CAP_SR:
System setting 8MHz
PC.2 Port H & G setting output port
A,#00000101B
MOV
TR01CON,A
A,#0XFF
MOV
A,#0FFH
MOV
TRL0H,A
MOV
TRL0L,A
MOV
TRL0L,A
MOV
A,#03FH
MOV
TRL0H,A
; --- (8MHz/2)/65536=61Hz
A,#00010000B
MOV
TR2CON,A
INTCON,TMR0IE
INTSTA,TMR0I
CPUCON,GLINT
TimeLoop:
; --- Out Timer 0 count to Port H:G
MOVRP
SJMP
PORTH,T0CH
MOV
A,#00000100B
MOV
TR01CON,A
A,#00100000B
MOV
SFCR,A
BS
INTCON,CPIE
A,#00100000B
MOV
TR2CON,A
BC
INTFLAG,F_ICAP
BS
CPUCON,GLINT
CAP_LOOP:
MOVRP PORTG,T0CL
JBC
INTFLAG,F_ICAP,CAP_LOOP
TimeLoop
BC
INTFLAG,F_ICAP
PORTH,T0CH
MOVRP
PORTG,T0CL
SJMP
CAP_LOOP
45
ePG3231
RISC II-2G Series Microcontroller
A,#0XFF
MOV
TRL0L,A
CLR
TRL0H
BS
TR01CON,T0CS
; Fper/2
MOV
A,#01000000B
MOV
SFCR,A
MOV
A,#00110000B
MOV
TR2CON,A
MOVRP
PORTH,T0CH
MOVRP
PORTG,T0CL
SJMP
EV_LOOP
; Rising edge
EV_LOOP:
TRL1
reload
underflow
Fosc
Prescaler
Timer1
T1PSR1~0
Timer1 is a general-purpose 8-bit countdown counter for applications that require time
count. Furthermore, Timer 1 offers interrupt and wake-up functions for users
convenience. The clock source is from the oscillator clock (Fosc).
The Timer also offers a prescaler, where the T1PSR1~T1PSR0 bits of TR01CON
register determine the prescaler ratio while generating different clock rates as clock
source for the timer. Setting T1WKEN bit of TR01CON register to 1, will enable Timer
1 to underflow wake up function under IDLE MODE.
46
ePG3231
RISC II-2G Series Microcontroller
Counter value will decrease by one (countdown) according to the frequency of the
timer clock source. When the counter value underflows, the timer interrupt will trigger if
the global interrupt and Timer1 interrupt are both enabled. At the same time, TRL1 will
automatically reload into 8 bits counter.
T=
1
Pr escaler (TRL1 + 1)
Focs
The Timer 1 frequency ranges from 0.5 Hz (TRL1 = 0FFh, prescaler = 1:256) to
8.192kHz (TRL1 = 0h, prescaler = 1:4). The clock source is from the oscillator clock
(Fosc).
TRL1 (R26h): Used to store the auto-reload value of Timer 1. When enabling
Timer 1 or when underflow occurs, TRL1 register will automatically
reload into 8 bits counter.
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
T1WKEN
T1EN
T1PSR1
T1PSR0
IREN
T0CS
T0PSR1
T0PSR0
Prescaler Value
00
01
10
11
1:4
1:16
1:64
1:256
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
47
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIE
ADIE
URXIE
UTXIE
UERRIE
TMR2IE
TMR1IE
TMR0IE
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIF
ADIF
URXI
UTXI
UERRI
TMR2I
TMR1I
TMR0I
48
ePG3231
RISC II-2G Series Microcontroller
TRL2
reload
Fosc
underflow
Fcs
Prescaler
Timer 2 INT
Timer 2
Fper/2
TR2C
T2CS
T2PSR1~0
T2EN
T=
1
Pr escaler (TRL 2 + 1)
Fcs
Fosc (32.768kHz)
Fpll (8MHz)
Fosch (16MHz)
Fper / 2
TRL0H:TRL0L
Prescaler
Timer 0 Freq.
4MHz
8MHz
FFh
0Fh
0Fh
1:8
1:1
1:1
16Hz
250kHz
500kHz
TRL2 (R10h): is used to store the auto-reload value of Timer 2 when Timer 2 is
enabled or underflow occurs. TRL2 register will automatically
reload into 8 bits counter.
49
ePG3231
RISC II-2G Series Microcontroller
Bit 6
IRPSR1
IRPSR0
Bit 5
Bit 4
T0FNEN1 T0FNEN0
Bit 3
Bit 2
Bit 1
Bit 0
T2EN
T2CS
T2PSR1
T2PSR0
Bit 2
GLINT
Bit 1
MS1
Bit 0
MS0
Bit 2
TMR2IE
Bit 1
TMR1IE
Bit 0
TMR0IE
Prescaler Value
00
01
10
11
1:1
1:2
1:4
1:8
Bit 6
-
Bit 5
-
Bit 4
SMCAND
Bit 3
SMIER
Bit 6
ADIE
Bit 5
URXIE
Bit 4
UTXIE
Bit 3
UERRIE
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIF
ADIF
URXI
UTXI
UERRI
TMR2I
TMR1I
TMR0I
50
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === Timer 2 interrupt
TIMERINT:
PUSH
JBC
INTSTA,TMR2I,Q_Time
BC
INTSTA,TMR2I
BTG
PORTC,3
Q_Time:
POP
RETI
; === Timer2 = (8M/2) / [4 x 3F + 1]
Timer2SR:
:
System setting 8MHz
Port G setting output port
:
MOV
A,#00000110B
MOV
TR2CON,A
MOV
A,#03FH
MOV
TRL2,A
BS
TR2CON,T2EN
BS
INTCON,TMR2IE
BC
INTSTA,TMR2I
BS
CPUCON,GLINT
TMR2Loop:
MOVRP
PORTH,TR2C
SJMP
TMR2Loop
TRLIR
reload
Fper
Prescaler
8 bits counter
underflow
Divide
by 2
IROT
IREN
IRPSR1~0
51
ePG3231
RISC II-2G Series Microcontroller
IR function is enabled by IREN bit and is output on the IROT (Port B.2) pin by a
general-purpose 8 bits countdown counter. When IREN is low, the T-flip-flop should be
initialized, as IROT equals zero. The clock source is from Fper and the IRPSR1 ~
IRPSR0 bit of TR2CON register determine the prescaler ratio while generating different
clock rates as the clock source for the timer. The counter value will decrease by one
(countdown) according to the actual type of timer clock source in use. When counter
value underflows, the IR reload register value will be reloaded into the counter.
T=
2
Pr escaler (TRLIR + 1)
Fper
Fpll (8MHz)
Fosch (16MHz)
Fper
TRL0H:TRL0L
Prescaler
Timer 0 Freq.
8MHz
16MHz
0Fh
0Fh
1:1
1:1
250kHz
500kHz
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
T1WKEN
T1EN
T1PSR1
T1PSR0
IREN
T0CS
T0PSR1
T0PSR0
Bit 6
IRPSR1
IRPSR0
Bit 5
Bit 4
T0FNEN1 T0FNEN0
Bit 3
Bit 2
Bit 1
Bit 0
T2EN
T2CS
T2PSR1
T2PSR0
52
IRPSR1: IRPSR0
Prescaler Value
00
01
10
11
1:1
1:4
1:16
1:64
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === IR generator 31kHz
:
MOV
A,#10000000B
MOV
TR2CON,A
MOV
A,#9
MOV
TRLIR,A
BS
TR01CON,IREN
SJMP
IR_Loop
; Prescaler 1:16
; 10MHz / [ 2 x 16 x ( 9 + 1 ) ] = 31kHz
IR_Loop:
Internal
RC OSC.
(16KHz20%)
FWDT
Prescaler
8-bit Counter
(WDT)
overflow
Enable
WDTPSR1~0
WDTEN
The watchdog timer (WDT) clock source is from the on-chip RC oscillator (16kHz
20%). The WDT will keep on running even when the oscillator has been turned off (i.e.
in SLEEP MODE). WDT time-out will cause the MCU to reset (if WDT is enabled). To
avoid a reset to occur, user should clear the WDT value by using the WDTC
instruction before WDT time-out. Setting the WDTEN bit will enable the WDT function.
Disable is the WDT default condition. There is also a prescaler to generate different
clock rates for the WDT clock source. The prescaler ratio is defined by WDTPSR1 ~
WDTPSR0.
T=
1
FWDT
Pr escaler (WDT + 1)
The WDT time out range is from 64ms (prescaler = 1:4) to 2.048 second (prescaler = 1:128).
53
ePG3231
RISC II-2G Series Microcontroller
WDTEN
Bit 6
Bit 5
EXTMEM ADWKEN
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
FSS
ADOT1
ADOT0
Bit 6
Bit 5
AGMD2
AGMD1
AGMD0
Bit 4
Bit 3
WDTPSR1 WDTPSR0
Bit 2
Bit 1
Bit 0
SPHSB
CSB1
CSB0
Prescaler Value
00
01
10
11
1:4
1:16
1:64
1:128
Code Example:
; === WDT setting 2.048sec
:
Timer 1 (0.5sec wakeup)
:
BS
SFCR,WDTPSR0
BS
SFCR,WDTPSR1
BC
CPUCON,MS1
WDTC
SLEP
WDT_Loop:
SJMP
WDT_Loop
; Prescaler 1:128
; Change to sleep mode
54
ePG3231
RISC II-2G Series Microcontroller
RS232C compatible
Interrupt available for Tx buffer empty, Rx buffer full, and receiver error
Baud rate
Generator
Fper
RXE
RX Control
Interrupt
Control
TX Control
TXE
RXD
UINVEN
0
RX shift register
Parity Control
0
1
UINVEN
Error flag
TXD
Data Bus
Fig. 8-6 UART Function Block Diagram
55
ePG3231
RISC II-2G Series Microcontroller
START
bit
D0
D1
1 bit
D2
Idle state
(mark)
Parity STOP
bit
bit
Dn
7 or 8 bits
1 bit
1 bits
Mode 1
Mode 2
Mode 3
PRE
10
11
START
7 bits DATA
STOP
START
7 bits DATA
Parity
START
8 bits DATA
STOP
START
8 bits DATA
Parity STOP
START
9 bits DATA
STOP
STOP
d) Stop bit:
e) Mark state:
output 1 continues until the start bit of the next transmit data
4. After transmitting the stop bit, the UART generates a UTXI interrupt (if enabled)
56
ePG3231
RISC II-2G Series Microcontroller
b) Frame check:
The baud rate generator comprises of a circuit that generates a clock pulse which
determines the transfer speed of the transmitted/received data in the UART.
The input clock of the baud rate generator is derived from the system clock divided
by 64 or from Timer 0 divided by 32.
The system clock should be at 9.830MHz (PFS = 150) or 14.745MHz (PFS = 225)
when UART is enabled.
The BRATE2 ~ BRATE0 bits of the UARTCON register can determine the desired
baud rate.
57
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TB8
UMODE1
UMODE0
BRATE2
BRATE1
BRATE0
UTBE
TXE
0: Fper = Fpll
BRATE2 ~ 0
Fper
(PFS = 4 ~ 255)
Fper = 9.83MHz
(PFS = 150)
000
001
010
011
100
101
110
111
Timer0/32
Fper/4096 baud
Fper/2048 baud
Fper/1024 baud
Fper/512 baud
Fper/256 baud
Fper/128 baud
Fper/64 baud
Timer0/32
2400 baud
4800 baud
9600 baud
19200 baud
38400 baud
76800 baud
153600 baud
Timer0/32
3600 baud
7200 baud
14400 baud
28800 baud
57600 baud
115200 baud
230400 baud
Timer0/32
2400 baud
4800 baud
9600 baud
19200 baud
38400 baud
76800 baud
153600 baud
UART Mode
00
01
10
11
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RB8
EVEN
PRE
PRERR
OVERR
FMERR
URBF
RXE
58
ePG3231
RISC II-2G Series Microcontroller
NOTE
When receive data is enabled, URBF (read-only) bit will be cleared by
hardware. Hence, read-only UARTRX register is required to avoid
overrun error.
Bit 2 (FMERR) Framing error flag. Set to 1 when framing error occurs
Clear to 0 by software
Bit 3 (OVERR): Overrun error flag. Set to 1 when overrun error occurs
Clear to 0 by software
Bit 4 (PRERR): Parity error flag. Set to 1 when parity error occurs
Clear to 0 by software
Bit 5 (PRE):
Bit 6 (EVEN):
Bit 7 (RB8):
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TB7
TB6
TB5
TB4
TB3
TB2
TB1
TB0
Bit 7 ~ Bit 0 (TB7 ~ TB0): Transmit data register. UARTTX register is write-only.
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
Bit 7 ~ Bit0 (RB7 ~ RB0): Receive data register. UARTRX register is read-only.
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
UINVEN
/REN
BitST
ALL
STB3
STB2
STB1
STB0
Bit 7 (UINVEN): Enable UART TXD and RXD port inverse output
0 : Disable TXD and RXD port inverse output
1 : Enable TXD and RXD port inverse output
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
59
ePG3231
RISC II-2G Series Microcontroller
Bit 2 (GLINT): Global interrupt control bit
0 : Disable all interrupts
1 : Enable all un-mask interrupts
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIE
ADIE
URXIE
UTXIE
UERRIE
TMR2IE
TMR1IE
TMR0IE
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIF
ADIF
URXI
UTXI
UERRI
TMR2I
TMR1I
TMR0I
Bit 5 (URXI):
10
11
12 13
14 15
16
TSYSTEM/16
One bit cycle
TXD pin
Start bit
Bit 0
Fig. 8-9 UART Transmit Counter Timing
60
ePG3231
RISC II-2G Series Microcontroller
STA RT
b it
D0
D1
D2
Dn
P a rity S T O P
b it
b it
STA RT
b it
D0
D1
D2
C le a r b y h a rd w a re w h e n
w rite d a ta in to U A R T T x .
A n d s ta rt tra n sm ittin g .
UTBE
C le a r b y
so ftw a re
UTXI
Code Example:
; === UART Transfer buffer empty interrupt
PERIPH:
PUSH
JBC
INTSTA,UTXI,Q_UTXINT
BC
INTSTA,UTXI
MOV
A,UTX_NO
COMA
ACC
MOV
UTX_NO,A
MOV
UARTTX,A
Q_UTXINT: POP
RETI
; === UART 38400 baud 8bit inverse
UTX_SR:
:
System setting 9.83MHz
:
BS
STBCON,UINVEN
MOV
A,#00110101B
MOV
UARTCON,A
MOV
A,#01100000B
MOV
UARTSTA,A
BC
INTSTA,UTXI
BS
INTCON,UTXIE
BS
CPUCON,GLINT
MOV
A,#0X55
MOV
UTX_NO,A
MOV
UARTTX,A
TX_loop:
SJMP
TX_loop
; Tx data 55
61
ePG3231
RISC II-2G Series Microcontroller
13
10
11
12
13
14
15
16
T SYSTEM /16
One bit cycle
RXD pin
Stop bit
Start bit
Bit 0
Sampling
Timing
8.6.10 UART Receive Operation (8-Bit Data with Parity and Stop Bit)
ST A R T
bit
RXD
pin
D0
D1
D2
Dn
Parity ST O P
bit
bit
ST A R T
bit
D0
D1
D2
Synchronization
Sam ple
T im ing
C lear by hardw are w hen
read data from U A R T R x
URBF
C lear by
softw are
URXI
PR E R R
OVERR
FM E R R
62
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === UART Receiver buffer full interrupt
PERIPH:
PUSH
JBC
INTSTA,URXI,UERRINT
BC
INTSTA,URXI
MOVPR
URX_NO,UARTRX
SJMP
Q_RXINT
;
; === UART error interrupt
UERRINT:
JBC
INTSTA,UERRI,Q_RXINT
BC
INTSTA,UERRI
; --- Framing error flag.
; --- Over run error flag.
; --- Parity error flag.
MOV
A,UARTSTA
AND
A,#00011100B
MOV
PORTH,A
BC
UARTSTA,FMERR
BC
UARTSTA,OVERR
BC
UARTSTA,PRERR
Q_RXINT:
POP
RETI
63
ePG3231
RISC II-2G Series Microcontroller
VREX
ADIN5
ADIN6
8-channel
ADIN7
MUX
ADIN8
&
Reference
Voltage generator
VRS
DET
10 bits SAR A/D
CHS2~0
S/DB
ADEN
ADOTH ~
ADOTL [1:0]
Fosc
Fper
FA/D
Clock
Factor
8
ADCF
FSS
VREX:
XN (Port C.7):
YN (Port C.6):
This A/D converter is an 8-channel 10 bit resolution. When the MCU is in Slow or Fast
mode and ADEN=1, the A/D conversion will run immediately. The two channels; XP
and YP with low on-resistance switches, are used for driving touch screen application.
The remaining 6 channels are for general application.
64
ePG3231
RISC II-2G Series Microcontroller
The A/D converter operation for touch panel application is as follows:
Step 1: Pen down detection
If the panel is not tapped, the PIRQB is high. When the touch panel is tapped,
the PIRQB is low and PIRQB interrupt occurs (if INT is enabled).
Step 2: Measure the X position
If the PIRQB remains low and steady for awhile, the DET bit is cleared, then
the PIRQB returns to high and the X position is measured.
Step 3: Measure the Y position
Y position is immediately measured after Step 2
Step 4: Back to Step 1
Bit 6
VRS
Bit 5
ADEN
Bit 4
PIRQB
Bit 3
S/DB
Bit 2
CHS2
Bit 1
CHS1
Bit 0
CHS0
Bit 2 ~ Bit 0 (CHS2 ~ CHS0): 2-channel touch screen & 6-channel A/D input selection
Bit 3 (S/DB): Reference mode control bit
0 : Differential reference mode
1 : Single-ended reference mode
Bit 4 (PIQRB): Touch screen status bit. It is a read bit
0 : touch screen is tapped
1 : touch screen is not tapped
Bit 5 (ADEN): A/D enable control bit. Automatically clears to 0 when ADIF occurs.
0 : A/D disabled
1 : A/D enabled
Bit 6 (VRS):
65
ePG3231
RISC II-2G Series Microcontroller
Bit 7 (DET):
ADEN
DET
CHS[2:0]
Vin
VRS
Mode
0
0
1
0
1
0
000
YP
1
1
1
Standby mode
Pen-down detection
Measure X position (Touch panel)
1
1
0
0
001
010
XP
ADIN3
1
0/1
011
ADIN4
0/1
Measure ADIN4
100
ADIN5
0/1
Measure ADIN5
101
ADIN6
0/1
Measure ADIN6
110
ADIN7
0/1
Measure ADIN7
111
ADIN8
0/1
Measure ADIN8
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
ADOT9
ADOT8
ADOT7
ADOT6
ADOT5
ADOT4
ADOT3
ADOT2
Bit 7 ~ Bit 0 (ADOT9 ~ ADOT2: 10-bit resolution A/D output data for Registers
ADOT9 ~ ADOT2
WDTEN
Bit 6
Bit 5
EXTMEM ADWKEN
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
FSS
ADOT1
ADOT0
Bit 1 ~ Bit 0 (ADOT1 ~ ADOT0): 10-bit resolution A/D output data for ADOT1 ~ ADOT0
Bit 2 (FSS):
66
ePG3231
RISC II-2G Series Microcontroller
FA / D =
FPLL
2( ADCF + 1)
ADCF=3
ADCF=7
ADCF=15
ADCF=31
ADCF=63
ADCF=95
ADCF=127
ADCF=159
ADCF=191
ADCF=223
ADCF=255
(PFS=61)
(PFS=122)
(PFS=150)
(PFS=183)
(PFS=214)
(PFS=255)
FA/D=254k
FA/D=127k
FA/D=63k
FA/D=31k
FA/D=15k
FA/D=11k
FA/D=10k
FA/D=6k
FA/D=5k
FA/D=4.5k
FA/D=3.9k
FA/D=499k
FA/D=250k
FA/D=125k
FA/D=62k
FA/D=31k
FA/D=21k
FA/D=21k
FA/D=12k
FA/D=10k
FA/D=8.9k
FA/D=7.8k
FA/D=999k
FA/D=499k
FA/D=250k
FA/D=125k
FA/D=62k
FA/D=42k
FA/D=31k
FA/D=25k
FA/D=21k
FA/D=17.8k
FA/D=15.6k
FA/D=1229k
FA/D=614k
FA/D=307k
FA/D=154k
FA/D=77k
FA/D=60k
FA/D=51k
FA/D=31k
FA/D=25k
FA/D=21.9k
FA/D=19.2k
FA/D=1499k
FA/D=749k
FA/D=374k
FA/D=187k
FA/D=93k
FA/D=73k
FA/D=62k
FA/D=37k
FA/D=31k
FA/D=26.8k
FA/D=23.4k
FA/D=1753k
FA/D=876k
FA/D=438k
FA/D=219k
FA/D=109k
FA/D=86k
FA/D=73k
FA/D=44k
FA/D=37k
FA/D=31.3k
FA/D=27.3k
FA/D=2089k
FA/D=1044k
FA/D=522k
FA/D=261k
FA/D=130k
FA/D=102k
FA/D=87k
FA/D=52k
FA/D=44k
FA/D=37.3k
FA/D=32.6k
NOTE
Any FA/D value greater than 1.4MHz is invalid.
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
Bit 0 (MS0):
Bit 1 (MS1):
High frequency enable (only effective when the MCU is in Idle or Slow
mode)
0 : Disable PLL
1 : Enable PLL
67
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIE
ADIE
URXIE
UTXIE
UERRIE
TMR2IE
TMR1IE
TMR0IE
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
CPIF
ADIF
URXI
UTXI
UERRI
TMR2I
TMR1I
TMR0I
CHS[2:0]
011
Tset2 Thld
ADEN
Clear to 0 automatically
Tcon
ADSTART
Tacq
FA/D
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
D9
ADIF
FAST mode
FA/D
FA/D
ADEN
ADEN
ADSTART
(Internal enableA/D signal)
SLOWmode
ADSTART
(Internal enableA/D signal)
Fig. 8-15 A/D Converter vs. MCU Mode Correlation
68
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; === A/D interrupt.
PERIPH:
PUSH
JBC
INTSTA,ADIF,Q_ADINT
BC
INTSTA,ADIF
BS
INTFLAG,F_IAD
Q_ADINT:
POP
RETI
; === Fpll=8MHz & ADCF=7 => FA/D=499kHz
AD_SR:
:
System setting 8MHz
Port H & G setting output port
:
; --- PLL enable
BS
CPUCON,PEN
; --- Clock source is PLL
BS
ADOTL,FSS
; --- FA/D=499kHz
MOV
A,#7
MOV
ADCF,A
; --- VRIN, Differential, ADIN3
MOV
A,#00000010B
MOV
ADCON,A
; --- AD interrupt enable
BS
INTCON,ADIE
BC
INTSTA,ADIF
BS
CPUCON,GLINT
69
ePG3231
RISC II-2G Series Microcontroller
A,#122
PFS,A
CPUCON,PEN
ADOTL,FSS
ADOTL,ADWKEN
A,#7
ADCF,A
A,#11000000B
ADCON,A
INTCON,ADIE
INTSTA, ADIF
CPUCON,GLINT
ADCON,DET
INTFLAG,F1ITP
ADCON,DET
PUSH STATUS
JBS
ADCON,PIRQB
=1
=0
JBS
INTFLAG,F1ITP
=0
BC ADCON,DET
BS INTFLAG,F_ITP
BC INTFALG,F1ITP
Touch pad OK
POP STATUS
=0
JBC
INTFLAG,F_ITP
=1
BC
INTFLAG,FITP
MOV
A,#3
AD Interrupt
PUSH STATUS
BC
BS
ADCON,CHS0
ADCON,ADEN
=1
JBC
INTSTA,ADIF
Check if AD Interrupt
occurs
=0
JBS ADCON,ADEN
>0
BC INTSTA,ADIF
=0
JDNZ
POP STATUS
ACC
=0
MOV
BS
BS
A,#3
ADCON,CHS0
ADCON,ADEN
=1
JBS ADCON,ADEN
>0
=0
JDNZ
ACC
=0
BS
ADCON,DET
70
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; *** Touch Panel Interrupt
INPTINT:
PUSH
JBS
ADCON,PIRQB,Q_TPINT
JBS
INTFLAG,F1ITP,TPINT1
BC
ADCON,DET
BS
INTFLAG,F_ITP
TPINT1:
BC
INTFLAG,F1ITP
Q_TPINT:
POP
RETI
; === A/D Interrupt
PERIPH:
PUSH
JBC
INTSTA,ADIF,Q_ADINT
BC
INTSTA,ADIF
Q_ADINT:
POP
RETI
; === Touch panel routine
TP_SR:
:
System setting 8MHz
Port H & G setting output port
:
BS
CPUCON,PEN
BS
ADOTL,FSS
BS
ADOTL,ADWKEN
MOV
A,#7
MOV
ADCF,A
MOV
A,#11000000B
MOV
ADCON,A
BS
INTCON,ADIE
BC
INTSTA,ADIF
BS
CPUCON,GLINT
; PLL enable
; Clock source is PLL
; AD wakeup
; FA/D=499kHz
; VREX, Differential
; AD interrupt enable
TPILoop:
BC
BS
BS
ADCON,DET
INTFLAG,F1ITP
ADCON,DET
TPILp1:
JBC
INTFLAG,F_ITP,TPILp1
BC
INTFLAG,F_ITP
; --- Repeat YP detect A/D 3 times
MOV
A,#3
YP3times:
BS
ADCON,CHS0
BS
ADCON,ADEN
WaitYAD:
JBS
ADCON,ADEN,WaitYAD
JDNZ
ACC,YP3times
MOVRP
PORTG,ADOTH
; --- Repeat XP detect A/D 3 times
MOV
A,#3
XP3times:
BC
ADCON,CHS0
BS
ADCON,ADEN
WaitXAD:
JBS
ADCON,ADEN,WaitXAD
JDNZ
ACC,XP3times
MOVRP
PORTH,ADOTH
BS
ADCON,DET
:
SJMP
TPILoop
; YP detection
; AD enable
; XP detection
; AD enable
71
ePG3231
RISC II-2G Series Microcontroller
Port J~K
16
ePG3231
Port A.0~A.7
Keyboard
Port A.0 ~ Port A.7 are input ports with controllable pull up resistor.
VDD
/REN
Port J ~ Port K
(Key strobe)
KON Resistance
VOL
RON
VIN
Port A.0~.7
(Key input)
72
ePG3231
RISC II-2G Series Microcontroller
Port J ~ Port K are designed for 16-bit key strobe or general I/O. When the STBCON
register is set to BitST bit, Ports J and K become key strobe pin. The 16 to 1 Port J
and Port K multiplex are selected by STB3 ~ STB0 bits of the STBCON register. Only
the selected pin will output low and the other 15 pins will remain high. Likewise, when
the STBCON register is set to ALL bit, all strobe pins will output low.
The detailed function is summarized in the following table:
STBCON
BitS ALL STB3~0 PJ.0 PJ.1 PJ.2 PJ.3 PJ.4 PJ.5 PJ.6 PJ.7 PK.0 PK.1 PK.2 PK.3 PK.4 PK.5 PK.6 PK.7
0
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PA7
PA6
PA5
PA4
PA3
PA2
PA1
PA0
Bit 7 ~ Bit 0: Input key. Input falling edges interrupt or wake up pin.
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PA7IE
PA6IE
PA5IE
PA4IE
PA3IE
PA2IE
PA1IE
PA0IE
73
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PA7I
PA6I
PA5I
PA4I
PA3I
PA2I
PA1I
PA0I
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
WKEN7
WKEN6
WKEN5
WKEN4
WKEN3
WKEN2
WKEN1
WKEN0
Bit 7
UINVEN
Bit 6
/REN
Bit 5
BitST
Bit 4
ALL
Bit 3
STB3
Bit 2
STB2
Bit 1
STB1
Bit 0
STB0
DCRJK (R39h): Port J & Port K Direction and Pull-up Resistor Control
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
KHNPU
KLNPU
KHNDC
KLNDC
JHNPU
JLNPU
JHNDC
JLNDC
Bit 1, Bit 5 (JHNDC, KHNDC) & Bit 0, Bit 4 (JLNDC, KLNDC): Ports J & K high/low
nibbles direction control
0 : Set to output pin
1 : Set to input pin
Bit 3, Bit 7 (JHNPU, KHNPU) & Bit 2, Bit 6 (JLNPU, KLNPU): Enable Ports J & K
high/low nibbles pull-up resistor
0 : Disable pull-up resistor
1 : Enable pull-up resistor
74
ePG3231
RISC II-2G Series Microcontroller
Code Example:
; Key matrix 1 (Port A and Ground):
; *** Interrupt Port A data
INPTINT:
PUSH
MOVRP
PORTH,PAINTSTA
CLR
PAINTSTA
POP
RETI
; === Sleep mode
PAIN_SR:
:
; --- Port A wakeup
MOV
A,#11111111B
MOV
PAWAKE,A
:
:
; --- /REN Pull-up enable
BC
; --- Port A interrupt enable
MOV
MOV
CLR
BS
; --- Sleep MODE
BC
PAINloop:
SLEP
NOP
:
SJMP
STBCON,REN
A,#11111111B
PAINTEN,A
PAINTSTA
CPUCON,GLINT
CPUCON,MS1
PAINloop
; Key_No:XXXX 0000
; Bit strobe disable
; Key_No:0XXX XXXX
75
ePG3231
RISC II-2G Series Microcontroller
EXMA [21:16]
EXMA [15:8]
External
Memory
EXMA [7:0]
EXMD [7:0]
EXMD [15:8]
Port D [5:0]
Port E
Port F
EPG3231
Port G
Port H
Port D [6]
WEB
Port D.5~0, Port E and Port F are designed for external memory address bus, while
Port G and Port H are for external memory data bus. Set the EMPE bit of POST_ID
register to 1 to enable the external memory address post increase or post decrease
function. Then set up the EM_ID bit of POST_ID register to determine whether post
increase or post decrease. After reading data from Port G (low byte) register, the Port
D [5:0]: Port E: Port F registers will auto increase or decrease. This function can
achieve sequential memory access without changing the address data. A negative
pulse will be generated from Port D.6 (WEB pin) when writing to Port G register (refer to
WEB signal timing). This signal can be used as WEB for external memory.
WDTEN
Bit 6
Bit 5
EXTMEM ADWKEN
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
FSS
ADOT1
ADOT0
Bit 6
EM_ID
Bit 5
Bit 4
Bit 3
FSR1_ID
FSR0_ID
EMPE
Bit 2
Bit 1
Bit 0
FSR1PE
FSR0PE
Bit 7 (EM_ID):
Setting this bit means auto increase Port F: Port E: Port D [6:0]
registers, resetting this bit means auto decrease.
Bit 3 (EMPE):
76
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
WEN
SRBFIE
SRBFI
SPWKEN
SMP
DCOL
RBF
Bit 7 (WEN): Enable Port D.6 as external memory data output WEB signal.
(Refer to the timing diagram)
0 : Disable
1 : Enable
(WEB signal output is only available when writing to Port G register).
Port D (R1Ah): Bit 5 ~ Bit 0 (D.5~D.0): High byte of external memory address bus
DCRDE (R36h): Direction Control & Pull-up resistor Control of Port D & Port E
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
EHNPU
ELNPU
EHNDC
ELNDC
DHNPU
DLNPU
DHNDC
DLNDC
Bit 1, Bit 5 (DHNDC, EHNDC) & Bit 0, Bit 4 (DLNDC, ELNDC): Ports D & E high / low
nibbles direction control
0 : Set to output pin
1 : Set to input pin
Bit 3, Bit 7 (DHNPU, EHNPU) & Bit 2, Bit 6 (DLNPU, ELNPU): Enable Ports D & E
high / low nibble pull-up resistor
0 : Disable pull-up resistor
1 : Enable pull-up resistor
PORTF (R1Ch): Low byte of the external memory address bus. Port F has ability to
carry into/borrow from Port E register
PORTG (R1Dh): Low byte register of the external memory data bus
DCRFG (R37h): Direction control & Pull up resistor control of Ports F & Port G
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
GHNPU
GLNPU
GHNDC
GLNDC
FHNPU
FLNPU
FHNDC
FLNDC
Bit 1, Bit 5 (FHNDC, GHNDC) & Bit 0, Bit 4 (FLNDC, GLNDC): Ports F & G high / low
nibbles direction control.
0 : Set to output pin
1 : Set to input pin
77
ePG3231
RISC II-2G Series Microcontroller
Bit 3, Bit 7 (FHNPU, GHNPU) & Bit 2, Bit 6 (FLNPU, GLNPU): Enable Ports F & G
high / low nibble pull-up resistor
0 : Disable pull-up resistor
1 : Enable pull-up resistor
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
IHNPU
ILNPU
IHNDC
ILNDC
HHNPU
HLNPU
HHNDC
HLNDC
Bit 1 & Bit 0 (HHNDC & HLNDC): Port H high & low nibbles direction control
0 : Set to output pin
1 : Set to input pin
Bit 3 & Bit 2 (HHNPU & HLNPU): Enable Port H high & low nibbles pull up resistor
0 : Disable pull-up resistor
1 : Enable pull-up resistor
Address
0Fh:FFh:FFh
Address
10h:00h:00h
Address10h:
00h:01h
Data7:0
(PortG)
Instruction
..
MOV CC,PORTG
..
78
ePG3231
RISC II-2G Series Microcontroller
EMPE=1 (enable post increase/decrease function), EM_ID=0 (set to address auto decrease)
Address auto
decrease by 1
after reading data
from Port G
Address 21:0
Address 10h:00h:00h
(PortD:PortE
Address 0Fh:FFh:FFh
Address 0Fh:
FFh:FEh
PortF)
Data7:0
(PortG)
..
Instruction
MOV CC,PORTG
..
Instruction
..
REG01=01h (*1)
MOVRP PORTG,A
MOV A,PORTG
(*2)
REG06=06h (*1)
06h
01h
Port G
(Data7~0)
..
MOVRP PORTG,A
WEB
(Port D.6)
Twpl
Twph
79
ePG3231
RISC II-2G Series Microcontroller
(PortD[5:0]:PortE
:PortF)
Address 0Fh:FFh:FFh
Address 10h:00h:00h
Data15:8
(PortH)
Data7:0
(PortG)
Instruction
..
MOV CC,PORTH
MOV CC,PORTG
MOV CC,PORTH
..
Address 21:0
(PortD[5:0]:PortE
:PortF)
Address 0Fh:FFh:FFh
Address 10h:00h:00h
Data15:8
(PortH)
Data7:0
(PortG)
Instruction
..
MOV ACC,PORTH
MOV ACC,PORTG
MOV ACC,PORTH
..
80
ePG3231
RISC II-2G Series Microcontroller
MOV A,PORTH
Instruction
(*2)
R01= 01h
MOV A,PORTG
MOVRP PORTH,R01
(*2)
MOVRP PORTH,R06
..
01h
Port H
(data15~8)
Port G
06h
(data7~0)
WEB
(Port D.6)
Twpl
Twph
Code Example:
INCLUDE
"ExDATA.hdr"
;***External memory control
;--- Address D:E:F & Data output G:H
CLR
DCRDE
CLR
DCRFG
CLR
DCRHI
;---External memory enable auto INC. & WEN signal
BS
POST_ID,EM_ID
BS
POST_ID,EMPE
BS
SPISTA,WEN
;---RAM enable auto INC.
BS
POST_ID,FSR1_ID
BS
POST_ID,FSR1PE
;---Bank 1 address 80
MOV
A,#1
MOV
BSR1,A
CLR
FSR1
;---Address 10000
CLR
PORTF
CLR
PORTE
MOV
A,#11000001B
MOV
PORTD,A
;---Memory IC CE active
BC
PORTD,CE
;---Bank 1 address 80 ~ 9Fh data out to 10000 ~ 1000Fh
MOV
A,#16
DataOut:
MOVPR
PORTH,INDF1
MOVPR
PORTG,INDF1
JDNZ
ACC,DataOut
;---Memory IC CE pin disable
BS
PORTD,CE
:
:
81
ePG3231
RISC II-2G Series Microcontroller
SDO
SDI
/ SS
Master Device
Slave Device
SDI
SDO
SCK
SCK
Bit 0
Bit 23
SPI module
Bit 0
Bit 23
SDO
SDI
SCK
/ SS
EPD3330
Master
PB.7
PB.6
PB.5
PB.4
/SS SDO
SCK
SDI
Slave Device 1
/SS SDO
SCK
SDI
Slave Device 2
/SS SDO
SCK
SDI
Slave Device 3
/SS SDO
SCK
SDI
Slave Device 4
82
ePG3231
RISC II-2G Series Microcontroller
The MCU communicates with other devices through an SPI module. If the MCU is
defined as the master controller, it sends clock through the SCK pin. An 8-bit data is
transmitted and received at the same time. If the MCU, however, is defined as a slave,
its SCK pin could be programmed as an input pin. Data will continue to be shifted at
selected clock rate and selected edge.
Setup the TLS1 ~ TLS0 bits of SPICON register to select the shift register length of
SPI and enable/disable SPI function.
Setup the BRS2 ~ BRS0 bit of SPICON register to select the SPI mode
(master/slave) and Bit Rate. When in Master mode, the clock source can be
selected from system clock or half of timer 0 interval. When in Slave mode, the /SS
pin can be enabled or disabled.
Setup the DORD bit of SPICON register to determine the shift direction.
Setup the EDS bit of SPICON register to select the raising edge or falling edge
latch of the data.
Setup the SMP bit of SPISTA register to select the sample phase at the middle or
the end of the data output time.
SDO (O):
Serial Data Output pin. Transmit data serially. Under Slave mode, defined
as high-impedance, if not selected.
SCK (I/O): Serial Clock input/output pin. When in Master mode, sends clock through
the SCK pin. However, under Slave mode, SCK pin is programmed as an
input pin).
/SS (I):
/Slave Select pin. This pin becomes active when /SS function is enabled.
(BRS=110), else /SS pin is a general purpose I/O.
Master device remains low to /SS pin to signify the slave(s) for
transmit/receive data. Ignore the data on the SDI and SDO pins when /SS
pin is high, because the SDO is no longer driven.
83
ePG3231
RISC II-2G Series Microcontroller
Receiver is active during SPI transfer. When the receive buffer is full, RBF flag is set
and interrupt occurs (if enable). During read out of the shift register content, it is only
after SPRL register has been read out that the hardware will automatically clear the
RBF flag. If SPRL register has not been read out, RBF bit will remain set and data
collision will take place at the next clock in.
SPRH; SPRM; SPRL (R41h; R42h; R43h): SPI shift buffer for 24/16/8 bits length
respectively.
The buffer will deny any write attempt until shifting is completed. If a 24-bit shift buffer
is selected, it will include the SPRH, SPRM, and SPRL registers. Else, if 8-bit shift
buffer is selected, only the SPRL register is included.
When writing data into SPRL register, the SE bit of SPICON register is set by hardware
and shifting starts. When the shift buffer becomes empty and the receive buffer is full at
the same time, the received data is shifted into SPRH, SPRM,and SPRL registers.
After SPRL register is read out, hardware will automatically clear the RBF flag.
84
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TLS1
TLS0
BRS2
BRS1
BRS0
EDS
DORD
SE
Bit 0 (SE):
Shift enable. Set to 1 automatically when writing data into the SPRL
register and shifting starts. Reset to 0 when a transfer buffer empty is
detected.
NOTE
The SE bit is read-only and is cleared by hardware when SPI is enabled.
Therefore, writing to the SPRL register is necessary when you want to
start shifting the data.
Bit Rate
001
010
011
100
101
(FPLL/2) /4
(FPLL/2) /16
(FPLL/2) /64
(FPLL/2) /256
(FPLL/2) /1024
FPLL / 2
16MHz
10MHz
4MHz
4000000
1000000
250000
62500
15625
2500000
625000
156250
39063
9766
1000000
250000
62500
15625
3096
32.768kHz
8196
2048
512
128
32
Bit 7 ~ Bit 6 (TLS1 ~ TLS0): Shift buffer length select. Shift buffer length is
programmable as follows:
00 : SPI disable
01 : Enable SPI and shift buffer length = 24 bits
10 : Enable SPI and shift buffer length = 16 bits
11 : Enable SPI and shift buffer length = 8 bits
85
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
WEN
SRBFIE
SRBFI
SPWKEN
SMP
DCOL
RBF
Bit 0 (RBF):
Bit 1 (DCOL):
Bit 2 (SMP):
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
Bit 2 (GLINT):
86
ePG3231
RISC II-2G Series Microcontroller
SCK
(EDS=0)
SCK
(EDS=1)
SDO
(DORD=0)
SDO
(DORD=1)
SDI
(DORD=0
SMP=0)
Data Sample
(SMP=0)
SDI
(DORD=1
SMP=1)
Data Sample
(SMP=1)
Bit23 Bit22
Bit3
Bit0
Bit0
Bit3
Bit23 Bit22
Bit1
Bit23 Bit22
Bit0
Bit1
Bit2
Bit2
Bit1
Bit1
Bit0
Bit23 Bit22
Bit0
Bit0
Cleared when
reading data
from the
SPRL register
RBF
Bit1
SE
Bit1
Set when
writing data to
SPRL register
87
ePG3231
RISC II-2G Series Microcontroller
SCK
(EDS=0)
SCK
(EDS=1)
SDO
(DORD=0)
SDO
(DORD=1)
SDI
(DORD=0
SMP=0)
Data Sample
(SMP=0)
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit7
Bit0
Bit1
Bit2
Bit3
Bit4
Bit5
Bit6
Bit7
Bit0
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit7
SDO remains
at high
impedance
when /SS=1
Bit6
Bit5
Cleared when
read data from
SPRL register
RBF
Set when
writing data to
SPRL register
SE
Data
Collision
DCOL
/SS
88
ePG3231
RISC II-2G Series Microcontroller
89
ePG3231
RISC II-2G Series Microcontroller
Melody Channel 2
Melody Channel 3
Melody/Speech
Channel 4
R44h
000
001
010
011 / 1
R45h
ADDL
ADDL
ADDL
ADDL / -
R46h
ADDM
ADDM
ADDM
ADDM / -
R47h
ADDH
ADDH
ADDH
ADDH / -
R48h
ENV
ENV
ENV
ENV / SPHDR
R49h
MTCON
MTCON
MTCON
MTCON / SPHTCON
R4Ah
MTRL
MTRL
MTRL
MTRL / SRHTRL
Bit 6
Bit 5
AGMD2
AGMD1
AGMD0
Bit 4
Bit 3
WDTPSR1 WDTPSR0
Bit 2
Bit 1
Bit 0
SPHSB
CSB1
CSB0
90
SFCR[2:0]
Channel Selection
000
Melody Channel 1
Bank 0
001
Melody Channel 2
Bank 1
010
Melody Channel 3
Bank 2
011
Melody Channel 4
Bank 3
Speech Channel
Bank 3
ePG3231
RISC II-2G Series Microcontroller
Interrupt _ rate =
FPer MTPSR
MTRL[10 : 0] + 1
These registers, i.e., ADDL, ADDM, and ADDH are treated as instrument waveform
address. Each melody channel has its own waveform data address pointer that points
to the waveform start address in the data ROM. The address values are written by the
program and its total length is 24 bits.
The envelope register stores the envelope value for the current melody channel. The
users program should calculate the proper envelope value to obtain a suitable ADSR
(Attack-Decay-Sustain-Release) for different instruments. The tone generator will
process the waveform data with the envelope automatically and then synthesize the
final instrument melody to the mixer of the PWM and D/A converter.
The data written to the envelope register should be a 7-bit unsigned value and located
in Bits 0~6 (the corresponding envelope value must be 0 to 127), which means the
envelope resolution is of 128 steps. The reset initial value is 0.
91
ePG3231
RISC II-2G Series Microcontroller
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
MTRL7
MTRL6
MTRL5
MTRL4
MTRL3
MTRL2
MTRL1
MTRL0
Melody timer is the 11-bit down counter for melody applications. The frequency
generated by the melody timer is determined by the value of the 11-bit melody timer
auto-reload register (including MTRL and MTRLH0~2 of MTCON). When the counter
value underflows, the timer will auto-reload. To obtain the correct frequency, consult
the following frequency reference table and fetch the correct value for MTRL and
MTRLH0~2 of MTCON.
Pitch
A2
A#2
B2
C3
C#3
D3
D#3
E3
F3
F#3
G3
G#3
A3
A#3
B3
C4
C#4
Index No.
0X00
0X01
0X02
0X03
0X04
0X05
0X06
0X07
0X08
0X09
0X0A
0X0B
0X0C
0X0D
0X0E
0X0F
0X10
Pitch
D4
D#4
E4
F4
F#4
G4
G#4
A4
A#4
B4
C5
C#5
D5
D#5
E5
F5
F#5
Index No.
0X11
0X12
0X13
0X14
0X15
0X16
0X17
0X18
0X19
0X1A
0X1B
0X1C
0X1D
0X1E
0X1F
0X20
0X21
Pitch
G5
G#5
A5
A#5
B5
C6
C#6
D6
D#6
E6
F6
F#6
G6
G#6
A6
A#6
Index No.
0X22
0X23
0X24
0X25
0X26
0X27
0X28
0X29
0X2A
0X2B
0X2C
0X2D
0X2E
0X2F
0X30
0X31
The MTCON is used to determine the three MSBs of the 11-bit auto-reload register
and to enable/disable the melody timer of the current melody channel. Once the
melody timer is enabled, it will fetch the waveform data (pointed to by the address
registers) from data ROM, process the data with the envelope, and then feed the data
to the DAC or PWM mixer automatically.
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
MTIE
MTPSR1
MTPSR0
MTI
MTEN MTRLH2 MTRLH1 MTRLH0
(Mode2 only) (Mode2 only) (Mode2 only) (Mode2 only)
92
MTEN
ePG3231
RISC II-2G Series Microcontroller
Bit 5 (MTI): Melody timer interrupt flag. Set to 1 when a melody timer interrupt
occurs. Clear to 0 by software or disable melody timers (Mode2 only).
Bit 7 ~ 6 (MTPSR1 ~ MTPSR0): Melody timer prescaler control bits (Mode2 only).
MTPSR1: MTPSR0
Prescaler Value
00
01
10
11
1:1
1:4
1:16
1:64
Interrupt _ rate =
FPer SPHTPSR
SPHTRL[10 : 0] + 1
In speech function control, SPHDR acts as an output window to the PWM and D/A
converter mixer. The program should write the synthesized data to SPHDR, and the
data is fed into the mixer at the next speech timer underflow. For correct mixing
operation, the value to be written to SPHDR must be an 8-bit signed data. The reset
initial value is 0.
The Speech timer is an 11-bit down counter for speech applications. The frequency
generated by the speech timer is determined by the value of the 11-bit auto-reload
register, including SPHTRL and SPHTRLH0 ~ SPHTRLH2 of SPHTCON. When the
counter value underflows, timer interrupt will occur and auto-reloads from the 11-bit
auto-reload register.
SPHTCON is used to determine the three MSB of the 11-bit auto-reload register and
enable/disable speech timer.
Bit 7
Bit 6
SPHTPSR1 SPHTPSR0
(Mode2 only) (Mode2 only)
Bit 5
Bit 4
SPHTI
SPHTIE
Bit 3
Bit 2
Bit 1
Bit 0
93
ePG3231
RISC II-2G Series Microcontroller
Bits 4 ~ 3 (SPHTIE, PSHTEN): Speech timer enable control bits
SPHTIE SPHTEN
Bit 5 (SPHTI): Speech timer interrupt flag. Set to 1 when the speech timers interrupt
occurred. Clear (0) by software or speech timers disabled.
Bits 7 ~ 6 (SPHTPSR1 ~ SPHTPSR0): Speech timer prescaler control bits (Mode 2
only)
SPHTPSR1: SPHTPSR0
Prescaler Value
00
1:2
01
1:8
10
1:32
11
1:128
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
PEN
SMCAND
SMIER
GLINT
MS1
MS0
T period =
94
128
1
Pr escaler; Tduty =
Pr escaler (PWD + 1)
FPer
FPer
ePG3231
RISC II-2G Series Microcontroller
VO EN PW M PSR
Code O ption
DAO /VO 1
Mixer
PW M
PW M or
DAC
Selection
VO 2
Mixer
DAC
PWM or
DAC
Selection
4 ~ 8 ohm
DAO/VO1
8050
680 ~1K5
If both SPHSB and VOEN bits are set to 1 and SPHTEN bit is cleared (0), the data of
speech data register will be output immediately through D/A converter or PWM when
the register changes.
95
ePG3231
RISC II-2G Series Microcontroller
560
C2
1.5K
0.1uF
R3
VREX
R2
C1
2.2K
1uF
C4
100K
0.1uF
C3
10nF
VSS
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
VOEN
DAC
SETR1
SETR0
PWMPSR
VOL2
VOL1
VOL0
Volume
000
001
010
011
100
101
110
111
1 (min.)
2
3
4
5
6
7
8 (max.)
96
ePG3231
RISC II-2G Series Microcontroller
Bit 5 ~ 4 (SETR1 ~ SETR0): Set dynamic range
While mixing, the mixer accumulation result may have a large dynamic
range (up to 11-bit), while DAC has only 9-bit resolution and PWM has
only 8-bit. You can define a suitable output data range to prevent the
saturation condition from occurring.
SETR1~SETR0
10
01
00 or 11
Bit 6 (DAC): D/A converter output control bit (for Code option Current D/A converter
reference source)
0 : D/A converter output control is by melody timer or speech timer
1 : D/A output control is through SPHDR register
Bit 7 (VOEN): Voice output control bit
0 : DAC/PWM disabled
1 : DAC/PWM enabled
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
DET
VRS
ADEN
PIRQB
S/DB
CHS2
CHS1
CHS0
Bit 6 (VRS): A/D input reference voltage select and enable/disable internal reference
generator bit
1 : Disable internal reference generator and the reference voltage is
sourced from external VREX pin
0 : Enable internal reference generator and the reference voltage is
sourced from internal reference voltage generator
Code Example:
Refer to the Melody & Speech Application Note (available upon request).
97
ePG3231
RISC II-2G Series Microcontroller
Electrical Characteristics
Absolute Maximum Ratings
Items
Sym.
Supply voltage
Input voltage (general input port)
Power Dissipation (Topr=70C)
Soldering Temperature (time)
Operating temperature range
Storage temperature range
Condition
Limits
Unit
-0.3 to +3.6
-0.5 to VDD +0.5
400
350 (3sec)
-10 to +70
-55 to +125
VDD
VIN
PD
Tsld
Topr
Tstr
V
V
mW
o
Sym.
Condition
Limits
VDD
Supply voltage
AVDD
VIH
Input voltage
VIL
ADRG
Topr
Unit
2.2 to 3.6
2.4 to 3.6
VDD x 0.9 to VDD
0 to VDD x 0.1
0 to VREX
-10 to +70
V
V
V
V
o
Sym.
Fmain
CLOCK
Fsub
Idd1
Idd2
Idd3
Supply Current
Idd4
Condition
Main-clock frequency
Sub-clock frequency
SLEEP mode
IDLE mode
SLOW mode
Idd5
Idd6
Input Voltage
FAST mode
MHz
16
41
Crystal OSC
32.768
VDD=3V, no load
VDD=3V RC OSC
12
20
30
900
1200
2000
3000
3000
4000
VDD0.7
VDD
VDD0.3
0.5VDD
0.75VDD
0.2VDD
0.4VDD
VT-
Unit
32.8
VIL1
VT+
Max
Voltage (Schmitt)
Typ
24.6
RC OSC
VIH1
Input Threshold
98
Min
kHz
V
V
ePG3231
RISC II-2G Series Microcontroller
Parameter
Sym.
Output Current
IOH1
IOL1
IOH2
IOH3
IOL3
output port)
PB[1] (as D/A output)
PB[1:0] (as PWM output)
Typ
Max
-1.1
-2.2
-3.3
VDD=3V, VOL=0.2V
+1.1
+2.2
+3.3
VDD=3.0V, VOH=0.7V
-2.5
-3.5
-4.5
VDD=3.0V, VOH=2.5V
-70
-100
-150
+150
Unit
mA
VDD=3.0V, VOL=0.5V
+70
+100
VDD=3.0V, VOH=1.0V
-3
-6
-9
IOL4
output)
VDD=3.0V, VOL=0.5V
+1.5
+3
+4.5
VDD=3.0V, VOH=2.4V
-5
-10
-15
VDD=3.0V, VOL=0.2V
+0.5
+1
+1.5
mA
IOL5
IOH6
IOL6
IOH7
IOL7
Current
Min
VDD=3V, VOH=2.4V
IOH4
IOH5
Input Leakage
Condition
PB[0:7], PC[0:7], PI[7:4],
IIL
VDD=3.0V, VOH=2.6V
-1.1
-2.2
-3.3
mA
VDD=3.0V, VOL=0.4V
+1.1
+2.2
+3.3
mA
VDD=3.0V, VOH=2.1V
-5
-10
-15
mA
VDD=3.0V, VOL=0.9V
+5
+10
+15
mA
Large Pull-Up
RPU1 PA[7:0]~PK[7:0]
Vin=GND
500
1000
1500
Resistance
RPU2 RSTB
Vin=GND
250
500
750
Small Pull-Up
RPU3 PA[7:0]~PK[7:0]
Vin=2V
50
100
200
Resistance
RPU4 RSTB
Vin=2V
50
100
200
RPD1 TEST
Vin=VDD
250
500
750
RPD2 TEST
Vin=1V
1.0
2.5
4.0
Vin=VDD
25
50
100
Vret
1.6
Vpor
1.4
1.5
1.6
0.1
10
Bits
INL
-2
+2
LSB
DNL
-2
+2
LSB
Offset Error
OErr
-4
+4
LSB
Gain Error
GErr
-4
+4
LSB
Large Pull-Down
Resistance
Small Pull-Down
Resistance
K
K
Touch Panel
Pull- Down
Resistance
Data Retention
Voltage
Power-on Reset
Voltage
Imux
System Performance
Resolution
Integral
Nonlinearity
Differential
Nonlinearity
No Missing Code
No missing
MC
bit
code
AVDD Supply
Ivdd3
0.5
0.7
Current
Ivdd4
ADEN = 0, VRS = 1
mA
uA
Driver Current
IOH
-20
-30
-45
mA
Sink Current
IOL
+20
+30
+45
mA
99
ePG3231
RISC II-2G Series Microcontroller
Parameter
Sym.
Condition
Min
Typ
Max
Unit
Reference Voltage
Internal
VRIN
1.8
2.0
2.2
Ivrin
400
500
VREX Input
Iref1
ADEN = 1, VRS = 1
300
500
Current
Iref2
ADEN = 0, VRS = 1
Min
Typ
Max
Unit
2*
0.5*
0.34*
37
43
40
46
80
60
-
51
54
Reference Voltage
Internal
Reference Supply
Current
Sym.
Condition
Fmain=1MHz
Fmain=4MHz
Fmain=16MHz
A/D Conversion (VDD=3.0V, AVDD=3.0V, Ta=-10~+70C)
Throughput
THP1
VDD=3.0V, AVDD=3.0V
Rate
THP2
VDD=2.4V, AVDD=2.4V
Power Supply PSRR1+
Rejection Ratio PSRR1
Signal to Noise
SNR
Ratio
Instruction
Cycle Time
Tcycle
ksps
dB
dB
100
ePG3231
RISC II-2G Series Microcontroller
VDD
TEST
RESET_KEY
VDD
VDD
PORT
All Input Port
(with P.U. resistor)
PORT
OB
DATA BUS
DL
PDWR
CK
0
1
PDRD
DB
101
ePG3231
RISC II-2G Series Microcontroller
11 Application Circuit
Keyboard
128 keys
LCM
CLK
/CS
SDI
SCK
SDO
max.
/RST
16
FLASH
CLKO
C.3
C.2
C.0
I.1
I.0
PortJ
8
PortA
OEB
D.7
C.5
XP
WEB
D.6
C.7
XN
D.5~D.0
C.4
YP
C.6
YN
A.21~A.16
~PortK
A.15~A.0
PortE~PortF
D15~D0
PortG~PortH
Reset
RSTB
RS-232C
Driver
RXD
B.6
TXD
B.7
B.0
EPG3231
B.1
CPIN
Speaker
Vdd
I.3
B.2(IROT)
IR
Transceiver
Touch
Screen
I.2~I.1
B.5
Reserved
PLLC
OSCI
OSCO
B.4
B.3
Reserved
I.7
I.6
SDO SDI
I.5
I.4
SCK
/SS
Slave Device
102
ePG3231
RISC II-2G Series Microcontroller
12 Instruction Set:
Legend: addr: address
b: bit
Type
Instruction Binary
Mnemonic
System
NOP
No operation.
Operation
None
Status Affected
Control
WDTC
None
SLEP
None
Cycle
RPT r
None
BANK #k
BSR k.
None
Rom Table
TBPTL #k
TABPTRL k.
None
Look Up
TBPTM #k
TABPTRM k.
None
TBPTH #k
TABPTRH k.
None
TBRD i,r
None
TBRD A,r
rROM[(TABPTR+ACC)]. (*3)
None
Data
CLR r
r 0.
Transfer
MOV A,#k
A k.
None
MOV A,r
A r.
MOV r,A
r A.
None
MOVRP p,r
Register p Register r.
None
MOVPR r,p
Register r Register p.
None
Exchange
SWAP r
r(0:3)r(4:7)
None
SWAPA r
r(0:3)A(4:7);r(4:7)A(0:3)
None
Bit
BC r,b
r(b) 0
None
Manipulation
BS r,b
r(b) 1
None
BTG r,b
r(b) /r(b)
None
Arithmetic
INCA r
A r+1.
C,Z
Operation
INC r
r r+1
C,Z
ADD A,r
A A+r
C,DC,Z,OV,SGE,SLE
ADD r,A
r r+A (*4)
C,DC,Z,OV,SGE,SLE
ADD A,#k
A A+k
C,DC,Z,OV,SGE,SLE
ADC A,r
A A+r+C
C,DC,Z,OV,SGE,SLE
ADC r,A
r r+A+C
C,DC,Z,OV,SGE,SLE
ADC A,#k
A A+k+C
C,DC,Z,OV,SGE,SLE
DECA r
A r-1
C,Z
DEC r
r r-1
C,Z
SUB A,r
A r-A (*5)
C,DC,Z,OV,SGE,SLE
SUB r,A
r r-A (*5)
C,DC,Z,OV,SGE,SLE
SUB A,#k
A k-A (*5)
C,DC,Z,OV,SGE,SLE
SUBB A,r
A r-A-/C (*5)
C,DC,Z,OV,SGE,SLE
SUBB r,A
r r-A-/C (*5)
C,DC,Z,OV,SGE,SLE
SUBB A,#k
A k-A-/C (*5)
C,DC,Z,OV,SGE,SLE
103
ePG3231
RISC II-2G Series Microcontroller
Type
Arithmetic
Operation
(cont)
Logic
Operation
Rotate
Shift
Instruction Binary
Mnemonic
MUL A,r
PRODH:PRODL A*r
None
MUL A,#k
PRODH:PRODL A*k
None
ADDDC A,r
C,DC,Z
ADDDC r,A
C,DC,Z
SUBDB A,r
C,DC,Z
SUBDB r,A
C,DC,Z
OR A,r
A A .or. r.
OR r,A
r r .or. A.
OR A,#k
A A .or. k.
AND A,r
A A .and. r.
AND r,A
r r .and. A.
AND A,#k
A A .and. k.
XOR A,r
A A .xor. r.
XOR r,A
r r .xor. A.
XOR A,#k
A A .xor. k.
COMA r
A /r.
COM r
r /r.
RRCA r
RRC r
RLCA r
RLC r
SHRA r
A(n-1)r(n); A(7)C
None
SHLA r
A(n+1)r(n); A(0)C
None
None
None
None
None
None
None
None
None
None
& Jump
Jump
104
Cycle
Compare &
Status Affected
Bit Compare
Compare
Operation
JBC r,b,addr
JBS r,b,addr
TEST r
If r(b)=0,jump to addr;
PC[15:0] addr. (*6)
If r(b)=1,jump to addr;
PC[15:0] addr. (*6)
Z 0 if r<>0;Z 1 if r=0.
A r-1, jump to addr if not
JDNZ A,r,addr
zero;
PC [15:0] addr. (*6) (*7)
JDNZ r,addr
JINZ A,r,addr
zero;
PC[15:0] addr. (*6) (*7)
JINZ r,addr
JGE A,#k,addr
JLE A,#k,addr
JE A,#k,addr
ePG3231
RISC II-2G Series Microcontroller
Instruction Binary
Mnemonic
Compare &
Type
JGE A,r,addr
Jump
(cont)
JLE A,r,addr
Cycles
None
None
Status Affected
Operation
Jump to addr if Ar;
None
PC addr;
None
PC [13..16] unchanged.
Subroutine
LJMP addr
(2 words)
S0CALL addr
PC addr.
None
None
PC [11:0] addr;
2
2
2
1
2
SCALL addr
None
PC [12:0] addr;
PC [13:16] unchanged.
0000 0000 0011 aaaa
LCALL addr
(2 words)
PC addr.
None
RET
PC (Top of Stack).
None
RETI
PC (Top of Stack);
None
Enable Interrupt.
2
1
1
(*1) r is the repeat value of Register r which determines the number of times the next instruction has to be
repeated.
(*2) TBRD i, r:
r ROM [(TABPTR)];
i=00: TABPTR no change
i=01: TABPTRTABPTR+1
i=10: TABPTRTABPTR-1
(*3) TABPTR=(TABPTRH: TABPTRM: TABPTRL)
Bit0=0: Low byte of the pointed ROM data
Bit0=1: High byte of the pointed ROM data
NOTE
Bit 0 of TABPTRL is used to select low byte or high byte of the pointed ROM data.
The maximum table look up space is internal 8Mbytes.
(*4) Carry bit of ADD PCL, A or ADD TABPTRL, A will automatically carry into PCM or TABPTRM.
The Instruction cycle of write to PC (program counter) takes 2 cycles.
(*5) When in SUB operation, borrow flag is indicated by the inverse of carry bit, i.e., B=/C.
(*6) The maximum jump range is 64K absolute address; means only can jump within the same 64K range.
(*7) Do not use JDNZ & JINZ at FSR1 (09B) special register.
(*8) S0CALL address ability is from 0x000 to 0xFFF (4K space).
105
ePG3231
RISC II-2G Series Microcontroller
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
ELAN
(0,0)
EPG32
EPG3231
30
26
27
28
29
30
31
32
33
34
35
36
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
106
Symbol
NC
NC
NC
PI_3
PI_2
PI_1
PI_0
PJ_0
PJ_1
PJ_2
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
1960.0
1830.0
1710.0
1590.0
1472.5
1355.0
1240.0
Pin No.
65
66
67
68
69
70
71
72
73
74
Symbol
NC
PC_4
PC_5
PC_6
PC_7
VREX
AVDD
PD_7
PD_6
PD_5
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
-1838.8
-1718.8
-1598.8
-1483.8
-1368.8
-1258.8
-1148.8
-1038.8
-933.8
ePG3231
RISC II-2G Series Microcontroller
Pin No.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Symbol
PJ_3
PJ_4
PJ_5
PJ_6
PJ_7
PK_0
PK_1
PK_2
PK_3
PK_4
PK_5
PK_6
PK_7
TEST
OSCI
OSCO
RSTB
AVSS
HOSCI
HOSCO
PMD
PA_0
PA_1
PA_2
PA_3
PA_4
NC
NC
NC
NC
NC
NC
PA_5
PA_6
PA_7
VDD
PB_0
PB_1
GND
PB_2
PB_3
PB_4
PB_5
PB_6
PB_7
PC_0
PC_1
PC_2
PC_3
NC
NC
NC
NC
NC
X
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
-895.0
Y
1125.0
1010.0
895.0
782.5
670.0
557.5
447.5
337.5
230.7
125.7
20.7
-84.2
-189.3
-294.3
-399.2
-710.2
-815.2
-920.2
-1030.2
-1142.7
-1257.7
-1372.7
-1487.7
-1602.7
-1717.7
-1835.2
-895.0
-768.0
-648.0
-533.0
-420.5
-310.5
-200.5
-100.5
-0.5
99.5
199.5
299.5
399.5
499.5
605.5
711.5
817.5
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
-1960.0
Pin No.
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
Symbol
PD_4
PD_3
PD_2
PD_1
PD_0
PE_7
PE_6
PE_5
PE_4
PE_3
PE_2
PE_1
PE_0
PF_7
PF_6
PF_5
PF_4
PF_3
PF_2
PF_1
PF_0
PG_0
PG_1
PG_2
PG_3
NC
NC
NC
NC
NC
NC
NC
NC
NC
PG_4
PG_5
PG_6
PG_7
PH_0
PH_1
PH_2
PH_3
PH_4
PH_5
PH_6
PH_7
PI_7
PI_6
PI_5
PI_4
NC
NC
NC
NC
X
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
895.0
Y
-828.8
-723.8
-618.8
-513.8
-408.8
-303.8
-198.8
-93.8
11.2
116.2
221.2
326.2
431.2
536.2
641.2
746.2
851.2
956.2
1066.2
1176.2
1286.2
1401.2
1516.2
1636.2
1756.2
788.9
683.5
579.5
475.5
371.5
267.5
163.5
59.5
-44.5
-148.5
-252.5
-356.5
-460.5
-564.5
-668.5
-772.5
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
1960.0
107
ePG3231
14 Package
Date
A2
A1
Hd
He
L1
2.540
0.250
14.000
17.200
20.000
23.200
0.800
1.600
0.5(bsc)
2.720
0.350
0.2(TYP)
Normal
13.900
17.000
19.900
23.000
0.650
1.400
Max
3.400
2.900
0.450
14.100
17.400
20.100
23.400
0.950
1.800
Sheet:1 of 1
Material:
Scale: Free
Unit : mm
Edtion: A
TITLE:
QFP-128L(14*20 MM) FOOTPRINT 3.2mm
PACKAGE OUTLINE DIMENSION
QFP128
File :
Symbal
Name
89/11/27
89/11/27
Seven Tsai
DWG NO:
POD-035
Draw
Stacy Chen
108
Check
Approved
ePG3231
RISC II-2G Series Microcontroller
109