Rainbow Electronics AT89C51SND1C User Manual

Features

MPEG I/II-Layer 3 Hardwired Decoder
– Stand-alone MP3 Decoder – 48, 44.1, 32, 24, 22.05, 16 kHz Sampling Frequency – Separated Digital Volume Control on Left and Right Channels (Software Control
using 31 Steps) – Bass, Medium, and Treble Control (31 Steps) – Bass Boost Sound Effect – Ancillary Data Extraction – CRC Error and MPEG Frame Synchronization Indicators
Programmable Audio Output for Interfacing with Common Audio DAC
PCM Format CompatibleI2S Format Compatible
8-bit MCU C51 Core Based (F
2304 Bytes of Internal RAM
64K Bytes of Code Memory
AT89C51SND1C: Flash (100K Eras e/Write Cycles)AT83C51SND1C: ROM
4K Bytes of Boot Flash Memory (AT89C51SND1C)
ISP: Download from USB or UART
USB Rev 1.1 Controller
Full Speed Data Transmission
Built-in PLL
MP3 Audio ClocksUSB Clock
MultiMedia Card
Atmel DataFlash
IDE/ATAPI Interface
2 Channels 10-bit ADC, 8 kHz (8-true bit)
Battery V ol tage MonitoringVoice Recording Controlled by Software
Up to 44 Bits of General-purpose I/Os
4-bit Interrupt Keyboard Port for a 4 x n MatrixSmartMedia
2 Standard 16-bit Timers/Counters
Hardware Watchdog Timer
Standard Full Duplex UART with Baud Rate Generator
Two Wire Master and Slave Modes Controller
SPI Master and Slave Modes Controller
Power Management
Power-on ResetSoftware Programmable MCU ClockIdle Mode, Power-down Mode
Operating Conditions:
3V , ±10%, 25 mA Typical Operating at 25°CTemperature Range: -40°C to +85 °C
Packages
TQFP80, BGA81, PLCC84 (Development Board)Dice
®
Interface Compatibility
®
SPI Interface Compatibility
®
Software Interface
= 20 MHz)
MAX
Single-Chip Flash Microcontroller with MP3 Decoder and Human Interface
AT83C51SND1C AT89C51SND1C
Preliminary

Description

The AT8xC51SND1C are fully integr ated stan d-alone ha rdwired M PEG I/II-L ayer 3 decoder with a C51 microcontroller core handling data flow and MP3-player control.
The AT89C51SND1C includes 64K Bytes of Flash memory and allows In-System Pro­gramming through an embedded 4K Bytes of Boot Flash memory.
Rev. 4109E–8051–06/0 3
The AT83C51SND1C includes 64K Bytes of ROM memory. The AT8xC51SND1C include 2304 Bytes of RAM memory. The AT8xC51SND1C provides the necessary features for human interface like timers,
keyboard port, serial or parallel interface (USB, TWI, SPI, IDE), ADC input, I and all external memory interface (NAND or NOR Flash, SmartMedia, MultiMedia, DataFlash cards).

Typical Applications MP3-Player

PDA, Camera, Mobile Phone MP3
Car Audio/Multimedia MP3
Home Audio/Multimedia MP3

Block Diagram

Figure 1. AT8xC51SND1C Block Diagram
INT0 INT1 MOSIMISO
33
Interrupt
Handler Unit
VSSVDD
RAM
2304 Bytes
UVSSUVDD
Flash ROM
64 KBytes
Flash Boot
4 KBytes
AVSSAVDD
AIN1:0
AREF
10-bit A to D
Converter
or
10-bit ADC
2
S output,
RXDTXD
33 33444411
UART
and
BRG
T1T0
Timers 0/1
Watchdog
SS
SPI/DataFlash
Controller
SCK
SCL SDA
TWI
Controller
C51 (X2 Core)
Clock and PLL
Unit
FILT X2X1
1 Alternate function of Port 1 3 Alternate function of Port 3 4 Alternate function of Port 4
RST
MP3 Decoder
Unit
ISP
ALE
8-Bit Internal Bus
I2S/PCM
Audio Interface
DSELDCLK SCLKDOUT
USB
Controller
D+ D-
MCLK
MMC
Interface
MDAT
MCMD
Keyboard
Interface
1
KIN3:0
I/O
Ports
IDE
Interface
P0-P5
2
AT8xC51SND1C
4109E–8051–06/03

Pin Description

Pinouts Figure 2. AT89C51SND1C 80-pin QFP Package

P0.3/AD3
P0.4/AD4
P0.5/AD5
VSS
VDD
717069
72
P0.6/AD6
ALE
ISP
/NC P1.0/KIN0 P1.1/KIN1 P1.2/KIN2 P1.3/KIN3
P1.4 P1.5
P1.6/SCL
P1.7/SDA
VDD
PVDD
FILT
PVSS
VSS
X2 X1
TST UVDD UVSS
P0.2/AD2
P0.1/AD1
P0.0/AD0
P5.0
P5.1
73
74
75
76
77
78
79
80
1
(1)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
AT89C51SND1C-RO (FLASH)
AT83C51SND1C-RO (ROM)
P0.7/AD7
AT8xC51SND1C
P2.0/A8
P4.3/SS
68
P4.2/SCK
67
P4.1/MOSI
66
P4.0/MISO
65
64
P2.1/A9
63
P4.7
62
P4.6
61
60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41
P4.5 P4.4 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 VSS VDD MCLK MDAT MCMD RST SCLK DSEL DCLK DOUT VSS VDD
21222324252627
D-
D+
VSS
VDD
P3.0/RXD
28
302932
P3.4/T0
P3.1/TXD
P3.2/INT0
P3.5/T1
P3.3/INT1
31
P3.6/WR
33
34353637383940
AVSS
AVDD
P3.7/RD
AREFP
Note: 1. ISP pin is only available in AT89C51SND1C product.
Do not connect this pin on AT83C51SND1C product.
P5.3
P5.2
AIN1
AIN0
AREFN
4109E–8051–06/03
3
Figure 3. AT8xC51SND1C 81-pin BGA Package
P4.6
P4.4
P2.5/
A13
P2.4/
A12
VDD
RST
DSEL
DCLK
89765432
P2.0/
P4.7
P2.2/
P2.6/
A14
P2.3/
A11
MCMD
SCLK
VSS
P4.0/
MISO SCK AD2
P4.1/
MOSI
P2.1/
A9A10
P4.5
VSS
MCLK
DOUT
AIN1
P4.2/
P4.3/
SS
P0.6
P0.7/
AD7 AD5
P2.7/
A15
MDAT
P5.3
AVSS
VDD
P0.1/
VSS
P0.5/
AVDD
P3.7/
AIN0
RD
P0.2/
P0.4/
AD4 AD0AD1
P5.1
P1.6/
SCL SDA
FILT
P3.4/
T0
P3.5/
T1
P3.3/
INT1
P0.3/
AD3A8
P0.0/
P1.0/ KIN0
P1.7/
PVDD
UVSS
VDD
P3.1/
TXD
P5.0
ISP
(1)
NC
P1.3/ KIN3
P1.5
X1
PVSS
TST
D-
1
ALE
/
P1.1
P1.2/ KIN2
P1.4
VDD
X2
VSS
UVDD
A
B C
D
E
F
G
H
VDD
P5.2
AREFP
AREFN
P3.6/
WR
P3.2/
INT0
P3.0/
RXD
Note: 1. ISP pin is only available in AT89C51SND1C product.
Do not connect this pin on AT83C51SND1C product.
VSS
D+
J
4
AT8xC51SND1C
4109E–8051–06/03
Figure 4. AT8xC51SND1C 84-pin PLCC Package
P0.3/AD3
P0.4/AD4
P0.5/AD5
VSS
VDD
P0.6/AD6
P0.7/AD7
1
84838281807978
43
444546474849505152
ALE
ISP P1.0/KIN0 P1.1/KIN1 P1.2/KIN2 P1.3/KIN3
P1.4 P1.5
P1.6/SCL
P1.7/SDA
VDD
PAVDD
FILT
PAVSS
VSS
X2
NC
X1
TST
UVDD
UVSS
NC
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
3334353637
P5.1
10
P0.2/AD2
P0.1/AD1
P5.0
P0.0/AD0
432
5
6
7
8
9
AT89C51SND1C-SR (FLASH)
3839404142
AT8xC51SND1C
P2.0/A8
P4.0/MISO
P2.1/A9
77
P4.7
76
P4.6
75
53
74 73 7271P4.4
70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54
P4.2/SCK
P4.1/MOSI
P4.3/SS
NC P4.5
P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 VSS VDD MCLK MDAT MCMD RST SCLK DSEL DCLK DOUT VSS VDD
D+
D-
VSS
VDD
P3.4/T0
P3.5/T1
P3.0/RXD
P3.1/TXD
P3.3/INT1
P3.2/INT0
P3.6/WR
P3.7/RD
AVSS
AVDD
AREFP
AIN1
AIN0
AREFN
NC
P5.2
P5.3
4109E–8051–06/03
5

Signals All the AT8xC51SND1C signals are detailed by functionality in Table 1 to Table 14.

Table 1. Ports Signal Description
Signal
Name Type Description
Port 0
P0.7:0 I/O
P1.7:0 I/O
P2.7:0 I/O
P3.7:0 I/O
P4.7:0 I/O
P0 is an 8-bit open-drain bidirectional I/O port. Port 0 pins that have 1s written to them float and can be used as high impedance inputs. To avoid any parasitic current consumption, floating P0 inputs must be polarized to V
Port 1
P1 is an 8-bit bidirectional I/O port with internal pull-ups.
Port 2
P2 is an 8-bit bidirectional I/O port with internal pull-ups.
Port 3
P3 is an 8-bit bidirectional I/O port with internal pull-ups.
Port 4
P4 is an 8-bit bidirectional I/O port with internal pull-ups.
DD
Alternate
Function
AD7:0
or VSS.
KIN3:0
SCL SDA
A15:8
RXD TXD
INT0 INT1
T0 T1
WR
RD
MISO MOSI
SCK
SS
P5.3:0 I/O
Port 5
P5 is a 4-bit bidirectional I/O port with internal pull-ups.
Table 2. Clock Si gna l Desc r ipt ion
Signal
Name Type Description
Input to the on-chip inverting oscillator amplifier
X1 I
X2 O
FILT I
To use the internal oscillator, a crystal/resonator circuit is connected to this pin. If an external oscillator is used, its output is connected to this pin. X1 is the clock source for internal timing.
Output of the on-chip inverting oscillator amplifier
To use the internal oscillator, a crystal/resonator circuit is connected to this pin. If an external oscillator is used, leave X2 unconnected.
PLL Low Pass Filter input
FILT receives the RC network of the PLL low pass filter.
-
Alternate
Function
-
-
-
6
AT8xC51SND1C
4109E–8051–06/03
Table 3. Timer 0 and Timer 1 Signal Description
AT8xC51SND1C
Signal
Name Type Description
Timer 0 Gate Input
serves as external run control for timer 0, when selected by
INT0 GATE0 bit in TCON register.
INT0
INT1
T0 I
T1 I
I
External Interrupt 0
INT0
input sets IE0 in the TCON register. If bit IT0 in this register is set, bit IE0 is set by a falling edge on INT0#. If bit IT0 is cleared, bit IE0 is set by a low level on INT0#.
Timer 1 Gate Input
serves as external run control for timer 1, when selected by
INT1 GATE1 bit in TCON register.
I
External Interrupt 1
INT1
input sets IE1 in the TCON register. If bit IT1 in this register is set, bit IE1 is set by a falling edge on INT1#. If bit IT1 is cleared, bit IE1 is set by a low level on INT1#.
Timer 0 External Clock Input
When timer 0 operates as a counter, a falling edge on the T0 pin increments the count.
Timer 1 External Clock Input
When timer 1 operates as a counter, a falling edge on the T1 pin increments the count.
Table 4. Audio Interface Signal Description
Alternate
Function
P3.2
P3.3
P3.4
P3.5
Signal
Name Type Description
DCLK O DAC Data Bit Clock -
DOUT O DAC Audio Data -
DSEL O
SCLK O
DAC Channel Select Signal
DSEL is the sample rate clock output.
DAC System Clock
SCLK is the oversampling clock synchronized to the digital audio data (DOUT) and the channel selection signal (DSEL).
Table 5. USB Controller Signal Description
Signal
Name Type Description
D+ I/O
D- I/O USB Negative Data Upstream Port -
USB Positive Data Upstream Port
This pin requires an external 1.5 K pull-up to V operation.
for full speed
DD
Alternate
Function
-
-
Alternate
Function
-
4109E–8051–06/03
7
Table 6. MutiMediaCard Interface Signal Description
Signal
Name Type Description
MCLK O
MCMD I/O
MDAT I/O
MMC Clock output
Data or command clock transfer.
MMC Command line
Bidirectional command channel used for card initialization and data transfer commands. To avoid any parasitic current consumption, unused MCMD input must be polarized to V
MMC Data line
Bidirectional data channel. To avoid any parasitic current consumption, unused MDAT input must be polarized to V
Table 7. UART Signal Description
Signal
Name Type Description
Receive Serial Data
RXD I/O
TXD O
RXD sends and receives data in serial I/O mode 0 and receives data in serial I/O modes 1, 2 and 3.
Transmit Serial Data
TXD outputs the shift clock in serial I/O mode 0 and transmits data in serial I/O modes 1, 2 and 3.
DD
or VSS.
DD
Alternate
Function
-
-
or VSS.
-
Alternate
Function
P3.0
P3.1
Table 8. SPI Controller Signal Description
Signal
Name Type Description
MISO I/O
MOSI I/O
SCK I/O
SS
SPI Master Input Slave Output Data Line
When in master mode, MISO receives data from the slave peripheral. When in slave mode, MISO outputs data to the master controller.
SPI Master Output Slave Input Data Line
When in master mode, MOSI outputs data to the slave peripheral. When in slave mode, MOSI receives data from the master controller.
SPI Clock Line
When in master mode, SCK outputs clock to the slave peripheral. When in slave mode, SCK receives clock from the master controller.
SPI Slave Select Line
I
When in controlled slave mode, SS
Table 9. TWI Controller Signal Description
Signal
Name Type Description
TWI Serial Clock
SCL I/O
When TWI controller is in master mode, SCL outputs the serial clock to the slave peripherals. When TWI controller is in slave mode, SCL receives clock from the master controller.
enables the slave mode.
Alternate
Function
P4.0
P4.1
P4.2
P4.3
Alternate
Function
P1.6
SDA I/O
8
AT8xC51SND1C
TWI Serial Data
SDA is the bidirectional Two Wire data line.
P1.7
4109E–8051–06/03
Table 10. A/D Converter Signal Description
AT8xC51SND1C
Signal
Name Type Description
AIN1:0 I A/D Converter Analog Inputs -
AREFP I Analog Positive Voltage Reference Input -
AREFN I
Analog Negative Voltage Reference Input
This pin is internally connected to AVSS.
Table 11. Keypad Interface Signal Description
Signal
Name Type Description
KIN3:0 I
Keypad Input Lines
Holding one of these pins high or low for 24 oscillator periods triggers a keypad interrupt.
Table 12. External Access Signal Description
Signal
Name Type Description
Address Lines
A15:8 I/O
Upper address lines for the external bus. Multiplexed higher address and data lines for the IDE interface.
Alternate
Function
-
Alternate
Function
P1.3:0
Alternate
Function
P2.7:0
AD7:0 I/O
ALE O
ISP
RD
WR
I/O
O
O
Address/Data Lines
Multiplexed lower address and data lines for the external memory or the IDE interface.
Address Latch Enable Output
ALE signals the start of an external bus cycle and indicates that valid address information is available on lines A7:0. An external latch is used to demultiplex the address from address/data bus.
ISP Enable Input AT89C51SND1C Only
This signal must be held to GND through a pull-down resistor at the falling reset to force execution of the internal bootloader.
Read Signal
Read signal asserted during external data memory read operation.
Write Signal
Write signal asserted during external data memory write operation.
P0.7:0
-
-
P3.7
P3.6
4109E–8051–06/03
9
Table 13. System Signal Description
Signal
Name Type Description
Reset Input
Holding this pin high for 64 oscillator periods while the oscillator is running resets the device. The Port pins are driven to their reset conditions when a voltage lower than V
RST I
TST
oscillator is running. This pin has an internal pull-down resistor which allows the device to be reset by connecting a capacitor between this pin and V Asserting RST when the chip is in Idle mode or Power-Down mode returns the chip to normal operation.
Test Input
I
Tes t mode entry signal. This pin must be set to V
Table 14. Power Signal Description
Signal
Name Type Description
VDD PWR
VSS GND
AVDD PWR
Digital Supply Voltage
Connect these pins to +3V supply voltage.
Circuit Ground
Connect these pins to ground.
Analog Supply Voltage
Connect this pin to +3V supply voltage.
is applied, whether or not the
IL
.
DD
.
DD
Alternate
Function
-
-
Alternate
Function
-
-
-
AVSS GND
PVDD PWR
PVSS GND
UVDD PWR
UVSS GND
Analog Ground
Connect this pin to ground.
PLL Supply voltage
Connect this pin to +3V supply voltage.
PLL Circuit Ground
Connect this pin to ground.
USB Supply Voltage
Connect this pin to +3V supply voltage.
USB Ground
Connect this pin to ground.
-
-
-
-
-
10
AT8xC51SND1C
4109E–8051–06/03

Internal Pin Structure Table 15. Detailed Internal Pin Structure

(1)
Circuit
VDD
AT8xC51SND1C
Type Pins
Watchdog Output
Latch Output
TST
R
2 osc
periods
VDD VDD
P
1
N
VSS
VDD
P
N
VDD
P
VSS
P
Input TST
Input/Output RST
RST
R
VDD
(2)
P
3
2
Input/Output
P1 P2
(3)
P3 P4
P53:0
P0
Input/Output
MCMD
MDAT
ISP
VSS
VDD
ALE
SCLK
P
N
VSS
D+
Output
Input/Output
DCLK
DOUT
DSEL MCLK
D+ D-
D-
Notes: 1. For information on resistors value, input/output levels, and drive capability, refer to
the Section DC Characteristics, page 181.
2. When the Two Wire controller is enabled, P
, P2, and P3 transistors are disabled
1
allowing pseudo open-drain structure.
3. In Port 2, P1 transistor is continuously driven when outputting a high level bit address (A15:8).
4109E–8051–06/03
11

Clock Controller The AT8xC51SND1C clock controller is based on an on-chip oscillator feeding an on-

chip Phase Lock Loop (PLL). All internal clocks to the peripherals and CPU core are generated by this controller.

Oscillator The AT8xC51SND1C X1 and X2 pins are the input and the output of a single -stage on-

chip inverter (see Figure 5) that can be configured with off-chip components such as a Pierce oscillator (see Figure 6). Value of capacitors and crystal characteristics are detailed in the section DC Characteristics”.
The oscillator outputs three different clocks: a clock for the PLL, a clock for the CPU core, and a clock for the per ipherals as shown in Figu re 5. These clocks are either enabled or disabled, de pendin g on th e power red uctio n mode as detailed in the sec tion Power Management on page 46. The peripheral clock is used to generate the Timer 0, Timer 1, MMC, ADC, SPI, and Port sampling clocks.
Figure 5. Oscillator Block Diagram and Symbol
CPU
0 1
X2
CKCON.0
Peripheral Clock
CPU Core Clock
IDL
PCON.0
Oscillator Clock
OSC
CLOCK
Oscillator Clock Symbol
X1
X2
PD
PCON.1
PER
CLOCK
Peripheral Clock Symbol
÷ 2
CLOCK
CPU Core Clock Symbol
Figure 6. Crystal Connection
X1
C1
Q
C2
VSS
X2

X2 Feature Unlike standard C51 products that require 12 oscillator clock periods per machine cycle,

the AT8xC51SND1C need only 6 oscillator clock periods per machine cycle. This fea­ture called the X2 feature can be enabl ed usin g the X2 b it and allows the AT8x C51SND1C to operate in 6 or 12 oscillator cloc k periods per machine cycle. As shown in Figure 5, both CPU and peripheral clocks are affected by this feature. Figure 7 shows the X2 mode switching waveforms. After reset the standard mode is activated. In standard mode the CPU and peripheral clock frequency is the oscillator frequency divided by 2 while in X2 mode, it is the oscillator frequency.
(1)
in CKCON (see Table 16)
12
Note: 1. The X2 bit reset value depends on the X2B bit in the Hardware Security Byte (see
Table 22 on page 22). Using the AT89C51SND1C (Flash Version) the system can boot either in standard or X2 mode depending on the X2B value. Using AT83C51SND1C (ROM Version) the system always boots in standard mode. X2B bit can be changed to X2 mode later by software.
AT8xC51SND1C
4109E–8051–06/03
Figure 7. Mode Switching Waveforms
X1
X1 ÷ 2
X2 Bit
Clock
AT8xC51SND1C
STD Mode STD Mode
Note: 1. In order to prevent any incorrect operation while operating in X2 mode, user must be
aware that all peripherals using clock frequency as time reference (timers, etc.) will have their time reference divided by 2. For example, a free running timer generating an interrupt every 20 ms will then generate an interrupt every 10 ms.
X2 Mode
(1)
PLL
PLL Description The AT8xC51SND1C PLL is us ed to generate internal hi gh frequency clo ck (the PLL
Clock) synchronized with an ex ternal low-frequency (the O scillator Clock). The P LL clock provides the MP3 decoder, the audi o interface, and the USB interface cl ocks. Figure 8 shows the internal structure of the PLL.
The PFLD block is the Phase Frequency Comparator and Lock Detector. This block makes the comparison between the reference clock coming from the N divider and the reverse clock coming from the R divider and generates some pulses on the Up or Down signal dependin g on the edge posi tion of the r everse c lock. The P LLEN bit in PLLCO N register is used to enab le the c lock gene ratio n. When the PLL is l ocked, th e bit PL OCK in PLLCON register (see Table 17) is set.
The CHP block is the Charge Pump that generates the voltage reference for the VCO by injecting or extracting charges from the exter nal filte r connected on PFILT pin (see Figure 9). Value of the filter components are detailed in the Section “DC Characteristics”.
4109E–8051–06/03
The VCO block is the Voltage Controlled Oscillator controlled by the voltage V duced by the charge pump. It generates a square wave signal: the PLL clock.
Figure 8. PLL Block Diagram and Symbol
PFILT
CHP
R divider
R9:0
Vref
VCO
PLL
CLOCK
PLL Clock Symbol
OSC
CLOCK
N divider
N6:0
PLLclk
PLLCON.1
PLLCON.0
OSCclk R 1+()×
-----------------------------------------------= N1+
PLLEN
Up
PFLD
Down
PLOCK
ref
PLL Clock
pro-
13
Figure 9. PLL Filter Connection
FILT
R
C1
VSS
C2
VSS
PLL Programming The PLL is programmed using the flow shown in Figure 10. As soon as clock generation
is enabled, the user must wait until the lo ck indic ator is set to ens ure the cl ock output is stable. The PLL clock fr equenc y will dep end on MP 3 deco der cloc k and au dio int erfac e clock frequencies.
Figure 10. PLL Programming Flow
PLL
Programming
Configure Dividers
N6:0 = xxxxxxb
R9:0 = xxxxxxxxxxb
Enable PLL
PLLRES = 0
PLLEN = 1
PLL Locked?
PLOCK = 1?
14
AT8xC51SND1C
4109E–8051–06/03

