AT89C51RC2_0312 ATMEL | Alldatasheet

Document overview

  • Manufacturer or author: Provided By ALLDATASHEET.COM(FREE DATASHEET DOWNLOAD SITE)
  • PDF pages: 127

Technical content

Features

 80C52 Compatible – 8051 Pin and Instruction Compatible – Four 8-bit I/O Ports – Three 16-bit Timer/Counters – 256 Bytes Scratch Pad RAM – 9 Interrupt Sources with 4 Priority Levels – Dual Data Pointer  Variable Length MOVX for Slow RAM/Peripherals  ISP (In-system Programming) Using Standard VCC Power Supply  Boot ROM Contains Low Level Flash Programming Routines and a Default Serial Loader  High-speed Architecture – In Standard Mode: 40 MHz (Vcc 2.7V to 5.5V, both Internal and external code execution) 60 MHz (Vcc 4.5V to 5.5V and Internal Code execution only) – In X2 mode (6 Clocks/machine cycle) 20 MHz (Vcc 2.7V to 5.5V, both Internal and external code execution) 30 MHz (Vcc 4.5V to 5.5V and Internal Code execution only) – 16K/32K Bytes On-chip Flash Program/Data Memory – Byte and Page (128 Bytes) Erase and Write – 100K Write Cycles  On-chip 1024 Bytes Expanded RAM (XRAM) – Software Selectable Size (0, 256, 512, 768, 1024 Bytes) – 256 Bytes Selected at Reset for TS87C51RB2/RC2 Compatibility  Keyboard Interrupt Interface on Port P1  SPI Interface (Master/Slave Mode)  8-bit Clock Prescaler  Improved X2 Mode with Independent Selection for CPU and Each Peripheral  Programmable Counter Array 5 Channels – High-speed Output – Compare/Capture – Pulse Width Modulator – Watchdog Timer Capabilities  Asynchronous Port Reset  Full Duplex Enhanced UART  Dedicated Baud Rate Generator for UART  Low EMI (Inhibit ALE)  Hardware Watchdog Timer (One-time Enabled with Reset-out)  Power Control Modes – Idle Mode – Power-down Mode – Power-off Flag  Power Supply: – 2.7 to 3.6 (3V Version) – 2.7 to 5.5V (5V Version)  Temperature Ranges: Commercial (0 to +70°C) and Industrial (-40°C to +85°C)  Packages: PDIL40, PLCC44, VQFP44

Description

The AT89C51RB2/RC2 is a high-performance Flash version of the 80C51 8-bit micro- controllers. It contains a 16K or 32K Bytes Flash memory block for program and data. The Flash memory can be programmed either in parallel mode or in serial mode with the ISP capability or with software. The programming voltage is internally generated from the standard VCC pin. 8-bit Microcontroller with 16K/ 32K Bytes Flash AT89C51RB2 AT89C51RC2

2 AT89C51RB2/RC2

RAM, a 9-source 4-level interrupt controller and three timer/counters.

1024 Bytes, a Hardware Watchdog Timer, a Keyboard Interface, an SPI Interface, a

and a speed improvement mechanism (X2 mode). The Pinout is the standard 40/44 pins of the C52. allowing it to bring the clock frequency down to any value, even DC, without loss of data. mode, the RAM is saved and all other functions are inoperative. alarms, motor control, corded phones, and smart card readers. Table 1. Memory Size

Figure 1. Block Diagram Notes: 1. Alternate function of Port 1.

  1. Alternate function of Port 3.

4 AT89C51RB2/RC2

4180C–8051–12/03 SFR Mapping The Special Function Registers (SFRs) of the AT89C51RB2/RC2 fall into the following categories:  C51 core registers: ACC, B, DPH, DPL, PSW, SP  I/O port registers: P0, P1, P2, P3  Timer registers: T2CON, T2MOD, TCON, TH0, TH1, TH2, TMOD, TL0, TL1, TL2, RCAP2L, RCAP2H  Serial I/O port registers: SADDR, SADEN, SBUF, SCON  PCA (Programmable Counter Array) registers: CCON, CCAPMx, CL, CH, CCAPxH, CCAPxL (x: 0 to 4)  Power and clock control registers: PCON  Hardware Watchdog Timer registers: WDTRST, WDTPRG  Interrupt system registers: IEN0, IPL0, IPH0, IEN1, IPL1, IPH1  Keyboard Interface registers: KBE, KBF, KBLS  SPI registers: SPCON, SPSTR, SPDAT  BRG (Baud Rate Generator) registers: BRL, BDRCON  Flash register: FCON  Clock Prescaler register: CKRL  Others: AUXR, AUXR1, CKCON0, CKCON1

Table 2. C51 Core SFRs Table 3. System Management SFRs Table 4. Interrupt SFRs Table 5. Port SFRs

6 AT89C51RB2/RC2

Table 6. Timer SFRs Table 7. PCA SFRs

Table 8. Serial I/O Port SFRs Table 9. SPI Controller SFRs Table 10. Keyboard Interface SFRs

8 AT89C51RB2/RC2

Table 11 shows all SFRs with their address and their reset value. Table 11. SFR Mapping

  1. FCON access is reserved for the Flash API and ISP software.

Figure 2. Pin Configurations

10 AT89C51RB2/RC2

Table 12. Pin Description for 40 - 44 Pin Packages during memory programming and verification. SPI is in slave mode, MISO outputs data to the master controller.

is in slave mode, MOSI receives data from the master controller. 80C51 family, as listed below. watchdog forces a system reset. bit. With this bit set, ALE will be inactive during internal fetches. Table 12. Pin Description for 40 - 44 Pin Packages (Continued)

12 AT89C51RB2/RC2

security level 1 is programmed, EA will be internally latched on Reset.

CPU clocks, in order to pull the port pin high quickly. Then it turns off again. ports when latch data is logical 0. The quasi-bidirectional port configuration is shown in Figure 3. Figure 3. Quasi-Bidirectional Output

2 CPU

14 AT89C51RB2/RC2

Table 14. PCON Register Set to select double baud rate in mode 1, 2 or 3. Cleared to select SM0 bit in SCON register. Set to select FE bit in SCON register. The value read from this bit is indeterminate. Do not set this bit. Cleared to recognize next reset type. Cleared by software for general-purpose usage. Set by software for general-purpose usage. Cleared by software for general-purpose usage. Set by software for general-purpose usage. Cleared by hardware when reset occurs. Set to enter power-down mode. Cleared by hardware when interrupt or reset occurs.

Figure 4. Functional Oscillator Block Diagram

16 AT89C51RB2/RC2

 Divide frequency crystals by 2 (cheaper crystals) while keeping same CPU power.  Save power consumption while keeping same CPU power (oscillator power saving).  Increase CPU power by 2 while keeping same crystal frequency. the CPU core and the peripherals. bypassed, the signals on XTAL1 must have a cyclic ratio between 40 to 60%. the switching mode waveforms. Figure 5. Clock Generation Diagram

Figure 6. Mode Switching Waveforms X2 bit activates the X2 feature (X2 mode).

18 AT89C51RB2/RC2

Table 15. CKCON0 Register

7 Reserved

Cleared to select 6 clock periods per peripheral clock cycle. Set to select 12 clock periods per peripheral clock cycle. periods per peripheral clock cycle. periods per peripheral clock cycle. Cleared to select 6 clock periods per peripheral clock cycle. Set to select 12 clock periods per peripheral clock cycle. periods per peripheral clock cycle. periods per peripheral clock cycle.

Table 16. CKCON1 Register Clear to select 6 clock periods per peripheral clock cycle. Set to select 12 clock periods per peripheral clock cycle.

20 AT89C51RB2/RC2

code to switch between them (see Figure 7). Figure 7. Use of Dual Pointer

Table 17. AUXR1 register Note: 1. Bit 2 stuck at 0; this allows using INC AUXR1 to toggle DPS without changing GF3.

0008 LOOP:

The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit.

5 ENBOOT

Cleared to disable boot ROM. Set to map the boot ROM between F800h - 0FFFFh. The value read from this bit is indeterminate. Do not set this bit. 3G F 3 This bit is a general-purpose user flag.

20 Always Cleared

The value read from this bit is indeterminate. Do not set this bit.

22 AT89C51RB2/RC2

4180C–8051–12/03 INC is a short (2 Bytes) and fast (12 clocks) way to manipulate the DPS bit in the AUXR1 SFR. However, note that the INC instruction does not directly force the DPS bit to a particular state, but simply toggles it. In simple routines, such as the block move example, only the fact that DPS is toggled in the proper sequence matters, not its actual value. In other words, the block move routine works the same whether DPS is '0' or '1' on entry. Observe that without the last instruction (INC AUXR1), the routine will exit with DPS in the opposite state.

