Port pins in quasi-bidirectional output mode function similar to the standard 8051 port pins. A
quasi-bidirectional port can be used as an input and output without the need to reconfigure the
port. This is possible because when the port outputs logic high, it is weakly driven, allowing an
external device to pull the pin low. When the pin outputs low, it is driven strongly and able to
sink a large current. There are three pull-up transistors in the quasi-bidirectional output that
serve different purposes.
One of these pull-ups, called the “very weak” pull-up, is turned on whenever the port register
for the pin contains a logic “1”. This very weak pull-up sources a very small current that will
pull the pin high if it is left floating.
A second pull-up, called the “weak” pull-up, is turned on when the port register for the pin
contains a logic “1” and the pin itself is also at a logic “1” level. This pull-up provides the
primary source current for a quasi-bidirectional pin that is outputting a ‘1’. If this pin is pulled
low by the external device, this weak pull-up turns off, and only the very weak pull-up remains
on. In order to pull the pin low under these conditions, the external device has to sink enough
current to over-power the weak pull-up and pull the port pin below its input threshold voltage.
The third pull-up is referred to as the “strong” pull-up. This pull-up is used to speed up
low-to-high transitions on a quasi-bidirectional port pin when the port register changes from a
logic “0” to a logic “1”. When this occurs, the strong pull-up turns on for two CPU clocks,
quickly pulling the port pin high.
VDDVDDVDD
2 clocks
delay
StrongVery weak
Port latch data
Weak
Port pin
Input data
STC12C5Axx Technical Summary 19
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Open-drain Output
The open-drain output configuration turns off all pull-ups and only drives the pull-down
transistor of the port pin when the port register contains logic “0”. To use this configuration in
application, a port pin must have an external pull-up, typically tied to VDD. The input path of
the port pin in this configuration is the same as quasi-bidirection mode.
Port pin
Port latch data
Input data
Input-only Mode
The input-only configuration is a Schmitt-triggered input without any pull-up resistors on the
pin.
Input data
Port pin
Push-pull Output
The push-pull output configuration has the same pull-down structure as both the open-drain
and the quasi-bidirectional output modes, but provides a continuous strong pull-up when the
port register contains a logic “1”. The push-pull mode may be used when more source current
is needed from a port output.
VDD
Port latch data
Port pin
Input data
20 STC12C5Axx Technical Summary
Timer/Counter
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5Axx has two 16-bit timers, and they are named T0 and T1. Each of them can also
be used as a general event counter, which counts the transition from 1 to 0.
Since the STC12C5Axx is a RISC-like MCU which execute faster than traditional 80C51 MCU
from other providers. Based on consideration of compatibility with traditional 80C51 MCUs,
the frequency of the clock source for T0 and T1 is designed to be selectable between
oscillator frequency divided-by-12 (default) or oscillator frequency.
The user can configure T0/T1 to work under mode-0, mode-1, mode-2 and mode-3. It is fully
the same to a traditional 80C51 MCU.
There are two SFR designed to configure timers T0 and T1. They are TMOD, TCON.
The user also should take a glace of SFR AUXR which decide the frequency of the clock
source driving the T0 and T1.
SFR:
TMOD(Timer Mode Control Register)
Read/Write Address: 0X89H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
GATE: = Gating control
C//T: = Timer or Counter function selector. 0: =timer, 1: =counter
{M1, M0}: mode select
GATE
0: = (default)
Timer x is enabled whenever “TRx” control bit is set.
1: =
Timer/Counter x is enabled only while “/INTx” pin is high and “TRx” control bit is set.
0: = (default)
Configure Tx as Timer use
1: =
Configure Tx as Counter use
{0, 0}: =
Configure Tx as 13-bit timer/counter
{0, 1}: =
Configure Tx as 16-bit timer/counter
{1, 0}: =
Configure Tx as 8-bit timer/counter with automatic reload capability
{1, 1}: =
for T0, set TL0 as 8-bit timer/counter, TH0 is locked into 8-bit timer
for T1, set Timer/Counter1 Stopped
For Timer-1 Only For Timer-0 Only
C//T
M1 M0 GATE
C//T
M1 M0
STC12C5Axx Technical Summary 21
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
SFR:
TCON
Read/Write Address: 0X88H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
TF1 TR1 TF0 TR0 IE1 IT1 IE01 IT0
TF1: = Timer1 overflow flag.
This bit is automatically set by hardware on T1 overflow, and will be automatically cleared by
hardware when the processor vectors to the interrupt routine.
TR1: = Timer1 run control bit.
0: = (default)
Stop T1 counting
1: =
Start T1 counting
TF0: = Timer0 overflow flag.
This bit is automatically set by hardware on T0 overflow, and will be automatically cleared by
hardware when the processor vectors to the interrupt routine.
TR0: = Timer0 run control bit.
0: = (default)
Stop T0 counting
1: =
Start T0 counting
IE1: = External Interrupt-1 flag.
This bit is automatically set by hardware on interrupt from the external interrupt-1, and will be
automatically cleared by hardware when the processor vectors to the interrupt routine.
IT1: = Interrupt-1 type control bit.
0: = (default)
Set the interrupt-1 triggered by low duty from pin EX1
1: =
Set the interrupt-1 triggered by negative falling edge from pin EX1
IE0: = External Interrupt-0 flag.
This bit is automatically set by hardware on interrupt from the external interrupt-0, and will be
automatically cleared by hardware when the processor vectors to the interrupt routine.
IT0: = Interrupt-0 type control bit.
0: = (default)
Set the interrupt-0 triggered by low duty from pin EX1
1: =
Set the interrupt-0 triggered by negative falling edge from pin EX1
Set the frequency of the clock source for T0 as the oscillator frequency divided-by-12.
It will compatible to the traditional 80C51 MCU.
1: =
Set the frequency of the clock source for T0 as the oscillator frequency.
It will drive the T0 faster than a traditional 80C51 MCU.
T1X12: = T1 clock source selector
0: = (default)
Set the frequency of the clock source for T1 as the oscillator frequency divided-by-12.
It will compatible to the traditional 80C51 MCU.
1: =
Set the frequency of the clock source for T1 as the oscillator frequency.
It will drive the T1 faster than a traditional 80C51 MCU.
UARTM0X6: = Baud rate selector of UART while it is working under Mode-0
0: = (default)
Set the baud rate of the UART functional block as oscillator frequency divided-by-12.
It will compatible to the traditional 80C51 MCU.
1: =
Set the baud rate of the UART functional block as oscillator frequency divided-by-2.
It will transmit/receive data faster than a traditional 80C51 MCU.
BRTR: = Setting this bit will enable the baud-rate generator of UART2 to run.
S2SMOD: = Setting this bit can double up the baud-rate of UART2.
BRTRX12: = Set this bit to set the clock source for the UART2 is BRT, or clear it to set the clock
source for or the UART2 as BRT/12.
S1BRS: = S1 Baud-Rate clock source selector
0: = (default)
Select timer-1 for baud-rate clock source to S1
1: =
Select BRT for baud-rate clock source to S1
STC12C5Axx Technical Summary 23
x
/
/
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Mode 0
The timer register is configured as a 13-bit register. As the count rolls over from all 1s to all 0s,
it sets the timer interrupt flag TFx. The counted input is enabled to the timer when TRx = 1
and either GATE=0 or INTx = 1. Mode 0 operation is the same for Timer0 and Timer1.
OSC/12
OSC
AUXR.x
0
1
T0 or T1 pin
(sampled)
C
GATE
/INTx
0
1
T
TR
0
1
TLx[4:0] THx[7:0]
TFx
Mode 1
Mode1 is the same as Mode0, except that the timer register is being run with all 16 bits.
OSC/12
OSC
AUXR.x
0
1
T0 or T1 pin
(sampled)
0
1
0
1
TLx[7:0] THx[7:0]
TFx
Interrupt
Interrupt
GATE
/INTx
Mode 2
Mode 2 configures the timer register as an 8-bit counter (TLx) with automatic reload. Overflow
from TLx does not only set TFx, but also reloads TLx with the content of THx, which is
determined by user’s program. The reload leaves THx unchanged. Mode 2 operation is the
same for Timer0 and Timer1.
OSC/12
OSC
AUXR.x
0
1
T0 or T1 pin
(sampled)
GATE
/INTx
0
1
0
1
TLx [7:0]
THx [7:0]
Reload
TFx
Interrupt
24 STC12C5Axx Technical Summary
Mode 3
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Timer1 in Mode3 simply holds its count, the effect is the same as setting TR1 = 1. Timer0 in
Mode 3 enables TL0 and TH0 as two separate 8-bit counters. TL0 uses the Timer0 control bits
such like C/T, GATE, TR0, INT0 and TF0. TH0 is locked into a timer function (can not be
external event counter) and take over the use of TR1, TF1 from Timer1. TH0 now controls the
Timer1 interrupt.
OSC/12
OSC
AUXR.x
0
1
Sampled T0 pin
0
1
0
1
TL0 [7:0]
TF0
Interrupt
GATE
/INT0
OSC/12
OSC
AUXR.x
0
1
TR1
0
1
TH0 [7:0]
BAUD-RATE GENERATOR(BRT)
BAUD-RATE GENERATOR(BRT)
Baud-Rate Generator and P1.0/P4.1 programmable clock output
TF1
Interrupt
BRTCLKO
To UART
toggle
P1.0 or
P4.1
Fosc/12
Fosc01
S2TX12
BRTR
8-bit timer
BRT
Overflow
Baud-Rate Generator for th e UART
STC12C5Axx Technical Summary 25
r
r
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5Axx is able to generate a programmable clock output on P1.0 or P4.1. When BRTCLKO bit
in WAKE_CLKO is set, BRT timer overflow pulse will toggle P1.0 or P4.1 latch to generate a 50%
duty clock. The frequency of clock-out is as following :
BRT timer overflow rate =
Fosc
o
256 – BRT
Fosc/12
256 – BRT
P1.0 / P4.1 Clock output frequency =
Fosc /2
256 – BRT
o
Fosc/24
256 – BRT
26 STC12C5Axx Technical Summary
Interrupt
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
There are 10 interrupt sources available in STC12C5Axx. Each interrupt source can be individually
enabled or disabled by setting or clearing a bit in the SFR named IE. This register also contains a global
disable bit (EA), which can be cleared to disable all interrupts at once.
Each interrupt source has two corresponding bits to represent its priority. One is located in SFR named
IPH and the other in IP register. Higher-priority interrupt will be not interrupted by lower-priority interrupt
request. If two interrupt requests of different priority levels are received simultaneously, the request of
higher priority is serviced. If interrupt requests of the same priority level are received simultaneously, an
internal polling sequence determine which request is serviced. The following table shows the internal
polling sequence in the same priority level and the interrupt vector address.
Source Vector address Priority within level
/INT0 03H0 (highest)
Timer 0 0BH1
/INT1 13H2
Timer1 1BH3
UART 23H4
ADC 2BH5
LVD 33H6
PCA 3BH7
UART2 43H8
SPI 4BH9
The external interrupt /INT0, and /INT1 can each be either level-activated or transition-activated,
depending on bits IT0 and IT1 in register TCON. The flags that actually generate these interrupts are bits
IE0 and IE1 in TCON. When an external interrupt is generated, the flag that generated it is cleared by
the hardware when the service routine is vectored to only if the interrupt was transition –activated,
otherwise the external requesting source is what controls the request flag, rather than the on-chip
hardware.
The Timer0 and Timer1 interrupts are generated by TF0 and TF1, which are set by a rollover in their
respective Timer/Counter registers in most cases. When a timer interrupt is generated, the flag that
generated it is cleared by the on-chip hardware when the service routine is vectored to.
The serial port interrupt is generated by the logical “1” of RI and TI. Neither of these flags is cleared by
hardware when the service routine is vectored to. The service routine should poll RI and TI to determine
which one to request service and it will be cleared by software.
The SPI interrupt is generated by the flag SPIF. It can only be cleared by writing a “1” to SPIF bit in software.
The ADC interrupt is generated by the flag ADC_FLAG. It should be cleared by software.
STC12C5Axx Technical Summary 27
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
The PCA interrupt is generated by the logical OR of CF, CCF0 ~ CCF1. The service routine should poll
CF and CCF0 ~ CCF1 to determine which one to request service and it will be cleared by software.
The Low Voltage Detect interrupt is shared by the flag LVDF in PCON.5 register. They should be cleared
by software.
The UART2 interrupt is generated by the logical “1” of S2RI and S2TI. Neither of these flags is cleared
by hardware when the service routine is vectored to. The service routine should poll S2RI and S2TI to
determine which one to request service and it will be cleared by software.
All of the bits that generate interrupts can be set or cleared by software, with the same result as though it
had been set or cleared by hardware. In other words, interrupts can be generated or pending interrupts
can be canceled in software.
How does the STC12C5Axx take the Interrupts
External interrupt pins and other interrupt sources are sampled at rising edge of each clock cycle. The
samples are polled during the next clock cycle. If one of the flags was in a set condition of the first cycle,
the second cycle of polling cycles will find it and the interrupt system will generate an hardware LCALL to
the appropriate service routine as long as it is not blocked by any of the following conditions.
The 2B
interrupt is shared by the logical “1” of ADC interrupt and interrupt. Neither of these flags is
H
cleared by hardware when the service routine is vectored to. The service routine should poll them to
determine which one to request service and it will be cleared by software.
The 4BH interrupt is shared by the logical “1” of SPI interrupt and interrupt. Neither of these flags is
cleared by hardware when the service routine is vectored to. The service routine should poll them to
determine which one to request service and it will be cleared by software.
The 33H interrupt is shared by the logical “1” of LVD interrupt (Low-Voltage Detector) interrupt. Neither of
these flags is cleared by hardware when the service routine is vectored to. The service routine should
poll them to determine which one to request service and it will be cleared by software.
The 3BH interrupt is shared by the logical “1” of PCA interrupt and interrupt. Neither of these flags is
cleared by hardware when the service routine is vectored to. The service routine should poll them to
determine which one to request service and it will be cleared by software.
All of the bits that generate interrupts can be set or cleared by software, with the same result as though it
had been set or cleared by hardware. In other words, interrupts can be generated or pending interrupts
can be canceled in software.
28 STC12C5Axx Technical Summary
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
If one of the following conditions happens, a coming interrupt will be blocked.
An interrupt of equal or higher priority level is already in progress.
The current cycle(polling cycle) is not the final cycle in the execution of the instruction in
progress.
The instruction in progress is RETI or any write to SFRs IE, IP, IP2, IPH and IP2H registers.
Condition 2 ensures that the instruction in progress will be completed before vectoring into any service
routine. Condition 3 ensures that if the instruction in progress is RETI or any access to SFRs IE, IP, IP2,
IPH or IP2H, then at least one or more instruction will be executed before any interrupt is vectored to.
The following content describes several SFR related to interrup t mechanism.
F0: = Flag 0.(Available to the user for general purposes)
RS1: = Register bank select control bit 1.
RS0: = Register bank select control bit 0.
OV : = Overflow flag.
F1 : = Flag 1. User-defined flag.
P : = Parity flag.
CY AC F0 RS1 RS0 OV F1 P
0: = (default)
Disable
1: =
Enable
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
SFR: IE(Interrupt Enable)
Read/Write Address: 0XA8H
Default: XXXX-XX00
Bit 7 6 5 4 3 2 1 0
Name
EA ELVD EADC ES ET1 EX1 ET0 EX0
EA
: = Global interrupt controller.
0: = (default)
Disable all interrupts
1: =
Release interrupt control to all individual interrupt controllers.
ELVD
: = Interrupt controller of Low-Voltage Detector
0: = (default)
Disable
1: =
Enable
EADC: =
Interrupt controller of A/D Converter (ADC).
0: = (default)
Disable
1: =
Enable
ES: = Interrupt controller of Universal Asynchronous Receiver/Transmitter (UART).
0: = (default)
Disable
1: =
Enable
ET1: = Interrupt controller of Timer-1 interrupt.
0: = (default)
Disable
1: =
Enable
EX1: = Interrupt controller of external interrupt-1.
0: = (default)
Disable
1: =
Enable
ET0: = Interrupt controller of Timer-0 interrupt.
0: = (default)
Disable
1: =
Enable
EX0: = Interrupt controller of external interrupt-0.
0: = (default)
Disable
1: =
30 STC12C5Axx Technical Summary
Enable
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
SFR: IP(Interrupt Priority Low)
Read/Write Address: 0xB8H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
PPCA PLVDI PADC PS PT1 PX1 PT0 PX0
PPCA: = If set, Set priority for PCA interrupt higher
PLVD: = If set, Set priority for Low Voltage interrupt higher
PADC: = If set, Set priority for ADC interrupt highe
PS: = If set, Set priority for serial port interrupt higher(UART)
PT1: = If set, Set priority for timer1 interrupt higher
PX1: = If set, Set priority for external interrupt 1 higher
PT0: =
If set, Set priority for timer0 interrupt higher
PX0: = If set, Set priority for external interrupt 0 higher
SFR: IPH (Interrupt Priority High)
Read/Write Address: 0XB7H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
PPCAHPLVDH PADCHPSH PT1H PX1H PT0H PX0H
PPCAH: = If set, Set priority for PCA interrupt higher
PLVDH: = If set, Set priority for Low Voltage interrupt higher
PADC: = If set, Set priority for ADC interrupt higher
PSH: = If set, Set priority for serial port interrupt higher (UART)
PT1H: = If set, Set priority for timer1 interrupt higher
PX1H: = If set, Set priority for external interrupt 1 higher
PT0H: = If set, Set priority for timer0 interrupt higher
PX0H: = If set, Set priority for external interrupt 0 higher
STC12C5Axx Technical Summary 31
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
SFR: IP2 (Interrupt Priority High)
Read/Write Address: 0XB6H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
PSPI PS2
SFR: IP2H (Interrupt Priority High)
Read/Write Address: 0XB7H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
IP and IPH are combined to form 4-level priority interrupt as the following table.
PSPIH PS2H
{IPH.x, IP.x}
11 1 (highest)
10 2
01 3
00 4
Priority
Level
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Highest Priority Level
Interrupt
e
Sequenc
/INT0
TF0
/INT1
TF1
RI
TI
TF2
EXF2
IE, XICON,AUXIE Registers
IE.
IE0
IE1
0
IE.
1
IE.
2
IE.
3
IE.
4
IE.
5
IP,IP2,IPH,IPH2
Registers
CF
ECF
CCF0
ECCF0
CCF1
ECCF1
CCF2
ECCF2
EPOF
POF
ELVD
LVDF
SPIF
ADC_FLAG
S2RI
S2TI
IE2.1
IE.5
ECF
IE2.0
IE.6
Individual
Enable
Global Enable
(IE.7)
Polling
Interrupt
Lowest Priority
Level Interrupt
Interrupt Control Block
STC12C5Axx Technical Summary 33
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Watch Dog Timer
The watch dog timer in STC12C5Axx consists of an 8-bit pre-scalar timer and a 15-bit timer.
The timer is one-time enabled by setting EN_WDT. Clearing ENW can not stop WDT
counting. When the WDT is enabled, software should always reset the timer by writing 1 to
CLR_WDT bit before the WDT overflows. If STC12C5Axx is out of control by any disturbance,
that means the CPU can not run the software normally, then WDT may miss the “writing 1 to
CLR_WDT” and overflow will come. WDT overflow reset the CPU to restart.
1/256
1/128
1/64
Fosc/12
1/32
1/16
1/8
1/4
1/2
8-bit prescalar
15-bit timer
IDLE
WDT_
FLAG
EN_
WDT
CLR_
WDT
IDL_
WDT
PS2 PS1 PS0-
WDT_CONTR
To make good use of the watch-dog-timer, the user should take notice on SFR WDT_CONTR.
SFR: WDT_CONTR (WDT Control Register) C1H
Read/Write Address: 0XC1H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
WDT_FLAG EN_WDTCLR_WDTIDL_WDTPS2 PS1 PS0
WDT_FLAG: = When WDT overflows, this bit is set. It can be cleared by software.
EN_WDT: = Control bit to enable Watch-Dog-Timer. (One-time enabled, can not be disabled)
0: = (default)
Disable Watch Dog Timer
1: =
Enable Watch Dog Timer start counting
CLR_WDT: = Set this bit to recount WDT. Hardware will automatically clear this bit.
34 STC12C5Axx Technical Summary
IDL_WDT: = Behavior controller of the WDT while the device is put under idle
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
0: = (default)
Stop Watch Dog Timer counting
1: =
Keep Watch Dog Timer counting (so further reset could happen)
{PS2, PS1, PS0}: selector of the WDT pre-scalar output.
{0, 0, 0}: = set the pre-scaling value 2
{0, 0, 1}: = set the pre-scaling value 4
{0, 1, 0}: = set the pre-scaling value 8
{0, 1, 1}: = set the pre-scaling value 16
{1, 0, 0}: = set the pre-scaling value 32
{1, 0, 1}: = set the pre-scaling value 64
{1, 1, 0}: = set the pre-scaling value 128
{1, 1, 1}: = set the pre-scaling value 256
STC12C5Axx Technical Summary 35
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Universal Asynchronous Serial Port (UART)
The serial port of STC12Cxx is duplex. It can transmit and receive simultaneously. The
receiving and transmitting of the serial port share the same SFR SBUF, but actually there are
two SBUF registers implemented in the chip, one is for transmitting and the other is for
receiving. The serial port can be operated in 4 different modes.
Mode 0
Generally, this mode purely is used to extend the I/O features of this device.
Operating under this mode, the device receives the serial data or transmits the serial data via
pin RXD, while there is a clock stream shifted via pin TXD which makes convenient for
external synchronization. An 8-bit data is serially transmitted/received with LSB first. The baud
rate is fixed at 1/12 the oscillator frequency. If AUXR.5 (URM0X6) is set, the baud rate is 1/2
oscillator frequency.
Mode1
A 10-bits data is serially transmitted through pin TXD or received through pin RXD. The frame
data includes a start bit (0), 8 data bits and a stop bit (1). After finishing a receiving, the device
will keep the stop bit in RB8 which from SRF SCON.
Baud Rate (for Mode 1) =
2
32
X (Timer-1 overflow rate)
SMOD
Mode2
An 11-bit data is serially transmitted through TXD or received through RXD. The frame data
includes a start bit (0), 8 data bits, a programmable 9th bit and a stop bit (1). On transmit; the
9th data bit comes from TB8 in SFR SCON. On receive; the 9th data bit goes into RB8 in
SCON. The baud rate is programmable, and permitted to be set either 1/32 or 1/64 the
oscillator frequency.
Baud Rate (for Mode 2) =
2
SMOD
64
X Fosc
36 STC12C5Axx Technical Summary
Mode3
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Mode 3 is the same as mode 2 except the baud rate is variable.
SMOD
Baud Rate (for Mode 3) =
2
In all four modes, transmission is initiated by any instruction that uses SBUF as a destination
register. Reception is initiated in mode 0 by the condition RI = 0 and REN = 1. Reception is
initiated in the other modes by the incoming start bit with 1-to-0 transition if REN=1.
There are several SFRs related to serial port configuration described as following.
32
X (Timer-1 overflow rate)
SFR:
SCON (Serial Control)
Read/Write Address: 0x98H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SM0/FESM1 SM2 REN TB8 RB8 TI RI
FE: = Frame Error bit
This bit is set by the receiver when an invalid stop bit is detected. The FE bit is not cleared by
valid frames but should be cleared by software. The SMOD0 bit must be set to enable access
to the FE bit.
{SM0, SM1}: = Used to set operating mode of the serial port.
{0, 0}: = set the serial port operate under Mode 0
{0, 1}: = set the serial port operate under Mode 1
{1, 0}: = set the serial port operate under Mode 2
{1, 1}: = set the serial port operate under Mode 3
SM2: = Enable the automatic address recognition feature in mode 2 and 3.
If SM2=1, RI will not be set unless the received 9th data bit is 1, indicating an address, and the
received byte is a Given or Broadcast address. In mode1, if SM2=1 then RI will not be set
unless a valid stop Bit was received, and the received byte is a Given or Broadcast address.
REN: = Enable the serial port reception.
0: = (default)
Disable the serial port reception.
1: =
Enable the serial port reception.
TB8: = The 9th data bit, which will be transmitted in Mode 2 and Mode 3.
RB8: = In mode 2 and 3, the received 9th data bit will be put into this bit.
TI: = Transmitting done flag. After a transmitting has been finished, the hardware will set this
STC12C5Axx Technical Summary 37
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
bit.
RI: = Receive done flag. After reception has been finished, the hardware will set this bit.
38 STC12C5Axx Technical Summary
SFR: SBUF (Serial Buffer)
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Read/Write Address: 0x99H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
Frame Error Detection
When used for frame error detect, the UART looks for missing stop bits in the communication.
A missing bit will set the FE bit in the SCON register. The FE bit shares the SCON.7 bit with
SM0 and the function of SCON.7 is determined by PCON.6 (SMOD0). If SMOD0 is set then
SCON.7 functions as FE. SCON.7 functions as SM0 when SMOD0 is cleared. When used as
FE, SCON.7 can only be cleared by software.
Automatic Address Recognition
There is an extra feature makes the device convenient to act as a master, which
communicates to multiple slaves simultaneously. It is really Automatic Address Recognition.
There are two SFR SADDR and SADEN implemented in the device. The user can read or
write both of them. Finally, the hardware will make use of these two SFR to “generate” a
“compared byte”. The formula specifies as following.
Bit[ i ] of Compared Byte = (SADEN[ i ] == 1 )? SADDR[ i ] : x
For example:
Set SADDR = 11000000b
Set SADEN = 11111101b
Ö The achieved “Compared Byte” will be “110000x0” (x means don’t care)
For another example:
Set SADDR = 11100000b
Set SADEN = 11111010b
Ö The achieved “Compared Byte” will be “11100x0x”
After the generic “Compared Byte” has been worked out, the STC12Cxx will make use of this
byte to determine how to set the bit RI in SFR SCON.
Normally, an UART will set bit RI whenever it has done a byte reception; but for the UART in
the STC12Cxx, if the bit SM2 is set, it will set RI according to the following formula.
In other words, not all data reception will respond to RI, while specific data does.
By setting the SADDR and the SADEN, the user can filter out those data byte that he doesn’t
like to care. This feature brings great help to reduce software overhead.
The above feature adapts to the serial port when operated in Mode1, Mode2, and Mode3.
Dealing with Mode 0, the user can ignore it.
STC12C5Axx Technical Summary 39
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
Secondary Universal Asynchronous Serial Port (S2)
S2 is the secondary UART of STC12C5Axx whose function is fully the same with the major UART
excepting that no enhanced function included. An additional baud-rate generator (S2BRT) is available in
S2 to simplify the baud-rate generation and release Timer1 for use in other purposes. The additional
baud-rate generator can also be configured to provide a programmable clock output on P1.0/P4.1.
Combined with Timer1 and BRT, STC12C5Axx will be able to provide three individual programmable
clock outputs on three general-purpose I/O pins, respectively.
Mode 0
Serial data enters and exits through pin RXD2 (P1.2/P4.2), and pin TXD2 (P1.3/P4.3) outputs the shift
clock. Eight data bits are transmitted/received with the LSB first. The baud rate is fixed at 1/12 the
oscillator frequency. Regardless of baud-rate generation, the operation in Mode 0 for S2 UART is the
same as the major UART in Mode 0.
Mode1
10 bits are transmitted through pin TXD2 or received through pin RXD2. The frame data includes a start
bit(0), 8 data bits and a stop bit(1). One receive, the stop bit goes into S2RB8 in SFR S2CON. The baud
rate is determined by the BRT overflow rate. Regardless of baud-rate generation, the operation in Mode
1 for S2 UART is the same as the standard UART in Mode 1.
Baud Rate (for Mode 1) =
2
X (BRT timer overflow rate)
32
Mode2
11 bits are transmitted through pin TXD2 or received through pin RXD2. The frame data includes a start
bit(0), 8 data bits, a programmable 9th bit and a stop bit(1). On transmit, the 9th data bit comes from
S2TB8 in S2CON. On receive, the 9th data bit goes into S2RB8 in S2CON. The baud rate is
programmable to either 1/32 or 1/64 the oscillator frequency.
The operation in Mode 2 for S2 is the same as the major UART in Mode 2.
Baud Rate (for Mode 2) =
2
X BRT
64
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Mode3
Mode 3 is the same as mode 2 except the baud rate is variable.
Baud Rate (for Mode 3) =
2
X (BRT timer overflow rate)
32
The user can redirect functional pins RXD2 and RXD2 from pins P1.2 and P1.3 to pins P4.2 and P4.3 by
setting bit S2P4 in SFR AUXR1.
There are several special function registers which should be understood by users before using the
secondary UART.
SFR: S2CON
Read/Write Address: 0x9AH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
S2SM0 S2SM1 S2SM2 S2REN S2TB8S2RB8S2TI S2RI
{ S2SM0, S2SM1 } := Used to set operating mode of the serial port.
{ 0, 0 } := set the serial port operate under Mode 0(8-bit shift register)
{ 0, 1 } := set the serial port operate under Mode 1(8-bit UART)
{ 1, 0 } := set the serial port operate under Mode 2(9-bit UART)
{ 1, 1 } := set the serial port operate under Mode 3(9-bit UART)
S2SM2 := Enable the automatic address recognition feature in mode 2 and 3.
If SM2=1, RI will not be set unless the received 9th data bit is 1, indicating an address, and
the received byte is a Given or Broadcast address. In mode1, if SM2=1 then RI will not be
set unless a valid stop Bit was received, and the received byte is a Given or Broadcast
address.
S2REN := Enable the serial port reception.
0 := (default)
Disable the secondary serial port reception.
1 :=
Enable the secondary serial port reception.
S2TB8 :=
The 9th data bit, which will be transmitted in Mode 2 and Mode 3.
STC12C5Axx Technical Summary 41
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
S2RB8 :=
S2TI :=
S2RI :=
In mode 2 and 3, the received 9th data bit will be put into this bit.
Transmitting done flag. After a transmitting has been finished, the hardware will set
this bit.
Receive done flag. After reception has been finished, the hardware will set this bit.
SFR: S2BUF
Read/Write Address: 0x9BH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SFR: BRT
Read/Write Address: 0x9CH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
It is used as the reload register for generating the baud-rate of the secondary UART only
Set this bit to set the clock source for timer 0 is Fosc, or clear it to set the clock source for
timer 0 as Fosc/12.
T1X12 :=
Set this bit to set the clock source for timer 0 is Fosc, or clear it to set the clock source for
timer 1 as Fosc/12.
UARTM0x6 :=
Set this bit to set the clock source for the major UART is Fosc/2, or clear it to set the clock
source for or the major UART as Fosc/12.
BRTR :=
Setting this bit will enable the baud-rate generator of secondary UART to run.
S2SMOD:=
Setting this bit can double up the baud-rate of secondary UART.
BRTX12:=
42 STC12C5Axx Technical Summary
Set this bit to set the clock source for the secondary UART is BRT, or clear it to set the clock
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
source for or the secondary UART as BRT/12.
EXTRAM :=
0: =
On-chip auxiliary RAM is enabled and located at the address 0x0000 to 0x03FF. For
address above 0x03FF, external RAM becomes the target automatically.
1 : =
On-chip auxiliary RAM is always disabled..
S1BRS :=
Set this bit to set the clock source for the UART is BRT, or clear it to set the clock source for
or the UART as Timer-1.
SFR: WAKE_CLKO
Read/Write Address: 0x8FH
Default: 0000-0X00
Bit 7 6 5 4 3 2 1 0
Name
WAKEUP
WAKEUP: =
If this bit has been enabled, the PCA interrupt can wake-up the device from power-down mode.
RXD_PIN_IE:
If this bit has been enabled, the RXD interrupt can wake-up the device from power-down mode..
T1_PIN_IE: =
If this bit has been enabled, the Timer-1 interrupt can wake-up the device from power-down
mode..
T0_PIN_IE: =
If this bit has been enabled, the Timer-0 interrupt can wake-up the device from power-down mode.
PCA
RXD_PIN_
IE
T1_PIN_
IE
T0_PIN_
IE
LVD_
WAKE
BRTCLKO T1CLKO T0CLKO
LVD_WAKE: = Setting the bit, the LVD interrupt can wake-up the device from power-down mode.
0: = (default)
1: =
BRTCLKO:=
Setting this bit can enable BRT clock output on P1.0. The frequency of the output
clock will be set as (BRT overflow rate / 2 )
STC12C5Axx Technical Summary 43
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
T1CLKO :=
TCLKO :=
Setting this bit can enable timer 0 clock output on P3.5. The frequency of the output clock will be
set as ( Timer 1 overflow rate / 2 )
Setting this bit can enable timer 0 clock output on P3.4. The frequency of the output clock will be
set as ( Timer 0 overflow rate / 2 )
44 STC12C5Axx Technical Summary
Programmable Counter Array (PCA)
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
The Programmable Counter Array is a special 16-bit Timer that has two 16-bit capture/compare modules
associated with it. Each of the modules can be programmed to operate in one of four modes:
z rising and/or falling edge capture (calculator of duty length for high/low pulse)
z software timer
z high-speed output
z pulse width modulator
Each module has a pin associated with it in port 1. Module-0 is connected to pin P1.3, module-1 to pin
P1.4.
The PCA timer is a common time base for all two modules and can be programmed to run at 1/12 the
oscillator frequency, 1/2 the oscillator frequency, the Timer-0 overflow or the input on pin ECI (P3.4). The
timer count source is determined from CPS1 and CPS0 bits in the SFR
16 Bit
PCA
Timer/Counter
Programmable Counter Array
Module-0
Capture/Compare
Register
Module-1
Capture/Compare
Register
CMOD.
P1.3/CEX0/
PCA0/PWM0
P1.4/CEX1/
PCA1/PWM1
In the CMOD SFR, there are two additional bits associated with the PCA. On of them is CIDL which
determines if to stop the PCA while the MCU is put under idle, the other bit is ECF which controls if to
pass the interrupt from PCA into the MCU.
The CCON SFR contains the run control bit for PCA and several flags for the PCA timer and each
module. To start the PCA counting, the CR bit (CCON.6) must be set by software; oppositely clearing bit
CR will shut off the PCA. There is a bit named CF in SFR CCON. The CF bit (CCON.7) will be set when
the PCA timer overflows, and an interrupt will be generated if the ECF (CMOD.0) is set. The CF bit can
only be cleared by software. There are two bits named CCF0 and CCF1 in SFR CCON. The CCF0 and
CCF1 serve as flags for module-0 and module-1 respectively. They are set by hardware when either a
match or a capture occurs. These flags also can only be cleared by software.
STC12C5Axx Technical Summary 45
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
IDLE
Fosc/12
Fosc/2
Timer0 overflow
External input
ECI (P3.4)
--
PCA Timer/Counter
--CIDL
-
--CF
CHCL
CPS1 CP S0 ECF
- CCF1 CCF0CR
16-bit counter
CMOD
CCON
To PCA module
SFR: CMOD (PCA Mode Control Register)
Read/Write Address: 0xD9FH
PCA
interrupt
Default: 0XXX-X000
Bit 7 6 5 4 3 2 1 0
Name
CIDL CPS1 CPS0 ECF
CIDL := Behavior control of the PCA.
0 := (default)
Disable counting of the PCA counter while the MCU is put under idle state.
1 :=
Enable counting of the PCA counter while the MCU is put under idle state.
{ CPS1, CPS0 } := Used to select the clocking source for PCA counter
{ 0, 0 } := set the frequency of the PCA counter clock source as oscillator’s frequency over 12
{ 0, 1 } := set the frequency of the PCA counter clock source as oscillator’s frequency over 2
{ 1, 0 } := set the PCA counter clock source as Timer-0 overflow
{ 1, 1 } := set the PCA counter clock source as pin ECI(pin P3.4)
ECF := Control bit of deciding if to pass interrupt from PCA timer overflow to the MCU
0 := (default)
Inhibit the interrupt from PCA timer to the MCU
1 :=
Permit the interrupt from PCA timer to the MCU
46 STC12C5Axx Technical Summary
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
SFR: CCON (PCA Counter Control Rregister)
Read/Write Address: 0XD8FH
Default: 0XXX-X000
Bit 7 6 5 4 3 2 1 0
Name
CF CR CCF1 CCF0
CF := PCA Counter overflow Flag
This bit must be set by hardware itself. It can be cleared by software program.
CR := PCA Run control bit
0 := (default)
Disable counting of the PCA counter
1 :=
Start counting of the PCA counter
CCF1 := Module-1 interrupt Flag
This bit must be set by hardware itself when a match or capture from module-1 occurs.
It can be cleared by software program.
A match means the value of the PCA counter equals the value of the Capture/Compare
Register in the module-1.
A capture means a specific edge from CEX1 happens, so the Capture/Compare register
latches the value of the PCA counter, and the CCF1 is set.
CCF0 := Module-0 interrupt Flag
This bit must be set by hardware itself when a match or capture from module-0 occurs.
It can be cleared by software program.
Each module in the PCA has a special function register associated with it, CCAPM0 for
module0 and CCAPM1 for module-1. The register contains the bits that control the mode in
which each module will operate. The ECCFn bit controls if to pass the interrupt from CCFn
flag in the CCON SFR to the MCU when a match or compare occurs in the associated module.
PWMn enables the pulse width modulation mode. The TOGn bit when set causes the pin
CEXn output associated with the module to toggle when there is a match between the PCA
counter and the module’s Capture/Compare register. The match bit(MATn) when set will
cause the CCFn bit in the CCON register to be set when there is a match between the PCA
counter and the module’s Capture/Comp are register.
The next two bits CAPNn and CAPPn determine the edge type that a capture input will be
active on. The CAPNn bit enables the negative edge, and the CAPPn bit enables the positive
edge. If both bits are set, both edges will be enabled and a capture will occur for either
transition. The bit ECOMn when set enables the comparator function.
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
SFR:
CL (PCA Base Counter Low Byte)
Read/Write Address: 0XE9H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SFR: CH (PCA Base Counter High Byte)
Read/Write Address: 0XF9H
Default: 00000-0000
Bit 7 6 5 4 3 2 1 0
Name
SFR: CCAP0L (Low byte of PCA module-0 Compare/Capture register)
Read/Write Address: 0XEAH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SFR: CCAP0H (High byte of PCA module-0 Compare/Capture register)
Read/Write Address: 0XFAH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SFR: CCAP1L (Low byte of PCA module-1 Compare/Capture register)
Read/Write Address: 0XEBH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SFR: CCAP1H (High byte of PCA module-1 Compare/Capture register)
Read/Write Address: 0XFBH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
48 STC12C5Axx Technical Summary
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
CCAPM0 (PCA Modul-0 Mode Register)
SFR:
Read/Write Address: 0XDAH
Default: X000-0000
Bit 7 6 5 4 3 2 1 0
Name
ECOM0 CAPP0CAPNOMAT0TOG0 PWM0 ECCF0
SFR: CCAPM1 (PCA Modul-1 Mode Register)
Read/Write Address: 0XDBH
Default: X000-0000
Bit 7 6 5 4 3 2 1 0
Name
ECOMn:= used to determine if Enable Comparator
CAPPn: = configure the module-n’s register to latch the PCA counter on Positive edge of
CAPNn: = configure the module-n’s register to latch the PCA counter on Negative edge of
MATn: = used to determine if set the bit CCFn in SFR CCON while a match from module-n
TOGn: = Toggle the output pin
PWMn: = Enable plus width modulation mode n .
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
ECOM1 CAPP1CAPN1MAT1TOG1 PWM1 ECCF1
0 := (default)
Disable the comparator function
1 :=
Enable the comparator function
EXIn or not
0 := (default)
configure the module-n’s register not to latch the PCA counter on CAPPn posedge.
1 :=
configure the module-n’s register to latch the PCA counter on CAPPn posedge.
EXIn or not
0 := (default)
configure the module-n’s register not to latch the PCA counter on pin CAPPn negedge.
1 :=
configure the module-n’s register to latch the PCA counter on pin CAPPn negedge.
occurs.
0 := (default)
Don’t set the bit CCFn while a match occurs between the PCA counter and module-n’s
register.
1 :=
Set the bit CCFn while a match occurs between the PCA counter and module-n’s
register.
0 := (default)
Don’t toggle the pin CEXn while a match occurs between the PCA counter and
module-n’s register.
1 :=
Toggle the pin CEXn while a match occurs between the PCA counter and
module-n’s register.
0 := (default)
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Inhibit the PWM functionality from module-n output to pin PWMn
1 :=
Enable the pin PWMn as the output of the PWM functionality from module-n
50 STC12C5Axx Technical Summary
ECCFn: = Enable the CCFn flag in the CCON SFR to generate an interrupt.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
0 := (default)
Inhibit the interrupt(CCFn) from module-n to the MCU
1 :=
Permit the interrupt(CCFn) from module-n to the MCU
Configure PCA Module
ECOMn CAPPn CAPNn MATn TOGnPWMnECCFnModule function
0 0 0 0 0 0 0 No operation
X 1 0 0 0 0 X 16-bit capture by a positive-edge trigger on
CEXn
X 0 1 0 0 0 X 16-bit capture by a negative trigger on CEXn
X 1 1 0 0 0 X 16-bit capture by a transition on CEXn
1 0 0 1 0 0 X 16-bit Software Timer
1 0 0 1 1 0 X 16-bit High Speed Output
1 0 0 0 0 1 0 8-bit PWM
PCA Capture Mode
To use one of the PCA modules in the capture mode, one or both of bits CAPPn and CAPNn
in SFR CCAPMn should be set. The external CEXn input for the module is sampled for a
transition. When a valid transition occurs, the PCA hardware loads the value of the PCA
counter register(CH and CL) into the module’s capture registers(CCAPnH and CCAPnL). If
the bit CCFn for the module in the SFR CCON and the bit ECCFn in the SFR CCAPMn are
set then an interrupt will be generated.
CEXn
-
--CF
- CCF1 CCF0CR
CAPTURE
CCON
PCA
interrupt
CHCL
CCAPnH CCAPnL
-
0000
TOGn PWMn ECCFnECOMn CAPPnCAPNn MATn
MDnCON
PCA Capture Mode
STC12C5Axx Technical Summary 51
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
16-bit Software Timer Mode
The PCA modules can be used as software timers by setting both the ECOMn and MATn bits
in the CCAPMn register. The PCA timer will be compared to the module’s capture registers
and when a match occurs an interrupt will be generated if the CCFn and ECCFn bits for the
module are both set.
High Speed Output Mode
In this mode the CEXn output (port latch) associated with the PCA module will toggle each
time a match occurs between the PCA counter and the module’s capture registers. To activate
this mode the TOGn, MATn, and ECOMn bits in the SFR CCAPMn must be set.
Pulse Width Modulator Mode
All of the PCA modules can be used as PWM outputs. The frequency of the output depends
on the PCA counter. All of the modules will have the same frequency of output because they
all share the PCA counter. The duty cycle of each module is independently variable using the
module’s capture register CCAPnL[7:0] and bits EPCnL in SFR PCAPWMn. When the value
of the SFR CL is less than the value in the module’s {EPCnL, CCAPnL [7:0]}, the output will
be low. When it is equal to or greater than, the output will be high. When CL overflows from
FF
to 00
H
, {EPCnL, CCAPnL [7:0 ]} is reloaded with the value in {EPCnH, CCAPnH [7:0]}.
H
That allows smoothly updating the PWM duty without glitches. The bits PWMn and ECOMn
bits in the CCAPMn must be set to enable the PWM mode.
SFR:
PCA_PWM0 (PCA PWM0 Auxiliary Register)
Read/Write Address: 0XF2H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
EPC0H EPC0L
SFR: PCA_PWM1 (PCA PWM1 Auxiliary Register)
Read/Write Address: 0XF3H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
CF CR EPC1H EPC1L
EPCnL: = concatenated with CCAPnL, used to control the duty of the PWM output
The bit EPCnL is going to be combined with CCAPnL to form a 9-bit data which will
be compared with PCA counter low byte CL, so to determine the duty of the module-n’s PWM
output.
If {CL[7:0]} < { EPCnL, CCAPnL[7:0]} , PWM output LOW
else PWM output HIGH
EPCnH: = Reloaded value of EPCnL while CL [7:0] counts from FF
to 00H
H
52 STC12C5Axx Technical Summary
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Write to CCAPnL
Write to CCAPnL
Write to CCAPnH
01
Enable
Write to CCAPnH
CCAPnHCCAPnL
16-bit
comparator
CHCL
-
PCA Software Timer Mode
-
-
MATCH
00
--CF
--CF
- CCF1 CCF0CR
CCON
PCA
interrupt
To CCFn
TOGn PWMn ECCFnECOMn C APPn CAPNn MATn
CCAPMn
00
- CCF1 CCF0CR
CCON
01
Enable
CCAPnHCCAPnL
16-bit
comparator
MATCH
CHCL
-
00
PCA High-Speed Ouput Mode
To CCFn
TOGn PWMn ECCFnECOMn C APPn CAPNn MATn
10
CCAPMn
Toggle
PCA
interrupt
CEXn
STC12C5Axx Technical Summary 53
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
CCAPnHEPCnH
0
CCAPnLEPCnL
{0, CL [7:0]} < {EP CnL, CCAPnL[7:0]}
{0, CL [7:0]} >= {E PCnL, CCAPnL[7:0]}
1
CEXn
Enable
CL overflow
ECOMn CAPPn CAPNn M ATnTOGn PWMnECCFn
9-BIT
COMPARATOR
0
00000
CL
PCA PWM mode
CCAPMn
54 STC12C5Axx Technical Summary
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
Serial Peripheral Interface(SPI)
The device provides another high-speed serial communication interface, the SPI interface. The SPI is a
full-duplex, high-speed, synchronous communication bus with two operation modes: Master mode and
Slave mode. Up to 3Mbit/s can be supported in either Master or Slave mode under the Fosc=12MHz.
Two status flags are provided to signal the transfer completion and write-collision occurrence.
P1.6
(MISO)
P1.5
(MOSI)
P1.7
(SPICLK)
P1.4
(SS)
Fosc
Clock Divider
4,
16,
64
128
Shift In Register
Shift Out Register
SPI Control
SPI block diagram
I/O control
SPR0SPR1CPHACPOLMSTRDORDSPENSSIG
------WCOLSPIF
SPICTL
SPISTAT
There are three pins implementing the SPI functionality, one of them is SCLK(P1.7), next is MISO(P1.6),
the other is MOSI(P1.5). An extra pin SS(P1.4) is designed to configure the SPI to run under Master or
Slave mode. Data flows from master to slave via MOSI(Master Out Slave In) pin and flows from slave to
master via MISO(Master In Slave Out) pin. The SCLK plays as an output pin when the device works
under Master mode, while as an input pin when the device works under Slave mode. If the SPI system is
disabled, i.e. SPEN(SPCTL.6)=0, these pins are configured as general-purposed I/O port(P1.4 ~ P1.7).
Two devices with SPI interface communicate with each other via one synchronous clock signal , one
input data signal, and one output data signal. There are two concerns the user could take care, one of
them is latching data on the negative edge or positive edge of the clock signal which named polarity, the
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
other is keeping the clock signal low or high while the device idle which named phase. Permuting those
states from polarity and phase, there could be four modes formed, they are SPI-MODE-0, SPI-MODE-1, SPI-MODE-2, SPI-MODE-3. Many device declares that they meet SPI mechanism, but few of them are
adaptive to all four modes. The STC12C5Axx is a device flexible to be configured to communicate to
another device with MODE-0, MODE-1, MODE-2 or MODE-3 SPI, and play part of Master and Slave.
There is a SFR named SPICTL designed to configure the SPI behavior of the device.
SFR:
SPCTL (SPI Control register)
Read/Write Address: 0X85H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
SSIG SPEN DORDMSTRCPOLCPHA SPR1 SPR0
SSIG := used to determine if Ignore the pin SS
0 := (default)
Reserve the function of pin SS
1 :=
Ignore the SS pin function
SPEN := Enable the SPI
0 := (default)
Disable the SPI function. All related pins play as general-purposed I/O ports.
1 :=
Enable the SPI function.
DORD := Data Order
0 := (default)
Transmit/Receive the MSB of the data byte first.
1 :=
Transmit/Receive the LSB of the data byte first.
MSTR := Set to Master mode
0 := (default)
Set the SPI to play as Slave part.
1 :=
Set the SPI to play as Master part.
CPOL := Clock Polarity
0 := (default)
Set the SPCLK as LOW while the communication is kept idle. That implies the leading
edge of the clock is the rising edge, and the trailing edge is the falling
edge.
56 STC12C5Axx Technical Summary
1 :=
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Set the SPCLK as HIGH while the communication is kept idle. That implies the leading
edge of the clock is the falling edge, and the trailing edge is the falling rising edge.
CPHA := Clock Phase
0 := (default)
Data is driven when pin SS is low and changes on the trailing edge of SPCLK,
and is sampled on the leading edge. (This setting is only valid while SSIG==0.)
1 :=
Data is driven on the leading edge of SPCLK, and is sampled on the trailing edge.
{SPR1, SPR0} := SPI clock Rate selector
{0,0} := (default)
Set the clock rate of the SPI as the frequency of the clock source over 4.
{0,1} :=
Set the clock rate of the SPI as the frequency of the clock source over 16.
{1,0} :=
Set the clock rate of the SPI as the frequency of the clock source over 64. {1,1} :=
Set the clock rate of the SPI as the frequency of the clock source over 128.
There are two extra SFRs make relation with SPI application.
SPDAT (SPI Data register)
SFR:
Read/Write Address: 0X86H
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
The SFR SPDAT holds the data to be transmitted or the data received.
SFR: SPSTAT (SPI STATe register)
Read/Write Address: 0X84H
Default: 00XX-XXXX
Bit 7 6 5 4 3 2 1 0
Name
SPIF WCOL
SPIF := SPI transfer completion flag.
When a serial transfer finishes, the SPIF bit is set and an interrupt is generated if both the
ESPI(AUXR.3) bit and the EA(IE.7) bit are set. If SS is an input and is driven low when
SPI is in master mode with SSIG=0, SPIF will also be set to signal the “mode change”.
The SPIF is cleared in software by “writing 1 to this bit”.
WCOL := SPI Write Collision flag
STC12C5Axx Technical Summary 57
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
The WCOL bit is set if the SPI data register SPIDAT is written during a data transfer. The
WCOL flag is cleared in software by “writing 1 to this bit”.
Configure the device to Master/Slave mode
SPEN SSIG SS MSTR Mode MISO MOSI SPICLKRemark
0 X X X SPI disable GPI/O GPI/O GPI/O SPI is disabled.
1 0 0 0 Active Salveoutput inputinput Selected as slave
1 0 1 0 InActive
Hi-Z inputinput Not selected.
Slave
1 0 0 1→0 slave output inputinput Convert from Master to
Slave
1 0 1 1 Master inputoutput output SPCLK depends on
CPOL
1 1 X 0 Slave output inputinput Slave
1 1 X 1 Master inputoutput output Master
58 STC12C5Axx Technical Summary
Typical Connection
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Master
Master/Slave
MISOMISO
MOSIMOSI
SPCLK
SPCLK
SSPort Pin
SPI single master sing l e slave configurartion
MISOMISO
MOSIMOSI
Slave/Master
SPCLK
SPCLK
Slave
SSSS
SPI dual device configuarion, where either can be a maste r or a slave
MISOMISO
MOSIMOSI
Slave #1
SPCLK
SPCLK
SSPort Pin 1
Master
MISO
MOSI
Slave #2
SPCLK
SSPort Pin 2
SPI single master multiple slaves configurartion
STC12C5Axx Technical Summary 59
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Communication
In SPI, transfers are always initiated by the master. If the SPI is enabled(SPEN=1) and selected as
master, any instruction that use SPI data register SPIDAT as the destination will starts the SPI clock
generator and a data transfer. The data will start to appear on MOSI about one half SPI bit-time to one
SPI bit-time after it. Before starting the transfer, the master may select a slave by driving the SS pin of
the corresponding device low. Data written to the SPDAT register of the master shifted out of MOSI pin
of the master to the MOSI pin of the slave. And at the same time the data in SPDAT register of the
selected slave is shifted out of MISO pin to the MISO pin of the master. During one byte transfer, data in
the master and in the slave is interchanged. After shifting one byte, the transfer completion flag(SPIF) is
set and an interrupt will be created if the SPI interrupt is enabled.
If SPEN=1, SSIG=0, SS pin=1 and MSTR=1, the SPI is enabled in master mode. Before the instruction
that use SPDAT as the destination register, the master is in idle state and can be selected as slave
device by any other master drives the idle master SS pin low. Once this happened, MSTR bit of the idle
master is cleared by hardware and changes its state a selected slave. User software should always
check the MSTR bit. If this bit is cleared by the mode change of SS pin and the user wants to continue to
use the SPI as a master later, the user must set the MSTR bit again, otherwise it will always stay in slave
mode.
The SPI is single buffered in transmit direction and double buffered in receive direction. New data for
transmission can not be written to the shift register until the previous transaction is complete. The WCOL
bit is set to signal data collision when the data register is written during transaction. In this case, the data
currently being transmitted will continue to be transmitted, but the new data which causing the collision
will be lost. For receiving data, received data is transferred into a internal parallel read data buffer so that
the shift register is free to accept a second byte. However, the received byte must be read from the data
register(SPDAT) before the next byte has been completely transferred. Otherwise the previous byte is
lost. WCOL can be cleared in software by “writing 1 to the bit”.
60 STC12C5Axx Technical Summary
Typical Timing Diagram
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Clock Cycle
SPCLK/CPOL=0
Driven from Master
SPCLK/CPOL=1
Driven from Master
MOSI (input)
Driven from Master
MISO (output)
SS pin (if SSIG bit = 0 )
Driven from Master
DORD=
DORD=
12345678
DORD=
MSB
65 4 3 21
LSB
12 3 4 56
65 4 3 21
12 3 4 56
0
1
0
DORD=
1
MOSI turns to input
MSB
LSB
MISO turns to output
SPI slave transfer format with CPHA=0
LSB
MSB
LSB
MSB
Clock
Cycle
SPCLK/CPOL=0
Driven from Master
SPCLK/CPOL=1
Driven from Master
MOSI (input)
Driven from Master
MISO (output)
SS pin (if SSIG bit = 0 )
Driven from Master
Clock Cycle
SPCLK/CPOL=0
SPCLK/CPOL=1
MOSI (Output)
MISO (Input)
Driven from the target
slave
Target slave SS pin
Control GPIO pin by software
DORD=
DORD=
MOSI turns to
DORD=
MSB
0
DORD=
LSB
1
MISO turns to
SPICLK is strongly output-driving.
SPEN=1 and MSTR=1, MOSI turns to ou tput data
MISO turns to input da ta
DORD=0
DORD=1
DORD=0
DORD=1
MSB
LSB
MSB
LSB
12345678
MSB
0
1
input
output
65 4 3 21
LSB
12 3 4 56
65 4 3 21
12 3 4 56
SPI slave transfer format with
CPHA=1
12345678
65 4 3 21
12 3 4 56
MOV SPDAT,#data in software
65 4 3 21
12 3 4 56
LSB
MSB
LSB
MSB
SPEN=0 or MSTR=0, MOSI switched not to output
data of SPI communication, also SPICLK is
released from SPI control
The ADC on STC12C5Axx an 10-bit resolution, successive-approximation approach, medium-speed
A/D converter. V
REFP
/ V
is the positive/negative reference voltage input for internal voltage-scaling
REFM
DAC use, the typical sink current on it is 600uA ~ 1mA. For STC12C5A, these two references are
internally tied to VDD and GND, separately.
Conversion is invoked since ADC_START bit is set. Prior to ADC conversion, the desired I/O ports for
analog inputs should be configured as input-only or open-drain mode first. The conversion takes around
a fourth cycles to sample analog input data and other three fourths cycles in successive-approximation
steps. Total conversion time is controlled by two register bits – SPEED1 and SPEED0. Analog input
source comes from P1.
x, one of the eight-channels is multiplexed by analog multiplexer into the
comparator. When conversion is completed, the result will be saved onto {ADC_RES[7:0],
ADC_RESL[1:0]} register. After the result has been loaded onto {ADC_RES[7:0], ADC_RESL[1:0]}
register, ADC_FLAG will be set. ADC_FLAG associated with its enable register IE.5(EADC).
ADC_FLAG should be cleared in software. The ADC interrupt service routine vectors to 2B
. When the
H
chip enters idle mode or power-down mode, the power of ADC is turned off by hardware.
{ADC_RES,ADC_RESL[1:0] =
Vin – V
V
REFP
- V
REFM
REFM
STC12C5Axx Technical Summary 63
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
ADC_CONTR (ADC Control register)
SFR:
Read/Write Address: 0XECH
Default: 0XX0-0000
Bit 7 6 5 4 3 2 1 0
Name ADC_POWERSPEED1 SPEED0ADC_FLAGADC_STARTCHS2 CHAS1 CHS0
ADC_POWER :=
When clear shut down the power of ADC block. When set turn on the power of
ADC block.
{SPEED1, SPEED0} := Conversion speed selector
{0,0} := (default)
A conversion takes 840 clock cycles
{0,1} :=
A conversion takes 630 clock cycles
{1,0} :=
A conversion takes 420 clock cycles
{1,1} :=
A conversion takes 210 clock cycles
ADC_START := ADC Start control
Set to start an A/D conversion. It will be automatically cleared by the device after
the device has finished the conversion.
ADC_FLAG := ADC Interrupt flag
It will be set by the device after the device has finished a conversion, and should
be cleared by the user’s software.
{CHS2, CHS1, CHS0} := Input Channel Selector
{0,0,0} := (default)
Set P1.0 as the A/D channel input
{0,0,1} :=
Set P1.1 as the A/D channel input
{0,1,0} :=
Set P1.2 as the A/D channel input
{0,1,1} :=
Set P1.3 as the A/D channel input
{1,0,0} :=
Set P1.4 as the A/D channel input
{1,0,1} :=
Set P1.5 as the A/D channel input
{1,1,0} :=
Set P1.6 as the A/D channel input
{1,1,1} :=
Set P1.7 as the A/D channel input
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
SFR: ADC_RES (ADC Value register):
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Read/Write Address: 0XBDH
Default: 0000-0000
Bit 7 6 5 4 3 2 1 0
Name
The ADC_RES is the final result from the A/D conversion.
SFR: ADC_RESL (Low Byte of ADC Value register):
Read/Write Address: 0XBEH
Default: XXXX-XX00
Bit 7 6 5 4 3 2 1 0
Name
The ADC_RESL (Low Bytes of ADC Value register)
STC12C5Axx Technical Summary 65
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Power Management
IDLE Mode
An instruction setting PCON.0 causes the device go into the idle mode, the internal clock is
gated off to the CPU but not to the interrupt, timer, PCA, SPI, ADC, WDT and serial port
functions.
There are two ways to terminate the idle. Activation of any enabled interrupt will cause
PCON.0 to be cleared by hardware, terminating the idle mode. The interrupt will be serviced,
and following RETI instruction, the next instruction to be executed will be the one following the
instruction that puts the device into idle. Another way to wake-up from idle is to pull pin RST
high to generate internal hardware reset.
Save Power Consumption under IDLE Mode
A clock divider(CLKDIV) associated with idle mode is used to slow down the system clock
source in order to save power in advance. Everybody knows that slower the clock oscillates,
less power consumed. Software could program this clock divider register prior to enter the idle
mode. When the chip enters the idle mode, the clock is switched to the divider. When the
chip exits the idle mode, clocking will return to the original clock behavior.
SFR:
CLK_DIV (Power Control )
Read/Write Address: 0X97H
Default: XXXX-X000
Bit 7 6 5 4 3 2 1 0
Name CKS2 CKS1 CKS0
{CKS2, CKS1, CKS0}: Clock selector under idle mode
{0, 0,0} : = (default)
In idle mode, clock is not divided (default state)
{0, 0, 1} : =
In idle mode, clock is divided by 2
{0, 1, 0} : =
In idle mode, clock is divided by 4
{0, 1, 1} : =
In idle mode, clock is divided by 8
{1, 0,0} : =
In idle mode, clock is divided by 16
{1, 0, 1} : =
In idle mode, clock is divided by 32
{1, 1, 0} : =
In idle mode, clock is divided by 64
{1, 1, 1} : =
In idle mode, clock is divided by 128
66 STC12C5Axx Technical Summary
POWER-DOWN Mode
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
An instruction setting PCON.1 causes the device go into the POWER-DOWN mode. In the
POWER-DOWN mode, the on-chip oscillator is stopped. The contents of on-chip RAM and
SFRs are maintained.
The power-down mode can be woken-up by either pin RST event or interrupt from INT0 or
INT1. When it is woken-up by RST, the program will execute from the address 0x0000. Be
carefully to keep RST pin active for at least 10ms in order for a stable clock. If it is woken-up
from pin INT0 or INT1, the CPU will rework through jumping to related interrupt service routine.
Before the CPU rework, the clock is blocked and counted until 32768 in order for de-bouncing
the unstable clock. To use INT0/INT1 wake-up, interrupt-related registers have to be enabled
and programmed accurately before entering power-down. Pay attention to add at least one “NOP” instruction subsequent to the power-down instruction if I/O wake-up is used.
SFR: PCON (Power Control)
Read/Write Address: 0X897H
Default: XXXX-X000
Bit 7 6 5 4 3 2 1 0
Name SMOD SMOD0 LVDF POF GF1 GF0 PD IDL
SMOD: = Double baud rate of UART interface
0: =
Keep normal baud rate when the UART is used in mode 1,2 or 3.
1: =
Double baud rate when the UART is used in mode 1,2 or 3.
SMOD0:=
SM0/FE bit select for SFR SCON.7 ; Setting this bit will set SFR SCON.7 as Frame Error function.
Clearing it to set SCON.7 as one bit of UART mode selection bits.
(This bit is serial port related, see the further description about the serial port)
LVDF: = Low-Voltage Flag
After power-up, this bit will be initially set. The user should clear it by his program.
Continuously on operating, it will be set if the power supply drops under 3.7V/2.3V
(Operate in the 5V/3V).
POF: = Power-On flag
This bit will be set after the device was powered on.
It must be cleared by the user’s software.
PD: = Power-Down switch
Set this bit to drive the device enter
POWER-DOWN mode.
STC12C5Axx Technical Summary 67
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
IDL: = Idle flag
Set this bit to drive the device enter
IDLE mode.
68 STC12C5Axx Technical Summary
In System Programming and In Application Programming
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
In System Programming (ISP)
To develop a good program for ISP function, the user has to understand the architecture of the
embedded flash.
The embedded flash consists of 16 pages. Each page contains 512 bytes.
Dealing with flash, the user must erase it in page unit before writing (programming) data into
it.
Erasing flash means setting the content of that flash as FFh. Two erase modes are available
in this chip. One is mass mode and the other is page mode. The mass mode gets more
performance, but it erases the entire flash. The page mode is something performance less,
but it is flexible since it erases flash in page unit.
Unlike RAM’s real-time operation, to erase flash or to write (program) flash often takes long
time so to wait finish.
Furthermore, it is a quite complex timing procedure to erase/program flash. Fortunately, the
STC12C5Axx carried with convenient mechanism to help the user read/change the flash
content. Just filling the target address and data into several SFR, and triggering the built-in
ISP automation, the user can easily erase, read, and program the embedded flash.
There are several SFR designed to help the user implement the ISP functionality.
SFR:
IAP_DATA (ISP Flash Data register)
Bit-7 Bit-6 Bit-5 Bit-4 Bit-3 Bit-2 Bit-1 Bit-0
Data to be written into flash, or data got from flash
IFD is the data port register for ISP/IAP operation. The data in IFD will be written into the desired
address in operating ISP write and it is the data window of readout in operating ISP read.
SFR: IAP_ADDRH (ISP Flash Address High byte)
Bit-7 Bit-6 Bit-5 Bit-4 Bit-3 Bit-2 Bit-1 Bit-0
Must be cleared to 000 ISP/IAP address High byte
IFADRH is the high byte address for all ISP/IAP operation.
Against in advertise effect, if one bit of IFADRH [7:5] is set, the ISP write function must fail.
SFR: IAP_ADDRL (ISP Flash Address Low byte)
Bit-7 Bit-6 Bit-5 Bit-4 Bit-3 Bit-2 Bit-1 Bit-0
ISP/IAP address Low byte
IFADRL is the low byte address for all ISP/IAP operation.
(CPU progressing will be hold here)
(CPU continues and currently IAP_DATA contain the desired data byte )
← 100xx010
set WAIT=010, 11 MC; assumed 10M X’s*/
← (Address high byte) /* specify the address to be read */
← (Address low byte)
Program a byte into flash
/* choice byte-read command */
B
/* set IAPEN=1 to enable flash change.
B
Read a byte from flash
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
STC TECHNOLOGY Co.,Ltd.
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5A08/16/32/60
8-bit micro-controller
In-Application Program (IAP)
The In-Application Program feature is designed for user to Read/Write nonvolatile data flash.
It may bring great help to store parameters those should be independent of power-up and
power-done action. In other words, the user can store data in data flash memory, and after he
shutting down the MCU and rebooting the MCU, he can get the original value, which he had
stored in.
The user can program the data flash according to the same way as ISP program, so he should
get deeper understanding related to SFR IAP_DATA, IAP_ADDRL, IAP_ADDRH, IAPCMD, IAP_TRIG, and IAP_CONTR.
The data flash can be programmed by the AP program as well as the ISP program.
The ISP program may program the AP memory and data flash, while the AP program may
program the data flash but not the ISP memory. If the AP program desires to change the ISP
memory associated with specific address space, the hardware will ignore it.
Instructions Set
DATA TRASFER
MNEMONIC DESCRIPTION BYT CYC
MOV A, Rn Move register to Acc 1 1
MOV A, direct Move direct byte o Acc 2 2
MOV A, @Ri Move indirect RAM to Acc 1 2
MOV A, #data Move immediate data to Acc 2 2
MOV Rn, A Move Acc to register 1 2
MOV Rn, direct Move direct byte to register 2 4
MOV Rn, #data Move immediate data to register 2 2
MOV direct, A Move Acc to direct byte 2 3
MOV direct, Rn Move register to direct byte 2 3
MOV direct, direct Move direct byte to direct byte 3 4
MOV direct, @Ri Move indirect RAM to direct byte 2 4
MOV direct, #data Move immediate data to direct byte 3 3
MOV @Ri, A Move Acc to indirect RAM 1 3
MOV @Ri, direct Move direct byte to indirect RAM 2 3
MOV @Ri, #data Move immediate data to indirect RAM 2 3
MOV DPTR,#data16 Load DPTR with a 16-bit constant 3 3
MOVC A,@A+DPTR Move code byte relative to DPTR to Acc 1 4
MOVC A,@A+PC Move code byte relative to PC to Acc 1 4
PUSH direct PUSH DIRECT BYTE ONTO STACK 2 4
POP direct POP DIRECT BYTE FROM STACK 2 3
XCH A, Rn EXCHANGE REGISTER WITH ACC 1 3
XCH A, direct EXCHANGE DIRECT BYTE WITH ACC 2 4
XCH A, @Ri EXCHANGE INDIRECT RAM WITH ACC 1 4
XCHD A, @Ri EXCHANGE LOW-ORDER DIGIT INDIRECT RAM WITH ACC 1 4
This document contains information on a new product under development by STC.STC reserves the right to change or discontinue this
product without notice. 2007/12 version A1
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
ARITHEMATIC OPERATIONS
MNEMONIC DESCRIPTION BYT CYC
ADD A, Rn ADD REGISTER TO ACC 1 2
ADD A, direct ADD DIRECT BYTE TO ACC 2 3
ADD A, @Ri ADD INDIRECT RAM TO ACC 1 3
ADD A, #data ADD IMMEDIATE DATA TO ACC 2 2
ADDC A, Rn ADD REGISTER TO ACC WITH CARRY 1 2
ADDC A, direct ADD DIRECT BYTE TO ACC WITH CARRY 2 3
ADDC A, @Ri ADD INDIRECT RAM TO ACC WITH CARRY 1 3
ADDC A, #data ADD IMMEDIATE DATA TO ACC WITH CARRY 2 2
SUBB A, Rn SUBTRACT REGISTER FROM ACC WITH BORROW 1 2
SUBB A, direct SUBTRACT DIRECT BYTE FROM ACC WITH BORROW 2 3
SUBB A, @Ri SUBTRACT INDIRECT RAM FROM ACC WITH BORROW 1 3
SUBB A, #data SUBTRACT IMMEDIATE DATA FROM ACC WITH BORROW 2 2
INC A INCREMENT ACC 1 2
INC Rn INCREMENT REGISTER 1 3
INC direct INCREMENT DIRECT BYTE 2 4
INC @Ri INCREMENT INDIRECT RAM 1 4
DEC A DECREMENT ACC 1 2
DEC Rn DECREMENT REGISTER 1 3
DEC direct DECREMENT DIRECT BYTE 2 4
DEC @Ri DECREMENT INDIRECT RAM 1 4
INC DPTR INCREMENT DPTR 1 1
MUL AB MULTIPLY A AND B 1 4
DIV AB DIVIDE A BY B 1 5
DA A DECIMAL ADJUST ACC 1 4
LOGIC OPERATION
MNEMONIC DESCRIPTION BYT CYC
ANL A, Rn AND REGISTER TO ACC 1 2
ANL A, direct AND DIRECT BYTE TO ACC 2 3
ANL A, @Ri AND INDIRECT RAM TO ACC 1 3
ANL A, #data AND IMMEDIATE DATA TO ACC 2 2
ANL direct, A AND ACC TO DIRECT BYTE 2 4
ANL direct, #data AND IMMEDIATE DATA TO DIRECT BYTE 3 4
ORL A, Rn OR REGISTER TO ACC 1 2
ORL A, direct OR DIRECT BYTE TO ACC 2 3
ORL A, @Ri OR INDIRECT RAM TO ACC 1 3
ORL A, #data OR IMMEDIATE DATA TO ACC 2 2
ORL direct, A OR ACC TO DIRECT BYTE 2 4
ORL direct, #data OR IMMEDIATE DATA TO DIRECT BYTE 3 4
XRL A, Rn EXCLUSIVE-OR REGISTER TO ACC 1 2
XRL A, direct EXCLUSIVE-OR DIRECT BYTE TO ACC 2 3
XRL A, @Ri EXCLUSIVE-OR INDIRECT RAM TO ACC 1 3
XRL A, #data EXCLUSIVE-OR IMMEDIATE DATA TO ACC 2 2
XRL direct, A EXCLUSIVE-OR ACC TO DIRECT BYTE 2 4
XRL direct, #data EXCLUSIVE-OR IMMEDIATE DATA TO DIRECT BYTE 3 4
CLR A CLEAR ACC 1 1
CPL A COMPLEMENT ACC 1 2
RL A ROTATE ACC LEFT 1 1
RLC A ROTATE ACC LEFT THROUGH THE CARRY 1 1
RR A ROTATE ACC RIGHT 1 1
RRC A ROTATE ACC RIGHT THROUGH THE CARRY 1 1
SWAP A SWAP NIBBLES WITHIN THE ACC 1 1
BOOLEAN VARIABLE MANIPULATION
MNEMONIC DESCRIPTION BYT CYC
CLR C CLEAR CARRY 1 1
CLR bit CLEAR DIRECT BIT 2 4
SETB C SET CARRY 1 1
SETB bit SET DIRECT BIT 2 4
CPL C COMPLEMENT CARRY 1 1
CPL bit COMPLEMENT DIRECT BIT 2 4
ANL C, bit AND DIRECT BIT TO CARRY 2 3
STC12C5Axx Technical Summary 73
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
ANL C, /bit AND COMPLEMENT OF DIRECT BIT TO CARRY 2 3
ORL C, bit OR DIRECT BIT TO CARRY 2 3
ORL C, /bit OR COMPLEMENT OF DIRECT BIT TO CARRY 2 3
MOV C, bit MOVE DIRECT BIT TO CARRY 2 3
MOV bit, C MOVE CARRY TO DIRECT BIT 2 4
BOOLEAN VARIABLE BRANCH
MNEMONIC DESCRIPTION BYT CYC
JC rel JUMP IF CARRY IS SET 2 3
JNC rel JUMP IF CARRY NOT SET 2 3
JB bit, rel JUMP IF DIRECT BIT IS SET 3 4
JNB bit, rel JUMP IF DIRECT BIT NOT SET 3 4
JBC bit, rel JUMP IF DIRECT BIT IS SET AND THEN CLEAR BIT 3 5
PROAGRAM BRACHING
MNEMONIC DESCRIPTION BYT CYC
ACALL addr11 ABSOLUTE SUBROUTINE CALL 2 6
LCALL addr16 LONG SUBROUTINE CALL 3 6
RET RETURN FROM SUBROUTINE 1 4
RETI RETURN FROM INTERRUPT SUBROUTINE 1 4
AJMP addr11 ABSOLUTE JUMP 2 3
LJMP addr16 LONG JUMP 3 4
SJMP rel SHORT JUMP 2 3
JMP @A+DPTR JUMP INDIRECT RELATIVE TO DPTR 1 3
JZ rel JUMP IF ACC IS ZERO 2 3
JNZ rel JUMP IF ACC NOT ZERO 2 3
CJNE A, direct, rel COMPARE DIRECT BYTE TO ACC AND JUMP IF NOT EQUAL 3 5
CJNE A, #data, rel COMPARE IMMEDIATE DATA TO ACC AND JUMP IF NOT EQUAL 3 4
CJNE Rn, #data, rel
CJNE @Ri, #data, rel COMPARE IMMEDIATE DATA TO INDIRECT RAM AND JUMP IF NOT 3 5
EQUAL
DJNZ Rn, rel DECREMENT REGISTER AND JUMP IF NOT EQUAL 2 4
DJNZ direct, rel DECREMENT DIRECT BYTE AND JUMP IF NOT EQUAL 3 5
NOP NO OPERATION 1 1
MNEMONIC DESCRIPTION BYT CYC
MOVX A, @Ri Move external RAM(8-bit address) to Acc 1 3
MOVX A, @DPTR MOVE EXTERNAL RAM(16-BIT ADDRESS) TO ACC 1 2
MOVX @Ri, A MOVE ACC TO EXTERNAL RAM(8-BIT ADDRESS) 1 3
MOVX @DPTR, A MOVE ACC TO EXTERNAL RAM(16-BIT ADDRESS) 1 2
COMPARE IMMEDIATE DATA TO REGISTER AND JUMP IF NOT
EQUAL
****** INHIBITED INSTRUCTION ******
3 4
74 STC12C5Axx Technical Summary
Absolute Maximum Rating (STC12C5Axx)
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Parameter Rating
Operating Voltage 4.5V ~ 5.5V
Operating temperature under bias -40oC ~ 85oC*1
Storage temperature -40oC ~ 125oC
Voltage on any pin -0.5 ~ 5.5V
Operating Frequency DC ~ 25MHz
*1
Tested by sampling
DC Characteristics
VSS = 0V, TA = 25 ℃, V
CC
(STC12C5Axx)
= 5.0V
unless otherwise specified
Symbol Parameter Test
Condition
V
IH1
V
IH2
Input High voltage for P1 and P3
Input High voltage for RESET pin
VIL Input Low voltage
IOL Output Low current V
I
Output High current(push-pull) V
OH1
I
Output High current(Quasi-bidirectional) V
OH2
I
Logic 0 input current(Quasi-bidirectional) V
IL1
I
Logic 0 input current(Input-Only) V
IL2
ILK Input Leakage current(Open-Drain output)V
I
Logic 1 to 0 transition current V
H2L
IOP Operating current F
I
Idle mode current F
IDLE
IPD Power down current V
Vcc=5.0V
Vcc=5.0V
Vcc=5.0V
=0.45V 12 20 mA
PIN
=2.4V 12 20 mA
PIN
=2.4V 220 uA
PIN
=0.45V 17 50 uA
PIN
=0.45V 0 10 uA
PIN
= VCC 0 10 uA
PIN
=1.8V 230 500 uA
PIN
= 12MHz 12 30 mA
OSC
= 12MHz 6 15 mA
OSC
=5.0V 0.1 50 uA
CC
Limits Unit
min typ max
2.0 V
3.5 V
0.8 V
R
Internal reset pull-down resistance V
RST
=5.0V 100 Kohm
CC
STC12C5Axx Technical Summary 75
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Absolute Maximum Rating (STC12LE5Axx)
Parameter Rating
Operating Voltage 2.4V ~ 3.6V
Operating temperature under bias -40oC ~ 85oC*1
Storage temperature -40oC ~ 125oC
Voltage on any pin -0.5 ~ 3.6V
Operating Frequency DC ~ 25MHz
*1
Tested by sampling
DC Characteristics
VSS = 0V, TA = 25 ℃, V
CC
(STC12LE5Axx)
= 3.3V
unless otherwise specified
Symbol Parameter Test
Condition
V
IH1
V
IH2
Input High voltage for P1 and P3
Input High voltage for RESET pin
VIL Input Low voltage
IOL Output Low current V
I
Output High current(push-pull) V
OH1
I
Output High current(Quasi-bidirectional) V
OH2
I
Logic 0 input current(Quasi-bidirectional) V
IL1
I
Logic 0 input current(Input-Only) V
IL2
ILK Input Leakage current(Open-Drain output)V
I
Logic 1 to 0 transition current(P1,3) V
H2L
IOP Operating current F
I
Idle mode current F
IDLE
IPD Power down current V
Vcc=3.3V
Vcc=3.3V
Vcc=3.3V
=0.45V 8 14 mA
PIN
=2.4V 4 8 mA
PIN
=2.4V 64 uA
PIN
=0.45V 7 50 uA
PIN
=0.45V 0 10 uA
PIN
= VCC 0 10 uA
PIN
=1.4V 100 600 uA
PIN
= 12MHz 9 15 mA
OSC
= 12MHz 3.5 6 mA
OSC
=3.3V 0.1 50 uA
CC
Limits Unit
min typ max
2.0 V
2.8 V
0.8 V
R
Internal reset pull-down resistance V
RST
=3.3V 100 Kohm
CC
76 STC12C5Axx Technical Summary
Package Dimension
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
STC12C5Axx Technical Summary 77
http://www.DataSheet4U.net/
datasheet pdf - http://www.DataSheet4U.net/
Version History
Version Date PageDescription
A1 2008/09
Initial issue
-
-
-
78 STC12C5Axx Technical Summary
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.