Registers Table 16. CKCON Register

CKCON (S:8Fh) – Clock Control Register
76543210
- WDX2 - - - T1X2 T0X2 X2
AT8xC51SND1C
Bit
Number
7-
6WDX2
5 - 3 -
2T1X2
1T0X2
0X2
Bit
Mnemonic Description
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Watchdog Clock Control Bit
Set to select the oscillator clock divided by 2 as watchdog clock input (X2 independent). Clear to select the peripheral clock as watchdog clock input (X2 dependent).
Reserved
The values read from these bits are indeterminate. Do not set these bits.
Timer 1 Clock Control Bit
Set to select the oscillator clock divided by 2 as timer 1 clock input (X2 independent). Clear to select the peripheral clock as timer 1 clock input (X2 dependent).
Timer 0 Clock Control Bit
Set to select the oscillator clock divided by 2 as timer 0 clock input (X2 independent). Clear to select the peripheral clock as timer 0 clock input (X2 dependent).
System Clock Control Bit
Clear to select 12 clock periods per machine cycle (STD mode, F
/2).
F
OSC
Set to select 6 clock periods per machine cycle (X2 mode, F
CPU
CPU
= F
= F
PER
Reset Value = 0000 000Xb (AT89C51SND1C) or 0000 0000b (AT83C51SND1C) Table 17. PLLCON Register
PLLCON (S:E9h) – PLL Control Register
= F
PER
=
OSC
).
4109E–8051–06/03
76543210
R1 R0 - - PLLRES - PLLEN PLOCK
Bit
Number
7 - 6 R1:0
5 - 4 -
3 PLLRES
2-
1 PLLEN
0PLOCK
Bit
Mnemonic Description
PLL Least Significant Bits R Divider
2 LSB of the 10-bit R divider.
Reserved
The values read from these bits are always 0. Do not set these bits.
PLL Reset Bit
Set this bit to r e set the PLL. Clear this bit to free the PLL and allow enabling.
Reserved
The value read from this bit is always 0. Do not set this bit.
PLL Enable Bit
Set to enable the PLL. Clear to disable the PLL.
PLL Lock Indicator
Set by hardware when PLL is locked. Clear by hardware when PLL is unlocked.
Reset Value = 0000 1000b
15
Table 18. PLLNDIV Register
PLLNDIV (S:EEh) – PLL N Divider Register
76543210
- N6N5N4N3N2N1N0
Bit
Number
7-
6 - 0 N6:0
Bit
Mnemonic Description
Reserved
The value read from this bit is always 0. Do not set this bit.
PLL N Divider
7 - bit N divider.
Reset Value = 0000 0000b
Table 19. PLLRDIV Register PLLRDIV (S:EFh) – PLL R Divider Register
76543210
R9 R8 R7 R6 R 5 R4 R3 R2
Bit
Number
7 - 0 R9:2
Bit
Mnemonic Description
PLL Most Significant Bits R Divider
8 MSB of the 10-bit R divider.
Reset Value = 0000 0000b
16
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Program/Code Memory

The AT8xC51SND1C implement 64K Bytes of on-chip program/c ode memory. Figure 11 shows the split of internal and external program/code memory spaces depending on the product.
The AT83C51SND1C product provides the internal program/code memory in ROM memory while the AT89C51S ND1 C pr odu ct p ro vides it in F la sh memo r y. The se 2 prod­ucts do not allow external code memory execution.
The Flash memory increa ses EP ROM and ROM func tional ity by in-cir cui t electric al era­sure and programming. The high voltage needed for programming or erasing Flash cells is generated on-chip using the standard V charge pump. Thus, the AT89C51SND1C can be programmed using only one voltage and allows In-application software programming. Hardware programming mode is also available using common programming tools. See the application note ‘Programming T89C51x and AT89C51x with Device Programmers’.
The AT89C51SND1C implements an additional 4K Bytes of on-chip boot Flash memory provided in Fla sh memor y. Thi s bo ot memo ry is deli vered p rogr ammed with a stand ard boot loader so ftware allowi ng In-System Programm ing (ISP). It also con tains som e Application Prog rammin g Interface r outines named API ro utines allo wing In Appl icatio n Programming (IAP) by using users own boot loader.
Figure 11. Program/Code Memory Organization
FFFFh
FFFFh
F000h
voltage, made possible by the internal
DD
FFFFh
F000h
4K Bytes
Boot Flash
64K Bytes
Code ROM
0000h
AT83C51SND1C

ROM Memory Architecture

As shown in Figure 11 the AT83C51SND1C ROM memory is composed of one space detailed in the following paragraphs.
Figure 12. AT83C51SND1C Memory Architecture
FFFFh
0000h
64K Bytes
ROM Memory
64K Bytes
Code Flash
AT89C51SND1C
User
4109E–8051–06/03
0000h
17
User Space This space is composed of a 64K Bytes ROM memory programmed during the manu-
facturing process. It contains the users application code.

Flash Memory Architecture

As shown in Figure 13 the AT89C51 SND1C Flas h memor y is compos ed of four spac es detailed in the following paragraphs.
Figure 13. AT89C51SND1C Memory Architecture
Hardware Security
FFFFh
64K Bytes
Flash Memory
0000h
Extra Row
User
FFFFh
F000h
4K Bytes
Flash Memory
Boot
User Space This space is composed of a 64K Bytes Flash memory organized in 512 pages of 128
Bytes. It contains the users application code. This space can be read or written by both software and hardware modes.
Boot Space This spa ce is composed of a 4K Bytes F l ash m emory. It contains the b oot lo ader f or In-
System Programming and the routines for In Application Programming. This space can only be read or wr itt en by hardwa re mode using a par all el progr am min g
tool.
Hardware Security Space This space is composed of one Byte: the Hardware Security Byte (HSB see Table 22)
divided in 2 separ ate n ibble s. The MSN conta ins the X2 mo de con figur ation bit an d the Boot Loader Jump Bit as detailed in Section Boot Memory Execution, page 19 and can be written by software while the LS N co nta ins the l oc k system lev el to pro tec t the mem­ory content against piracy as detailed in Section Hardware Security System, page 19 and can only be written by hardware.
Extra Row Space This space is composed of 2 Bytes:
The Software Boot Vector (SBV, see Table 23). This Byte is used by the software boot loader to build the boot address.
The Software Security Byte (SSB, see Table 24). This Byte is used to lock the execution of some boot loader commands.
18
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Hardware Security System

The AT89C51SND1C implem ents three lock bits LB2:0 in the LSN of HSB ( see Table 22) providing three levels of se curity for user s program as descri bed i n Ta ble 2 2 while the AT83C51SND1C is always set in read disabled mode.
Level 0 is the level of an erased part and does not enable any security feature. Level 1 locks the hardware programming of both user and boot memories. Level 2 locks also hardware verifying of both user and boot memories Level 3 locks also the external execution.
Table 20. Lock Bit Feat ur es
Level LB2
0 U U U Enable Enable Enable Enable Enable 1 U U P Enable Enable Enable Disable Enable 2 U P X Enable Enable Disable Disable Enable
(3)
3
Notes: 1. U means unprogrammed, P means programmed and X means dont care (pro-
(2)
LB1 LB0
P X X Enable Dis able Disable Disable Enable
grammed or unprogrammed).
2. LB2 is not implemented in the AT8xC51SND1C products.
3. AT89C51SND1C products are delivered with third level programmed to ensure that the code programmed by software using ISP or users boot loader is secured from any hardware piracy.
(1)
Internal
Execution
External
Execution
Hardware
Verifying
Hardware
Programming
Software
Programming

Boot Memory Execution As internal C51 code space is limited to 64K Bytes, some mechanisms are implemented

to allow boot memory to be mapped in the code space for ex ecution at addre sses from F000h to FFFFh. The boot memory is enabled by setting the ENBOOT bit in AUXR1 (see Figure 21). The three ways to set this bit are detailed in the following sections.
Software Boot Mapping The software way to set ENBOOT consists in writing to AUXR1 from the users soft-
ware. This enables boot loader or API routines execution.
Hardware Condition Boot Mapping
The hardware condition is based on the ISP
pin. When driving this pin to low level, the chip reset sets ENBOOT and for ce s the res et vector to F000 h ins te ad of 00 00h i n order to execute the boot loader software.
As shown in Figure 14 the hardware condition always allows in-system recovery when users memory has been corrupted.
Programmed Condition Boot Mapping
The programmed con dition is based on the Boot Loader Ju mp Bit (BLJB) in HSB. As shown in Figure 14 when this bit is programmed (by hardware or software programming mode), the chip reset set ENBOOT and forces the reset vec tor to F000h instead of 0000h, in order to execute the boot loader software.
4109E–8051–06/03
19
Figure 14. Hardware Boot Process Algorithm
RESET
Hard Cond?
ISP = L?

Preventing Flash Corruption

HardwareSoftware
Process Process
Standard Init
ENBOOT = 0
PC = 0000h
FCON = F0h
User’s
Application
Prog Cond?
BLJB = P?
Prog Cond Init
ENBOOT = 1
PC = F000h
FCON = F0h
Atmel’s
Boot Loader
Hard Cond Init
ENBOOT = 1
PC = F000h FCON = 00h
The software process (boot loader) is detailed in the Boot Loader Datasheet Document.
See Section Reset Recommendation to Prevent Flash Corruption, page 47.
20
AT8xC51SND1C
4109E–8051–06/03

Registers Table 21. AUXR1 Register

AUXR1 (S:A2h) – Auxiliary Register 1
76543210
- - ENBOOT - GF3 0 - DPS
AT8xC51SND1C
Bit
Number
7 - 6 -
5 ENBOOT
4-
3GF3
20
1-Reserved for Data Pointer Extension.
0DPS
Bit
Mnemonic Description
Reserved
The value read from these bits are indeterminate. Do not set these bits.
Enable Boot Flash
Set this bit to map the boot Flash in the code space between at addresses F000h
1
to FFFFh. Clear this bit to disable boot Flash.
Reserved
The value read from this bit is indeterminate. Do not set this bit.
General Flag
This bit is a general-purpose user flag.
Always Zero
This bit is stuck to logic 0 to allow INC AUXR1 instruction without affecting GF3 flag.
Data Pointer Select Bit
Set to select second data pointer: DPTR1. Clear to select first data pointer: DPTR0.
Reset Value = XXXX 00X0b
Note: 1. ENBOOT bit is only ava il abl e in AT89C51SND1C product.
4109E–8051–06/03
21

Hardware Bytes Table 22. HSB Byte – Hardware Security Byte

76543210
X2B BLJB - - - LB2 LB1 LB0
Bit
Number
7X2B
6BLJB
5 - 4 -
3-
2 - 0 LB2:0
Bit
Mnemonic Description
X2 Bit
(1)
Program this bit to start in X2 mode. Unprogram (erase) this bit to start in standard mode.
Boot Loader Jump Bit
Program this bit to execute the boot loader at address F000h on next reset.
(2)
Unprogram (erase) this bit to execute users application at address 0000h on next reset.
Reserved
The value read from these bits is always unprogrammed. Do not program these bits.
Reserved
The value read from this bit is always unprogrammed. Do not program this bit.
Hardware Lock Bits
Refer to for bits description.
Reset Value = XXUU UXXX, UUUU UUUU after an hardware full chip erase.
Note: 1. X2B initializes the X2 bit in CKCON during the reset phase.
2. In order to ensure boot loader activation at first power-up, AT89C51SND1C products are delivered with BLJB programmed.
3. Bits 0 to 3 (LSN) can only be programmed by hardware mode.
Table 23. SBV Byte – Software Boot Vector
76543210
ADD15 ADD14 ADD13 ADD12 ADD11 ADD10 ADD9 ADD8
Bit
Number
7 - 0 ADD15:8
Bit
Mnemonic Description
MSB of the users boot loader 16-bit addre ss location
Refer to the boot loader datasheet for usage information (boot loader dependent)
Reset Value = XXXX XXXX, UUUU UUUU after an hardware full chip erase.
Table 24. SSB Byte – Software Security Byte
76543210
SSB7SSB6SSB5SSB4SSB3SSB2SSB1SSB0
Bit
Number
7 - 0 SSB7:0
Bit
Mnemonic Description
Software Security Byte Data
Refer to the boot loader datasheet for usage information (boot loader dependent)
Reset Value = XXXX XXXX, UUUU UUUU after an hardware full chip erase.
22
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Data Memory The AT8xC51SND1C provides data memory access in 2 different spaces:

1. The internal space mapped in three separate segments:
The lower 128 Bytes RAM segment The upper 128 Bytes RAM segment The expanded 2048 Bytes RAM segment
2. The external space. A fourth internal segment is available but dedicated to Special Function Registers,
SFRs, (addresses 80h to FFh) accessible by direct addressing mode. For information on this segment, refer to the Section Special Function Registers, page 30.
Figure 15 shows the internal and external data memory spaces organization.
Figure 15. Internal and External Data Memory Organization
FFFFh
64K Bytes
External XRAM
7FFh FFh
00h
2K Bytes
Internal ERAM
EXTRAM = 0
80h 80h 7Fh
00h
Upper
128 Bytes
Internal RAM
Indirect Addressing
Lower
128 Bytes
Internal RAM
Direct or Indirect
Addressing
FFh
Direct Addressing
Special
Function
Registers
0800h
0000h
EXTRAM = 1

Internal Space

Lower 128 Bytes RAM The lower 128 Bytes of RAM (see Figure 16) are accessibl e from address 00h to 7Fh
using direct or indirect address ing modes. T he lowest 32 Bytes are grouped in to 4 banks of 8 registers (R0 to R7). 2 bits RS0 and RS1 in PSW register (see Table 28) select which bank is in use according to Table 25. This allows more efficient use of code space, since register instructions are shorter than instructions that use direct address­ing, and can be used for context switching in interrupt service routines.
Table 25. Register Bank Selection
RS1 RS0 Description
0 0 Register bank 0 from 00h to 07h
4109E–8051–06/03
0 1 Register bank 1 from 08h to 0Fh 1 0 Register bank 2 from 10h to 17h 1 1 Register bank 3 from 18h to 1Fh
The next 16 Bytes above the register banks form a block of bit-addressable memory space. The C51 instruction set includes a wide selection of single-bit instructions, and the 128 bits in this area can be directly addressed by these instructions. The bit addresses in this area are 00h to 7Fh.
23
Figure 16. Lower 128 Bytes Internal RAM Organization
7Fh
30h
20h 18h 10h 08h 00h
2Fh
Bit-Addressable Space (Bit Addresses 0-7Fh)
1Fh
17h
4 Banks of 8 Registers
0Fh
R0-R7
07h
Upper 128 Bytes RAM The upper 128 Bytes of RAM are accessible from address 80h to FFh using only indirect
addressing mode.
Expanded RAM The on-chip 2K Bytes of expa nded RAM (E RAM ) are acces s ible fr om a ddr ess 0 000h to
07FFh using i ndirect ad dressing mode thro ugh MOVX in structio ns. In this a ddress range, EXTRAM bit in AUXR register (see Table 29) is used to select the ERAM (default) or the XRAM. As shown in Figure 15 when EXTRAM = 0, the ERAM is selected and when EXTRAM = 1, the XRAM i s selected (see Section Extern al Sp ace ”).
The ERAM memo ry can be resiz ed using XRS1: 0 bits in AUXR re gister to dynam ically increase externa l ac cess to the XRAM spac e. T able 2 6 detai ls the s elec ted ER AM size and address range.
Table 26. ERAM Size Selection
XRS1 XRS0 ERAM Size Address
0 0 256 Bytes 0 to 00FFh 0 1 512 Bytes 0 to 01FFh 1 0 1K Byte 0 to 03FFh 1 1 2K Bytes 0 to 07FFh
Note: Lower 128 Bytes RAM, Upper 128 Bytes RAM, and expanded RAM are made of volatile
memory cells. This means that the RAM content is indeterminate after power-up and must then be initialized properly.
24
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

External Space

Memory Interfac e The external memory interface comprises the external bus (port 0 and port 2) as well as
the bus control signals (RD Figure 17 shows the structure of the external address bus. P0 carries address A7:0
while P2 carries address A15:8. Data D7:0 is multiplexed with A7:0 on P0. Table 27 describes the external memory interface signals.
Figure 17. External Data Memory Interface Structure
, WR, and ALE).
AT8xC51SND1C
AD7:0
A15:8
Latch
A7:0
P2
ALE
P0
WR
Table 27. External Data Memory Interface Signals
Signal
Name Type Description
A15:8 O
AD7:0 I/O
ALE O
RD
Address Lines
Upper address lines for the external bus.
Address/Data Lines
Multiplexed lower address lines and data for the external memory.
Address Latch Enable
ALE signals indicates that valid address information are available on lines AD7:0.
Read
O
Read signal output to external data memory.
RAM
PERIPHERAL
A15:8
A7:0
D7:0 OERD
WR
Alternate Function
P2.7:0
P0.7:0
-
P3.7
WR
O
Write signal output to external memory.
P3.6
Write
Page Access Mode The AT8xC51SND1C im plemen t a feature called Pag e Access that dis ables the out put
of DPH on P2 wh en execut ing MO VX @DP TR instru ction. P age Ac cess is enable by setting the DPHDIS bit in AUXR register.
Page Access is useful when appli cation uses both ERAM and 256 Bytes of XRAM. In this case, software modifies intensively EXTRAM bit to select access to ERAM or XRAM and must save it if used in interrupt service routine. Page Access allows external access above 00FFh address with out generating DP H on P2. Thus ERAM is accessed u sing MOVX @Ri or MOVX @DPTR with DPTR < 0100h, and XRAM is accessed using MOVX @DPTR with DPTR 0100h while keeping P2 for general I/O usage.
25
4109E–8051–06/03
External Bus Cycles This s ection describes the bus cycles the AT 8xC51SND1C executes to read (see
Figure 18), and write data (see Figure 19) in the external data memory. External memory cycle takes 6 CPU clock periods. This is equivalent to 12 oscillator clock period in standard mode or 6 oscillator clock periods in X2 mode. For further infor­mation on X2 mode, refer to the Section X2 Feature, page 12.
Slow peripherals can be acc essed b y stretc hing th e read and write cycles . This is done using the M0 bit in AUXR reg ister. S etting t his bi t changes the widt h of the RD
and WR
signals from 3 to 15 CPU clock periods. For simplicity, Figure 18 and Figure 19 depict the bus cycle waveforms in idealized form
and do not provide precis e timing in forma tion. For bus cycl e timing p aramet ers refe r to the Section AC Characteristics”.
Figure 18. External Data Read Waveforms
CPU Clock
ALE
(1)
RD
P0
P2
Notes: 1. RD signal may be stretched using M0 bit in AUXR register.
P2
2. When executing MOVX @Ri instruction, P2 outputs SFR conte nt.
3. When executing MOVX @DPTR instruction, if DPHDIS is set (Page Access Mode), P2 outputs SFR content instead of DPH.
DPL or Ri D7:0
DPH or P2
(2),(3)
Figure 19. External Data Write Waveforms
CPU Clock
ALE
(1)
WR
P0
P2
Notes: 1. WR signal may be stretched using M0 bit in AUXR register.
2. When executing MOVX @Ri instruction, P2 outputs SFR conte nt.
3. When executing MOVX @DPTR instruction, if DPHDIS is set (Page Access Mode),
P2
P2 outputs SFR content instead of DPH.
DPL or Ri D7:0
DPH or P2
(2),(3)
26
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Dual Data Pointer

Description The AT8xC51SND1C impl ement a se cond data po int er for spe eding up cod e execu tion
and reducing code size in case of intensive usage of external memory accesses. DPTR0 and DPTR1 ar e seen by the CPU as DPTR and a re access ed using t he SFR
addresses 83h and 84h that are the DPH and DPL addresses. The DPS bit in AUXR1 register (see Table 21 ) is used to se lect whet her DPTR is the data poin ter 0 or the da ta pointer 1 (see Figure 20).
Figure 20. Dual Data Pointer Implementation
DPL0 DPL1
DPTR0
DPTR1
DPH0 DPH1
0 1
DPS
0 1
DPL
AUXR1.0
DPH
DPTR
Application Software can take advantage of the additional data pointers to both increase speed and
reduce code size, for example, block operations (copy, compare, search ) are well served by using one data pointe r as a “source” pointer and the oth er one as a “destina- tion pointer.
Below is an example of block move implementation using the 2 pointers and coded in assembler. T he latest C compi ler also takes ad vantage of this feature by provid ing enhanced algorithm libraries.
The INC instruction is a short (2 Bytes) and fast (6 CPU clocks) way to manipulate the DPS bit in the AUXR 1 reg ister. H owever , note that th e INC i nstruc tion do es no t direc tly force the DPS bit to a particular state, but simply toggles it. In simple routines, such as the block move exa mple, o nly the f act that DP S is tog gled i n the pr oper s equenc e mat­ters, not its actual value. In other words, the block move routine works the same whether DPS is '0' or '1' on entry.
4109E–8051–06/03
; ASCII block move using dual data pointers ; Modifies DPTR0, DPTR1, A and PSW ; Ends when encountering NULL character ; Note: DPS exits opposite of entry state unless an extra INC AUXR1 is added
AUXR1 EQU 0A2h
move: mov DPTR,#SOURCE ; address of SOURCE
inc AUXR1 ; switch data pointers mov DPTR,#DEST ; address of DEST
mv_loop: inc AUXR1 ; switch data pointers
movx A,@DPTR ; get a Byte from SOURCE inc DPTR ; increment SOURCE address inc AUXR1 ; switch data pointers movx @DPTR,A ; write the Byte to DEST inc DPTR ; increment DEST address jnz mv_loop ; check for NULL terminator
end_move:
27