space for increased data parameter handling and high-level language usage. and location are described in Table 18. Table 18. Expanded RAM

  1. The Lower 128 Bytes of RAM (addresses 00h to 7Fh) are directly and indirectly
  2. The Upper 128 Bytes of RAM (addresses 80h to FFh) are indirectly addressable
  3. The Special Function Registers, SFRs, (addresses 80h to FFh) are directly
  4. The expanded RAM Bytes are indirectly accessed by MOVX instructions, and

with the EXTRAM bit cleared in the AUXR register (see Table 18). physically separate from SFR space. Figure 8. Internal and External Data Memory Address addressing mode used in the instruction. MOV 0A0H, # data, accesses the SFR at location 0A0h (which is P2).

128 Bytes

24 AT89C51RB2/RC2

4180C–8051–12/03  Instructions that use indirect addressing access the Upper 128 Bytes of data RAM. For example: MOV @R0, # data where R0 contains 0A0h, accesses the data Byte at address 0A0h, rather than P2 (whose address is 0A0h).  The XRAM Bytes can be accessed by indirect addressing, with EXTRAM bit cleared and MOVX instructions. This part of memory that is physically located on-chip, logically occupies the first Bytes of external data memory. The bits XRS0 and XRS1 are used to hide a part of the available XRAM as explained in Table 18. This can be useful if external peripherals are mapped at addresses already used by the internal XRAM.  With EXTRAM = 0, the XRAM is indirectly addressed, using the MOVX instruction in combination with any of the registers R0, R1 of the selected bank or DPTR. An access to XRAM will not affect ports P0, P2, P3.6 (WR) and P3.7 (RD). For example, with EXTRAM = 0, MOVX @R0, # data where R0 contains 0A0H, accesses the XRAM at address 0A0H rather than external memory. An access to external data memory locations higher than the accessible size of the XRAM will be performed with the MOVX DPTR instructions in the same way as in the standard 80C51, with P0 and P2 as data/address busses, and P3.6 and P3.7 as write and read timing signals. Accesses to XRAM above 0FFH can only be done by the use of DPTR.  With EXTRAM = 1 , MOVX @RI and MOVX @DPTR will be similar to the standard 80C51. MOVX @ Ri will provide an eight-bit address multiplexed with data on Port0 and any output port pins can be used to output higher order address bits. This is to provide the external paging capability. MOVX @DPTR will generate a sixteen-bit address. Port2 outputs the high-order eight address bits (the contents of DPH) while Port0 multiplexes the low-order eight address bits (DPL) with data. MOVX @ RI and MOVX @DPTR will generate either read or write signals on P3.6 (WR ) and P3.7 (RD). The stack pointer (SP) may be located anywhere in the 256 Bytes RAM (lower and upper RAM) internal data memory. The stack may not be located in the XRAM. The M0 bit allows to stretch the XRAM timings; if M0 is set, the read and write pulses are extended from 6 to 30 clock periods. This is useful to access external slow peripherals.

4180C–8051–12/03 Registers Table 19. AUXR Register AUXR - Auxiliary Register (8Eh) Reset Value = XX0X 00’HSB. XRAM’0b (see Table 65) Not bit addressable 76543210 DPU - M0 - XRS1 XRS0 EXTRAM AO Bit Number Bit Mnemonic Description 7D P U Disable Weak Pull-up Cleared to activate the permanent weak pull up when latch data is logical 1 Set to disactive the weak pull-up (reduce power consumption) 6- Reserved The value read from this bit is indeterminate. Do not set this bit. 5M 0 Pulse Length Cleared to stretch MOVX control: the RD and the WR pulse length is 6 clock periods (default). Set to stretch MOVX control: the RD and the WR pulse length is 30 clock periods. 4- Reserved The value read from this bit is indeterminate. Do not set this bit. 3X R S 1 XRAM Size XRS1 XRS0 XRAM size 0 0 256 Bytes (default) 0 1 512 Bytes 1 0 768 Bytes 1 1 1024 Bytes 2X R S 0

1 EXTRAM

Cleared to access internal XRAM using movx @ Ri/ @ DPTR. Set to access external memory. Programmed by hardware after Power-up regarding Hardware Security Byte (HSB), default setting, XRAM selected. 0A O ALE Output Bit Cleared, ALE is emitted at a constant rate of 1/6 the oscillator frequency (or 1/3 if X2 mode is used). (default) Set, ALE is active only during a MOVX or MOVC instruction is used.

26 AT89C51RB2/RC2

4180C–8051–12/03 Timer 2 The Timer 2 in the AT89C51RB2/RC2 is the standard C52 Timer 2. It is a 16-bit timer/counter: the count is maintained by two eight-bit timer registers, TH2 and TL2 are cascaded. It is controlled by T2CON (Table 20) and T2MOD (Table 21) registers. Timer 2 operation is similar to Timer 0 and Timer 1C/T2 selects FOSC /12 (timer operation) or external pin T2 (counter operation) as the timer clock input. Setting TR2 allows TL2 to increment by the selected input. Timer 2 has 3 operating modes: capture, autoreload and Baud Rate Generator. These modes are selected by the combination of RCLK, TCLK and CP/RL2 (T2CON). see the Atmel 8-bit Microcontroller Hardware description for the description of Capture and Baud Rate Generator Modes. Timer 2 includes the following enhancements:  Auto-reload mode with up or down counter  Programmable clock-output Auto-reload Mode The auto-reload mode configures Timer 2 as a 16-bit timer or event counter with auto- matic reload. If DCEN bit in T2MOD is cleared, Timer 2 behaves as in 80C52 (see the Atmel C51 Microcontroller Hardware description). If DCEN bit is set, Timer 2 acts as an Up/down timer/counter as shown in Figure 9. In this mode the T2EX pin controls the direction of count. When T2EX is high, Timer 2 counts up. Timer overflow occurs at FFFFh which sets the TF2 flag and generates an interrupt request. The overflow also causes the 16-bit value in RCAP2H and RCAP2L registers to be loaded into the timer registers TH2 and TL2. When T2EX is low, Timer 2 counts down. Timer underflow occurs when the count in the timer registers TH2 and TL2 equals the value stored in RCAP2H and RCAP2L registers. The underflow sets TF2 flag and reloads FFFFh into the timer registers. The EXF2 bit toggles when Timer 2 overflows or underflows according to the direction of the count. EXF2 does not generate any interrupt. This bit can be used to provide 17-bit resolution.

Figure 9. Auto-Reload Mode Up/Down Counter (DCEN = 1)  Set T2OE bit in T2MOD register.  Clear C/T2 bit in T2CON register. reload value or a different one depending on the application.  To start the timer, set TR2 run control bit in T2CON register. independent since both functions use the values in the RCAP2H and RCAP2L registers.

28 AT89C51RB2/RC2

Figure 10. Clock-Out Mode C/T2 = 0

4180C–8051–12/03 Registers Table 20. T2CON Register T2CON – Timer 2 Control Register (C8h) Reset Value = 0000 0000b Bit addressable 76543210 TF2 EXF2 RCLK TCLK EXEN2 TR2 C/T2# CP/RL2# Bit Number Bit Mnemonic Description

7 TF2

Must be cleared by software. Set by hardware on Timer 2 overflow, if RCLK = 0 and TCLK = 0. 6E X F 2 Timer 2 External Flag Set when a capture or a reload is caused by a negative transition on T2EX pin if EXEN2 = 1. When set, causes the CPU to vector to Timer 2 interrupt routine when Timer 2 interrupt is enabled. Must be cleared by software. EXF2 doesn’t cause an interrupt in Up/down counter mode (DCEN = 1).

5 RCLK

Cleared to use timer 1 overflow as receive clock for serial port in mode 1 or 3. Set to use Timer 2 overflow as receive clock for serial port in mode 1 or 3. 4T C L K Transmit Clock Bit Cleared to use timer 1 overflow as transmit clock for serial port in mode 1 or 3. Set to use Timer 2 overflow as transmit clock for serial port in mode 1 or 3.

3 EXEN2

Timer 2 External Enable Bit Cleared to ignore events on T2EX pin for Timer 2 operation. Set to cause a capture or reload when a negative transition on T2EX pin is detected, if Timer 2 is not used to clock the serial port. 2T R 2 Timer 2 Run Control Bit Cleared to turn off Timer 2. Set to turn on Timer 2. 1C / T 2 # Timer/Counter 2 Select Bit Cleared for timer operation (input from internal clock system: F CLK PERIPH ). Set for counter operation (input from T2 input pin, falling edge trigger). Must be 0 for clock out mode. 0C P / R L 2 # Timer 2 Capture/Reload Bit If RCLK = 1 or TCLK = 1, CP/RL2# is ignored and timer is forced to auto-reload on Timer 2 overflow. Cleared to auto-reload on Timer 2 overflows or negative transitions on T2EX pin if EXEN2 = 1. Set to capture on negative transitions on T2EX pin if EXEN2 = 1.

30 AT89C51RB2/RC2

Table 21. T2MOD Register The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. Cleared to program P1.0/T2 as clock input or I/O port. Set to program P1.0/T2 as clock output.

0 DCEN

Cleared to disable Timer 2 as up/down counter. Set to enable Timer 2 as up/down counter.

4180C–8051–12/03 Programmable Counter Array (PCA) The PCA provides more timing capabilities with less CPU intervention than the standard timer/counters. Its advantages include reduced software overhead and improved accu- racy. The PCA consists of a dedicated timer/counter which serves as the time base for an array of five compare/capture Modules. Its clock input can be programmed to count any one of the following signals:  Peripheral clock frequency (F CLK PERIPH ) ÷ 6  Peripheral clock frequency (FCLK PERIPH ) ÷ 2  Timer 0 overflow  External input on ECI (P1.2) Each compare/capture Modules can be programmed in any one of the following modes:  Rising and/or falling edge capture  Software timer  High-speed output  Pulse width modulator Module 4 can also be programmed as a watchdog timer (see Section "PCA Watchdog Timer", page 42). When the compare/capture Modules are programmed in the capture mode, software timer, or high speed output mode, an interrupt can be generated when the Module exe- cutes its function. All five Modules plus the PCA timer overflow share one interrupt vector. The PCA timer/counter and compare/capture modules share Port 1 for external I/O. These pins are listed below. If one or several bits in the port are not used for the PCA, they can still be used for standard I/O. The PCA timer is a common time base for all five Modules (see Figure 11). The timer count source is determined from the CPS1 and CPS0 bits in the CMOD register (Table 22) and can be programmed to run at:  1/6 the peripheral clock frequency (FCLK PERIPH )  1/2 the peripheral clock frequency (FCLK PERIPH )  The Timer 0 overflow  The input on the ECI pin (P1.2) PCA Component External I/O Pin 16-bit Counter P1.2/ECI 16-bit Module 0 P1.3/CEX0 16-bit Module 1 P1.4/CEX1 16-bit Module 2 P1.5/CEX2 16-bit Module 3 P1.6/CEX3

32 AT89C51RB2/RC2

Figure 11. PCA Timer/Counter

4180C–8051–12/03 Registers Table 22. CMOD Register CMOD – PCA Counter Mode Register (D9h) Reset Value = 00XX X000b Not bit addressable The CMOD register includes three additional bits associated with the PCA.  The CIDL bit which allows the PCA to stop during idle mode.  The WDTE bit which enables or disables the watchdog function on Module 4.  The ECF bit which when set causes an interrupt and the PCA overflow flag CF (in the CCON SFR) to be set when the PCA timer overflows. The CCON register contains the run control bit for the PCA and the flags for the PCA timer (CF) and each Module (see Table 23).  Bit CR (CCON. 6) must be set by software to run the PCA. The PCA is shut off by clearing this bit.  Bit CF: The CF bit (CCON. 7) is set when the PCA counter overflows and an interrupt will be generated if the ECF bit in the CMOD register is set. The CF bit can only be cleared by software.  Bits 0 through 4 are the flags for the Modules (bit 0 for Module 0, bit 1 for Module 1, etc. ) and are set by hardware when either a match or a capture occurs. These flags also can only be cleared by software. 76543210 CIDL WDTE - - - CPS1 CPS0 ECF Bit Number Bit Mnemonic Description 7C I D L Counter Idle Control Cleared to program the PCA Counter to continue functioning during idle Mode. Set to program PCA to be gated off during idle. 6W D T E Watchdog Timer Enable Cleared to disable Watchdog Timer function on PCA Module 4. Set to enable Watchdog Timer function on PCA Module 4. 5- Reserved The value read from this bit is indeterminate. Do not set this bit. 4- Reserved The value read from this bit is indeterminate. Do not set this bit. 3- Reserved The value read from this bit is indeterminate. Do not set this bit.

2 CPS1 PCA Count Pulse Select

0 0 Internal clock F CLK PERIPH /6 0 1 Internal clock F LK PERIPH /2 1 0 Timer 0 Overflow 1 1 External clock at ECI/P1.2 pin (max rate = fCLK PERIPH/ 4)

1 CPS0

PCA Enable Counter Overflow Interrupt Cleared to disable CF bit in CCON to inhibit an interrupt. Set to enable CF bit in CCON to generate an interrupt.

34 AT89C51RB2/RC2

Table 23. CCON Register The watchdog timer function is implemented in Module 4 (see Figure 14). The PCA interrupt system is shown in Figure 12. Must be cleared by software to turn the PCA counter off. Set by software to turn the PCA counter on. The value read from this bit is indeterminate. Do not set this bit.

4 CCF4

Must be cleared by software. Set by hardware when a match or capture occurs.

3 CCF3

Must be cleared by software. Set by hardware when a match or capture occurs.

2 CCF2

Must be cleared by software. Set by hardware when a match or capture occurs.

1 CCF1

Must be cleared by software. Set by hardware when a match or capture occurs.

0 CCF0

Must be cleared by software. Set by hardware when a match or capture occurs.

Figure 12. PCA Interrupt System In addition, Module 4 can be used as a Watchdog Timer. registers contain the bits that control the mode that each Module will operate in. compare occurs in the associated Module.  PWM (CCAPMn. 1) enables the pulse width modulation mode. enabled and a capture will occur for either transition. Table 24 shows the CCAPMn settings for the various PCA functions.

36 AT89C51RB2/RC2

Table 24. CCAPMn Registers (n = 0-4) The value read from this bit is indeterminate. Do not set this bit. Cleared to disable the comparator function. Set to enable the comparator function.

5 CAPPn

Cleared to disable positive edge capture. Set to enable positive edge capture.

4 CAPNn

Cleared to disable negative edge capture. Set to enable negative edge capture.

2 TOGn

compare/capture register causes theCEXn pin to toggle. Cleared to disable the CEXn pin to be used as a pulse width modulated output. Set to enable the CEXn pin to be used as a pulse width modulated output.

Table 25. PCA Module Modes (CCAPMn Registers) Table 26. CCAPnH Registers (n = 0-4)

0000000 N o O p e r a t i o n

38 AT89C51RB2/RC2

Table 27. CCAPnL Registers (n = 0-4) Table 28. CH Register Table 29. CL Register

Figure 13. PCA Capture Mode

40 AT89C51RB2/RC2

SFR) and the ECCFn (CCAPMn SFR) bits for the Module are both set (see Figure 14). Figure 14. PCA Compare Mode and PCA Watchdog Timer otherwise an unwanted match could occur. Writing to CCAPnH will set the ECOM bit. ECOM bit can still be controlled by accessing to CCAPMn register.

each time a match occurs between the PCA counter and the modules capture registers. must be set (see Figure 15). A prior write must be done to CCAPnL and CCAPnH before writing the ECOMn bit. Figure 15. PCA High-speed Output Mode otherwise an unwanted match could occur. ECOM bit can still be controlled by accessing to CCAPMn register.

42 AT89C51RB2/RC2

Modules will have the same frequency of output because they all share the PCA timer. the module's CCAPMn register must be set to enable the PWM mode. Figure 16. PCA PWM Mode

  1. Periodically change the compare value so it will never match the PCA timer.
  2. Periodically change the PCA timer value so it will never match the compare
  3. Disable the watchdog by clearing the WDTE bit before a match occurs and then

4180C–8051–12/03 changing the time base for other Modules would not be a good idea. Thus, in most appli- cations the first solution is the best option. This watchdog timer won’t generate a reset out on the reset pin.

44 AT89C51RB2/RC2

Figure 17. Framing Error Block Diagram SCON register (See Table 33.) bit is set. last data bit (See Figure 18. and Figure 19.). Figure 18. UART Timings in Mode 1

Figure 19. UART Timings in Modes 2 and 3 nication feature is enabled (SM2 bit in SCON register is set). is not interrupted by command frames addressed to other devices. be enabled in mode 0 (i. e. setting SM2 bit in SCON register in mode 0 has no effect). slaves at a time. The following example illustrates how a given address is formed.

46 AT89C51RB2/RC2

4180C–8051–12/03 The SADEN byte is selected so that each slave may be addressed separately. For slave A, bit 0 (the LSB) is a don’t-care bit; for slaves B and C, bit 0 is a 1.To commu- nicate with slave A only, the master must send an address where bit 0 is clear (e. g. 1111 0000b). For slave A, bit 1 is a 1; for slaves B and C, bit 1 is a don’t care bit. To communicate with slaves B and C, but not slave A, the master must send an address with bits 0 and 1 both set (e. g. 1111 0011b). To communicate with slaves A, B and C, the master must send an address with bit 0 set, bit 1 clear, and bit 2 clear (e. g. 1111 0001b). Broadcast Address A broadcast address is formed from the logical OR of the SADDR and SADEN registers with zeros defined as don’t-care bits, e. g. : SADDR0101 0110b SADEN1111 1100b Broadcast =SADDR OR SADEN1111 111Xb The use of don’t-care bits provides flexibility in defining the broadcast address, however in most applications, a broadcast address is FFh. The following is an example of using broadcast addresses: Slave A:SADDR1111 0001b SADEN 1111 1010b Broadcast1111 1X11b, Slave B:SADDR1111 0011b SADEN 1111 1001b Broadcast1111 1X11B, Slave C:SADDR=1111 0011b SADEN 1111 1101b Broadcast1111 1111b For slaves A and B, bit 2 is a don’t care bit; for slave C, bit 2 is set. To communicate with all of the slaves, the master must send an address FFh. To communicate with slaves A and B, but not slave C, the master can send and address FBh. Reset Addresses On reset, the SADDR and SADEN registers are initialized to 00h, i. e. the given and broadcast addresses are XXXX XXXXb (all don’t-care bits). This ensures that the serial port will reply to any address, and so, that it is backwards compatible with the 80C51 microcontrollers that do not support automatic address recognition.