Registers Table 28. PSW Register

PSW (S:8Eh) – Program Status Word Register
76543210
CY AC F0 RS1 RS0 OV F1 P
Bit
Number
7CY
6AC
5F0User Definable Flag 0
4 - 3 RS1:0
2OV
1F1User Definable Flag 1
0P
Bit
Mnemonic Description
Carry Flag
Carry out from bit 1 of ALU operands.
Auxiliary Carry Flag
Carry out from bit 1 of addition operands.
Register Bank Select Bits
Refer to Table 25 for bits description.
Overflow Flag
Overflow set by arithmetic operations.
Parity Bit
Set when ACC contains an odd number of 1’s. Cleared when ACC contains an even number of 1’s.
Reset Value = 0000 0000b
28
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 29. AUXR Register
AUXR (S:8Eh) – Auxiliary Control Register
76543210
- EXT16 M0 DPHDIS XRS1 XRS0 EXTRAM AO
Bit
Number
7-
6EXT16
5M0
4 DPHDIS
3 - 2 XRS1:0
1EXTRAM
0AO
Bit
Mnemonic Description
Reserved
The value read from this bit is indeterminate. Do not set this bit.
External 16-bit Access Enable Bit
Set to enable 16-bit access mode during MOVX instructions. Clear to disable 16-bit access mode and enable standard 8-bit access mode during MOVX instructions.
External Memory Access Stretch Bit
Set to stretch RD Clear not to stretch RD
DPH Disable Bit
Set to disable DPH output on P2 when executing MOVX @DPTR instruction. Clear to enable DPH output on P2 when executing MOVX @DPTR instruction.
Expanded RAM Size Bits
Refer to T able26 for ERAM size description.
External RAM Enable Bit
Set to select the external XRAM when executing MOVX @Ri or MOVX @DPTR instructions. Clear to select the internal expanded RAM when executing MOVX @Ri or MOVX @DPTR instructions.
ALE Output Enable Bit
Set to output the ALE signal only during MOVX instructions. Clear to output the ALE signal at a constant rate of F
or WR signals duration to 15 CPU clock periods.
or WR signals and set duration to 3 CPU clock periods.
/3.
CPU
4109E–8051–06/03
Reset Value = X000 1101b
29

Special Function Registers

The Special Function Registers (SFRs) of the AT8xC51SND1C derivatives fall into the categories detailed in Table 30 to Table 46. The relative addresses of these SFRs are provided together with their reset values in Table 47. In this table, the bit-addressable registers are identified by Note 1.
Table 30. C51 Core SFRs
MnemonicAddName 76543210
ACC E0h Accumulator B F0h B Register PSW D0h Program Status Word CY AC F0 RS1 RS0 OV F1 P SP 81h Stack Pointer DPL 82h Data Pointer Low Byte DPH 83h Data Pointer High Byte
Table 31. System Management SFRs
MnemonicAddName 76543210
PCON 87h Power Control SMOD1 SMOD0 - - GF1 GF0 PD IDL AUXR 8Eh Auxiliary Register 0 - EXT16 M0 DPHDIS XRS1 XRS0 EXTRAM AO AUXR1 A2h Auxiliary Register 1 - - ENBOOT
(1)
-GF30 -DPS
NVERS FBh Version Number NV7 NV6 NV5 NV4 NV3 NV2 NV1 NV0
Note: 1. ENBOOT bit is only available in AT89C51SND1C product.
Table 32. PLL and System Clock SFRs
MnemonicAddName 76543210
CKCON8FhClock Control -------X2 PLLCON E9h PLL Control R1 R0 - - PLLRES - PLLEN PLOCK PLLNDIV EEh PLL N Divider - N6 N5 N4 N3 N2 N1 N0 PLLRDIV EFh PLL R Divider R9 R8 R7 R6 R5 R4 R3 R2
Table 33. Interrupt SFRs
MnemonicAddName 76543210
IEN0 A8h Interrupt Enable Control 0 EA EAUD EMP3 ES ET1 EX1 ET0 EX0 IEN1 B1h Interrupt Enable Control 1 - EUSB - EKB EADC ESPI EI2C EMM C IPH0 B7h Interrupt Priority Control High 0 - IPHAUD IPHMP3 IPHS IPHT1 IPHX1 IPHT0 IPHX0 IPL0 B8h Interrupt Priority Control Low 0 - IPLAUD IPLMP3 IPLS IPLT1 I PLX 1 IPLT0 IPLX0 IPH1 B3h Interrupt Priority Control High 1 - IPHUSB - IPHKB IPHADC IPHSPI IPHI2C IPHMMC IPL1 B2h Interrupt Priority Control Low 1 - IPLUSB - IPLKB IPLADC IPLSPI IPLI2C IPLMMC
30
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 34. Port SFRs
MnemonicAddName 76543210
P0 80h 8-bit Port 0 P1 90h 8-bit Port 1 P2 A0h 8-bit Port 2 P3 B0h 8-bit Port 3 P4 C0h 8-bit Port 4 P5D8h4-bit Port 5 ----
Table 35. Flash Memory SFR
MnemonicAddName 76543210
(1)
FCON
Note: 1. FCON register is only available in AT89C51SND1C product.
D1h Flash Control FPL3 FPL2 FPL1 FPL0 FPS FMOD1 FMOD0 FBUSY
Table 36. Timer SFRs
MnemonicAddName 76543210
TCON 88h Timer/Counter 0 and 1 Control TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0 TMOD 89h Timer/Counter 0 and 1 Modes GATE1 C/T1# M11 M01 GATE0 C/ T 0# M10 M00 TL0 8Ah Timer/Counter 0 Low Byte TH0 8Ch Timer/Counter 0 High Byte TL1 8Bh Timer/Counter 1 Low Byte TH1 8Dh WDTRST A6h Watchdog Ti mer Reset WDTPRG A7h Watchdog Timer Program -----WTO2WTO1WTO0
Timer/Counter 1 High Byte
4109E–8051–06/03
31
Table 37. MP3 Decoder SFRs
MnemonicAddName 76543210
MP3CON AAh MP3 Control MPEN MPBBST CRCEN MSKANC MSKREQ MSKLAY MSKSYN MSKCRC MP3STA C8h MP3 Status MPANC MPREQ ERRLAY ERRSYN ERRCRC MPFS1 MPFS0 MPVER MP3STA1 AFh MP3 Status 1 - - - MPFREQ MPBREQ - - ­MP3DAT ACh MP3 Data MPD7 MPD6 MPD5 MPD4 MPD3 MPD2 MPD1 MPD0 MP3ANC ADh MP3 Ancillary Data AND7 AND6 AND5 AND4 AND3 AND2 AND1 AND0 MP3VOL 9Eh MP3 Audio Volume Control Left - - - VOL4 VOL3 VOL2 VOL1 VOL0 MP3VOR 9Fh MP3 Audio Volume Control Right - - - VOR4 VOR3 VOR2 VOR1 VOR0 MP3BAS B4h MP3 Audio Bass Control - - - BAS4 BAS3 BAS2 BAS1 BAS0 MP3MED B5h MP3 Audio Medium Control - - - MED4 MED3 MED2 MED1 MED0 MP3TRE B6h MP3 Audio Treble Control - - - TRE4 TRE3 TRE2 TRE1 TRE0 MP3CLK EBh MP3 Clock Divider - - - MPCD4 MPCD3 MPCD2 MPCD1 MPCD0
Table 38. Audio Interface SFRs
MnemonicAddName 76543210
AUDCON0 9Ah Audio Control 0 JUST4 JUST 3 JUST2 JUST1 JUST0 POL DSIZ HLR AUDCON1 9Bh Audio Control 1 SRC DRQEN MSREQ MUDRN - DUP1 DUP0 AUDEN AUDSTA 9Ch Audio Status SREQ UDRN AUBUSY ----­AUDDAT 9Dh Audio Data AUD7 AUD6 AUD5 AUD4 AUD3 AUD2 AUD1 AUD0 AUDCLK EC h Audio Clock Divider - - - AUCD4 AUCD3 AUCD2 AUCD1 AUCD0
32
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 39. USB Controller SFRs
MnemonicAddName 76543210
USBCON BCh USB Global Control USBE SUSPCLK SDRMWUP - UPRSM RMWUPE CONFG FADDEN USBADDR C6h USB Address FEN UADD6 UADD5 UADD4 UADD3 UADD2 UADD1 UADD0 USBINT BDh USB Global Interrupt - - WUPCPU EORINT SOFINT - - SPINT USBIEN BEh USB Global Interrupt Enable - - EWUPCPU EEORINT ESOFINT - - ESPINT UEPNUMC7hUSB Endpoint Number ------EPNUM1EPNUM0 UEPCONX D4h USB Endpoint X Control EPEN NAKIEN NAKOUT NAKIN DTGL EPDIR EPTYPE1 EPTYPE0 UEPSTAX CEh USB Endpoint X Status DIR RXOUTB1 STALLRQ TXRDY STLCRC RXSETUP RXOUTB0 TXCMP UEPRSTD5hUSB Endpoint Reset -----EP2RSTEP1RSTEP0RST UEPINTF8hUSB Endpoint Interrupt -----EP2INTEP1INTEP0INT UEPIEN C2h USB Endpoint Interrupt Enable -----EP2INTEEP1INTEEP0INTE UEPDATX CFh USB Endpoint X FIFO Data FDAT7 FDAT6 FDAT5 FDAT4 FDAT 3 FDAT2 FDAT1 FDAT0 UBYCTX E2h USB Endpoint X Byte Counter - BYCT6 BYCT5 BYCT4 BYCT3 BYCT2 BYCT1 BYCT0 UFNUML BAh USB Frame Number Low FNUM7 FNUM6 FNUM5 FNUM4 FNUM3 FNUM2 FNUM1 FNUM0 UFNUMH BBh USB Frame Number High - - CRCOK CRCERR - FNUM10 FNUM9 FNUM8 USBCLKEAhUSB Clock Divider ------USBCD1USBCD0
Table 40. MMC Controller SFRs
MnemonicAddName 76543210
MMCON0 E4h MMC Control 0 DRPTR DTPTR CRPTR CTPTR MBLOCK DFMT RFMT CRCDIS MMCON1 E5h MMC Control 1 BLEN3 BLEN2 BLEN1 BLEN0 DATDI R DATEN RESPEN CMDEN MMCON2 E6h MMC Control 2 MMCEN DCR CCR - - DATD1 DATD0 FLOWC MMSTA DEh MMC Control and Status - - CBUSY CRC16S DATFS CRC7S RESPFS CFLCK MMINT E7h MMC Interrupt MCBI EORI EOCI EOFI F2FI F1FI F2EI F1EI MMMSK DFh MMC Interrupt Mask MCBM EORM EOCM EOFM F2FM F1FM F2EM F1EM MMCMD DDh MMC Command MC7 MC6 MC5 MC4 MC3 MC2 MC1 MC0 MMDAT DCh MMC Data MD7 MD6 MD5 MD4 MD3 MD2 MD1 MD0 MMCLK EDh MMC Clock Divider MMCD7 MMCD6 MMCD5 MMCD4 MMCD3 MMCD2 MMCD1 MMCD0
Table 41. IDE Interface SFR
MnemonicAddName 76543210
DAT16H F9h High Order Data Byte D15 D14 D13 D12 D11 D10 D9 D8
4109E–8051–06/03
33
Table 42. Serial I/O Port SFRs
MnemonicAddName 76543210
SCON 98h Serial Control FE/SM0 SM1 SM2 REN TB8 RB8 TI RI SBUF 99h Serial Data Buffer SADEN B9h Slave Address Mask SADDR A9h Slave Address BDRCON 92h Baud Rate Control BRR TBCK RBCK SPD SRC BRL 91h Baud Rate Reload
Table 43. SPI Controller SFRs
MnemonicAddName 76543210
SPCON C3h SPI Control SPR2 SPE N SSDIS MSTR CPOL CPHA SPR1 SPR0 SPSTAC4hSPI Status SPIFWCOL-MODF---­SPDAT C5h SPI D a ta SPD7 SPD6 SPD5 SPD4 SPD3 SPD2 SP D1 SPD0
Table 44. Two Wire Controller SFRs
MnemonicAddName 76543210
SSCON 93h Synchronous Serial Control SSCR2 SSPE SSSTA SSSTO SSI SSAA SSCR1 SSCR0 SSSTA 94h Synchronous Serial Status SSC4 SSC3 SSC2 SSC1 SSC0 0 0 0 SSDAT 95h Synchronous Serial Data SSD7 SSD6 SSD5 SSD4 SSD3 SSD2 SSD1 SSD0 SSADR 96h Synchronous Serial Address SSA7 SSA6 SSA5 SSA4 SSA3 SSA2 SSA1 SSGC
Table 45. Keyboard Interface SFRs
MnemonicAddName 76543210
KBCON A3h Keyboard Control KINL3 KINL2 KINL1 KINL0 KINM3 KINM2 KINM1 KINM0 KBSTA A4h Keyboard Status KPDE - - - KINF3 KINF2 KI NF1 KINF0
Table 46. A/D Controller SFRs
MnemonicAddName 76543210
ADCON F3h ADC Control - ADIDL ADEN ADEOC ADSST - - ADCS ADCLK F2h ADC Clock Divider - - - ADCD4 ADCD3 ADCD2 ADCD1 ADCD0 ADDLF4hADC Data Low Byte ------ADAT1ADAT0 ADDH F5h ADC Data High Byte ADAT9 ADAT8 ADAT7 ADAT6 ADAT5 ADAT4 ADAT3 ADAT2
34
AT8xC51SND1C
4109E–8051–06/03
Table 47. SFR Addresses and Reset Values
0/8 1/9 2/A 3/B 4/C 5/D 6/E 7/F
AT8xC51SND1C
F8h
F0h
E8h
E0h
D8h
D0h
C8h
C0h
B8h
B0h
A8h
A0h
UEPINT
0000 0000
(1)
B
0000 0000
(1)
ACC
0000 0000
(1)
P5
XXXX 1111
(1)
PSW
0000 0000 MP3STA
0000 0001
(1)
P4
1111 1111
(1)
IPL0
X000 0000
(1)
P3
1111 1111
(1)
IEN0
0000 0000
(1)
P2
1111 1111
(1)
DAT16H
XXXX XXXX
PLLCON
0000 1000
(3)
FCON
1111 0000
(4)
SADEN
0000 0000
IEN1
0000 0000
SADDR
0000 0000
ADCLK
0000 0000
USBCLK
0000 0000 UBYCTLX
0000 0000
UEPIEN
0000 0000
UFNUML
0000 0000
IPL1
0000 0000
MP3CON 00111111
AUXR1
XXXX 00X0
NVERS
XXXX XXXX
ADCON
0000 0000
MP3CLK
0000 0000
SPCON
0001 0100
UFNUMH
0000 0000
IPH1
0000 0000
KBCON
0000 1111
(2)
ADDL
0000 0000
AUDCLK
0000 0000
MMCON0
0000 0000
MMDAT
1111 1111
UEPCONX
1000 0000
SPSTA
0000 0000
USBCON
0000 0000
MP3BAS
0000 0000
MP3DAT
0000 0000
KBSTA
0000 0000
ADDH
0000 0000
MMCLK
0000 0000 MMCON1
0000 0000
MMCMD
1111 1111
UEPRST
0000 0000
SPDAT
XXXX XXXX
USBINT
0000 0000
MP3MED
0000 0000
MP3ANC
0000 0000
PLLNDIV
0000 0000
MMCON2
0000 0000
MMSTA
0000 0000
UEPSTAX
0000 0000
USBADDR
0000 0000
USBIEN
0001 0000
MP3TRE
0000 0000
WDTRST
XXX XXXX
PLLRDIV
0000 0000
MMINT
0000 0011
MMMSK
1111 1111
UEPDATX
XXXX XXXX
UEPNUM
0000 0000
IPH0
X000 0000
MP3STA1
0100 0001
WDTPRG
XXXX X000
FFh
F7h
EFh
E7h
DFh
D7h
CFh
C7h
BFh
B7h
AFh
A7h
98h
90h
88h
80h
SCON
0000 0000
(1)
P1
1111 1111
(1)
TCON
0000 0000
(1)
P0
1111 1111
SBUF
XXXX XXXX
BRL
0000 0000
TMOD
0000 0000
SP
0000 0111
AUDCON0
0000 1000
BDRCON
XXX0 0000
TL0
0000 0000
DPL
0000 0000
AUDCON1
1011 0010
SSCON
0000 0000
TL1
0000 0000
DPH
0000 0000
AUDSTA
11000000
SSSTA
1111 1000
TH0
0000 0000
AUDDAT
1111 1111
SSDAT
1111 1111
TH1
0000 0000
0/8 1/9 2/A 3/B 4/C 5/D 6/E 7/F
Reserved
Notes: 1. SFR registers with least significant nibble address equal to 0 or 8 are bit-addressable.
2. NVERS reset value depends on the silicon version: 1000 0100 for AT89C51SND1C product and 0000 0001 for AT83C51SND1C product.
3. FCON register is only available in AT89C51SND1C product.
4. FCON reset value is 00h in case of reset with hardware condition.
5. CKCON reset value depends on the X2B bit (programmed or unprogrammed) in the Hardware Byte.
4109E–8051–06/03
MP3VOL
0000 0000
SSADR
1111 1110
AUXR
X000 1101
MP3VOR
0000 0000
CKCON
0000 000X
PCON
XXXX 0000
9Fh
97h
8Fh
(5)
87h
35

Interrupt System The AT8xC51SND1C, l ike ot her contr ol-or iented compu ter arc hitec tures, em ploy a pro-

gram interrupt method. This operation branches to a subroutine and performs some service in r e spo ns e t o th e in te rr u pt. Wh en t h e su br ou ti ne co m pl e tes, ex ec ut i on r es um es at the point where the interrupt occurred. Interrupts may occur as a result of internal AT8xC51SND1C activity (e.g., timer overflow) or at the initiation of electrical signals external to the microcontroller (e.g., keyboard). In all cases, interrupt operation is pro- grammed by the system designer, who determines priority of interrupt service relative to normal code execution and other interrupt service routines. All of the interrupt sources are enabled or disabled by the system designer and may be manipulated dynamically.
A typical interrupt event chain occurs as follows:
An internal or external device initiates an interrupt-request signal. The AT8xC51SND1C, latches this event into a flag buffer.
The priority of the flag is compared to the priority of other interrupts by the interrupt handler. A high priority causes the handler to set an interrupt flag.
This signals the instruction execution unit to execute a context switch. This context switch breaks the current flow of instruction sequences. The execution unit completes the current instruction prior to a save of the program counter (PC) and reloads the PC with the start address of a software service rou tine.
The software service routine executes assigned tasks and as a final activity performs a RETI (return from interrupt) instruction. This instruction signals completion of the interrupt, resets the interrupt-in-progress priority and reloads the program counter. Program operation then continues from the original point of interruption.
Table 48. Interrupt System Signals

Interrupt System Priorities

Signal
Name Type Description
External Interrupt 0
INT0
INT1
KIN3:0 I
I
See section "External Interrupts", page 39.
External Interrupt 1
I
See section External Interrupts, page 39.
Keyboard Interrupt Inputs
See section Keyboard Interface, page 179.
Alternate Function
P3.2
P3.3
P1.3:0
Six interrupt register s ar e use d to cont rol t he int er rupt sy st em. 2 8- bit regi st er s are use d to enable sep aratel y the i nterr upt sour ces: IE N0 and IEN1 re giste rs (see Table 51 and Table 52). Four 8-bit registers ar e used to establi sh the priority l evel of the th irteen s ources : IPH0, IPL0, IPH1 and IPL1 registers (see Table 53 to Table 56).
Each of the thirteen interrupt sources on the AT8xC51SND1C can be individually pro­grammed to one of four priority levels. This is accomplished by one bit in the Interrupt Priority High registers (IPH0 and IPH1) and one bit in the Interrupt Priority Low registers (IPL0 and IPL1). This provides each interrupt source four possible priority levels accord­ing to Table 49.
36
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 49. Priority Levels
IPHxx IPLxx Priority Level
0 0 0 Lowest 011 102 1 1 3 Highest
A low-priority i nterrupt is always interrupted by a high er priority interrupt but not by another interrupt o f low er o r equ al p riority. Highe r pr iorit y in terrupt s are se rviced bef ore lower priority interrupts. The response to simultaneous occurrence of equal priority inter­rupts is determined by an internal hardware polling sequence detailed in Table 50. Thus, within each priority level there is a second priority structure determined by the polling sequence. The interrupt control system is shown in Figure 21.
Table 50. Priority within Same Level
Interrupt Name Priority Number
INT0 Timer 0 2 C:000Bh H INT1 Timer 1 4 C:001Bh H Serial Port 5 C:0023h S MP3 Decoder 6 C:002Bh S Audio Interface 7 C:0033h S MMC Interface 8 C:003Bh S Two Wire Controller 9 C:0043h S SPI Controller 10 C:004Bh S A to D Converter 11 C: 0053h S Keyboard 12 C:005Bh S Reserved 13 C:0063h ­USB 14 C:006Bh S Reserved 15 (Lowest Priority) C:0073h -
1 (Highest Priority) C:0003h H if edge, S if level
3 C:0013h H if edge, S if level
Interrupt Address
Vectors
Interrupt Request Flag
Cleared by Hardware
(H) or by Software (S)
4109E–8051–06/03
37
Figure 21. Interrupt Control System
INT0
INT1
TXD
RXD
MCLK MDAT
MCMD
SCL
SDA
SCK
SI
SO
AIN1:0
KIN3:0
D+
D-
External
Interrupt 0
Timer 0
External
Interrupt 1
Timer 1
Serial
Port
MP3
Decoder
Audio
Interface
MMC
Controller
TWI
Controller
SPI
Controller
A to D
Converter
Keyboard
USB
Controller
00 01 10 11
EX0
IEN0.0
ET0
IEN0.1
EX1
IEN0.2
ET1
IEN0.3
ES
IEN0.4
EMP3
IEN0.5
EAUD
IEN0.6
EMMC
IEN1.0
EI2C
IEN1.1
ESPI
IEN1.2
EADC
IEN1.3
EKB
IEN1.4
EUSB
IEN1.6
Interrupt Enable Lowest Priority Interrupts
EA
IEN0.7
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
00 01 10 11
IPH/L
Priority Enable
Highest
Priority
Interrupts
38
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