Table 31. SADDR Register the T2CON and BDRCON registers. Figure 20. Baud Rate Selection

48 AT89C51RB2/RC2

Table 32. Baud Rate Selection Table UART in BDRCON register and the value of the SMOD1 bit in PCON register. Figure 21. Internal Baud Rate

0000 T i m e r 1 T i m e r 1

1000 T i m e r 2 T i m e r 1

0100 T i m e r 1 T i m e r 2

1100 T i m e r 2 T i m e r 2

0 X 0 1 Timer 1 INT_BRG

1 X 0 1 Timer 2 INT_BRG

Table 33. SCON Register Clear to reset the error state, not cleared by a valid stop bit. Set by hardware when an invalid stop bit is detected. SMOD0 must be set to enable access to the FE bit. Refer to SM1 for serial port mode selection. SMOD0 must be cleared to enable access to the SM0 bit. Clear to disable multiprocessor communication feature. eventually mode 1.This bit should be cleared in mode 0. Clear to disable serial reception. Set to enable serial reception. Clear to transmit a logic 0 in the 9th bit. Set to transmit a logic 1 in the 9th bit. Cleared by hardware if 9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1. Clear to acknowledge interrupt. of the stop bit in the other modes. Clear to acknowledge interrupt. Set by hardware at the end of the 8th bit time in mode 0, see Figure 18. and Figure 19. in the other modes.

50 AT89C51RB2/RC2

Table 34. Example of Computed Value When X2=1, SMOD1=1, SPD=1 Table 35. Example of Computed Value When X2=0, SMOD1=0, SPD=0 Table 37. SADDR Register

Table 38. SBUF Register Table 39. BRL Register

52 AT89C51RB2/RC2

Table 40. T2CON Register Must be cleared by software. Set by hardware on timer 2 overflow, if RCLK = 0 and TCLK = 0. Cleared to use timer 1 overflow as receive clock for serial port in mode 1 or 3. Set to use timer 2 overflow as receive clock for serial port in mode 1 or 3. Cleared to use timer 1 overflow as transmit clock for serial port in mode 1 or 3. Set to use timer 2 overflow as transmit clock for serial port in mode 1 or 3. Cleared to ignore events on T2EX pin for timer 2 operation. detected, if timer 2 is not used to clock the serial port. Cleared to turn off timer 2. Set to capture on negative transitions on T2EX pin if EXEN2=1.

Table 41. PCON Register doesn’t affect the value of this bit. Set to select double baud rate in mode 1, 2 or 3. Cleared to select SM0 bit in SCON register. Set to select FE bit in SCON register. The value read from this bit is indeterminate. Do not set this bit. Cleared to recognize next reset type. Cleared by user for general purpose usage. Set by user for general purpose usage. Cleared by user for general purpose usage. Set by user for general purpose usage. Cleared by hardware when reset occurs. Set to enter power-down mode. Cleared by hardware when interrupt or reset occurs.

54 AT89C51RB2/RC2

Table 42. BDRCON Register The value read from this bit is indeterminate. Do not set this bit. Cleared to stop the internal Baud Rate Generator. Set to start the internal Baud Rate Generator. Cleared to select Timer 1 or Timer 2 for the Baud Rate Generator. Set to select internal Baud Rate Generator. Cleared to select Timer 1 or Timer 2 for the Baud Rate Generator. Set to select internal Baud Rate Generator.

1 SPD

Cleared to select the SLOW Baud Rate Generator. Set to select the FAST Baud Rate Generator. Set to select the internal Baud Rate Generator for UARTs in mode 0.

56 AT89C51RB2/RC2

Table 43. Priority Level Bit Values

Table 44. IENO Register Cleared to disable all interrupts. Set to enable all interrupts. Cleared to disable timer 2 overflow interrupt. Set to enable timer 2 overflow interrupt. Cleared to disable serial port interrupt. Set to enable serial port interrupt. Cleared to disable timer 1 overflow interrupt. Set to enable timer 1 overflow interrupt.

2 EX1

Cleared to disable external interrupt 1. Set to enable external interrupt 1. Cleared to disable timer 0 overflow interrupt. Set to enable timer 0 overflow interrupt.

0 EX0

Cleared to disable external interrupt 0. Set to enable external interrupt 0.

58 AT89C51RB2/RC2

Table 45. IPL0 Register The value read from this bit is indeterminate. Do not set this bit.

6 PPCL PCA Interrupt Priority Bit

see PPCH for priority level. see PT2H for priority level.

4 PSL Serial Port Priority Bit

see PT1H for priority level. see PX1H for priority level. see PT0H for priority level. see PX0H for priority level.

Table 46. IPH0 Register The value read from this bit is indeterminate. Do not set this bit.

6 PPCH

00 L o w e s t

4 PSH

2 PX1H

0 PX0H

60 AT89C51RB2/RC2

Table 47. IEN1 Register Cleared to disable SPI interrupt. Set to enable SPI interrupt.

0 KBD

Cleared to disable keyboard interrupt. Set to enable keyboard interrupt.

Table 48. IPL1 Register The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit.

2 SPIL SPI Interrupt Priority Bit

see SPIH for priority level. The value read from this bit is indeterminate. Do not set this bit.

0 KBDL Keyboard Interrupt Priority Bit

see KBDH for priority level.

62 AT89C51RB2/RC2

Table 49. IPH1 Register The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit.

0 KBDH

Table 50. Interrupt Sources and Vector Addresses

64 AT89C51RB2/RC2

exit from idle and power-down modes. register (Table 52), and KBF, the Keyboard Flag register (Table 51). input has the capability to detect a programmable level according to KBLS. x bit value. usage of P1 inputs for other purpose. Figure 23. Keyboard Interface Block Diagram Figure 24. Keyboard Input Circuitry

4180C–8051–12/03 Registers Table 51. KBF Register KBF - Keyboard Flag Register (9Eh) Reset Value = 0000 0000b This register is read only access, all flags are automatically cleared by reading the register. 76543210 KBF7 KBF6 KBF5 KBF4 KBF3 KBF2 KBF1 KBF0 Bit Number Bit Mnemonic Description 7K B F 7 Keyboard Line 7 Flag Set by hardware when the Port line 7 detects a programmed level. It generates a Keyboard interrupt request if the KBKBIE. 7 bit in KBIE register is set. Must be cleared by software. 6K B F 6 Keyboard Line 6 Flag Set by hardware when the Port line 6 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 6 bit in KBIE register is set. Must be cleared by software. 5K B F 5 Keyboard Line 5 Flag Set by hardware when the Port line 5 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 5 bit in KBIE register is set. Must be cleared by software. 4K B F 4 Keyboard Line 4 Flag Set by hardware when the Port line 4 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 4 bit in KBIE register is set. Must be cleared by software. 3K B F 3 Keyboard Line 3 Flag Set by hardware when the Port line 3 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 3 bit in KBIE register is set. Must be cleared by software. 2K B F 2 Keyboard Line 2 Flag Set by hardware when the Port line 2 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 2 bit in KBIE register is set. Must be cleared by software. 1K B F 1 Keyboard Line 1 Flag Set by hardware when the Port line 1 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 1 bit in KBIE register is set. Must be cleared by software. 0K B F 0 Keyboard Line 0 Flag Set by hardware when the Port line 0 detects a programmed level. It generates a Keyboard interrupt request if the KBIE. 0 bit in KBIE register is set. Must be cleared by software.

66 AT89C51RB2/RC2

Table 52. KBE Register

7 KBE7

Cleared to enable standard I/O pin. Set to enable KBF. 7 bit in KBF register to generate an interrupt request.

6 KBE6

Cleared to enable standard I/O pin. Set to enable KBF. 6 bit in KBF register to generate an interrupt request.

5 KBE5

Cleared to enable standard I/O pin. Set to enable KBF. 5 bit in KBF register to generate an interrupt request.

4 KBE4

Cleared to enable standard I/O pin. Set to enable KBF. 4 bit in KBF register to generate an interrupt request.

3 KBE3

Cleared to enable standard I/O pin. Set to enable KBF. 3 bit in KBF register to generate an interrupt request.

2 KBE2

Cleared to enable standard I/O pin. Set to enable KBF. 2 bit in KBF register to generate an interrupt request.

1 KBE1

Cleared to enable standard I/O pin. Set to enable KBF. 1 bit in KBF register to generate an interrupt request.

0 KBE0

Cleared to enable standard I/O pin. Set to enable KBF. 0 bit in KBF register to generate an interrupt request.

Table 53. KBLS Register Cleared to enable a low level detection on Port line 7. Set to enable a high level detection on Port line 7. Cleared to enable a low level detection on Port line 6. Set to enable a high level detection on Port line 6. Cleared to enable a low level detection on Port line 5. Set to enable a high level detection on Port line 5. Cleared to enable a low level detection on Port line 4. Set to enable a high level detection on Port line 4. Cleared to enable a low level detection on Port line 3. Set to enable a high level detection on Port line 3. Cleared to enable a low level detection on Port line 2. Set to enable a high level detection on Port line 2. Cleared to enable a low level detection on Port line 1. Set to enable a high level detection on Port line 1. Cleared to enable a low level detection on Port line 0. Set to enable a high level detection on Port line 0.

68 AT89C51RB2/RC2

communication between the MCU and peripheral devices, including other MCUs. Slave peripherals. The bus is made of three wires connecting all the devices. Figure 25. SPI Master/Slaves Interconnection port to control the four SS pins of the Slave devices. This 1-bit signal is directly connected between the Master Device and a Slave Device. is transmitted most significant bit (MSB) first, least significant bit (LSB) last. This 1-bit signal is directly connected between the Slave Device and a Master Device. word) is transmitted most significant bit (MSB) first, least significant bit (LSB) last. which allows to exchange one Byte on the serial lines.

selected at a time by the Master for a transmission. pin puts the MISO line of a Slave SPI in a high-impedance state.  The device is configured as a Master and the SSDIS control bit in SPCON is set. the SPSTA will never be set(1). pin to select the communicating Slave device. Note: 1. Clearing SSDIS control bit does not clear MODF.

  1. Special care should be taken not to set SSDIS control bit when CPHA = ’0’ because

in this mode, the SS is used to start the transmission. Table 54 gives the different clock rates selected by SPR2:SPR1:SPR0. Table 54. SPI Master Baud Rate Selection

000 F CLK PERIPH /2 2

001 F CLK PERIPH /4 4

010 F CLK PERIPH /8 8

011 F CLK PERIPH /16 16

100 F CLK PERIPH /32 32

101 F CLK PERIPH /64 64

110 F CLK PERIPH /128 128

70 AT89C51RB2/RC2

Functional Description Figure 26 shows a detailed structure of the SPI Module. Figure 26. SPI Module Block Diagram interfere with SPI bus activities.

Figure 27. Full-Duplex Master-Slave Interconnection SCK. Simultaneously, another Byte shifts in from the Slave on the Master’s MISO pin. device must be set to ’0’. SS must remain low until the transmission is complete. sampled and the edges on which the output data are shifted (Figure 28 and Figure 29).

  1. The SPI Module should be configured as a Master before it is enabled (SPEN set). Also,

the Master SPI should be configured before the Slave SPI.

  1. The SPI Module should be configured as a Slave before it is enabled (SPEN set).
  2. The maximum frequency of the SCK for an SPI configured as a Slave is the bus clock
  3. Before writing to the CPOL and CPHA bits, the SPI should be disabled (SPEN = ’0’).

72 AT89C51RB2/RC2

Figure 28. Data Transmission Format (CPHA = 0) Figure 29. Data Transmission Format (CPHA = 1) Figure 30. CPHA/SS Timing between each Byte transmitted (Figure 30). only one Slave driving the MISO data line.

when the SS signal becomes ’0’. device is pulled low, there is no way that another Master attempts to drive the network. pin as a general-purpose I/O pin. inal set state after the MODF bit has been cleared. done during a transmit sequence. WCOL does not cause an interruption, and the transfer continues uninterrupted. last cleared. A read of the SPDAT returns this Byte. All others Bytes are lost. This condition is not detected by the SPI peripheral. by writing 0 to SPEN bit (reset of the SPI state machine). Table 55. SPI Interrupts has been completed. SPIF bit generates transmitter CPU interrupt requests. CPU interrupt requests. When SSDIS is set, no MODF interrupt request is generated. Figure 31 gives a logical view of the above statements.

74 AT89C51RB2/RC2

Figure 31. SPI Interrupt Requests Generation are describes in the following paragraphs. Table 56. SPCON Register

7 SPR2 Serial Peripheral Rate 2

Bit with SPR1 and SPR0 define the clock rate.

6 SPEN

Cleared to disable the SPI interface. Set to enable the SPI interface. Cleared to enable SS in both Master and Slave modes. interrupt request is generated. Cleared to configure the SPI as a Slave. Set to configure the SPI as a Master. Cleared to have the SCK set to ’0’ in idle state. Set to have the SCK set to ’1’ in idle low.

Table 57 describes the SPSTA register and explains the use of every bit in the register. Table 57. SPSTA Register

1 SPR1

0 SPR0

7 SPIF

approved by a clearing sequence. Set by hardware to indicate that the data transfer has been completed. approved by a clearing sequence. Set by hardware to indicate that a collision has been detected.

5 SSERR

Set by hardware when SS is deasserted before the end of a received data. Cleared by disabling the SPI (clearing SPEN bit in SPCON). has been approved by a clearing sequence. Set by hardware to indicate that the SS pin is at inappropriate logic level. The value read from this bit is indeterminate. Do not set this bit.

76 AT89C51RB2/RC2

Table 58. SPDAT Register  Writing to the SPDAT will cause an overflow. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit.

that will periodically be executed within the time required to prevent a WDT reset. WDTPRG register description, Table 59. Table 59. WDTRST Register

78 AT89C51RB2/RC2

Table 60. WDTPRG Register pulled high. It is suggested that the WDT be reset during the interrupt service routine. it is better to reset the WDT just before entering power-down. periodically exit Idle, service the WDT, and re-enter Idle mode. The value read from this bit is undetermined. Do not try to set this bit.

 Hold ALE low as RST is deactivated. drive the circuit. Table 61 shows the status of the port pins during ONCE mode. Normal operation is restored when normal reset is applied. Table 61. External Pin Status during ONCE Mode

80 AT89C51RB2/RC2

dynamically divided by 2 using the X2 mode detailed in Section “X2 Feature”. the Section “DC Characteristics” of the AT89C51RB2/RC2 datasheet. Figure 32. Reset Circuitry and Power-On Reset 50 KΩ and different oscillator startup and VDD rise times.

Table 1. Minimum Reset Capacitor Value for a 50 kΩ Pull-down Resistor(1) discharged, leading to a bad reset sequence. periods is mode independent (X2 or X1). resistor must be added as shown Figure 33. Figure 33. Reset Circuitry for WDT Reset-out Usage

82 AT89C51RB2/RC2

4180C–8051–12/03 Reset Recommendation to Prevent Flash Corruption An example of bad initialization situation may occur in an instance where the bit ENBOOT in AUXR1 register is initialized from the hardware bit BLJB upon reset. Since 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 bit ENBOOT in SFRs may be set. If the value of Program 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 An instruction that sets PCON.0 indicates that it is the last instruction to be executed before going into Idle mode. In Idle mode, the internal clock signal is gated off to the CPU, but not to the interrupt, Timer, and Serial Port functions. The CPU status is pre- served in its entirety: the Stack Pointer, Program Counter, Program Status Word, Accumulator and all other registers maintain their data during idle. The port pins hold the logical states they had at the time Idle was activated. ALE and PSEN hold at logic high level. There are two ways to terminate the Idle mode. Activation of any enabled interrupt will cause PCON.0 to be cleared by hardware, terminating the Idle mode. The interrupt will be serviced, and following RETI the next instruction to be executed will be the one fol- lowing the instruction that put the device into idle. The flag bits GF0 and GF1 can be used to give an indication if an interrupt occurred dur- ing normal operation or during idle. For example, an instruction that activates idle can also set one or both flag bits. When idle is terminated by an interrupt, the interrupt ser- vice routine can examine the flag bits. The other way of terminating the Idle mode is with a hardware reset. Since the clock oscillator is still running, the hardware reset needs to be held active for only two machine cycles (24 oscillator periods) to complete the reset. Power-down Mode To save maximum power, a Power-down mode can be invoked by software (see Table 14, PCON register). In Power-down mode, the oscillator is stopped and the instruction that invoked Power- down mode is the last instruction executed. The internal RAM and SFRs retain their value until the Power-down mode is terminated. V CC can be lowered to save further power. Either a hardware reset or an external interrupt can cause an exit from Power- down. To properly terminate Power-down, the reset or external interrupt should not be executed before V CC is restored to its normal operating level and must be held active long enough for the oscillator to restart and stabilize. Only external interrupts INT0, INT1 and Keyboard Interrupts are useful to exit from Power-down. For that, interrupt must be enabled and configured as level or edge sensi- tive interrupt input. When Keyboard Interrupt occurs after a power down mode, 1024 clocks are necessary to exit to power down mode and enter in operating mode. Holding the pin low restarts the oscillator but bringing the pin high completes the exit as detailed in Figure 34. When both interrupts are enabled, the oscillator restarts as soon as one of the two inputs is held low and power down exit will be completed when the first input will be released. In this case, the higher priority interrupt service routine is exe- cuted. Once the interrupt is serviced, the next instruction to be executed after RETI will