External Interrupts

INT1:0 Inputs External interrupts INT0 and INT1 (INTn, n = 0 or 1) pins may each be programmed to
be level-triggered or edge-triggered, dependent upon bits IT0 and IT1 (ITn, n = 0 or 1) in TCON register as shown i n Figure 22. If ITn = 0, INTn pin. If ITn = 1, INTn
is negative-edge trig gered . E xte rnal interrupts are enabled with bits EX0 and EX1 (EXn, n = 0 or 1) in IEN0. Events on INTn in TCON register. If the interrupt is edge-triggered, the request flag is cleared by hard­ware when vectoring to the interrupt service routine. If the interrupt is level-triggered, the interrupt service routine must clear the request flag and the interrupt must be deas­serted before the end of the interrupt service routine.
INT0
and INT1 inputs provide b oth t he cap ability t o exit from P ower-do wn mode o n low
level signals as detail ed in sect i on “Exiting Power-down Mode, page 48.
is triggered by a low level at the
set the interrupt request flag IEn
Figure 22. INT1:0
INT0/1
Input Circuitry
0 1
IT0/1
TCON.0/2
IE0/1
TCON.1/3
EX0/1
IEN0.0/2
INT0/1 Interrupt Request
KIN3:0 Inputs External interrupts KIN0 to KIN3 provide the capability to connect a matrix keyboard. For
detailed information on these inputs, refer to section Keyboard Interface, page 179.
Input Sampling Ex ternal i nterrupt pins (INT1 :0
and KIN3:0) are sampled once per peripheral cycle (6 peripheral clock periods) (see Figure 23) . A le ve l- trig ger ed inte rrup t pi n hel d lo w or hig h for more than 6 peripheral clock periods (12 oscillator in standard mode or 6 oscillator clock periods in X2 mode) guar antees detectio n. Edge-trigger ed external i nterrupts must hold the request pin low for at least 6 peripheral clock periods.
Figure 23. Minimum Pulse Timings
Level-Triggered Interrupt
> 1 Peripheral Cycle
1 cycle
4109E–8051–06/03
Edge-Triggered Interrupt
> 1 Peripheral Cycle
1 cycle 1 cycle
39

Registers Table 51. IEN0 Register

IEN0 (S:A8h) – Interrupt Enable Register 0
76543210
EA EAUD EMP3 ES ET1 EX1 ET0 EX0
Bit
Number
7EA
6 EAUD
5EMP3
4ES
3ET1
2EX1
1ET0
Bit
Mnemonic Description
Enable All Interrupt Bit
Set to enable all interrupts. Clear to disable all interrupts.
If EA = 1, each interrupt source is individually enabled or disabled by setting or clearing its interrupt enable bit.
Audio Interface Interrupt Enable Bit Set to enable audio interface interrupt. Clear to disable audio interface interrupt.
MP3 Decoder Interrupt Enable Bit
Set to enable MP3 decoder interrupt. Clear to disable MP3 decoder interrupt.
Serial Port Interrupt Enable Bit
Set to enable serial port interrupt. Clear to disable serial port interrupt.
Timer 1 Overflow Interrupt Enable Bit
Set to enable timer 1 overflow interrupt. Clear to disable timer 1 overflow interrupt.
External Interrupt 1 Enable bit
Set to enable external interrupt 1. Clear to disable external interrupt 1.
Timer 0 Overflow Interrupt Enable Bit
Set to enable timer 0 overflow interrupt. Clear to disable timer 0 overflow interrupt.
40
Reset Value = 0000 0000b
AT8xC51SND1C
0EX0
External Interrupt 0 Enable Bit
Set to enable external interrupt 0. Clear to disable external interrupt 0.
4109E–8051–06/03
AT8xC51SND1C
Table 52. IEN1 Register
IEN1 (S:B1h) – Interrupt Enable Register 1
76543210
- EUSB - EKB EADC ESPI EI2C EMMC
Bit
Number
7-
6EUSB
5-
4EKB
3 EADC
2ESPI
1EI2C
0EMMC
Bit
Mnemonic Description
Reserved
The value read from this bit is always 0. Do not set this bit.
USB Interface Interrupt Enable Bit
Set this bit to enable USB interrupts. Clear this bit to disable USB interrupts.
Reserved
The value read from this bit is always 0. Do not set this bit. Keyboard Interface Interrupt Enable Bit
Set to enable Keyboard interrupt. Clear to disable Keyboard interrupt.
A to D Converter Interrupt Enable Bit
Set to enable ADC interrupt. Clear to disable ADC interrupt.
SPI Controller Interrupt Ena ble Bit
Set to enable SPI interrupt. Clear to disable SPI interrupt.
Two Wire Controller Interrupt Enable Bit
Set to enable Two Wire interrupt. Clear to disable Two Wire interrupt.
MMC Interface Interrupt Enable Bit Set to enable MMC interrupt. Clear to disable MMC interrupt.
4109E–8051–06/03
Reset Value = 0000 0000b
41
Table 53. IPH0 Register
IPH0 (S:B7h) – Interrupt Priority High Register 0
76543210
- IPHAUD IPHMP 3 IPHS IPHT1 IPHX1 IPHT0 IPHX0
Bit
Number
7-
6IPHAUD
5IPHMP3
4IPHS
3IPHT1
2IPHX1
1IPHT0
0IPHX0
Bit
Mnemonic Description
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Audio Interface Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
MP3 Decoder Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
Serial Port Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
Timer 1 Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
External Interrupt 1 Priority Level MSB
Refer to Table 49 for priority level description.
Timer 0 Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
External Interrupt 0 Priority Level MSB
Refer to Table 49 for priority level description.
Reset Value = X000 0000b
42
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 54. IPH1 Register
IPH1 (S:B3h) – Interrupt Priority High Register 1
76543210
- IPHUSB - IPHKB IPHADC IPHSPI IPHI2C IPHMMC
Bit
Number
7-
6 IPHUSB
5-
4IPHKB
3IPHADC
2IPHSPI
1IPHI2C
0IPHMMC
Bit
Mnemonic Description
Reserved
The value read from this bit is always 0. Do not set this bit.
USB Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
Reserved
The value read from this bit is always 0. Do not set this bit.
Keyboard Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
A to D Converter Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
SPI Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
Two Wire Controller Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
MMC Interrupt Priority Level MSB
Refer to Table 49 for priority level description.
Reset Value = 0000 0000b
4109E–8051–06/03
43
Table 55. IPL0 Register
IPL0 (S:B8h) - Interrupt Priority Low Register 0
76543210
- IPLAUD IPLMP3 IPLS IPLT1 IPLX1 IPLT0 IPLX0
Bit
Number
7-
6IPLAUD
5IPLMP3
4IPLS
3IPLT1
2IPLX1
1IPLT0
0IPLX0
Bit
Mnemonic Description
Reserved
The value read from this bit is indeterminate. Do not set this bit.
Audio Interface Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
MP3 Decoder Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
Serial Port Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
Timer 1 Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
External Interrupt 1 Priority Level LSB
Refer to Table 49 for priority level description.
Timer 0 Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
External Interrupt 0 Priority Level LSB
Refer to Table 49 for priority level description.
Reset Value = X000 0000b
44
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 56. IPL1 Register
IPL1 (S:B2h) – Interrupt Priority Low Register 1
76543210
- IPLUSB - IPLKB IPLADC IPLSPI IPLI2C IPLMMC
Bit
Number
7-
6IPLUSB
5-
4IPLKB
3IPLADC
2IPLSPI
1IPLI2C
0IPLMMC
Bit
Mnemonic Description
Reserved
The value read from this bit is always 0. Do not set this bit.
USB Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
Reserved
The value read from this bit is always 0. Do not set this bit.
Keyboard Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
A to D Converter Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
SPI Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
Two Wire Controller Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
MMC Interrupt Priority Level LSB
Refer to Table 49 for priority level description.
Reset Value = 0000 0000b
4109E–8051–06/03
45

Power Management 2 power reduction modes are implemented in the AT8xC51SND1C: the Idle mode and

the Power-do wn mode . These modes are detai led in the fol lowing s ecti ons. In additio n to these power redu cti on mo des , t he cl oc ks o f th e c ore and peripherals can be dynam i­cally divided by 2 using the X2 mode detailed in section “X2 Feature, page 12.

Reset In order to start-up (cold reset) or to restart (warm reset) properly the microcontroller, an

high level has to be applied on the RST pin. A bad level leads to a wrong initialization of the internal regis ters like SFRs, Pr ogram Cou nter and to unpredictable behavi or of the microcontroller. A proper device reset in itializes the AT8xC5 1SND1C and vector s the CPU to address 0000h. RS T input has a pu ll-d own resi stor allo wing pow er-on r eset by simply connecti ng an ex tern al cap acito r to V can be applied eith er directl y on the RST pin or indirect ly by an inter nal reset so urce such as the watchdog timer. Resistor value and input c haracteristics are dis cussed in the Section DC Characteristics of the AT8xC51SND1C datashe et. The status of the Port pins during reset is detailed in Table 57.
Figure 24. Reset Circuitry and Power-On Reset
VDD
P
RST
RST
R
VSS
as shown in Figure 24 . A warm r eset
DD
From Internal Reset Source
To CPU Core and Peripherals
VDD
+
RST
Table 57. Pin Conditions in Special Operating Modes
Mode Port 0 Port 1 Port 2 Port 3 Port 4 Port 5 MMC Audio
Reset Floating High High High High High Floating Idle Data Data Data Data Data Data Data Data Power-down Data Data Data Data Data Data Data Data
Note: 1. Refer to section Audio Output Interface, page 73.
Cold Reset 2 conditions are required before enabling a CPU start-up:
V
must reach the specified VDD range
DD
The level on X1 input pin must be outside the specification (V If one of these 2 conditions are not me t, the mic rocontr oll er does no t start correctl y and
can execute an instruction fetch from anywhere in the program space. An active leve l applied on the RST pin must be maintained till both of the above conditions are met. A reset is active when the level V period of time wher e V
and the oscillator are not stabilized. 2 parameters have to be
DD
is reached and wh en the pulse width covers the
IH1
taken into account to determine the reset pulse width:
V
rise time,
DD
Oscillator startup time.
Power-on ResetRST input circuitry
IH
1
, VIL)
46
To determine the capacitor value to implement, the highest value of these 2 parameters has to be chosen. Table 58 give s some capaci tor value s exam ples for a mi nimum R of 50 K and different oscillator startup and VDD rise times.
AT8xC51SND1C
RST
4109E–8051–06/03
AT8xC51SND1C
Table 58. Minimum Reset Capacitor Value for a 50 k Pull-down Resistor
Oscillator
Start-Up Time
5 ms 820 nF 1.2 µF 12 µF
20 ms 2.7 µF 3.9 µF 12 µF
Note: 1. These values assume VDD starts from 0V to the nominal value. If the time between 2
on/off sequences is too fast, the power-supply de-coupling capacitors may not be fully discharged, leading to a bad reset sequence.
1 ms 10 ms 100 ms
VDD Rise Time
(1)
Warm Reset To achieve a valid reset, the reset signal must be maintained for at least 2 machine
cycles (24 oscillator clock periods) while the oscillator is running. The number of clock periods is mode independent (X2 or X1).
Watchdog Reset As detailed in section Watchdog Timer, page 59, the WDT generates a 96-clock period
pulse on the RST pin. In order to properly propagate this pulse to the rest of the applica­tion in case of external capacitor or power-supply supervisor circuit, a 1 k resistor must be added as shown in Figure 25.
Figure 25. Reset Circuitry for WDT Reset-out Usage
VDD
VDD
+
RST
1K
VDD
From WDT
P
Reset Source To CPU Core
and Peripherals
RST
VSS
R
To Other On-board
Circuitry

Reset Recommendation to Prevent Flash Corruption

RST
VSS
An example of bad initialization situation may occur in an instance where the bit ENBOOT in AUXR1 registe r is initiali zed from the har dware bit BLJB upon reset. Sinc e this bit allows mapping of the bootloader in the code area, a reset failure can be critical.
If one wants the ENBOOT cleared in order to unmap the boot from the code area (yet due to a bad reset) the b it ENBOOT in SFRs may be set. If the value of Progra m Counter is accidently in the range of the boot memory addresses then a Flash access (write or erase) may corrupt the Flash on-chip memory.
It is recommended to use an external reset circuitry featuring power supply monitoring to prevent system malfunction during periods of insufficient power supply voltage (power supply failure, power supply switched off).

Idle Mode Idle mode is a power reduction mode that reduces the power consumption. In this mode,

program execution halts. Idle mode freezes the cl ock to the CPU at known sta tes while the peripherals continue to be clocked (refer to section “Oscillator”, page 12). The CPU status before entering Idle mode is preserve d, i.e., the program cou nter and p rogram status word register retain their data for the duration of Idle mode. The contents of the SFRs and RAM are also retai ned. The status of the Po rt pins during Idle mod e is detailed in Table 57.
4109E–8051–06/03
47
Entering Idle Mode To enter Idle mode , the use r must set th e IDL bit in PCO N re gister (see Table 59). The
AT8xC51SND1C enters Idle mode upon e xecution of t he instructi on that sets I DL bit. The instruction that sets IDL bit is the last instruction executed.
Note: If IDL bit and PD bit are set simultaneously, the AT8xC51SND1C enter Power-down
mode. Then it does not go in Idle mode when exiting Power-down mode.
Exiting Idle Mode There are 2 ways to exit Idle mode:
1. Generate an enabled interrupt.
Hardware clears IDL bit in PCON register which restores the clock to the
CPU. Execution resumes with the interrupt service routine. Upon completion of the interrupt service routine, program execution resumes with the instruction immediately following the instruction that activated Idle mode. The general-purpose flags (GF1 and GF0 in PCON register) may be used to indicate whether an interrupt occurred during normal operation or during Idle mode. When Idle mode is exited by an interrupt, the interrupt service routine may examine GF1 and GF0.
2. Generate a reset.
A logic high on the RST pin clears IDL bit in PCON register directly and
asynchronously. This restores the clock to the CPU. Program execution momentarily resumes with the instruction immediately following the instruction that activated the Idle mode and may continue for a number of clock cycles before the internal reset algorithm takes control. Reset initializes the AT8xC51SND1C and vectors the CPU to address C:0000h.
Note: During the time that execution resumes, the in tern al R AM cann ot be acc es sed; how e ve r,
it is possible for the Port pins to be accessed. To avoid unexpected outputs at the Port pins, the instruction immediately following the instruction that activated Idle mode should not write to a Port pin or to the external RAM.

Power-down Mode The Power-down mode places the AT8xC51SND1C in a very low power state. Power-

down mode stops the os c illat or and free zes all c lock s a t kn own s tat es (ref er to the Se c­tion "Oscillator", page 12). The CPU status prior to entering Power-down mode is preserved, i.e., the program counter, program status word register retain their data for the duration of Power-down mode. In addition, the SFRs and RAM contents are pre­served. The status of the Port pins during Power-down mode is detailed in Table 57.
Note: VDD may be reduced to as l ow as V
dissipation. Notice, however, that V
Entering Power-down Mode To enter Power-down mode, set PD bit in PCON register. The AT8xC51SND1C enters
the Power-down mode upon execution of the instruction that sets PD bit. The instruction that sets PD bit is the last instruction executed.
Exiting Power-down Mode If V
was reduced during the Power-down mode, do not exit Power-down mode until
DD
V
is restored to the normal operating level.
DD
There are 2 ways to exit the Power-down mode:
1. Generate an enabled external interrupt.
The AT8xC51SND1C provides capability to exit from Power-down using
INT0
, INT1, and KIN3:0 inputs. In addition, using KIN input provides high or low level exit capability (see section Keyboard Interface, page 179). Hardware clears PD bit in PCON register which starts the oscillator and restores the clocks to the CPU and peripherals. Using INTn
during Power-down mode to further reduce power
RET
is not reduced until Power-down mode is invoked.
DD
input, execution
48
AT8xC51SND1C
4109E–8051–06/03
resumes when the input is released (see Figure 26) while using KINx input, execution resumes after counting 1024 clock ensuring the oscillator is restarted properly (see Figure 27). This behavior is necessary for decoding the key while it is still pressed. In both cases, execution resumes with the interrupt service routine. Upon completion of the interrupt service routine, program execution resumes with the instruction immediately following the instruction that activated Power-down mode.
Note: 1. The external interrupt used to exit Power-down mode must be configured as level
sensitive ( duration of the interrupt must be long enough to allow the oscillator to stabilize. The execution will only resume when the interrupt is deasserted.
2. Exit from power-down by external interrupt does not affect the SFRs nor the internal RAM content.
Figure 26. Power-down Exit Waveform Using INT1:0
INT1:0
OSC
AT8xC51SND1C
INT0 and INT1) and must be assigned the highest priority. In addition, the
Power-down Phase
Figure 27. Power-down Exit Waveform Using KIN3:0
1
KIN3:0
OSC
Power-down Phase
Note: 1. KIN3:0 can be high or low-level triggered.
2. Generate a reset. – A logic high on the RST pin clears PD bit in PCON register directly and
asynchronously. This starts the oscillator and restores the clock to the CPU and peripherals. Program execution momentarily resumes with the instruction immediately following the instruction that activated Power-down mode and may continue for a number of clock cycles before the internal reset algorithm takes control. Reset initializes the AT8xC51SND1C and vectors the CPU to address 0000h.
Notes: 1. During the t im e th at ex e cu tio n r esu me s, th e i nt er na l RAM ca n no t be ac ce ss ed ; how -
ever, it is possible for the Port pins to be accessed. To avoid unexpected outputs at the Port pins, the instruction immediately following the instruction that activated the Power-down mode should not write to a Port pin or to the external RAM.
2. Exit from power-down by res et r ede fine s all the SFRs, but does not af fect the internal RAM content.
Oscillator Restart Phase
1024 clock count Active phaseActive phase
Active PhaseActive phase
4109E–8051–06/03
49

Registers Table 59. PCON Register

PCON (S:87h) – Power Configuration Register
76543210
----GF1GF0PD IDL
Bit
Number
7 - 4 -
3GF1
2GF0
1PD
0IDL
Bit
Mnemonic Description
Reserved
The value read from these bits is indeterminate. Do not set these bits.
General-purpose flag 1
One use is to indicate whether an interrupt occurred during normal operation or during Idle mode.
General-purpose flag 0
One use is to indicate whether an interrupt occurred during normal operation or during Idle mode.
Power-down Mode bit
Cleared by hardware when an interrupt or reset occurs. Set to activate the Power-down mode. If IDL and PD are both set, PD takes precedence.
Idle Mode bit
Cleared by hardware when an interrupt or reset occurs. Set to activate the Idle mode. If IDL and PD are both set, PD takes precedence.
Reset Value = XXXX 0000b
50
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Timers/Counters The AT8xC51SND1C implement 2 general-purpose, 16-bit Timers/Counters. They are

identified as Timer 0 and Timer 1, an d can be in depende ntly confi gured to operate in a variety of modes as a Timer or as an event Coun ter. When op erating a s a Timer, th e Timer/Counter runs for a programmed length of time, then issues an interrupt request. When operating as a Counter, the Tim er/Counter counts n egative transit ions on an external pin. After a preset number of counts, the Counter issues an interrupt request.
The various o perating modes o f each Ti mer/Count er are de scribed in the fo llowing sections.

Timer/Counter Operations