Figure 34. Power-down Exit Waveform nal interrupt does no affect the SFRs. Table 62 shows the state of ports during idle and power-down modes. Port 0 can force a 0 level. A "one" will leave port floating. Table 62. State of Ports

84 AT89C51RB2/RC2

VCC is still applied to the device and could be generated by an exit from Power-down. software allowing the user to determine the type of reset. Table 63. PCON Register Set to select double baud rate in mode 1, 2 or 3. Cleared to select SM0 bit in SCON register. Set to select FE bit in SCON register. The value read from this bit is indeterminate. Do not set this bit. Cleared to recognize next reset type. Cleared by user for general-purpose usage. Set by user for general-purpose usage. Cleared by user for general-purpose usage. Set by user for general-purpose usage. Cleared by hardware when reset occurs. Set to enter power-down mode. Cleared by hardware when interrupt or reset occurs.

fetches. During ALE disabling, ALE pin is weakly pulled high. Table 64. AUXR Register Set to disactive the weak pull-up. The value read from this bit is indeterminate. Do not set this bit. The value read from this bit is indeterminate. Do not set this bit. Set to access external memory. (HSB), default setting, XRAM selected.

86 AT89C51RB2/RC2

4180C–8051–12/03 Flash EEPROM Memory The Flash memory increases EPROM and ROM functionality with in-circuit electrical erasure and programming. It contains 16K or 32K Bytes of program memory organized in 128 or 256 pages of 128 Bytes. This memory is both parallel and serial In-system Pro- grammable (ISP). ISP allows devices to alter their own program memory in the actual end product under software control. A default serial loader (bootloader) program allows ISP of the Flash. The programming does not require external dedicated programming voltage. The nec- essary high programming voltage is generated on-chip using the standard V CC pins of the microcontroller. Features  Flash EEPROM internal program memory.  Boot vector allows user provided Flash loader code to reside anywhere in the Flash memory space. This configuration provides flexibility to the user.  Default loader in Boot ROM allows programming via the serial port without the need of a user-provided loader.  Up to 64K Byte external program memory if the internal program memory is disabled (EA = 0).  Programming and erase voltage with standard 5V or 3V VCC supply.  Read/Programming/Erase: – Byte-wise read without wait state – Byte or page erase and programming (10 ms)  Typical programming time (32K Bytes) in 10 s  Parallel programming with 87C51 compatible hardware interface to programmer  Programmable security for the code in the Flash  10K write cycles  10 years data retention Flash Programming and Erasure The 16K or 32K Bytes Flash is programmed by Bytes or by pages of 128 Bytes. It is not necessary to erase a Byte or a page before programming. The programming of a Byte or a page includes a self erase before programming. There are three methods of programming the Flash memory:  First, the on-chip ISP bootloader may be invoked which will use low level routines to program the pages. The interface used for serial downloading of Flash is the UART.  Second, the Flash may be programmed or erased in the end-user application by calling low-level routines through a common entry point in the Boot ROM.  Third, the Flash may be programmed using the parallel method by using a conventional EPROM programmer. The parallel programming method used by these devices is similar to that used by EPROM 87C51 but it is not identical and the commercially available programmers need to have support for the AT89C51RB2/RC2. The bootloader and the Application Programming Interface (API) routines are located in the BOOT ROM.

which are handled by the parallel programmer. Table 65. Hardware Security Byte (HSB)  When this bit is programmed (‘1’ value) the boot address is 0000h. this bit is unprogrammed and the ISP is enabled. when programmed as shown in Table 66. Programmed (‘0’ value) to force X2 mode (6 clocks per instruction) after reset. Programmed to inhibit XRAM after reset. Unprogrammed, this bit to valid XRAM after reset (Default).

88 AT89C51RB2/RC2

Table 66. Program Lock Bits Note: U: unprogrammed or "one" level. P: programmed or "zero" level. These security bits protect the code access through the parallel programming interface. accessed by the ISP firmware. To load a new application with the parallel programmer, a chip erase must first be done. erence can always be read using Flash parallel programming modes.  BLJB: Programmed force ISP operation.  X2: Unprogrammed to force X1 mode (Standard Mode). hardware registers contents. These values are used by Atmel ISP.  Commands issued by the parallel memory programmer.  Commands issued by the ISP software.  Calls of API issued by the application software. Several software registers are described in Table 67. 1 U U U No program lock features enabled. disabled. ISP and software programming with API are still allowed.

Table 67. Default Values application to boot at 0000h. The content of the Software Security Byte (SSB) is described in Table 67 and Table 69. Table 68. Software Security Byte when programmed as shown in Table 69.

90 AT89C51RB2/RC2

Table 69. Program Lock Bits of the SSB Note: U: unprogrammed or "one" level. P: programmed or "zero" level. Figure 35. Flash Memory Possible Contents space is filled by internal Flash. When the EA pin is high, the processor fetches instructions from internal program Flash. 1 U U No program lock features enabled. 2 P U ISP programming of the Flash is disabled. 3 X P Same as 2, also verify through ISP programming interface is disabled.

routines can be called from the user application. Figure 36. Diagram Context Description

92 AT89C51RB2/RC2

Figure 37. Bootloader Functional Description frame (UART) into Flash memory acess (read, write, erase ...).

execute the end user’s code but can be manually forced into default ISP operation. be released at any time when reset input is low. during power-on (See Figure 38). Figure 38. Hardware conditions typical sequence during power-on. The on-chip bootloader boot process is shown in Figure 39. The Boot Loader Jump Bit forces the application execution. BLJB = 0 => Boot loader execution. BLJB = 1 => Application execution. The BLJB is a fuse bit in the Hardware Byte. That can be modified by hardware (programmer) or by software (API). The BLJB test is perform by hardware to prevent any program execution. SBV = FCh (default value) if no custumer bootloader in user Flash. The costumer bootloader is called by JMP [SBV]00h instruction.

94 AT89C51RB2/RC2

Figure 39. Bootloader process

Frame Description The Serial Protocol is based on the Intel Hex-type records. Table 70. Intel Hex Type Frame – Record Mark is the start of frame. This field must contain ’:’. the Record Type field of the record. – Data Program Record (see Section “ISP Commands Summary”). record types is described in Section “ISP Commands Summary”. field to and including the Checksum field, is zero.

96 AT89C51RB2/RC2

Software Security Bits (SSB)The SSB protects any Flash access from ISP command. The command "Program Software Security bit" can only write a higher priority level. From level 0, one can write level 1 or level 2. For this level it is impossible to write in the Flash memory, BSB and SBV. The Bootloader returns ’P’ on write access. From level 1, one can write only level 2. The level 2 forbids all read and write accesses to/from the Flash/EEPROM memory. The Bootloader returns ’L’ on read or write access. From level 2, one cannot read and write anything. Table 71. Software Security Byte Behavior

The Full Chip Erase does not affect the bootloader. Checksum Error When a checksum error is detected send ‘X’ followed with CR&LF. the bootloader waits for an autobaud sequence ( see section ‘autobaud performance’). to compute the baudrate (autobaud). Figure 40. Initialization

98 AT89C51RB2/RC2

AT89C51RB2/RC2 to establish the baud rate. Table 72 shows the autobaud capability. Table 72. Autobaud Performances

2400 OK OK OK OK OK OK OK OK OK OK

19200 OK - OK OK OK - - OK OK OK

2400 OK OK OK OK OK OK OK OK OK

4800 OK OK OK OK OK OK OK OK OK

9600 OK OK OK OK OK OK OK OK OK

100 AT89C51RB2/RC2

4180C–8051–12/03 Example HOST : 01 0010 00 55 9A BOOTLOADER: 01 0010 00 55 9A . CR LF Programming Data (write 55h at address 0010h in the Flash) HOST : 02 0000 03 05 01 F5 BOOTLOADER: 02 0000 03 05 01 F5. CR LF Programming Atmel function (write SSB to level 2) HOST : 03 0000 03 06 00 55 9F BOOTLOADER: 03 0000 03 06 00 55 9F . CR LF Writing Frame (write BSB to 55h)

4180C–8051–12/03 Blank Check Command Figure 43. Blank Check Flow

102 AT89C51RB2/RC2

4180C–8051–12/03 Display Data Figure 44. Display Flow Note: The maximum size of block is 400h. To read more than 400h Bytes, the Host must send a new command.

4180C–8051–12/03 Example Read Function This flow is similar for the following frames:  Reading Frame  EOF Frame/Atmel Frame (only reading Atmel Frame) Figure 45. Read Flow

104 AT89C51RB2/RC2

4180C–8051–12/03 ISP Commands Summary Table 73. ISP Commands Summary Command Command Name Data[0] Data[1] Command Effect 00h Program Data Program Nb Data Byte. Bootloader will accept up to 128 (80h) data Bytes. The data Bytes should be 128 Byte page Flash boundary. 03h Write Function 01h 00h Erase block0 (0000h-1FFFh) 20h Erase block1 (2000h-3FFFh) 40h Erase block2 (4000h-7FFFh) 80h Erase block3 (8000h- BFFFh) C0h Erase block4 (C000h- FFFFh) 03h 00h Hardware Reset 04h 00h Erase SBV & BSB 05h 00h Program SSB level 1 01h Program SSB level 2 06h 00h Program BSB (value to write in data[2]) 01h Program SBV (value to write in data[2]) 07h - Full Chip Erase (This command needs about 6 sec to be executed) 0Ah 02h Program Osc fuse (value to write in data[2]) 04h Program BLJB fuse (value to write in data[2]) 08h Program X2 fuse (value to write in data[2]) 04h Display Function Data[0:1] = start address Data [2:3] = end address Data[4] = 00h -> Display data Data[4] = 01h -> Blank check Display Data Note: The maximum number of data that can be read with a single command frame (difference between start and end address) is 1kbyte. Blank Check 05h Read Function 00h 00h Manufacturer ID 01h Device ID #1 02h Device ID #2 03h Device ID #3 07h 00h Read SSB 01h Read BSB 02h Read SBV 06h Read Extra Byte 0Bh 00h Read Hardware Byte 0Eh 00h Read Device Boot ID1 01h Read Device Boot ID2 0Fh 00h Read Bootloader Version

setting up the microcontroller’s registers before making a call to PGM_MTP at FFF0h. Results are returned in the registers. The API calls description and arguments are shown in Table 74. Table 74. API Call Summary

106 AT89C51RB2/RC2

Program up to 128 bytes in user Flash. is 128, valid values of DPL are 00h, or, 80h. Table 74. API Call Summary (Continued)

4180C–8051–12/03

Electrical Characteristics

Note: Stresses at or above those listed under “Absolute Maximum Ratings” may cause permanent damage to the device. This is a stress rating only and func- tional operation of the device at these or any other conditions above those indicated in the operational sections of this specification is not implied. Expo- sure to absolute maximum rating conditions may affect device reliability. Power dissipation value is based on the maximum allowable die temperature and the thermal resis- tance of the package. TA = -40°C to +85°C; VSS = 0V; VCC =2.7V to 5.5V and F = 0 to 40 MHz (both internal and external code execution) VCC =4.5V to 5.5V and F = 0 to 60 MHz (internal code execution only) Symbol Parameter Min Typ Max Unit Test Conditions VIL Input Low Voltage -0.5 0.2 V CC - 0.1 V V IH Input High Voltage except RST, XTAL1 0.2 V CC + 0.9 V CC + 0.5 V VIH1 (9) Input High Voltage RST, XTAL1 0.7 V CC VCC + 0.5 V V OL Output Low Voltage, ports 1, 2, 3, 4 (6) 0.3 0.45 1.0 V V V VCC = 4.5V to 5.5V I OL = 100 µA(4) IOL = 1.6 mA(4) IOL = 3.5 mA(4) 0.45 V VCC = 2.7V to 5.5V IOL = 0.8 mA(4) VOL1 Output Low Voltage, port 0, ALE, PSEN (6) 0.3 0.45 1.0 V V V VCC = 4.5V to 5.5V I OL = 200 µA(4) IOL = 3.2 mA(4) IOL = 7.0 mA(4) 0.45 V VCC = 2.7V to 5.5V IOL = 1.6 mA(4) V OH Output High Voltage, ports 1, 2, 3, 4 VCC - 0.3 VCC - 0.7 VCC - 1.5 V V V V CC = 5V ± 10% IOH = -10 µA IOH = -30 µA IOH = -60 µA

0.9 VCC V

VCC = 2.7V to 5.5V IOH = -10 µA

108 AT89C51RB2/RC2

4180C–8051–12/03 Notes: 1. Operating ICC is measured with all output pins disconnected; XTAL1 driven with TCLCH , TCHCL = 5 ns (see Figure 49.), VIL = VSS + 0.5V, VIH = VCC - 0.5V; XTAL2 N.C.; EA = RST = Port 0 = VCC . ICC would be slightly higher if a crystal oscillator used (see Figure 46). 2. Idle ICC is measured with all output pins disconnected; XTAL1 driven with TCLCH , TCHCL = 5 ns, VIL = VSS + 0.5V, VIH = VCC - 0.5V; XTAL2 N.C; Port 0 = VCC ; EA = RST = VSS (see Figure 47). 3. Power Down ICC is measured with all output pins disconnected; EA = VSS , PORT 0 = VCC ; XTAL2 NC.; RST = VSS (see Fig- ure 48). 4. Capacitance loading on Ports 0 and 2 may cause spurious noise pulses to be superimposed on the VOL s of ALE and Ports 1 and 3. The noise is due to external bus capacitance discharging into the Port 0 and Port 2 pins when these pins make 1 to 0 transitions during bus operation. In the worst cases (capacitive loading 100pF), the noise pulse on the ALE line may exceed 0.45V with maxi V OL peak 0.6V. A Schmitt Trigger use is not necessary. 5. Typical are based on a limited number of samples and are not guaranteed. The values listed are at room temperature and 5V. 6. Under steady state (non-transient) conditions, IOL must be externally limited as follows: Maximum IOL per port pin: 10 mA Maximum IOL per 8-bit port: Port 0: 26 mA Ports 1, 2 and 3: 15 mA Maximum total I OL for all output pins: 71 mA If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test conditions. 7. For other values, please contact your sales office. 8. Icc Flash Write operation current while an on-chip flash page write is on going. 9. Flash Retention is guaranteed with the same formula for VCC Min down to 0. VOH1 Output High Voltage, port 0, ALE, PSEN VCC - 0.3 VCC - 0.7 VCC - 1.5 V V V V CC = 5V ± 10% IOH = -200 µA IOH = -3.2 mA IOH = -7.0 mA VCC = 2.7V to 5.5V IOH = -10 µA R RST RST Pulldown Resistor 50 200 (5) 250 k Ω IIL Logical 0 Input Current ports 1, 2, 3, 4 and 5 -50 µAV IN = 0.45V ILI Input Leakage Current for P0 only ±10 µA 0.45V < V IN < VCC ITL Logical 1 to 0 Transition Current, ports 1, 2, 3, 4 -650 µAV IN = 2.0V C IO Capacitance of I/O Buffer 10 pF Fc = 3 MHz TA = 25°C IPD Power Down Current 100 150 µA4 . 5 V < VCC < 5.5V(3) ICCOP Power Supply Current on normal mode 0.4 x Frequency (MHz) + 5 mA V CC = 5.5V(1) ICCIDLE Power Supply Current on idle mode 0.3 x Frequency (MHz) + 5 mA V CC = 5.5V(1) ICCProg Power Supply Current during flash Write / Erase 0.4 x Frequency (MHz) + 20 mA V CC = 5.5V(8) TA = -40°C to +85°C; VSS = 0V; VCC =2.7V to 5.5V and F = 0 to 40 MHz (both internal and external code execution) VCC =4.5V to 5.5V and F = 0 to 60 MHz (internal code execution only) (Continued) Symbol Parameter Min Typ Max Unit Test Conditions