For instance, a basic operation is Timer registers THx and TLx (x = 0, 1) connected in cascade to form a 16-bit Timer. Setting the run control bit (TRx) in TCON register (see Table 60) turns the Timer on by allowing the selected input to increment TLx. When TLx overflows it increments THx; when THx overflows it sets the Timer overflow flag (TFx) in TCON register. S ettin g the TRx doe s not clea r the THx an d TLx Tim er regis ters. T imer registers can be ac cessed to obtain the curr ent count or to enter preset va lues. T hey can be read at any time but TRx bit must be cleared to preset their values, otherwise, the behavior of the Timer/Counter is unpredictable.
The C/Tx# control bit selects Timer operation or Counter operation by selecting the divided-down peripheral clock or external pin T x as the source for the counted sign al. TRx bit must be cleared when changing the mode of operation, otherwise the behavior of the Timer/Counter is unpredictable.
For Timer op erat ion (C/Tx # = 0 ), t he T ime r reg ist er co unts the div ided-d own peri phera l clock. The Timer register is incremented once every peripheral cycle (6 peripheral clock periods). The Time r cloc k rat e is F
/6, i.e., F
PER
/12 in standard mo de or F
OSC
OSC
/6 in X2
mode. For Counter operation (C/Tx # = 1), the T im er reg ister cou nts the neg ati ve tran si ti ons on
the Tx external input pin. The external input is sampled every peripheral cycles. When the sample is high in one cycle and low in the next one, the Counter is incremented. Since it takes 2 cycles (12 peripheral clock periods) to recognize a negative transition, the maximum count rate is F
/12, i.e., F
PER
/24 in standard mode or F
OSC
/12 in X2
OSC
mode. There are no restrictions on the duty cycle of the external input signal, but to ensure that a given level is sampled at least once before it changes, it should be held for at least one full peripheral cycle.

Timer Clock Controller As shown in Figure 28, the Timer 0 (FT0) and Timer 1 (FT1) clocks are de rived from

either the peripheral clock (F and T1X2 bits i n CKCON r egister. These c locks a re issu ed from the Clo ck Contro ller block as deta iled in Secti on Clock Controller, page 12. When T0X2 or T1X2 bit is set , the Timer 0 or Timer 1 clock frequency is fix ed and equal to the oscillator cl ock fre­quency divided by 2. Whe n cleared, the Timer cloc k frequen cy is equal to the oscillat or clock frequency divi ded by 2 in s tand ar d m ode or to the oscillator clock fr eq uency i n X 2 mode.
4109E–8051–06/03
) or the oscillator clock (F
PER
) depending on the T0X2
OSC
51
Figure 28. Timer 0 and Timer 1 Clock Controller and Symbols
PER
CLOCK
OSC
CLOCK
÷ 2
TIM0
CLOCK
0
Timer 0 Clock
1
T0X2
CKCON.1
PER
CLOCK
OSC
CLOCK
0
Timer 1 Clock
1
÷ 2
T1X2
CKCON.2
TIM1
CLOCK
Timer 0 Clock Symbol
Timer 1 Clock Symbol

Timer 0 Timer 0 functions as either a Timer or event Counter in four modes of operation.

Figure 29 through Figure 35 show the logical configuration of each mode. Timer 0 is controlled by the four lower bits of TMOD register (see Table 61) and bits 0, 1,
4 and 5 of TCON register (see Table 60). TMOD register selects the method of Timer gating (GATE0), Timer or Counter operation (C/T0#) and mode of operation (M10 and M00). TCON register provides Timer 0 control functions: overflow flag (TF0), run control bit (TR0), interrupt flag (IE0) and interrupt type control bit (IT0).
For normal Timer ope ratio n (GAT E0 = 0) , se tting TR 0 allows TL 0 to be increme nted by the selected input. Settin g GATE0 and TR0 allow s external pin IN T0 operation.
Timer 0 overflow (count rolls over from all 1s to all 0s) sets TF0 flag generating an inter­rupt request. It is important to stop Timer/Counter before changing mode.
Mode 0 (13-bit Timer) Mode 0 configures Timer 0 as a 13-bit Timer which is set up as an 8-bit Timer (TH0 reg-
ister) with a modulo 32 pre scaler implem ented with the lo wer five bits of TL0 r egister (see Figure 29). The upper three bits of TL0 register are indeterminate and should be ignored. Prescaler overflow increments TH0 register. Figure 30 gives the overflow period calculation form ula.
to control Timer
Figure 29. Timer/Counter x (x = 0 or 1) in Mode 0
TIMx
CLOCK
Tx
INTx
÷ 6
GATEx
TMOD Reg
0 1
C/Tx#
TMOD Reg
TRx
TCON Reg
Figure 30. Mode 0 Overflow Period Formula
6 (16384 – (THx, TLx))
=
PER
52
TFx
AT8xC51SND1C
F
TIMx
TLx
(5 Bits)
THx
(8 Bits)
Overflow
TFx
TCON reg
Timer x Interrupt Request
4109E–8051–06/03
AT8xC51SND1C
Mode 1 (16-bit Timer) Mode 1 configures Timer 0 as a 16-bit Timer with TH0 and TL0 registers connected in
cascade (see Figure 31). The selected input increments TL0 regi ster. Figure 32 gives the overflow period calculation formula when in timer mode.
Figure 31. Timer/Counter x (x = 0 or 1) in Mode 1
TIMx
CLOCK
÷ 6
0 1
Tx
C/Tx#
TMOD Reg
INTx
GATEx
TMOD Reg
TRx
TCON Reg
Figure 32. Mode 1 Overflow Period Formula
TFx
Mode 2 (8-bit Timer with Auto­Reload)
Mode 2 configures Timer 0 as an 8-b it Timer (TL0 register) tha t automatically reloads from TH0 register (see Table 6 2). TL0 overflow sets TF0 flag in TCON regis ter and reloads TL0 with the contents of TH0, which is preset by software. When the interrupt request is servic ed, ha rdware clears TF0. The reload leaves TH0 unch anged. The next reload value may be changed at any time by writing it to TH0 register. Figure 34 gives the autoreload period calculation formula when in timer mode.
Figure 33. Timer/Counter x (x = 0 or 1) in Mode 2
(65536 – (THx, TLx))
6
=
PER
THx
(8 bits)
F
TIMx
TLx
(8 bits)
Overflow
TFx
TCON Reg
Timer x Interrupt Request
TIMx
CLOCK
÷ 6
0 1
TLx
(8 bits)
Overflow
TFx
TCON reg
Timer x Interrupt Request
Tx
C/Tx#
TMOD reg
INTx
THx
GATEx
TMOD reg
TRx
TCON reg
(8 bits)
Figure 34. Mode 2 Autoreload Period Formula
PER
=
6 (256 – THx)
F
TIMx
TFx
Mode 3 (2 8-bit Timers) Mode 3 configures Timer 0 such that registers TL0 and TH0 operate as separate 8-bit
Timers (see Figure 35). This mode is provided for applications requiring an additional 8­bit Timer or Counter. TL0 uses the Timer 0 control bits C/T0# and GATE0 in TMOD reg­ister, and TR0 and TF0 in TCON register in the normal manner. TH0 is locked into a Timer function (counting F
/6) and takes over use of the Timer 1 interrupt (TF1) and
TF1
run control (TR1) bits. Thus , operation of Tim er 1 is restricted when Timer 0 is in mod e
4109E–8051–06/03
53
3. Figure 34 gives the auto reload perio d calculation for mulas for both T F0 and TF1 flags.
Figure 35. Timer/Counter 0 in Mode 3: 2 8-bit Counters
TIM0
CLOCK
T0
÷ 6
0 1
C/T0#
TMOD.2
INT0
TL0
(8 bits)
Overflow
TF0
TCON.5
Timer 0 Interrupt Request
TIM0
CLOCK
GATE0
TMOD.3
÷ 6
TR0
TCON.4
TH0
(8 bits)
Overflow
TF1
TCON.7
Timer 1 Interrupt Request
TR1
TCON.6
Figure 36. Mode 3 Overflow Period Formula
TF0
PER
=
6 (256 – TL0)
F
TIM0
TF1
PER
=
6 (256 – TH0)
F
TIM0

Timer 1 Timer 1 is identical to Timer 0 except for Mode 3 which is a hold-count mode. The fol-

lowing comments help to understand the differences:
Timer 1 functions as either a Timer or event Counter in three modes of op eration. Figure 29 through Figure 33 show the logical configuration for modes 0, 1, and 2. Timer 1s mode 3 is a hold-count mode.
Timer 1 is controlled by the four high-order bits of TMOD register (see Figure 61) and bits 2, 3, 6 and 7 of TCON register (see Figure 60). TMOD register selects the method of Timer gating (GATE1), Timer or Counter operation (C/T1#) and mode of operation (M11 and M01). TCON register provides Timer 1 control functions: overflow flag (TF1), run control bit (TR1), interrupt flag (IE1) and interrupt type control bit (IT1).
Timer 1 can serve as the Baud Rate Generator for the Serial Port. Mode 2 is best suited for this purpose.
For normal Timer operation (GATE1 = 0), setting TR1 allows TL1 to be incremented by the selected input. Setting GATE1 and TR1 allows external pin INT1 Timer operation.
Timer 1 overflow (count rolls over from all 1s to all 0s) sets the TF1 flag generating an interrupt request.
When Timer 0 is in mode 3, it uses Timer 1s overflow flag (TF1) and run control bit (TR1). For this situation, use Timer 1 only for applications that do not require an interrupt (such as a Baud Rate Generator for the Serial Port) and switch Timer 1 in and out of mode 3 to turn it off and on.
It is important to stop the Timer/Counter before changing modes.
to control
54
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Mode 0 (13-bit Timer) Mode 0 configures Timer 1 as a 13-bit Timer, which is set up as an 8-bit Timer (TH1 reg-
ister) with a modulo-32 prescaler implemented with the lower 5 bits of the TL1 register (see Figure 29) . The up per 3 bits of TL1 re gister are igno red. Pre scal er overf low inc re­ments TH1 register.
Mode 1 (16-bit Timer) Mode 1 configures Timer 1 as a 16-bit Timer with TH1 and TL1 registers connected in
cascade (see Figure 31). The selected input increments TL1 register.
Mode 2 (8-bit Timer with Auto­Reload)
Mode 2 configures Timer 1 as an 8-bit Timer (TL1 register) with automatic reload from TH1 register on ove rflow ( see Figu re 33 ). TL1 o verflo w sets T F1 flag in TCO N regis ter and reloads TL1 with the contents of TH1, which is preset by software. The reload leaves TH1 unchanged.
Mode 3 (Halt) Placing Timer 1 in mode 3 causes it to halt and ho ld its coun t. This can be used to halt
Timer 1 when TR1 run control bit is not available i.e. when Timer 0 is in mode 3.

Interrupt Each Timer handles one interrupt source that is the timer overflow flag TF0 or TF1. This

flag is set every time an overfl ow oc c urs. Fla gs are cl eared when v ec tor in g to the Timer interrupt routine. Interrupts are enabled by setting ETx bit in IEN0 register. This assumes interrupts are globally enabled by setting EA bit in IEN0 register.
Figure 37. Timer Interrupt System
TF0
TCON.5
ET0
IEN0.1
TF1
TCON.7
ET1
IEN0.3
Timer 0 Interrupt Request
Timer 1 Interrupt Request
4109E–8051–06/03
55

Registers Table 60. TCON Register

TCON (S:88h) – Timer/Counter Control Register
76543210
TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
Bit
Number
7TF1
6TR1
5TF0
4TR0
3IE1
2IT1
1IE0
Bit
Mnemonic Description
Timer 1 Overflow Flag
Cleared by hardware when processor vectors to interrupt routine. Set by hardware on Timer/Counter overflow, when Timer 1 register overflows.
Timer 1 Run Control Bit
Clear to turn off Timer/Counter 1. Set to turn on Timer/Counter 1.
Timer 0 Overflow Flag
Cleared by hardware when processor vectors to interrupt routine. Set by hardware on Timer/Counter overflow, when Timer 0 register overflows.
Timer 0 Run Control Bit
Clear to turn off Timer/Counter 0. Set to turn on Timer/Counter 0.
Interrupt 1 Edge Flag
Cleared by hardware when interrupt is processed if edge-triggered (see IT1). Set by hardware when external interrupt is detected on INT1
Interrupt 1 Type Control Bit
Clear to select low level active (level triggered) for external interrupt 1 (INT1 Set to select falling edge active (edge triggered) for external interrupt 1.
Interrupt 0 Edge Flag
Cleared by hardware when interrupt is processed if edge-triggered (see IT0). Set by hardware when external interrupt is detected on
pin.
INT0 pin.
).
0IT0
Interrupt 0 Type Control Bit
Clear to select low level active (level triggered) for external interrupt 0 (INT0 Set to select falling edge active (edge triggered) for external interrupt 0.
Reset Value = 0000 0000b
).
56
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 61. TMOD Register
TMOD (S:89h) – Timer/Counter Mode Control Register
76543210
GATE1 C/T1# M11 M01 GATE0 C/T0# M10 M00
Bit
Number
7GATE1
6C/T1#
5M11Timer 1 Mode Select Bits
4M01
3GATE0
2C/T0#
1
0
Bit
Mnemonic Description
Timer 1 Gating Control Bit
Clear to enable Timer 1 whenever TR1 bit is set. Set to enable Timer 1 only while INT1
Timer 1 Counter/Timer Select Bit
Clear for Timer operation: Timer 1 counts the divided-down system clock. Set for Counter operation: Timer 1 counts negative transitions on external pin T1.
M01 Operating mode
M11
0 0 Mode 0: 8-bit Timer/Counter (TH1) with 5-bit prescaler (TL1). 0 1 Mode 1: 16-bit Timer/Counter. 1 0 Mode 2: 8-bit auto-reload Timer/Counter (TL1).
1 1 Mode 3: Timer 1 halted. Retains count.
Timer 0 Gating Control Bit
Clear to enable Timer 0 whenever TR0 bit is set. Set to enable Timer/Counter 0 only while
Timer 0 Counter/Timer Select Bit
Clear for Timer operation: Timer 0 counts the divided-down system clock. Set for Counter operation: Timer 0 counts negative transitions on external pin T0.
M10 Timer 0 Mode Select Bit
M00
M10
M00 Operating mode 0 0 Mode 0: 8-bit Timer/Counter (TH0) with 5-bit prescaler (TL0). 0 1 Mode 1: 16-bit Timer/Counter. 1 0 Mode 2: 8-bit auto-reload Timer/Counter (TL0).
1 1 Mode 3: TL0 is an 8-bit Timer/Counter .
TH0 is an 8-bit Timer using Timer 1s TR0 and TF0 bits.
Notes: 1. Reloaded from TH1 at overflow.
2. Reloaded from TH0 at overflow.
pin is high and TR1 bit is set.
(1)
INT0 pin is high and TR0 bit is set.
(2)
4109E–8051–06/03
Reset Value = 0000 0000b
Table 62. TH0 Register TH0 (S:8Ch) – Timer 0 High Byte Register
76543210
--------
Bit
Number
7:0 High Byte of Timer 0
Bit
Mnemonic Description
Reset Value = 0000 0000b
57
Table 63. TL0 Register
TL0 (S:8Ah) – Timer 0 Low Byte Register
76543210
--------
Bit
Number
7:0 Low Byte of Timer 0
Bit
Mnemonic Description
Reset Value = 0000 0000b
Table 64. TH1 Register TH1 (S:8Dh) – Timer 1 High Byte Register
76543210
--------
Bit
Number
7:0 High Byte of Timer 1
Bit
Mnemonic Description
Reset Value = 0000 0000b
Table 65. TL1 Register TL1 (S:8Bh) – Timer 1 Low Byte Register
76543210
--------
Bit
Number
7:0 Low Byte of Timer 1
Bit
Mnemonic Description
Reset Value = 0000 0000b
58
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Watchdog Timer The AT8xC51SND1C implement a hardware Wa tchdo g T im er ( WDT) tha t au toma tic al ly

resets the chip if it is allowed to time out. The WDT provides a means of recovering from routines that do not complete successfully due to software or hardware malfunctions.

Description The WDT consists of a 14-bit prescaler followed by a 7-bit programmable counter. As

shown in Figure 38, the 14-bit prescaler is fed by the WDT clock detailed in Section Watchdog Clock Controller, page 59.
The Watchdog Timer Reset register (WDTRST, see Table 67) provides control access to the WDT, while the Watchdog Timer Program register (WDTPRG, see Figure 41) pro­vides time-out period programming.
Three operations contr ol the WDT:
Chip reset clears and disables the WDT.
Programming the time-out value to the WDTPRG register.
Writing a specific 2-Byte sequence to the WDTRST register clears and enables the
WDT.
Figure 38. WDT Block Diagram
WDT
CLOCK
System Reset

Watchdog Clock Controller

÷ 6
1Eh-E1h Decoder
RST
WDTRST
As shown in Figure 3 9 the W DT cloc k (F (F
) or the oscillator clock (F
PER
These clocks are issued from the Clock Contr oller block as detail ed in Section "Clock Controller", page 12. When WTX2 bit is set, the WDT clock frequency is fixed and equal to the oscillator clock frequency divided by 2. When cleared, the WDT clock frequency is equal to the os cill ator cl oc k fr eq uen cy d iv id ed by 2 in standard m ode o r to th e o sc illator clock frequency in X2 mode.
Figure 39. WDT Clock Controller and Symbol
PER
CLOCK
OSC
CLOCK
÷ 2
WTX2
CKCON.6
14-bit Prescaler
RST
EN
MATCH
0 1
OSC
WDT Clock
7-bit Counter
RST
OSC
CLOCK
WDT
OV
SET
WTO2:0
WDTPRG.2:0
) is derived from e ither the peri pheral c lock
To internal reset
RSTPulse Generator
) depending on the WTX2 bit in CKCON register .
WDT
CLOCK
WDT Clock Symbol
4109E–8051–06/03
59

Watchdog Operation After reset, the WDT is disabled. The W D T i s en abl ed b y w ritin g the sequence 1Eh and

E1h into the WDTRST register. As soon as it is enabled, there is no way except the chip reset to disable it. If it is not cleared using the previous sequence, the WDT overflows and forces a chip reset . This over flow gene rates a high lev el 96 osci llato r peri ods pu lse on the RST pin to globally reset the application (refer to Section Power Management”, page 46).
The WDT time-out period can be adjusted using WTO2:0 bits located in the WDTPRG register accordingly to the formula shown in Figure 40. In this formula, WTOval repre­sents the decimal value of WTO2:0 bits. Table 66 reports the time-out period depending on the WDT frequency.
Figure 40. WDT Time-Out Formula
14
2
F
WDT
8 MHz
WTOval
(1)
) – 1)
10 MHz
(ms)
F
WDT
(1)
12 MHz
(2)
16 MHz
(2)
20 MHz
(2)
WDT
6 ((2
=
TO
Table 66. WDT Time-Out Computation
(1)
WTO2 WTO1 WTO0
0 0 0 16.38 12.28 9.83 8.19 6.14 4.92 0 0 1 32.77 24.57 19.66 16.38 12.28 9.83 0 1 0 65.54 49.14 39.32 32.77 24.57 19.66
6 MHz
WDT Behavior during Idle and Power-down Modes
0 1 1 131.07 98.28 78.64 65.54 49.14 39.32 1 0 0 262.14 196.56 157.29 131.07 98.28 78.64 1 0 1 524.29 393.1 314.57 262.14 196.56 157.29 1 1 0 1049 786.24 629.15 524.29 393.12 314.57 1 1 1 2097 1572 1258 1049 786.24 629.15
Notes: 1. These frequencies are achieved in X1 mode or in X2 mode when WTX2 = 1:
= F
F
WDT
2. These frequencies are achieved in X2 mode when WTX2 = 0: F
OSC
÷ 2.
WDT
= F
OSC
.
Operation of the WDT during power reduction modes deserves special attention.
The WDT contin ues to coun t while th e AT8xC51S ND1C is in Id le mode. This mean s that you must dedicate some internal or external hardware to serv ice the WDT during Idle mode. One approach is to use a peripheral Timer to generate an interrupt request when the Timer overflows. The interrupt service routine then cl ears the WDT, reloads the peripheral Timer for the next se rv ice per iod and pu ts the AT 8 xC51S ND1C ba ck in to Idle mode.
The Power-down mode stops all phase clocks. This causes the WDT to stop counting and to hold its count. The WDT resumes counting from where it left off if the Power­down mode is terminate d by INT0
, INT1 or keyboard interrupt. To en sure that the W DT does not overflow shortly after exiting the Power-down mode, it is recommended to clear the WDT just before entering Power-down mode.
60
The WDT is cleared and disabled if the Power-down mode is terminated by a reset.
AT8xC51SND1C
4109E–8051–06/03

Registers Table 67. WDTRST Register

WDTRST (S:A6h Write only) – Watchdog Timer Reset Register
76543210
--------
AT8xC51SND1C
Bit
Number
7 - 0 - Watchdog Control Value
Bit
Mnemonic Description
Reset Value = XXXX XXXXb Figure 41. WDTPRG Register WDTPRG (S:A7h) – Watchdog Timer Program Register
76543210
-----WTO2WTO1WTO0
Bit
Number
7 - 3 -
2 - 0 WTO2:0
Bit
Mnemonic Description
Reserved
The value read from these bits is indeterminate. Do not set these bits.
Watchdog Timer Time-Out Selection Bits
Refer to Table 66 for time-out periods.
Reset Value = XXXX X000b
4109E–8051–06/03
61

MP3 Decoder The AT8xC51SND1C implement a MPEG I/II audio layer 3 decoder better known as

MP3 decoder. In MPEG I (ISO 11172-3) three layers of compression have been standardized support-
ing three sa mpling fre quencies : 48, 44.1 , and 3 2 kHz. A mong th ese layer s, layer 3 allows highest compression rate of about 12:1 while still maintaining CD audio quality. For example, 3 minutes of CD audio (16-bit PCM, 44.1 k Hz) data, which needs a bout 32M bytes of storage, can be encoded into only 2.7M bytes of MPEG I audio layer 3 data.
In MPEG II (ISO 13818-3), three additional sampling frequencies: 24, 22.05, and 16 kHz are supported for low bit rates applications.
The AT8xC51SND1C can decode in real-time the MPEG I audio layer 3 encoded data into a PCM audio data, and also supports MPEG II audio layer 3 additional frequencies.
Additional features are supported by the AT8xC51SND1C MP3 decoder such as volume control, bass, medium, and treble controls, bass boost effect and a ncillary data extraction.

Decoder

Description The C51 core interfaces to the MP3 decoder through nine special function registers:
MP3CON, the MP3 Control register (see Table 72); MP3STA, the MP3 Status register (see Table 73); MP3DAT, the MP3 Data register (see Table 74); MP3ANC, the Ancillary Data register (see Table 76); MP3VOL and MP3VOR, the MP3 Volume Left and Right Control registers (see Table 77 and Table 78); MP3BAS, MP3MED, and MP3TRE, the MP3 Bass, Medium, and Treble Control register s (see Table 79, Table 80, and Table 81); and MPCLK, the MP3 Clock Divider register (see Table 82).
Figure 42 shows the MP3 decoder block diagram.
Figure 42. MP3 Decoder Block Diagram
Audio Data
From C51
MP3
CLOCK
8
MPEN
MP3CON.7
1K Bytes
Frame Buffer
MP3DAT
MPxREQ
MP3STA1.n
Anti-Aliasing
MPBBST
MP3CON.6
MP3VOL MP3VOR MP3BAS MP3MED MP3TRE
Header Checker
Huffman Decoder
ERRxxx
MP3STA.5:3
MPFS1:0
MP3STA.2:1
IMDCT
MPVER
MP3STA.0
Dequantizer
Ancillary B uffer
Sub-band Synthesis
Side Information
MP3ANC
Stereo Processor
Decoded Data
16
To Audio Interface
62
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
MP3 Data The MP3 decoder does not start any frame decoding before having a complete frame in
its input buffer
(1)
. In order to manage the load of MP3 data in the frame buffer, a hard­ware handshake consisting of data request and data acknowledgment is implemented. Each time the MP3 decoder needs MP3 data, it sets the MPREQ, MPFREQ and MPBREQ flags respectively in MP3STA and MP3STA1 registers. MPREQ flag can gen­erate an interrupt if enabled as explained in Section “Interrupt”. Th e CP U m u st t hen load data in the buffer by writing it through MP3DAT register thus acknowledging the previ­ous request. As shown in Figure 43, the MPFREQ flag remains set while data (i.e a frame) is requested by the decoder. It is cleared when no more data is requested and set again when new data are requested. MPBREQ flag toggles at every Byte writing.
Note: 1. The first request after enable, consists in 1024 Bytes of data to fill in the input buffer.
Figure 43. Data Timing Diagram
MPREQ Flag
MPFREQ Flag
MPBREQ Flag
Write to MP3DAT
Cleared when Reading MP3STA
MP3 Clock The MP3 decoder clo ck is generat ed by div ision o f the PL L clock . The divi sion facto r is
given by MPCD4:0 bits in MP3CLK regis ter. Figure 44 shows the MP3 decoder clock generator and its calculation formula. The MP3 decoder clock frequency depends only on the incoming MP3 frames.
Figure 44. MP3 Clock Generator and Symbol
PLL
CLOCK
MP3CLK
MPCD4:0
MP3clk
MP3 Decoder Clock
PLLclk
----------------------------= MPCD 1+
MP3
CLOCK
MP3 Clock Symbol
As soon as the frame header has been decoded and the MPEG version extracted, the minimum MP3 input frequency must be programmed according to Table 68.
Table 68. MP3 Clock Frequency
MPEG Version Minimum MP3 Clock (MHz)
I21
II 10.5
4109E–8051–06/03
63

Audio Controls

Volume Control The MP3 decoder implements volume control on both right and left channels. The
MP3VOR and MP3VOL registers allow a 32-step volume control according to Table 69.
Table 69. Volume Control
VOL4:0 or VOR4:0 Volume Gain (dB)
00000 Mute 00001 -33 00010 -27 11110 -1.5
11111 0
Equalization Control So und can be adjusted using a 3-band equalize r: a bas s ban d unde r 750 Hz, a mediu m
band from 750 Hz to 3300 Hz and a treble band over 3300 Hz. The MP3BAS, MP3MED, and MP3TRE registers allow a 32-step gain control in each band according to Table 70.
Table 70. Bass, Medium, Treble Control
BAS4:0 or MED4:0 or TRE4:0 Gain (dB)
00000 - 00001 -14 00010 -10 11110 +1
11111 +1.5
Special Effect The MPBBST bit in MP3CON register allows enabling of a bass boost effect with the fol-
lowing characteristics: gain increase of +9 dB in the frequency under 375 Hz.

Decoding Errors The three different errors that can appear during frame proces sing are detailed in the

following sections. All these errors can trigger an interrupt as explained in Section "Inter­rupt", page 66.
Layer Error The ERRSYN flag in MP3STA is set whe n a non-su pported layer is deco ded in the
header of the frame that has been sent to the decoder.
Synchronization Error T he ERRSY N flag in MP 3STA is s et when no synchro nizatio n pattern is found in th e
data that have been sent to the decoder.
CRC Error When the CR C of a frame does not ma tch the one c alculated, th e flag ERRCRC i n
MP3STA is set. In this case, depending on the CRCEN bit in MP3CON, the frame is played or rejected. In both cases, noise may appear at audio output.
64
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Frame Information The MP3 frame header contains information on the audio data contained in the frame.

These informations is made available in the MP3STA register for you information. MPVER and MPFS1:0 bits allow decoding of the sampling frequency according to Table 71. MPVER bit gives the MPEG version (2 or 1).
Table 71. MP3 Frame Frequency Sampling
MPVER MPFS1 MPFS0 Fs (kHz)
0 0 0 22.05 (MPEG II) 0 0 1 24 (MPEG II) 0 1 0 16 (MPEG II) 0 1 1 Reserved 1 0 0 44.1 (MPEG I) 1 0 1 48 (MPEG I) 1 1 0 32 (MPEG I) 1 1 1 Reserved

Ancillary Data MP3 frames al so c ontain data bits call ed anc illary da ta. Th ese da ta are ma de ava ilable

in the MP3ANC register for each frame. As shown in Figure 45, the anc illary data a re available by Bytes when MPANC flag in MP3STA regis ter is set. MPANC flag is set when the ancillary buffer is not empty (at least one ancillary data is available) and is cleared only when there is no more ancillary data in the buffer. This flag can generate an interrupt as expl ained in Sectio n "Interr upt", pa ge 66. Wh en set, s oftware must read a ll Bytes to empty the ancillary buffer.
Figure 45. Ancillary Data Block Diagram
Ancillary
Data To C51
8
MP3ANC
8
7-Byte
Ancillary Buffer
MPANC
MP3STA.7
4109E–8051–06/03
65

Interrupt

Description As shown in Figure 46, the MP3 decoder implements five interrupt sources reported in
ERRCRC, ERRSYN, ERRLAY, MPREQ, and MPANC flags in MP3STA register. All these sources are maskable separately using MSKCRC, MSKSYN, MSKLAY,
MSKREQ, and MSKANC mask bits respectively in MP3CON register. The MP3 interrupt is enabled by setting EMP3 bit in IEN0 register. This assumes inter-
rupts are globally enabled by setting EA bit in IEN0 register. All interrupt flags b ut MP REQ an d MP AN C ar e cl eared when reading MP3STA regist er.
The MPREQ flag is cleared by hardware when no more data is requested (see Figure 43) and MPANC flag is cleared by hardware when the ancillary buffer becomes empty.
Figure 46. MP3 Decoder Interrupt System
MPANC
MP3STA.7
MSKANC
MPREQ
MP3STA.6
ERRLAY
MP3STA.5
ERRSYN
MP3STA.4
ERRCRC
MP3STA.3
MSKREQ
MP3CON.3
MSKSYN
MP3CON.1
MP3CON.4
MSKLAY
MP3CON.2
MSKCRC
MP3CON.0
MP3 Decoder Interrupt Request
EMP3
IEN0.5
Management Reading the MP3STA register automatically clears the interrupt flags (acknowledgment)
except the MPREQ and MPANC flag s. This im plies that regist er conte nt must be sa ved and tested, interrupt flag by interrupt flag to be sure not to forget any interrupts.
66
AT8xC51SND1C
4109E–8051–06/03
Figure 47. MP3 Interrupt Service Routine Flow
MP3 Decoder
ISR
Read MP3STA
Data Request?
MPFREQ = 1?
Data Request
Handler
AT8xC51SND1C
Write MP3 Data
to MP3DAT
Synchro Error
Handler
Reload MP3 Frame
Through MP3DAT
Ancillary Data?
MPANC = 1?
Sync Error?
ERRSYN = 1?
Layer Error?
ERRSYN = 1?
(1)
(1)
(1)
CRC Error
Handler
Load New MP3 Frame
Through MP3DAT
Ancillary Data
Handler
Read ANN2:0 Ancillary
Bytes From MP3ANC
Layer Error
Handler
4109E–8051–06/03
Note: 1. Test these bits only if needed (unmasked interrupt).
67

Registers Table 72. MP3CON Register

MP3CON (S:AAh) – MP3 Decoder Control Register
76543210
MPEN MPBBST C RCEN MSKANC MSKREQ MSKLAY MSKSYN MSKCRC
Bit
Number
7MPEN
6 MPBBST
5 CRCEN
4 MSKANC
3MSKREQ
2MSKLAY
1 MSKSYN
Bit
Mnemonic Description
MP3 Decoder Enable Bit
Set to enable the MP3 decoder. Clear to disable the MP3 decoder.
Bass Boost Bit
Set to enable the bass boost sound effect. Clear to disable the bass boost sound effect.
CRC Check Enable Bit
Set to enable processing of frame that contains CRC error. Frame is played whatever the error. Clear to disable processing of frame that contains CRC error. Frame is skipped.
MPANC Flag Mask Bit
Set to prevent the MPANC flag from generating a MP3 interrupt. Clear to allow the MPANC flag to generate a MP3 interrupt.
MPREQ Flag Mask Bit
Set to prevent the MPREQ flag from generating a MP3 interrupt. Clear to allow the MPREQ flag to generate a MP3 interrupt.
ERRLAY Flag Mask Bit
Set to prevent the ERRLAY flag from generating a MP3 interrupt. Clear to allow the ERRLAY flag to generate a MP3 interrupt.
ERRSYN Flag Mask Bit
Set to prevent the ERRSYN flag from generating a MP3 interrupt. Clear to allow the ERRSYN flag to generate a MP3 interrupt.
0 MSKCRC
ERRCRC Flag Mask Bit
Set to prevent the ERRCRC flag from generating a MP3 interrupt. Clear to allow the ERRCRC flag to generate a MP3 interrupt.
Reset Value = 0011 1111b
68
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 73. MP3STA Register
MP3STA (S:C8h Read Only) – MP3 Decoder Status Register
76543210
MPANC MPREQ ERRLAY ERRSYN ERRCRC MPFS1 MPFS0 MPVER
Bit
Number
7MPANC
6MPREQ
5 ERRLAY
4 E RRSYN
3 ERRCRC
2 - 1 M PF S1: 0
0 MPVER
Bit
Mnemonic Description
Ancillary Data Available Flag
Set by hardware as soon as one ancillary data is available (buffer not empty). Cleared by hardware when no more ancillary data is available (buffer empty).
MP3 Data Request Flag
Set by hardware when MP3 decoder request data. Cleared when reading MP3STA.
Invalid Layer Error Flag
Set by hardware when an invalid layer is encountered. Cleared when reading MP3STA.
Frame Synchronization Error Flag
Set by hardware when no synchronization pattern is encountered in a frame. Cleared when reading MP3STA.
CRC Error Flag
Set by hardware when a frame handling CRC is corrupted. Cleared when reading MP3STA.
Frequency Sampling Bits
Refer to Table 71 for bits description.
MPEG Version Bit
Set by the MP3 decoder when the loaded frame is a MPEG I frame. Cleared by the MP3 decoder when the loaded frame is a MPEG II frame.
Reset Value = 0000 0001b
4109E–8051–06/03
Table 74. MP3DAT Register MP3DAT (S:ACh) – MP3 Data Register
76543210
MPD7 MPD6 MPD5 MPD4 MPD3 MPD2 MPD1 MPD0
Bit
Number
7 - 0 MPD7:0
Bit
Mnemonic Description
Input Stream Data Buffer
8-bit MP3 stream data input buffer.
Reset Value = 0000 0000b
69
Table 75. MP3STA1 Register
MP3STA1 (S:AFh) – MP3 Decoder Status Register 1
76543210
- - - MPFREQ MPFREQ---
Bit
Number
7 - 5 -
4MPFREQ
3MPBREQ
2 - 0 -
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
MP3 Frame Data Request Flag
Set by hardware when MP3 decoder request data. Cleared when MP3 decoder no more request data .
MP3 Byte Data Request Flag
Set by hardware when MP3 decoder request data. Cleared when writing to MP3DAT.
Reserved
The value read from these bits is always 0. Do not set these bits.
Reset Value = 0001 0001b
Table 76. MP3ANC Register MP3ANC (S:ADh Read Only) – MP3 Ancillary Data Register
76543210
AND7 AND6 AND5 AND4 AND3 AND2 AND1 AND0
Bit
Number
Bit
Mnemonic Description
7 - 0 AND7:0
Ancillary Data Buffer
MP3 ancillary data Byte buffer.
Reset Value = 0000 0000b
Table 77. MP3VOL Regi ster MP3VOL (S:9Eh) – MP3 Volume Left Control Register
76543210
- - - VOL4 VOL3 VOL2 VOL1 VOL0
Bit
Number
7 - 5 -
4 - 0 VOL4:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Volume Le ft Value
Refer to Table 69 for the left channel volume control description.
Reset Value = 0000 0000b
70
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Table 78. MP3VOR Register
MP3VOR (S:9Fh) – MP3 Volume Right Control Register
76543210
- - - VOR4 VOR3 VOR2 VOR1 VOR0
Bit
Number
7 - 5 -
4 - 0 VOR4:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Volume Ri ght Value
Refer to Table 69 for the right channel volume control description.
Reset Value = 0000 0000b
Table 79. MP3BA S Register MP3BAS (S:B4h) – MP3 Bass Control Register
76543210
- - - BAS4 BAS3 BAS2 BAS1 BAS0
Bit
Number
7 - 5 -
4 - 0 BAS4:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Bass Gain Value
Refer to Table 70 for the bass control description.
Reset Value = 0000 0000b
4109E–8051–06/03
Table 80. MP3MED Register MP3MED (S:B5h) – MP3 Medium Control Register
76543210
- - MED5 MED4 MED3 MED2 MED1 MED0
Bit
Number
7 - 6 -
5-0 MED5:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Medium Gain Value
Refer to Table 70 for the medium control description.
Reset Value = 0000 0000b
71
Table 81. MP3TRE Register
MP3TRE (S:B6h) – MP3 Treble Control Register
76543210
- - TRE5 TRE4 TRE3 TRE2 TRE1 TRE0
Bit
Number
7 - 6 -
5-0 TRE5:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Treble Gain Value
Refer to Table 70 for the treble control description.
Reset Value = 0000 0000b
Table 82. MP3CLK Register MP3CLK (S:EBh) – MP3 Clock Divider Register
76543210
- - - MPCD4 M PCD3 MPCD2 MPCD1 MPCD0
Bit
Number
7 - 5 -
4-0 MPCD4:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
MP3 Decoder Clock Divider
5-bit divider for MP3 decoder clock generation.
Reset Value = 0000 0000b
72
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Audio Output Interface

The AT8xC51SND1C i mplemen t an audio ou tput inte rfac e allow ing t he aud io bitstrea m to be output in various format s. It is compa tible wit h right an d left jus tificatio n PCM an d
2
I
S formats and thanks to the on-chip PLL (see Section Clock Controller, page 12) allows connection of almost all of the commercial audio DAC families available on the market. The audio bitstream can be from 2 different types:
The MP3 decoded bitstream coming from the MP3 decoder for playing songs.
The audio bitstream coming from the MCU for outputting voice or sounds.

Description The C51 core interfaces to th e audio interface through f ive spec ial functio n regis ters:

AUDCON0 and AUDCON1, the Audio Control registers (see Tab le 84 and Table 85); AUDSTA, the Audio Status register (see Table 86); AUDDAT, the Audio Data register (see Table 87); and AUDCLK, the Audio Clock Divider register (see Table 88).
Figure 48 shows the audio interface block diagram, blocks are detailed in the following sections.
Figure 48. Audi o Interface Block Diagram
SCLK
AUD
CLOCK
AUDEN
AUDCON1.0
Data Ready
Clock Generator
HLR
AUDCON0.0
DSIZ
AUDCON0.1
0 1
POL
AUDCON0.2
DCLK
DSEL
Audio Data
From MP3
Decoder
Sample
Request To
MP3 Decoder
Audio Data
From C51
16
MP3 Buffer
DRQEN
AUDCON1.6
16 16
0 1
SRC
AUDCON1.7
Data Converter
JUST4:0
AUDCON0.7:3
DOUT
SREQ
8
Audio Buffer
AUDDAT
AUDSTA.7
UDRN
AUDSTA.6
AUBUSY
DUP1:0
AUDCON1.2:1
AUDSTA.5
4109E–8051–06/03
73

Clock Generator The audio interface clock is generated by division of the PLL clock. The division factor is

given by AUCD4:0 bits in CLKAUD register. Figure 49 shows the audio interface clock generator and its calculation formula. The audio interface clock frequency depends on the incoming MP3 frames and the audio DAC used.
Figure 49. Audio Clock Generator and Symb ol
PLL
CLOCK
AUDCLK
AUCD4:0
AUDclk
Audio Interface Clock
PLLclk
---------------------------= AUCD1+
AUD
CLOCK
Audio Clock Symbol
As soon as audio interface is enabled by setting AUDEN bit in AUDCON1 register, the master clock generated by the PL L is out put on the S CLK pin which i s the DAC sy stem clock. This clock is output at 256 or 384 times the sampling frequency depending on the DAC capabilities. HLR bit in AUDCON0 register mu st be set according to this rate for properly generating the audio bit clock on the DCLK pin and the word selection clock on the DSEL pin. These clocks are not generated when no data is available at the data converter input.
For DAC compatibilit y, the bit cl ock freque ncy is prog ramma ble for o utputti ng 16 bi ts or 32 bits per channel using the DSIZ bit in AUDCON0 register (see Section "Data Con­verter", page 74 ), and th e word sel ection sign al is pro grammable for outputti ng left channel on low or high level according to POL bit in AUDCON0 register as shown in Figure 50.
Figure 50. DSEL Output Polarity
POL = 0
Left Channel Right Channel
POL = 1
Left Channel Right Channel

Data Converter The data conv er ter bl oc k converts the audio stream input from the 16-b it p aral lel form at

to a serial format. For accepting all PCM formats and I AUDCON0 register are used to shift the data output point. As shown in Figure 51, these bits allow MSB justification by setting JUST4:0 = 00000, L SB justification by setting JUST4:0 = 10000, I
2
S Justification by setting JUST4:0 = 00001, a nd more than 16-bit
LSB justification by filling the low significant bits with logic 0.
2
S format, JUST4:0 bits in
74
AT8xC51SND1C
4109E–8051–06/03
Figure 51. Audio Output Format
AT8xC51SND1C
DSEL
DCLK
DOUT
DSEL
DCLK
DOUT
DSEL
DCLK
DOUT
DSEL
DCLK
DOUT
DSEL
DCLK
DOUT
Left Channel Right Channel
1 2 3 13 14 15 16
MSB
LSB B14 MSBLSB B14B1 B1
2
S Format with DSIZ = 0 and JUST4:0 = 00001.
I
Left Channel Right Channel
1 2 3 17 18 32
MSB
2
S Format with DSIZ = 1 and JUST4:0 = 00001.
I
Left Channel Right Channel
1 2 3 13 14 15 16
B14
MSB B1 B15MSB B1LSB LSB
MSB/LSB Justified Format with DSIZ = 0 and JUST4:0 = 00000.
Left Channel Right Channel
11618 32
115 3032
MSB B16
17 31
MSB B14 LSBB1 MSB B14 LS BB1
16-bit LSB Justified Format with DSIZ = 1 and JUST4:0 = 10000.
Left Channel Right Channel
16 31
B21B1 LS B
18-bit LSB Justified Format with DSIZ = 1 and JUST4:0 = 01110.
1 2 3 13 14 15 16
1 2 3 17 18 32
LSBB14 MSBLSB B14
1 2 3 13 14 15 16
1161817 31
15 30 3216 31
MSB B16
B2 B1 LSB
32
The data converter receives its audio stream from 2 sources selected by the SRC bit in AUDCON1 register. When cleared, the audio stream comes from the MP3 decoder (see Section MP3 Decoder, page 62) for so ng play ing. Whe n set, the aud io str eam is com­ing from the C51 core for voice or sound playing.
As soon as first a udio d ata is inpu t to the data conve rter, it e nables th e cl ock gene rator for generating the bit and word clocks.

Audio Buffer In voice or sound playing mode, the audi o stre am come s from the C51 cor e thro ugh an

audio buffer. The data is in 8-bit format and is sampled at 8 kHz. The audio buffer adapts the sample format and rate. The sample format is extended to 16 bits by filling the LSB to 00h. Rate is adapted to the DAC rate by duplicating the data using DUP1:0 bits in AUDCON1 register according to Table 83.
The audio buffer interfa ces to the C51 c ore th r ough thr ee fla gs: the s am pl e requ es t fla g (SREQ in AUDSTA register), the under-run flag (UNDR in AUDSTA register) and the busy flag (AUBUSY in AUDSTA register). SREQ and UNDR can generate an interrupt request as explained in Sec ti on "In ter ru pt R eque st ", p age 76. The buffer size is 8 Bytes large. SREQ i s set when the samp les numb er switc hes f rom 4 to 3 an d r eset when the samples number switches from 4 to 5; UNDR is set when the buffer becomes empty sig­naling that the audio interface ran out of samples; and AUBUSY is set when the buffer is full.
4109E–8051–06/03
75
Table 83. Sample Duplication Factor
DUP1 DUP0 Factor
0 0 No sample duplication, DAC rate = 8 kHz (C51 rate). 0 1 One sample duplication, DAC rate = 16 kHz (2 x C51 rate). 1 0 2 samples duplication, DAC rate = 32 kHz (4 x C51 rate). 1 1 Three samples duplication, DAC rate = 48 kHz (6 x C51 rate).

MP3 Buffer In song pla yin g mo de, the aud io s tre am co mes f ro m t he MP3 de co der t hr oug h a buf fer .

The MP3 buffer is used to store the d ecoded MP3 data a nd interfaces to the dec oder through a 16-bit data input and data request signal. This signal asks for data when the buffer has enough space to receive new data . Data request is co nditioned by the DREQEN bit in AUDCON1 regi ster. When set, the buffe r requests data to the MP3 decoder. When clear ed n o m or e d ata is requ es ted but dat a ar e out put unti l the buff er is empty. This bit can be used to suspend the audio generation (pause mode).

Interrupt Request The audio interrup t reques t can be gen erated b y 2 source s when in C51 audio mod e: a

sample request when SREQ fl ag in AUDST A regi st er is set to lo gi c 1, an d an un der -ru n condition when UDRN fl ag in AUDS TA register is set to l ogic 1. B oth sources can be enabled separatel y by masking one of th em using the MSREQ a nd MUDRN bits in AUDCON1 register. A global enable of the audio interface is provided by setting the EAUD bit in IEN0 register.
The interrupt is requested each time one of the 2 sources is set to one. The source flags are cleared by writing some data in the audio buffer through AUDDAT, but the globa l audio interrupt flag is cleared b y hardware when the interrupt se rvice routine is executed.
Figure 52. Audio Interface Interrupt System
UDRN
AUDSTA.6
SREQ
AUDSTA.7
MUDRN
AUDCON1.4
EAUD
IEN0.6
MSREQ
AUDCON1.5
Audio Interrupt Request

MP3 Song Playing In MP3 song playing mode, the operations t o do ar e t o c onf igu re the PLL and the audio

interface according to the DAC s elected. Th e audio clo ck is progr ammed to generate the 256·Fs or 384·Fs as explained in Section "Clock Generator", page 74. Figure 53 shows the configuration flow of the audio interface when in MP3 song mode.
76
AT8xC51SND1C
4109E–8051–06/03
Figure 53. MP3 Mode Audio Configuration Flow
MP3 Mode
Configuration
Program Audio Clock
AT8xC51SND1C
Enable DAC System
Clock
AUDEN = 1
Configure Interface
HLR = X DSIZ = X POL = X
JUST4:0 = XXXXXb
SRC = 0
Wait For
DAC Set-up Time
Enable Data Request
DRQEN = 1

Voice or Sound Playing In voice or sound playing mode, the operations required are to configure the PLL and

the audio interface according to the DAC selected. The audio clock is programmed to generate the 256·Fs or 384·Fs as for the MP3 playing mode. The data flow sent by the C51 is then regulated by interrupt and data is loaded 4 Bytes by 4 Bytes. Figure 54 shows the configuration flow of the audio interface when in voice or sound mode.
Figure 54. Voice or Sound Mode Audio Flows
Voice/Song Mode
Configuration
Program Audio Clock
Configure Interface
HLR = X
DSIZ = X
POL = X
JUST4:0 = XXXXXb
DUP1:0 = XX
Wait for DAC Enable Time
Select Audio
SRC = 1
Load 8 Samples in the
Audio Buffer
Audio Interrupt
Service Routine
Sample Request?
SREQ = 1?
Load 4 Samples in the
Audio Buffer
Under-run Condition
1
Enable DAC System
Clock
AUDEN = 1
Enable Interrupt
Set MSREQ & MUDRN
EAUD = 1
1
Note: 1. An under-run occurrence signifies that C51 core did not respond to the previous sample request interrupt. It may never
occur for a correct voice/sound generation. It is the users responsibility to mask it or not.
77
4109E–8051–06/03

Registers Table 84. AUDCON0 Register

AUDCON0 (S:9Ah) – Audio Interface Control Register 0
76543210
JUST4 JUST3 JUST2 JUS T 1 JUST0 POL DSIZ HLR
Bit
Number
7 - 3 JUST4:0
2POL
1DSIZ
0HLR
Bit
Mnemonic Description
Audio Stream Justification Bits
Refer to Section "Data Converter", page 74 for bits description.
DSEL Signal Output Polarity
Set to output the left channel on high level of DSEL output (PCM mode). Clear to output the left channel on the low level of DSEL output (I
Audio Data Size
Set to select 32-bit data output format. Clear to select 16-bit data output format.
High/Low Rate Bit
Set by software when the PLL clock frequency is 384·Fs. Clear by software when the PLL clock frequency is 256·Fs.
2
S mode).
Reset Value = 0000 1000b Table 85. AUDCON1 Register
AUDCON1 (S:9Bh) – Audio Interface Control Register 1
76543210
SRC DRQEN MSREQ MUDRN - DUP1 DUP0 AUDEN
Bit
Number
Bit
Mnemonic Description
78
2 - 1 D UP1: 0
Reset Value = 1011 0010b
AT8xC51SND1C
7SRC
6 DRQEN
5MSREQ
4 MUDRN
3-
0 AUDEN
Audio Source Bit
Set to select C51 as audio source for voice or sound playing. Clear to select the MP3 decoder output as audio source for song playing.
MP3 Decoded Data Request Enable Bit
Set to enable data request to the MP3 decoder and to start playing song. Clear to disable data request to the MP3 decoder.
Audio Sample Request Flag Mask Bit
Set to prevent the SREQ flag from generating an audio interrupt. Clear to allow the SREQ flag to generate an audio interrupt.
Audio Sample Under-run Flag Mask Bit
Set to prevent the UDRN flag from generating an audio interrupt. Clear to allow the UDRN flag to generate an audio interrupt.
Reserved
The value read from this bit is always 0. Do not set this bit.
Audio Duplication Factor
Refer to Table 83 for bits description.
Audio Interface Enable Bit
Set to enable the audio interface. Clear to disable the audio interface.
4109E–8051–06/03
AT8xC51SND1C
Table 86. AUDSTA Register
AUDSTA (S:9Ch Read Only) – Audio Interface Status Register
76543210
SREQ UDRN AUBUSY -----
Bit
Number
7SREQ
6 UDRN
5 AUBUSY
4 - 0 -
Bit
Mnemonic Description
Audio Sample Request Flag
Set in C51 audio source mode when the audio interface request samples (buffer half empty). This bit generates an interrupt if not masked and if enabled in IEN0. Cleared by hardware when samples are loaded in AUDDAT.
Audio Sample Under-run Flag
Set in C51 audio source mode when the audio interface runs out of samples (buffer empty). This bit generates an interrupt if not masked and if enabled in IEN0. Cleared by hardware when samples are loaded in AUDDAT.
Audio Interface Busy Bit
Set in C51 audio source mode when the audio interface can not accept more sample (buffer full). Cleared by hardware when buffer is no more full.
Reserved
The value read from these bits is always 0. Do not set these bits.
Reset Value = 1100 0000b Table 87. AUDDAT Register
AUDDAT (S:9Dh) – Audio Interface Data Register
76543210
AUD7 AUD6 AUD5 AUD4 AUD3 AUD2 AUD1 AUD0
4109E–8051–06/03
Bit
Number
7 - 0 AUD7:0
Bit
Mnemonic Description
Audio Data
8-bit sampling data for voice or sound playing.
Reset Value = 1111 1111b Table 88. AUDCLK Register
AUDCLK (S:ECh) – Audio Clock Divider Register
76543210
- - - AUCD4 AUCD3 AUCD2 AUCD1 AUCD0
Bit
Number
7 - 5 -
4 - 0 AUCD4:0
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Audio Clock Divider
5-bit divider for audio clock generation.
Reset Value = 0000 0000b
79

Universal Serial Bus T he AT8xC51S ND1C implemen ts a USB devic e controller supporting full speed dat a

transfer. In addition to the default control endpoint 0, it provides 2 other endpoints, which can be configured in control, bulk, interrupt or isochronous modes:
Endpoint 0: 32-Byte FIFO, default control endpoint
Endpoint 1, 2: 64-Byte Ping-pong FIFO,
This allows the firmware to be developed conforming to most USB device classes, for example:
USB Mass Storage Class Bulk-only Transport, Revision 1.0 - September 31, 1999
USB Human In terface Device Class, Version 1.1 - April 7, 1999
USB Device Firmware Upgrade Class, Revision 1.0 - May 13, 1999
USB Mass Storage Class Bulk-Only Transport
USB Device Firmware Upgrade (DFU)
Within the Bulk -only fram ework, the Control endpoin t is only use d to transp ort class­specific and standard USB requests for device set-up and configuration. One Bulk-out endpoint is used to transport commands and data from the host to the device. One Bulk in endpoint is used to transport status and data from the device to the host.
The following AT8xC51SND1C configuration adheres to those requirements:
Endpoint 0: 32 Bytes, Control In-Out
Endpoint 1: 64 Bytes, Bulk-in
Endpoint 2: 64 Bytes, Bulk-out
The USB Device Fir mware Upd ate (DFU ) proto col can b e used to upgrade th e on-chi p Flash memory of the AT89C51SND1C. This allows installing product enhancements and patches to devices that are already in the field. 2 different configurations and descriptor sets are used to support DFU functions. The Run-Time configuration co-exist with the usual functions of the device, which is USB Mass Storage for AT89C51SND1C. It is used to initiate DFU from the normal operating mode. The DFU configuration is used to perform the firmware update after device re-configuration and USB reset. It excludes any other function. Only the default control pipe (endpoint 0) is used to support DFU services in both configurations.
The only possible value for the MaxPacketSize in the DFU configuration is 32 Bytes, which is the size of the FIFO implemented for endpoint 0.
80
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Description The USB device controller pro vides the hardwa re that the AT 8xC51SN D1C needs to

interface a USB link to a data flow stored in a double port memory. It requires a 48 MHz referenc e cloc k provi de d by the cl oc k c ont ro ller as de tail ed in Se c-
tion "Clock Controlle r", pa ge 8 1. T his cloc k is use d to gen er ate a 12 MHz Full Spe ed bi t clock from the received USB differential data flow and to transmit data according to full speed USB device tolerance. Clock re covery is done by a Digital Phase Loc ked Loop (DPLL) block.
The Serial Interface Engine (SIE) block performs NRZI encoding and decoding, bit stuff­ing, CRC generation and checking, and the serial-parallel data conversion.
The Universal Functio n Interface (UFI) con trols the in terfac e betwee n the data flow and the Dual Port RAM, but also the interface with the C51 core itself.
Figure 55. USB Device Controller Block Diagram
USB
CLOCK
D+
D-
48 MHz 12 MHz
USB
Buffer
DPLL
SIE
UFI
To/From C51 Core
Clock Controller The USB controller clock is generated by division of the PLL clock. The division factor is
given by USBCD1:0 bits in USBCLK register (see Table 104). Figure 56 shows the USB controller clock g enerator and its calc ulation form ula. The USB controller clock fre­quency must always be 48 MHz.
Figure 56. USB Clock Generator and Symbol
PLL
CLOCK
USBCLK
USBCD1:0
48 MHz USB Clock
USB
CLOCK
4109E–8051–06/03
USBclk
PLLclk
--------------------------------= USBCD 1+
USB Clock Symbol
81
Serial Interface Engine (SIE) The SIE performs the following functions:
NRZI data encoding and decoding.
Bit stuffing and unstuffing.
CRC generation and checking.
ACKs and NACKs automatic generati on .
TOKEN type identifying.
Address checking.
Clock recovery (using DPLL).
Figure 57. SIE Block Diagram
End of Packet
Detector
D+
D-
Start of Packet
Detector
USB
CLOCK
48 MHz
NRZI NRZ
Bit Unstuffing
Packet Bit Counter
Clock
Recover
USB Pattern Generator
Parallel to Serial Converter
CRC16 Generator
SysClk (12 MHz)
Bit Stuffing
NRZI Converter
SYNC Detector
PID Decoder
Address Decoder
Serial to Parallel
Converter
CRC5 & CRC16
Generator/Check
8
Data In
8
Data Out
82
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
Function Interface Unit (UFI) The Function Interface Unit provides the interface between the AT8xC51SND1C and
the SIE. It manages transactions at the packet level with minimal intervention from the device firmware, which reads and writes the endpoint FIFOs.
Figure 59 shows typi cal USB IN and OUT tran sactions repor ting the split in the har d­ware (UFI) and software (C51) load.
Figure 58. UFI Block Diagram
USBCON
USBADDR
USBINT USBIEN
UEPNUM
UEPCONX
UEPSTAX
UEPRST
UEPINT UEPIEN
UEPDATX
UBYCTX
UFNUMH
UFNUML
To/From C51 Core
12 MHz DPLL
Transfer
Control
FSM
Asynchronous Information
To/From SIE
Endpoint Control
USB side
Figure 59. USB Typical Transaction Load
OUT Transactions:
HOST
OUT DATA0 (n Bytes)
UFI
C51
IN Transactions:
HOST
UFI
C51
IN
NACK
Endpoint FIFO Write
ACK
Endpoint 2 Endpoint 1 Endpoint 0
OUT DATA1
C51 interrupt
Endpoint FIFO read (n Bytes)
IN
DATA1
Endpoint Control
C51 side
NACK
IN
DATA1
OUT DATA1
ACK
ACK
C51 interrupt
Endpoint FIFO write
4109E–8051–06/03
83

Configuration

General Configuration USB controller enable
Before any USB tr ansaction, the 48 MHz requi red by the USB c ontroller must be correctly generated (See “Clock Controller” on page 19).
The USB controller should be then enabled by setting the EUSB bit in the USBCON register.
Set address
After a Reset or a USB r eset, th e s oftware has to set the FEN (Fu nc tio n En abl e) bi t in the USBADDR register. Thi s action will allo w the USB contr oller to answer to th e requests sent at the address 0.
When a SET_AD DRES S requ est ha s been r eceiv ed, the USB con trolle r must only answer to the address defined by the request. The new address should be stored in the USBADDR register. The FEN bit and the FADDEN bit in the USBCON register should be set to allow the USB controller to answer only to requests sent at the new address.
Set configuration
The CONFG bit in the USBCON register should be set after a SET_CONFIGURATION request with a non-zero value. Otherwise, this bit should be cleared.
Endpoint Configuration Selection of an Endpoint
The endpoint register access is performed using the UEPNUM register. The registers
UEPSTAX UEPCONX UEPDATX UBYCTX
Theses registers correspond to the endpoint whose number is stored in the UE P­NUM register. To select an Endpoint, the firmware has to write the endpoint number in the UEPNUM register.
Figure 60. Endpoint Selection
UEPSTA0 UEPCON0 UEPDAT0
UEPSTA2 UEPCON2 UEPDAT2
84
Endpoint 0
Endpoint 2
AT8xC51SND1C
UBYCT0
UBYCT2
0 1
X
2
UEPNUM
SFR Registers
UEPSTAX UEPCONX UEPDATX
UBYCTX
4109E–8051–06/03
AT8xC51SND1C
Endpoint enable
Before using an endpoint, thi s must be enabled by setting the EPEN bit in the UE P­CONX register.
An endpoint which is not enabled wont answer to any USB reque st. The Defa ult Control Endpoint (Endp oint 0) should always be ena bled in order to answer to USB standard requests.
Endpoint type configuration
All Standard Endp oin ts can be con figur ed in Contr ol, Bu lk, I nterrupt or Is ochron ous mode. The Ping-pong Endpoints can be configured in Bulk, Interrupt or Isochronous mode. The configuration of an e ndpoint is performed by setting the field EPTYPE with the following values:
Control: EPTYPE = 00b Isochronous:EPTYPE = 01b Bulk: EPTYPE = 10b Interrupt: EPTYPE = 11b
The Endpoint 0 i s the Defa ult Contr ol Endpo int an d sh ould always be c onfig ured in Control type.
Endpoint direction configuration
For Bulk, Interrup t and Isochrono us endpoints, th e direction is de fined with the EPDIR bit of the UEPCONX register with the following values:
IN: EPDIR = 1b OUT: EPDIR = 0b
For Control endpoints, the EPDIR bit has no effect.
Summary of Endpoint Configuration:
Do not forget to select th e cor rect end point nu mber in the UE PNUM reg ister before accessing endpoint specific registers.
Table 89. Summary of Endpoi nt Confi gu rat io n
Endpoint C onfiguration EPEN EPDIR EPTYPE UEPCONX
Disabled 0b Xb XXb 0XXX XXXb Control 1b Xb 00b 80h Bulk-in 1b 1b 10b 86h Bulk-out 1b 0b 10b 82h Interrupt-In 1b 1b 11b 87h Interrupt-Out 1b 0b 11b 83h Isochronous-In 1b 1b 01b 85h Isochronous-Out 1b 0b 01b 81h
4109E–8051–06/03
85
Endpoint FIFO reset
Before using an endpoint, its FIFO should be reset. This action resets the F IFO pointer to its original value, resets the B yte c ount er of th e end poi nt ( UB YCTX r egi s­ter), and resets the data toggle bit (DTGL bit in UEPCONX).
The reset of an endpoi nt FIFO is per formed by sett ing to 1 and resett ing to 0 the corresponding bit in the UEPRST register.
For example, in or der to res et the Endp oint n umber 2 FIFO , wr ite 00 00 010 0b the n 0000 0000b in the UEPRST register.
Note that the endpoint reset doesnt reset the bank number for ping-pong endpoints.

Read/Write Data FIFO

Read Data FIFO The read access for each OUT endpoint is performed using the UEPDATX register.
After a new valid pack et ha s be en r ec ei ved on an Endpoint, the data are sto r ed into the FIFO and the Byte counter of the endpoint is updated (UBYCTX registers). The firmware has to store the endpoint Byte counter before any access to the endpoint FIFO. The Byte counter is not updated when reading the FIFO.
To read data from an endpoint, select the correct endpoint number in UEPNUM and read the UEPDATX register. This action automatically decreases the corresponding address vector, and the next data is then available in the UEPDATX register.
Write Data FIFO The write access for each IN endpoint is performed using the UEPDATX register.
To write a Byte into an IN endpoint FIFO, select the correct endp oint number in UEP­NUM and write into the UEPDATX register. The corresponding address vector is automatically increased, and another write can be carried out.
Warning 1: The Byte counter is not updated. Warning 2: Do not write more Bytes than supported by the corresponding endpoint.
FIFO Mapping Figure 61. Endpoint FIFO Configuration
Endpoint 0
Endpoint 2
UEPSTA0 UEPCON0 UEPDAT0
UBYCT0
UEPSTA2 UEPCON2 UEPDAT2
UBYCT2
0
X
1
2
UEPNUM
SFR Registers
UEPSTAX UEPCONX UEPDATX
UBYCTX
86
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Bulk/Interrupt Transactions

Bulk/Interrupt OUT Transactions in Standard Mode
Bulk and Interrupt transactions are managed in the same way.
Figure 62. Bulk/Interrupt OUT transactions in Standard Mode
HOST UFI
OUT DATA0 (n Bytes)
OUT DATA1
OUT DATA1
DATA1
OUT
ACK
RXOUTB0
NAK
NAK
ACK
RXOUTB0
C51
Endpoint FIFO Read Byte 1 Endpoint FIFO Read Byte 2
Endpoint FIFO Read Byte n
Clear RXOUTB0
Endpoint FIFO Read Byte 1
An endpoint should be fir st e nab le d and co nfi gur ed befo r e being able to receive Bulk or Interrupt packets.
When a valid O UT pa cket is rece ived o n an en dpoint, the RXO UTB0 bi t is set by the USB controller. This tr iggers an int errupt i f enabl ed. The fi rmware h as to sel ect the cor­responding endpoint, store the number of data Bytes by reading the UBYCTX register. If the received packe t is a Z L P (Z er o L eng th P ac ket ), the UBYCTX register value is equal to 0 and no data has to be read.
When all the endpoint FIFO Bytes have been re ad, the firmware should clear the RXOUTB0 bit to allow the USB cont roller to a ccept the nex t OUT pack et on this end­point. Until the RXO UTB0 bit ha s been clear ed by the fi rmware, th e USB cont roller wi ll answer a NAK handshake for each OUT requests.
If the Host sends more Bytes than supported by the endpoint FIFO, the overflow data wont be stored, but the USB controller will consider that the packet is valid if the CRC is correct and the endpoint Byte counter contains the number of Bytes sent by the Host.
4109E–8051–06/03
87
Bulk/Interrupt OUT Transa ctions in Ping-pong Mode
Figure 63. Bulk/Interrupt OUT Transactions in Ping-pong Mode
HOST
OUT DATA0 (n Bytes)
DATA1 (m Bytes)
OUT
UFI C51
ACK
RXOUTB0
Endpoint FIFO bank 0 - Read Byte 1 Endpoint FIFO bank 0 - Read Byte 2
OUT DATA0 (p Bytes)
ACK
RXOUTB1
ACK
RXOUTB0
Endpoint FIFO bank 0 - Read Byte n
Clear RXOUTB0
Endpoint FIFO bank 1 - Read Byte 1 Endpoint FIFO bank 1 - Read Byte 2
Endpoint FIFO bank 1 - Read Byte m
Clear RXOUTB1
Endpoint FIFO bank 0 - Read Byte 1 Endpoint FIFO bank 0 - Read Byte 2
Endpoint FIFO bank 0 - Read Byte p
Clear RXOUTB0
An endpoint should be fir st e nab le d and co nfi gur ed befo r e being able to receive Bulk or Interrupt packets.
When a valid OUT packet is received on the endpoint bank 0, the RXOUTB0 bit is set by the USB controller. This triggers an interrupt if enabled. The firmware has to select the corresponding endpoi nt, s tore t he num ber o f data B ytes by readi ng the UBYCT X regi s­ter. If the received pack et is a ZLP (Zero Len gth Pac ket), the UBYCT X regis ter valu e is equal to 0 and no data has to be read.
88
When all the endpoint FIFO Bytes have been re ad, the firmware should clear the RXOUB0 bit to allow the USB contro ller to acc ept the next OUT packet on the endpoi nt bank 0. This action switches the endpoint bank 0 and 1. Until the RXOUTB0 bit has been cleared by the firmware, the USB controller will answer a NAK handshake for each OUT requests on the bank 0 endpoint FIFO.
When a new valid OUT packet is rece ived on the endpo int bank 1, the RXOUT B1 bit is set by the USB controller. This triggers an interrupt if enabled. The firmware empties the bank 1 endpoint FIFO before clearing the RXOUTB1 bit. Until the RXOUTB1 bit has been cleared by the firmware, the USB controller will answer a NAK handshake for each OUT requests on the bank 1 endpoint FIFO.
The RXOUTB0 and RXO UTB1 bits are, a lter nativ ely, s et b y the USB c ontr oller at e ach new valid packet receipt.
The firmware has to clear one of these 2 bits after having read all the data FIFO to allow a new valid packet to be stored in the corresponding bank.
A NAK handshake is sent by the USB co ntroller onl y if the banks 0 and 1 has not bee n released by the firmware.
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
If the Host sends more Bytes than supported by the endpoint FIFO, the overflow data wont be stored, but the USB controller will consider that the packet is valid if the CRC is correct.
Bulk/Interrupt IN Transactions in Standard Mode
Figure 64. Bulk/Interrupt IN Transactions in Standard Mod e
HOST
IN
IN
ACK
UFI C51
Endpoint FIFO Write Byte 1 Endpoint FIFO Write Byte 2
NAK
Endpoint FIFO Write Byte n
Set TXRDY
DATA0 (n Bytes)
TXCMPL
Clear TXCMPL
Endpoint FIFO Write Byte 1
An endpoint should be first enabled and configured before being able to send Bulk or Interrupt packets.
The firmware shou ld fill the FIF O with the da ta to be sen t and set th e TXRDY bit in the UEPSTAX register to allow the USB controller to send the data stored in FIFO at the next IN request concerning this endpoint. To send a Zero Length Packet, the firmware should set the TXRDY bit without writing any data into the endpoint FIFO.
Until the TXRDY bit has been set by the firmware, the USB controller will answer a NAK handshake for each IN requests.
To cancel the sending of this packet, the firmware has to reset the TXRDY bit. The packet stored in the endpoint FIFO is then cleared and a new packet can be written and sent.
When the IN packet has been sent and acknowledged by the Host, the TXCMPL bit in the UEPSTAX register is set by the USB controller. This triggers a USB interrupt if enabled. The firmware should clear the TXCMPL bit before filling the endpoint FIFO with new data.
The firmware should never write more Bytes than supported by the endpoint FIFO. All USB retry mechanisms are automatically managed by the USB controller.
4109E–8051–06/03
89
Bulk/Interrupt IN Transactions in Ping-pong Mode
Figure 65. Bulk/Interrupt IN transactions in Ping-pong mode
HOST
IN
UFI
NACK
C51
Endpoint FIFO bank 0 - Write Byte 1 Endpoint FIFO bank 0 - Write Byte 2
Endpoint FIFO bank 0 - Write Byte n
Set TXRDY
IN
DATA0 (n Bytes)
ACK
TXCMPL
IN
DATA1 (m Bytes)
ACK
TXCMPL
IN
DATA0 (p Bytes)
ACK
Endpoint FIFO bank 1 - Write Byte 1 Endpoint FIFO bank 1 - Write Byte 2
Endpoint FIFO bank 1 - Write Byte m
Clear TXCMPL
Set TXRDY
Endpoint FIFO bank 0 - Write Byte 1 Endpoint FIFO bank 0 - Write Byte 2
Endpoint FIFO bank 0 - Write Byte p
Clear TXCMPL
Set TXRDY
Endpoint FIFO bank 1 - Write Byte 1
An endpoint should be first enabled and configured before being able to send Bulk or Interrupt packets.
The firmware should fill the FIFO ban k 0 with the data to be sent and set the TXRDY bit in the UEPSTAX reg ister t o all ow the USB c ontroll er to send the data s tore d in FIF O at the next IN request concerning the endpoint. The FIFO banks are automatically switched, and the firmware can immediately write into the endpoint FIFO bank 1.
90
When the IN packet concerning the bank 0 has been sent and acknowledged by the Host, the TXCMPL bit is set by the USB controller. This triggers a USB interrupt if enabled. The firmware should clear the TXCMPL bit before filling the endpoint FIFO bank 0 with new data. The FIFO banks are then automatically switched.
When the IN packet concerning the bank 1 has been sent and acknowledged by the Host, the TXCMPL bit is set by the USB controller. This triggers a USB interrupt if enabled. The firmware should clear the TXCMPL bit before filling the endpoint FIFO bank 1 with new data.
The bank switch is performed by the USB controller each time the TXRDY bit is set by the firmware. Until the TXRDY bit has been set by th e firmware for an endpo int bank, the USB controller will answer a NAK handshake for each IN requests concerning this bank.
Note that in the example above, the firmware clears the Transmit Complete bit (TXCBulk-outMPL) before setting the Transmit Ready bit (TXRDY). This is done in order to avoid the firmware to clear at the same time the TXCMPL bit for for bank 0 and the bank 1.
The firmware should never write more Bytes than supported by the endpoint FIFO.
AT8xC51SND1C
4109E–8051–06/03

Control Transactions

Setup Stage The DIR bit in the UEPSTAX register should be at 0.
Receiving Setup packets is the same as receiving Bulk Out packets, except that the RXSETUP bit in the UEPSTAX register is set by the USB controller instead of the RXOUTB0 bit to indicate that an O ut pa cket wi th a S etu p P ID has be en rec eived on th e Control endpoint. When the RXSETUP bit has been set, all the o ther bits of the UEP­STAX register are cleared and an interrupt is triggered if enabled.
The firmware has to read the Se tup requ est s tored in the Co ntrol endpoi nt FIF O befor e clearing the RXSETUP bit to free the endpoint FIFO for the next transaction.
AT8xC51SND1C
Data Stage: Control Endpoint Direction
Status Stage The DIR bit in the UEPSTAX register should be reset at 0 for IN and OUT status stage.
The data stage management is similar to Bulk management. A Control endpoint is managed by the USB controller as a full-duplex endpoint: IN and
OUT. All othe r endpoi nt typ es are managed as ha lf-dup lex e ndpoint : IN or OUT. T he firmware has to specify the control endpoint direction for the data stage using the DIR bit in the UEPSTAX register.
If the data stage consists of INs, the firmware has to set the DIR bit in the UEPSTAX
register before writing into the FIFO and sending the data by setting to 1 the TXRDY bit in the UEPSTAX register. The IN transaction is complete when the TXCMPL has been set by the hardware. The firmware should clear the TXCMPL bit before any other transaction.
If the data stage consists of OUTs, the firmware has to leave the DIR bit at 0. The
RXOUTB0 bit is set by hardware when a new valid packet has been received on the endpoint. The firmware must read the data stored into the FIFO and then clear the RXOUTB0 bit to reset the FIFO and to allow the next transaction.
To send a STALL handshake, see STALL Handshake on page 94.
The status stage management is similar to Bulk management.
For a Control Write transaction or a No-Data Control transaction, the status stage
consists of a IN Zero Length Packet (see Bulk/Interrupt IN Transactions in Standard Mode on page 89). To send a STALL handshake, see “STALL Handshake on page 94.
For a Control Read transaction, the status stage consists of a OUT Zero Length
Packet (see Bulk/Interrupt OUT Transactions in Standar d Mod e on page 87).
4109E–8051–06/03
91

Isochronous Transactions

Isochronous OUT Transactions in Standard Mode
Isochronous OUT Transa ctions in Ping-pong Mode
An endpoint should be first enabled and configured before being able to receive Isochro­nous packets.
When an OUT packet is received on an endpoint, the RXOUTB0 bit is set by the USB controller. This triggers an interrupt if enabled. The firmware has to select the corre Bulk-outsponding endpoint, store the number of data Bytes by reading the UBYCTX register. If the received packet is a ZLP (Zero Length Packet), the UBYCTX register value is equal to 0 and no data has to be read.
The STLCRC bit in the UEPSTAX register is set by the USB controller if the packet stored in FIFO has a corrupted CRC. This bit is updated after each new packet receipt.
When all the endpoint FIFO Bytes have been re ad, the firmware should clear the RXOUTB0 bit to allow the USB controller to store the next OUT packet data into the endpoint FIFO. Until the RX OUTB0 bit has bee n cleared by th e firmwar e, the data sent by the Host at each OUT transaction will be lost.
If the RXOUTB0 bit is cleared while the Host is sending data, the USB controller will store only the remaining Bytes into the FIFO.
If the Host sends more Bytes than supported by the endpoint FIFO, the overflow data wont be stored, but the USB controller will consider that the packet is valid if the CRC is correct.
An endpoint should be first enabled and configured before being able to receive Isochro­nous packets.
When a OUT packet is received on the end point bank 0, the RXO UTB0 bit is set by the USB controller. This tr iggers an int errupt i f enabl ed. The fi rmware h as to sel ect the cor­responding endpoint, store the number of data Bytes by reading the UBYCTX register. If the received packe t is a Z L P (Z er o L eng th P ac ket ), the UBYCTX register value is equal to 0 and no data has to be read.
92
The STLCRC bit in the UEPSTAX register is set by the USB controller if the packet stored in FIFO has a corrupted CRC. This bit is updated after each new packet receipt.
When all the endpoint FIFO Bytes have been re ad, the firmware should clear the RXOUB0 bit to allow the USB contr oll er to sto re the nex t OUT pac ket data i nto the end­point FIFO bank 0. This a ction swi tc hes the end poi nt ba nk 0 an d 1. Un til the RXO UTB 0 bit has been clea red b y the fi rmware, the d ata s ent by the Host o n the bank 0 endp oint FIFO will be lost.
If the RXOUTB0 bit is cleared while the Host is sending data on the endpoint bank 0, the USB controller will store only the remaining Bytes into the FIFO.
When a new OUT packet is received on the endpoint bank 1, the RXOUTB1 bit is set by the USB controller. T his tr iggers an inte rrupt i f enabl ed. The fi rmware emptie s t he bank 1 endpoint FIFO before clearing the RXOUTB1 bit. Until the RXOUTB1 bit has been cleared by the firmwar e, the data sent by the Host on the bank 1 endp oint FIFO wil l be lost.
The RXOUTB0 and RXOUTB1 bits are alternatively set by the USB controller at each new packet receipt.
The firmware has to clear one of these 2 bits after having read all the data FIFO to allow a new packet to be stored in the corresponding bank.
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C
If the Host sends more Bytes than supported by the endpoint FIFO, the overflow data wont be stored, but the USB controller will consider that the packet is valid if the CRC is correct.
Isochronous IN Transactions in Standard Mode
Isochronous IN Transactions in Ping-pong Mode
An endpoint should be first enabled and configured before being able to send Isochro­nous packets.
The firmware shou ld fill the FIF O with the da ta to be sen t and set th e TXRDY bit in the UEPSTAX register to allow the USB controller to send the data stored in FIFO at the next IN request concerning this endpoint. If the TXRDY bit is not set when th e IN reques t occu rs, nothing wi ll be s ent by the USB controller.
When the IN packet has bee n sent, the TX CMPL bit in the UE PSTAX register is set by the USB controller. This triggers a USB interrupt if enabled. The firmware should clear the TXCMPL bit before filling the endpoint FIFO with new data.
The firmware should never write more Bytes than supported by the endpoint FIFO An endpoint should be first enabled and configured before being able to send Isochro-
nous packets. The firmware should fill the FIFO ban k 0 with the data to be sent and set the TXRDY bit
in the UEPSTAX reg ister t o all ow the USB c ontroll er to send the data s tore d in FIF O at the next IN request concerning the endpoint. The FIFO banks are automatically switched, and the firmware can immediately write into the endpoint FIFO bank 1. If the TXRDY bit is not set when th e IN reques t occu rs, nothing wi ll be s ent by the USB controller.
When the IN packet concerning the bank 0 has been sent, the TXCMPL bit is set by the USB controller. This triggers a USB interrupt if enabled. The firmware should clear the TXCMPL bit before filli ng t he e ndpo in t F IFO b ank 0 with n ew da ta. T he FI FO b anks ar e then automatically switched.
When the IN packet concerning the bank 1 has been sent, the TXCMPL bit is set by the USB controller. This triggers a USB interrupt if enabled. The firmware should clear the TXCMPL bit before filling the endpoint FIFO bank 1 with new data.
The bank switch is performed by the USB controller each time the TXRDY bit is set by the firmware. Until the TXRDY bit has been set by th e firmware for an endpo int bank, the USB controller wont send anything at each IN requests concerning this bank.
The firmware should never write more Bytes than supported by the endpoint FIFO.
4109E–8051–06/03
93

Miscellaneous

USB Reset The EORINT bit in the USBINT regis ter is set by hardware when a End Of Reset has
been detected o n the USB bus. This trig gers a US B inte rru pt if enab led. The USB c on­troller is still enabled, but all the USB registers are reset by hardware. The firmware should clear the EORINT bit to allow the next USB reset detection.
STALL Handshake This function is only available for Control, Bulk, and Interrupt endpoints.
The firmware has to set the STALLRQ bit in the UE PSTAX regis ter to send a STAL L handshake at the next request of the Host on the endpoint selected with the UEPNUM register. The RXSETUP, TXRDY, TXCMPL, RXOUTB0 and RXOUTB1 bits must be first resseted to 0. The bit STLCRC is set at 1 by the USB controller when a STALL has been sent. This triggers an interrupt if enabled.
The firmware should clear the STALLRQ and STLCRC bits after each STALL sent. The STALLRQ bit is cleared automatically by hardware when a valid SETUP PID is received on a CONTROL type endpoint.
Important note: when a Clear Halt Feature occurs for an endpoint, the firmware should reset this endpoint using the UEPRST resgister in order to reset the data toggle management.
Start of Frame Detectio n The SOFINT bit in the USBINT register is set when the USB controller detects a Start Of
Frame PID. This tr igge rs a n int er rupt if ena ble d . The fir mw ar e sho u ld c le ar the SOFINT bit to allow the next Start of Frame detection.
Frame Number When receiving a Start Of Frame, the frame number is automatically stored in the
UFNUML and UFNUMH registers. The CRCOK and CRCERR bits indicate if the CRC of the last Start Of Frame is valid (CRCOK set a t 1) or corrup ted (CRCERR set at 1). Th e UFNUML and UFNUMH registers are automatically updated when receiving a new Start of Frame.
Data Toggle Bit The Data Toggle bit is set by hardware when a DATA0 packet is received and accepted
by the USB controller and cleared by hardware when a DATA1 packet is received and accepted by the USB con trolle r. Thi s bit is res et wh en the firmwa re res ets the e ndpoint FIFO using the UEPRST register.
For Control endp oints , each S ETUP tr ansact ion star ts wit h a DATA0 a nd data to gglin g is then used as for Bulk endpoints until the end of the Data stage (for a control write transfer). The Status stage completes the data transfer with a DATA1 (for a control read transfer).
For Isochronous endpoints, the device firmware should ignore the data-toggle.
94
AT8xC51SND1C
4109E–8051–06/03
AT8xC51SND1C

Suspend/Resume Management

Suspend The Suspend state can be detected by the USB controller if all the clocks are enabled
and if the USB controller is enabled. The bit SPINT is set by hardware when an idle state is detected for more than 3 ms. This triggers a USB interrupt if enabled.
In order to reduce c urrent c onsumption, the firmw are can s top the c locks and pu t the C51 in Idle or Power-down mode. The Resume detection is still active.
The stop of the 48 MHz clock from the PLL should be done in the following order:
1. Disable of the 48 MHz clock input of the USB controller by setting to 1 the SUS-
PCLK bit in the USBCON register.
2. Disable the PLL by clearing the PLLEN bit in the PLLCON register.
Resume W hen the US B cont roller is in Sus pend s tate, the Re sume d etecti on is acti ve ev en if all
the clocks are disabled and if the C51 is in Idle or Power-down mode. The WUPCPU bit is set by hardware when a non-id le sta te occur s on the US B bus. Thi s trigge rs an in ter­rupt if enabled. This interrupt wakes up the CPU from its Idle or Power-down state and the interrupt function is then executed. The firmware should first enable the 48 MHz generation and then reset to 0 the SUSPCLK bit in the USBCON register if needed. The firmware has to clear the SPINT bit in the USBINT register before any other USB operation in order to wake up the USB controller from its Suspend mode.
The USB controller is then re-activated. Figure 66. Example of a Suspend/Resume management
USB Controller Init
SPINT
Detection of a SUSPEND State
Set SUSPCLK
Disable PLL
Microcontroller in Power-down
Detection of a RESUME State
WUPCPU
Enable PLL
Clear SUSPCLK
Clear SPINT Bit
4109E–8051–06/03
Clear WUPCPU Bit
95
Upstream Resume A USB device can be allowed by the Host to send an upstream resume for Remote
Wake-up purpose. When the USB controller receives the SET_FEATURE request:
DEVICE_REMOTE_WAKEUP, the firmware should set to 1 the RMWUPE bit in the USBCON register to enable this functionality. RMWUPE value should be 0 in the other cases.
If the device is in SUSPEND mode, the USB controller can send an upstream resume by clearing first the SPINT bit in the USBINT register and by setting then to 1 the SDRM­WUP bit in the USBCON register. The US B controller se ts to 1 the UPRSM bi t in the USBCON register. All clocks must be enabled first. The Remote Wake is sent only if the USB bus was in Susp end sta te for at leas t 5ms. When the upstre am resume is com­pleted, the UPRSM bit is reset to 0 by hardware. The firmware should then clear the SDRMWUP bit.
Figure 67. Example of REMOTE WAKEUP Management
USB Controller Init
SET_FEATURE: DEVICE_REMOTE_WAKEUP
Set RMWUPE
Detection of a SUSPEND state
UPRSM = 1
upstream RESUME sent
SPINT
Suspend Management
need USB resume
enable clocks
Clear SPINT
Set SDMWUP
UPRSM
Clear SDRMWUP
96
AT8xC51SND1C
4109E–8051–06/03

USB Interrupt System

Interrupt System Priorities Figure 68. USB Interrupt Control System
AT8xC51SND1C
D+
D-
USB
Controller
EUSB
IE1.6
Interrupt Enable Lowest Priority Interrupts
EA
IE0.7
00 01 10 11
IPH/L
Priority Enable
Table 1. Priority Levels
IPHUSB IPLUSB USB Priority Level
0 0 0..................Lowest
01 1 10 2
1 1 3..................Highest
USB Interrupt Control System As shown in Figure 69, many events can produce a USB interrupt:
TXCMPL: Transmitted In Data (Table 96 on page 103). This bit is set by hardware
when the Host accept a In packet.
RXOUTB0: Received Out Data Bank 0 (Table 96 on page 103). This bit is set by
hardware when an Out packet is accepted by the endpoint and stored in bank 0.
RXOUTB1: Received Out Data Bank 1 (only for Ping-pong endpoints) (Table 96 on
page 103). This bit is set by hardware when an Out packet is accepted by the endpoint and stored in bank 1.
RXSETUP: Received Setup (Table 96 on page 103). This bit is set by hardware
when an SETUP packet is accepted by the endpoint.
STLCRC: STALLED (only for Control, Bulk and Interrupt endpoints) (Table 96 on
page 103). This bit is set by hardware when a STALL handshake has been sent as requested by STALLRQ, and is reset by hardware when a SETUP packet is received.
SOFINT : S t art of Frame Interrupt (Table 92 on page 100). This bit is set by hardware
when a USB start of frame packet has been received.
WUPCPU: Wake-Up CPU Interrupt (Table 92 on page 100). This bit is set by
hardware wh en a USB res ume i s det ected on t he US B bus , af ter a SUSP END st a te.
SPINT: Suspend Interrupt (Table 92 on page 100). This bit is set by hardware when
a USB suspend is detected on the USB bus.
4109E–8051–06/03
97
Figure 69. USB Interrupt Control Block Diagram
Endpoint X (X = 0..2)
TXCMP
UEPSTAX.0
RXOUTB0
UEPSTAX.1
RXOUTB1
UEPSTAX.6
RXSETUP
UEPSTAX.2
STLCRC
UEPSTAX.3
NAKOUT
UEPCONX.5
NAKIN
UEPCONX.4
NAKIEN
UEPCONX.6
EPXINT
UEPINT.X
EPXIE
UEPIEN.X
WUPCPU
USBINT.5
EORINT
USBINT.4
SOFINT
USBINT.3
SPINT
USBINT.0
EWUPCPU
USBIEN.5
EEORINT
USBIEN.4
ESOFINT
USBIEN.3
ESPINT
USBIEN.0
EUSB
IE1.6
98
AT8xC51SND1C
4109E–8051–06/03

Registers Table 90. USBCON Register

USBCON (S:BCh) – USB Global Control Register
76543210
USBE SUSPCLK SDRMWUP - UPRSM RMWUPE CONFG FADDEN
AT8xC51SND1C
Bit
Number
7USBE
6SUSPCLK
5 SDRMWUP
4-
3UPRSM
2RMWUPE
Bit
Mnemonic Description
USB Enable Bit
Set this bit to enable the USB controller. Clear this bit to disable and reset the USB controller, to disable the USB transceiver an to disable the USB controllor clock inputs.
Suspend USB Clock Bit
Set to disable the 48 MHz clock input (Resume Detection is still active). Clear to enable the 48 MHz clock input.
Send Remote Wake-Up Bit
Set to force an external interrupt on the USB controller for Remote Wake UP purpose. An upstream resume is send only if the bit RMWUPE is set, all USB clocks are enabled AND the USB bus was in SUSPEND state for at least 5 ms. See UPRSM below. Cleared by software.
Reserved
The value read from this bit is always 0. Do not set this bit.
Upstream Resume Bit (read only)
Set by hardware when SDRMWUP has been set and if RMWUPE is enabled. Cleared by hardware after the upstream resume has been sent.
Remote Wake-Up Enable Bit
Set to enabled request an upstream resume signaling to the host. Clear after the upstream resume has been indicated by RSMINPR.
Note: Do not set this bit if the host has not set the DEVICE_REMOTE_WAKEUP feature for the device.
4109E–8051–06/03
Configuration Bit
This bit should be set by the device firmware after a SET_CONFIGURATION request with a non-zero value has been correctly processed.
1CONFG
0 FADDEN
It should be cleared by the device firmware when a SET_CONFIGURATION request with a zero value is received. It is cleared by hardware on hardware reset or when an USB reset is detected on the bus (SE0 state for at least 32 Full Speed bit times: typically 2.7 µs).
Function Address Enable Bit
This bit should be set by the device firmware after a successful status phase of a SET_ADDRESS transaction. It should not be cleared afterwards by the device firmware. It is cleared by hardware on hardware reset or when an USB reset is received (see above). When this bit is cleared, the default function address is used (0).
Reset Value = 0000 0000b
99
Table 91. USBADDR Register
USBADDR (S:C6h) – USB Address Register
76543210
FEN UADD6 UADD5 UADD4 UADD3 UADD2 UADD1 UADD0
Bit
Number
7FEN
6 - 0 UADD6:0
Bit
Mnemonic Description
Function En able Bit
Set to enable the function. The device firmware should set this bit after it has received a USB reset and participate in the following configuration process with the default address (FEN is reset to 0). Cleared by hardware at power-up, should not be cleared by the device firmware once set.
USB Address Bits
This field contains the default address (0) after power-up or USB bus reset. It should be written with the value set by a SET_ADDRESS request received by the device firmware.
Reset Value = 0000 0000b
Table 92. USBINT Register USBINT (S:BDh) – USB Global Interrupt Register
76543210
- - WUPCPU EORINT SOFINT - - SPINT
Bit
Number
7 - 6 -
Bit
Mnemonic Description
Reserved
The value read from these bits is always 0. Do not set these bits.
Wake Up CPU Interrupt Flag
5WUPCPU
4 EORINT
3 SOFINT
2 - 1 -
0SPINT
Set by hardware when the USB controller is in SUSPEND state and is re­activated by a non-idle signal from USB line (not by an upstream resume). This triggers a USB interrupt when EWUPCPU is set in the USBIEN. Cleared by software after re-enabling all USB clocks.
End of Reset Interrupt Flag
Set by hardware when a End of Reset has been detected by the USB controller. This triggers a USB interrupt when EEORINT is set in USBIEN. Cleared by software.
Start of Frame Interrupt Flag
Set by hardware when an USB Start of Frame packet (SOF) has been properly received. This triggers a USB interrupt when ESOFINT is set in USBIEN. Cleared by software.
Reserved
The value read from these bits is always 0. Do not set these bits.
Suspend Interrupt Fla g
Set by hardware when a USB Suspend (Idle bus for three frame periods: a J state for 3 ms) is detected. This triggers a USB interrupt when ESPINT is set in USBIEN. Cleared by software.
Reset Value = 0000 0000b
100
AT8xC51SND1C
4109E–8051–06/03
Loading...