4180C–8051–12/03 DC Parameters for Low Voltage TA = 0°C to +70°C; VSS = 0V; VCC = 2.7V to 3.6V; F = 0to 40 MHz TA = -40°C to +85°C; VSS = 0V; VCC = 2.7V to 3.6V; F = 0 to 40 MHz Notes: 1. Operating ICC is measured with all output pins disconnected; XTAL1 driven with TCLCH , TCHCL = 5 ns (see Figure 49.), VIL = VSS + 0.5V, VIH = VCC - 0.5V; XTAL2 N.C.; EA = RST = Port 0 = VCC . ICC would be slightly higher if a crystal oscillator used (see Figure 46). 2. Idle ICC is measured with all output pins disconnected; XTAL1 driven with TCLCH , TCHCL = 5 ns, VIL = VSS + 0.5V, VIH = VCC - 0.5V; XTAL2 N.C; Port 0 = VCC ; EA = RST = VSS (see Figure 47). 3. Power Down ICC is measured with all output pins disconnected; EA = VSS , PORT 0 = VCC ; XTAL2 NC.; RST = VSS (see Fig- ure 48). 4. Capacitance loading on Ports 0 and 2 may cause spurious noise pulses to be superimposed on the VOL s of ALE and Ports 1 and 3. The noise is due to external bus capacitance discharging into the Port 0 and Port 2 pins when these pins make 1 to 0 transitions during bus operation. In the worst cases (capacitive loading 100pF), the noise pulse on the ALE line may exceed 0.45V with maxi V OL peak 0.6V. A Schmitt Trigger use is not necessary. 5. Typical are based on a limited number of samples and are not guaranteed. The values listed are at room temperature and 5V. 6. Under steady state (non-transient) conditions, IOL must be externally limited as follows: Maximum IOL per port pin: 10 mA Maximum IOL per 8-bit port: Port 0: 26 mA Ports 1, 2 and 3: 15 mA Maximum total I OL for all output pins: 71 mA Symbol Parameter Min Typ Max Unit Test Conditions VIL Input Low Voltage -0.5 0.2 V CC - 0.1 V VIH Input High Voltage except RST, XTAL1 0.2 V CC + 0.9 V CC + 0.5 V V IH1 Input High Voltage, RST, XTAL1 0.7 V CC VCC + 0.5 V VOL Output Low Voltage, ports 1, 2, 3, 4(6) 0.45 V I OL = 0.8 mA(4) V OL1 Output Low Voltage, port 0, ALE, PSEN (6) 0.45 V I OL = 1.6 mA(4) VOH Output High Voltage, ports 1, 2, 3, 4 0.9 V CC VI OH = -10 µA V OH1 Output High Voltage, port 0, ALE, PSEN 0.9 VCC VI OH = -40 µA IIL Logical 0 Input Current ports 1, 2, 3, 4 -50 µAV IN = 0.45 V ILI Input Leakage Current for P0 only ±10 µA 0.45V < V IN < VCC ITL Logical 1 to 0 Transition Current, ports 1, 2, 3, -650 µAV IN = 2.0V R RST RST Pulldown Resistor 50 200 (5) 250 k Ω C IO Capacitance of I/O Buffer 10 pF Fc = 3 MHz TA = 25°C IPD Power Down Current 10 (5) 50 µA VCC = 2.7V to 3.6V(3) ICCOP Power Supply Current on normal mode 0.4 x Frequency (MHz) + 5 mA V CC = 3.6 V(1) ICCIDLE Power Supply Current on idle mode 0.3 x Frequency (MHz) + 5 mA V CC = 3.6 V(2) ICCProg Power Supply Current during flash Write / Erase 0.4 x Frequency (MHz) + mA V CC = 5.5V(8)

110 AT89C51RB2/RC2

than the listed test conditions.

  1. For other values, please contact your sales office.
  2. Icc Flash Write operation current while an on-chip flash page write is on going.

Figure 46. ICC Test Condition, Active Mode Figure 47. ICC Test Condition, Idle Mode Figure 48. ICC Test Condition, Power-down Mode Figure 49. Clock Signal Waveform for ICC Tests in Active and Idle Modes All other pins are disconnected. All other pins are disconnected. All other pins are disconnected.

AVLL = Time for Address Valid to ALE Low. TLLPL = Time for ALE Low to PSEN Low. Table 75 Table 78, and Table 80 give the description of each AC symbols. Table 77, Table 79 and Table 81 give the AC parameterfor each range. in the correponding column (-M or -L) and use this value in the formula. LLIU for -M and 20 MHz, Standard clock. Table 75. Symbol Description

112 AT89C51RB2/RC2

Table 76. AC Parameters for a Fix Clock Table 77. AC Parameters for a Variable Clock

4180C–8051–12/03 External Program Memory Read Cycle External Data Memory Characteristics Table 78. Symbol Description TPLIV TPLAZ ALE PSEN PORT 0 PORT 2 A0-A7A0-A7 INSTR ININSTR IN INSTR IN ADDRESS OR SFR-P2 ADDRESS A8-A15ADDRESS A8-A15

12 TCLCL

TLLDV ALE to Valid Data In TAVDV Address to Valid Data In TLLWL ALE to WR or RD TAVWL Address to WR or RD TQVWX Data Valid to WR Transition TQVWH Data set-up to WR High TWHQX Data Hold After WR TRLAZ RD Low to Address Float TWHLH RD or WR High to ALE high

114 AT89C51RB2/RC2

Table 79. AC Parameters for a Fix Clock

4180C–8051–12/03 External Data Memory Write Cycle Symbol Type Standard Clock X2 Clock X Parameter for - M Range X Parameter for - L Range Units TRLRH Min 6 T - x 3 T - x 25 25 ns TWLWH Min 6 T - x 3 T - x 25 25 ns TRLDV Max 5 T - x 2.5 T - x 30 30 ns TRHDX Min x x 0 0 ns TRHDZ Max 2 T - x T - x 25 25 ns TLLDV Max 8 T - x 4T -x 45 45 ns TAVDV Max 9 T - x 4.5 T - x 65 65 ns TLLWL Min 3 T - x 1.5 T - x 30 30 ns TLLWL Max 3 T + x 1.5 T + x 30 30 ns TAVWL Min 4 T - x 2 T - x 30 30 ns TQVWX Min T - x 0.5 T - x 20 20 ns TQVWH Min 7 T - x 3.5 T - x 20 20 ns TWHQX Min T - x 0.5 T - x 15 15 ns TRLAZ Max x x 0 0 ns TWHLH Min T - x 0.5 T - x 20 20 ns TWHLH Max T + x 0.5 T + x 20 20 ns TQVWHTLLAX ALE PSEN WR PORT 0 PORT 2 A0-A7 DATA OUT ADDRESS OR SFR-P2 TAVWL TLLWL TQVWX ADDRESS A8-A15 OR SFR P2 TWHQX TWHLH TWLWH

116 AT89C51RB2/RC2

Table 80. Symbol Description Table 81. AC Parameters for a Fix Clock Table 82. AC Parameters for a Variable Clock

4180C–8051–12/03 Shift Register Timing Waveforms External Clock Drive Waveforms AC Testing Input/Output Waveforms AC inputs during testing are driven at VCC - 0.5 for a logic “1” and 0.45V for a logic “0”. Timing measurement are made at VIH min for a logic “1” and VIL max for a logic “0”. Float Waveforms For timing purposes as port pin is no longer floating when a 100 mV change from load voltage occurs and begins to float when a 100 mV change from the loaded VOH /VOL level occurs. IOL /IOH ≥ ± 20mA. Clock Waveforms Valid in normal clock mode. In X2 mode XTAL2 must be changed to XTAL2/2. INPUT DATA VALIDVALID VALID VALID 0123456 8 7 ALE CLOCK OUTPUT DATA WRITE to SBUF CLEAR RI TXLXL TQVXH TXHQX TXHDV TXHDX SET TI SET RI INSTRUCTION 01234567 VALID VALID VALID VALID VCC -0.5V 0.45V 0.7VCC 0.2VCC -0.1 TCHCL TCLCX TCLCL TCLCH TCHCX INPUT/OUTPUT 0.2 VCC + 0.9 0.2 VCC - 0.1 VCC -0.5V 0.45 V FLOAT VOH - 0.1 V VOL + 0.1 V VLOAD VLOAD + 0.1 V VLOAD - 0.1 V

118 AT89C51RB2/RC2

Figure 50. Internal Clock Signals

120 AT89C51RB2/RC2

4180C–8051–12/03

Ordering Information

Table 83. Possible Order Entries

16 KBytes

32 KBytes

4180C–8051–12/03

Package Information

122 AT89C51RB2/RC2

4180C–8051–12/03 VQFP44

4180C–8051–12/03 PLC44

124 AT89C51RB2/RC2

4180C–8051–12/03 Datasheet Change Log Changes from 4180A- 08/02 to 4180B-04/03 1. Changed the endurance of Flash to 100, 000 Write/Erase cycles. 2. Added note on Flash retention formula for VIH1, in Section “DC Parameters for Standard Voltage”, page 107. Changes from 4180B- 04/03 to 4180C-12/03 1. Max frequency update for 4.5 to 5.5V range up to 60 MHz (internal code execution).

i Table of Contents

4180C–8051–12/03

4180C–8051–12/03

Printed on recycled paper. Disclaimer: Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company’s standard warranty which is detailed in Atmel’s Terms and Conditions located on the Company’s web site. The Company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual property of Atmel are granted by the Company in connection with the sale of Atmel products, expressly or by implication. Atmel’s products are not authorized for use as critical components in life support devices or systems. Atmel Corporation Atmel Operations

2325 Orchard Parkway

San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Regional Headquarters Europe Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500 Asia Room 1219 Chinachem Golden Plaza

77 Mody Road Tsimshatsui

Tel: (852) 2721-9778 Fax: (852) 2722-1369 Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Memory San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 Microcontrollers San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602

44306 Nantes Cedex 3, France

13106 Rousset Cedex, France

1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743 RF/Automotive Theresienstrasse 2 Postfach 3535

74025 Heilbronn, Germany

1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom Avenue de Rochepleine BP 123

38521 Saint-Egreve Cedex, France

www.atmel.com/literature 4180C–8051–12/03 © Atmel Corporation 2003. All rights reserved. Atmel® and combinations thereof are the registered trademarks of Atmel Corporation or its subsidiaries. ONCE® is a registered trademark of Intel Corporation. Other terms and product names may be the trademarks of others.