US 20010023489 A1
An 8051 microprocessor core having an ability to operate via an external crystal oscillator or be switched to operate in a low power mode via an internal ring oscillator.
1. A microprocessor, comprising:
a four cycle 8051 microprocessor core;
a crystal oscillator circuit for providing timing signals to said four cycle 8051 microprocessor core;
a means for connecting an external crystal oscillator to said crystal oscillator circuit;
a switching circuit, connected to said an output of said crystal oscillator circuit, for providing a timing output to said microprocessor; and
a ring oscillator circuit, for providing timing signals to said four cycle 8051 microprocessor core, connected to said switching circuit, said switching circuit being for switching between said crystal oscillator and said ring oscillator to provide said timing output.
2. The microprocessor of
3. The microprocessor of
4. The microprocessor of
5. A microcontroller, comprising:
a microcontroller core circuitry utilizing at least a portion of standardized 8051 instruction set;
an internal ring oscillator for producing a first oscillation signal;
a means for connecting to an external crystal oscillator;
crystal oscillation circuitry for producing a second oscillation signal, said crystal oscillation circuitry adapted to connect to said means for connecting and external crystal oscillator;
a switching circuit, receiving said first oscillation signal and said second oscillation signal, for switching between said first oscillation signal and said second oscillation signal, said switching circuit providing an output,
a plurality of divide-by circuits, receiving said output from said switching circuit, each said divide-by circuit providing a divided output;
means for selecting one of said divided outputs and for providing said selected divided output as a timing signal to said microcontroller core circuitry.
6. The microcontroller of
7. The microcontroller of
8. The microcontroller of
9. The microcontroller of
10. The microcontroller of
11. The microcontroller of
12. An integrated circuit comprising:
a microcontroller circuit core;
an internal oscillator circuit that can provide a first timing signal to said microcontroller core;
an external crystal oscillator connection for receiving a second timing signal that can be provided to said microcontroller circuit;
a switching means, under software control, for switching between said first timing signal and said second timing signal and providing one of said first timing signal and said second timing signal to said microcontroller core.
13. The integrated circuit of
14. The integrated circuit of
15. The integrated circuit of
16. The integrated circuit of
 1. Field of the Invention
 The present invention relates to integrated circuit electronic devices, and, more particularly, to microcomputers, microcontrollers, and microprocessors.
 2. Background and Objects of the Present Invention
 The demand for ever higher performance from computers generally, and microprocessors and microcontrollers in particular, has led to various enhancements, including higher clock rates and simpler instruction sets. Consequently, the control and flexibility of clock speeds and rates for all circuits, especially microprocessor and microcontroller integrated circuits, has become critical, as designers attempt to design faster and faster microprocessors and microcontrollers. Previous control systems for oscillators were simplistic and/or relied primarily on prewired hardware circuits, which are not very flexible.
 Preferred system embodiments of the disclosed CMOS 8-bit Microcontroller System Specification have a number of unique features. Preferred embodiments provide the software control of either an external crystal oscillator or an on-chip internal ring oscillator, so that the user can choose whether to use external crystal oscillator or internal ring oscillator as the main source clock to the system. Preferred embodiments also provide for software control to disable/enable the external oscillator while running from the internal ring oscillator, so that the user has the ability to disable an external oscillator to reduce current consumption tremendously. Preferred embodiments also provide for software control to divide the main system clock (ring or external crystal oscillator) to provide lower operating current, so that the user can change system clock divide ratio to lower operating current. Preferred embodiments have software enable/disable of a “Switch-back” mode to allow interrupts or serial port activity to immediately switch high divide ratios (slow clocks) to a lower divide ratio (high speed clocks), which allows switching back immediately in the event of interrupts or serial port activity, it will process information as soon as possible without losing any kind of data. Preferred embodiments also enable the software selection of a DX2 clocking system in which the DX2 clock generator is software enabled/disabled and provides 2X frequency multiplication of the crystal oscillator for use as an optional system clock source, so that the frequency is doubled. Preferred embodiments also provide a frequency doubler with 50 percent duty cycle.
 Preferred embodiments have the following features and advantages: compatible with Intel 80C52 (in that preferred embodiments have pin orientation and instruction sets that are compatible with the Intel 8051, four 8-bit I/O ports, three 16-bit timer/counters, and 256 bytes scratchpad RAM); large on-chip memory (16K bytes EPROM (OTP) and 1K byte extra on-chip SRAM for MOVX); ROMSIZE Feature (selects effective on-chip ROM size from 0 to 16K; allows access to entire external memory map; dynamically adjustable by software and useful as boot block for external FLASH); High-Speed Architecture (4 clocks/machine cycle (Intel 8051 has 12); Runs DC to 33 MHz clock rates; Single-cycle instruction in 121 nS; Dual data pointer; Optional variable length MOVX to access fast/slow RAM/peripherals; Power Management Mode (Programmable clock source to save power; CPU runs from (crystal/64) or (crystal/1024); provides automatic hardware and software exit); EMI Reduction Mode disables ALE; two full-duplex hardware serial ports; High integration controller (power-fail reset; early-warning power-fail interrupt; programmable Watchdog timer); and 16 total interrupt sources with 6 external. Preferred embodiments have 40-pin PDIP, 44-pin PLCC, 44-pin PQFP, and 40-pin windowed CERDIP packages.
 Further features and advantages will become apparent from the following and more particular description of the various embodiments of the invention, as illustrated in the accompanying drawings, wherein:
FIGS. 1A, 1B, and 1C show diagrams of preferred pin-outs of preferred system embodiments;
FIG. 2 is a system block circuit diagram of a preferred microcontroller;
FIG. 3 is a flow chart showing the invoking and clearing of PMM;
FIG. 4 is a timing diagram of a ring oscillator exit from stop mode;
FIG. 5 is a functional/structural block circuit diagram showing at least a portion of the enhanced circuitry portion of an exemplary microprocessor.
FIG. 6 is a preferred circuit diagram for a ring oscillator control circuit;
FIG. 7 is a state diagram corresponding power management register; and
FIG. 8 is a state diagram corresponding power management register.
 Generally, at the outset, note that preferred exemplary embodiments of the microcontroller disclosed below provide one of the fastest 8051 compatible microcontrollers available. It features a redesigned processor core without wasted clock and memory cycles. FIG. 2 is a system block circuit diagram of a preferred embodiment of a microcontroller 100, which includes the enhanced circuitry portion 20 that provides for, among other things, the enhanced speed.
 Preferred embodiments of the present microcontroller execute every 8051 instruction between 1.3 and 3 times faster than an ordinary 8051 microprocessor for the same crystal speed. Typical applications will see a speed improvement of 2.5 times using the same code and the same crystal. Preferred embodiments offer a maximum crystal speed of 33 MHz, resulting in apparent execution speeds of 62.5 MHz (approximately 2.5X).
 Preferred embodiments are pin compatible with all three packages of the standard 8051 and include standard resources such as 3 timer/counters, serial port, and four 8-bit I/O ports. It features 16K bytes of EPROM with an extra 1K byte of data RAM. Both OTP and windowed packages are available. FIGS. 1A, 1B and 1C show diagrams of preferred pin-outs of preferred system embodiments. Corresponding pin descriptions may be found in Chart 1 below:
 Besides greater speed, preferred embodiments may comprise a second serial port, seven additional interrupts, a programmable watchdog timer, a brown-out monitor, and power-fail reset circuitry.
 Preferred embodiments are also fully static CMOS 8051 compatible microcontrollers designed for high performance. In most cases, preferred embodiments can be placed into an existing socket for the 80C51, 80C52, 87C51, or 87C52 to improve the overall circuit operation significantly. While remaining familiar to 8051 family users, the present exemplary microcontroller has many new features. In general, software written for existing 8051 based systems works without modification on preferred system embodiments. The exception to this is that critical timing functions may not operate correctly since the High Speed Micro performs its instructions much faster than the Standard 8051 for any given crystal selection. Preferred embodiments run the standard 8051 family instruction set and is pin compatible with DIP, PLCC or QFP packages.
 Preferred embodiments of the present microcontroller provide three 16-bit timer/counters, full-duplex serial port (2), 256 bytes of direct RAM plus 1K bytes of extra MOVX RAM. I/O ports have the same operation as a standard 8051 product. Timers default to a 12 clock per cycle cooperation to keep their timing compatible with original 8051 family systems. However, timers are individually programmable to run at the new 4 clocks per cycle if desired.
 Preferred embodiments provide several new hardware features implemented by new Special Function Registers (SFRs). A summary of these SFRs is provided below.
 Regarding the performance overview, preferred embodiments feature a high speed 8051 compatible core. Higher speed comes not just from increasing the clock frequency, but from a newer, more efficient design.
 This updated core does not have the dummy memory cycles that are present in a standard 8051. A standard 8051 generates machine cycles using the clock frequency divided by 12. In preferred embodiments, the same machine cycle takes 4 clocks. Thus the fastest instruction, 1 machine cycle, executes 3 times faster for the same crystal frequency. Note that these are for identical instructions. The majority of instructions on preferred embodiments of the present invention will see the full 3 to 1 speed improvement. Some instructions will get between 1.5 and 2.4 speed improvement. All instructions are faster than the original 8051.
 The numerical average of all opcodes gives approximately a 2.5 to 1 speed improvement. Improvement of individual programs will depend on the actual instructions used. Speed sensitive applications would make the most use of instructions that are 3 times faster. However, the sheer number of 3 to 1 improved opcodes makes dramatic speed improvements likely for any code. These architecture improvements and 0.8μ CMOS produce a peak instruction cycle in 121 nS (8.25 MIPs). The Dual Data Pointer feature also allows the user to eliminate wasted instructions when moving blocks of memory.
 Regarding the Instruction Set Summary, all instructions in preferred embodiments perform the same functions as their 8051 counterparts. Their effect on bits, flags, and other status functions is identical. However, the timing of each instruction is different. This applies both in absolute and relative number of clocks.
 Counter/timers default to run at the older 12 clocks per increment. In this way, timer-based events occur at the standard intervals with software executing at higher speed. Timers optionally can run at 4 clocks per increment to take advantage of faster processor operation.
 The relative time of two instructions might be different in the new architecture. For example, in the original architecture, the “MOVX A, @DPTR” instruction and the “MOV direct, direct” instruction used two machine cycles or 24 oscillator cycles. Therefore, they required the same amount of time. In preferred embodiments, the MOVX instruction takes as little as two machine cycles or 8 oscillator cycles but the “MOV direct, direct” uses three machine cycles or 12 oscillator cycles. While both are faster than their original counterparts, they now have different execution times. This is because preferred embodiments usually use one machine instruction cycle for each instruction byte.
 Regarding the Special function Registers (“SFRs”), SFRs control most special features of preferred embodiments. This allows preferred embodiments to have many new features but use the same instruction set as an 8051. When writing software to use a new feature, an equate statement defines the SFR to an assembler or compiler. This is the only change needed to access the new function. Preferred embodiments duplicate the SFRs contained in the standard 80C52. Table 2 shown below shows the register addresses and bit locations. Many are standard registers.
 Referring to FIG. 2 and regarding memory resources, like the 8051, preferred embodiments use three memory areas. These are program (ROM), data (RAM), and scratchpad RAM (registers). Preferred embodiments contain on-chip quantities of all three areas.
 The total memory configuration of preferred embodiments is 16K bytes of ROM 40, 1K byte of data SRAM 42 and 256 bytes of scratchpad or direct RAM 44. The 1K byte of data space SRAM 42 is read/write accessible and is memory mapped. This on-chip SRAM is reached by the MOVX instruction. It is not used for executable memory. The scratchpad area is 256 bytes of register mapped RAM 44 and is identical to the RAM found on preferred embodiments. There is no conflict or overlap among the 256 bytes and the 1K as they “use” or “are accessed by” different addressing modes and separate instructions.
 Regarding program memory access, on-chip ROM 40 begins at address 0000h and is contiguous through 3FFFh (16K). Exceeding the maximum address of on-chip ROM will cause preferred embodiments to access off-chip memory. However, the maximum on-chip decoded address is selected by software using the ROMSIZE feature. Software can cause preferred embodiments to behave like a device with less on-chip memory. This is beneficial when overlapping external memory, such as FLASH, is used.
 The maximum memory size is dynamically variable. Thus, a portion of memory can be removed from the memory map to access off-chip memory, then restored to access on-chip memory. In fact, all of the on-chip memory can be removed from the memory map allowing the full 64K memory space to be addressed from off-chip memory. ROM addresses that are larger than the selected maximum are automatically fetched from outside the part via Ports 0 & 2.
 ROMSIZE register is used to select the maximum on-chip decoded address of ROM. Bits RS2, RS1, RS0 have the following effect.
 The reset default condition is a maximum on-chip ROM address of 16K bytes. Thus, no action is required if this feature is not used. Thus when accessing external program memory, the first 16K bytes would be inaccessible. To select a smaller effective ROM size, software must alter bits RS2-RS0. Altering these bits requires a Timed Access procedure as explained below.
 The ROMSIZE register should be manipulated from a safe area in the program memory map. This is a program memory address that will not be affected by the change. For example, one should not select a maximum ROM size of 4K from an internal ROM address of 5K. This would cause a current address to switch from internal to external and cause invalid operation. Similarly, one should not instantly switch from external to internal memory. For example, do not select a maximum ROM address of 16K from an external ROM address of 12K.
 Off-chip memory is accessed using the multiplexed address/data bus on P0 and the MSB address of P2. While serving as a memory bus, these pins are not I/O ports. This convention follows the standard 8051 method of expanding on-chip memory. Off-chip ROM access also occurs if an EA\ pin is a logic 0. The EA\ overrides all bit settings. The PSEN\ signal will go active (low) to serve as a chip enable or output enable when Ports 0 & 2 fetch from external ROM.
 Regarding data memory access, unlike many 8051 derivatives, preferred embodiments contain on-chip data memory. It also contains the standard 256 bytes of RAM accessed by direct instructions. These areas are separate. The MOVX instructions access the on-chip data memory. Although physically on-chip, software treats this area as though it was located off-chip. The 1K byte of SRAM is between address 000h and 03FFh.
 Access to the on-chip data RAM 42 is optional under software control. When enabled by software, the data SRAM is between 000h and 03FFh. Any MOVX instruction that uses this area will go to the on-chip RAM while enabled. MOVX addresses greater than 1K automatically go to external memory through Ports 0 & 2.
 When disabled, the 1K SRAM memory area 42 is transparent to the system memory map. Any MOVX directed to the space between 0000h and FFFFh goes to the expanded bus on Ports 0 & 2 (46, 48). This also is the default condition. This default allows preferred embodiments to drop into an existing system that uses these addresses for other hardware and still have full compatibility.
 The on-chip data area is software selectable using two bits in the Power Management Register 50 at location C4h. This selection is dynamically programmable. Thus access to the on-chip area becomes transparent to reach off-chip devices at the same addresses. The control bits are DME1 (PMR.1) and DME0 (PMR.0). They have the following operation:
 Regarding the stretch memory cycle, preferred embodiments allow software to adjust the speed of off-chip data memory access. The micro is capable of performing the MOVX in as little as two instruction cycles. The on-chip SRAM 42 uses this speed and any MOVX instruction directed internally uses two cycles. However, the time can be stretched for interface to external devices. This allows access to both fast memory and slow memory or peripherals with no glue logic. Even in high-speed systems, it may not be necessary or desirable to perform off-chip data memory access at full speed. In addition, there is a variety of memory mapped peripherals such as LCDs or UARTs that are slow.
 The Stretch MOVX is controlled by the Clock Control Register at SFR location 8Eh as described below. It allows the user to select a Stretch value between zero and seven. A stretch of zero will result in a two machine cycle MOVX. A Stretch of seven will result in a MOVX of nine machine cycles. Software can dynamically change this value depending on the particular memory or peripheral.
 On reset, the Stretch value will default to a one resulting in a three cycle MOVX for an external access. Therefore, off-chip RAM access is not at full speed. This is a convenience to existing designs that may not have fast RAM in place. Internal SRAM access is always at full speed regardless of the Stretch setting. When desiring maximum speed, software should select a Stretch value of zero. When using very slow RAM or peripherals, select a larger Stretch value. Note that this affects data memory only and the only way to slow program memory (ROM) access is to use a slower crystal.
 Using a Stretch value between one and seven causes the microcontroller to Stretch and read/write strobe and all related timing. Also, setup and hold times are increased by 1 clock when using a Stretch greater than 0. This results in a longer read/write strobe and relaxed interface timing, allowing more time for memory/peripherals to respond. The timing of the variable speed MOVX is in the Electrical Specifications. Table 4 below shows the resulting strobe widths for each Stretch value. The memory Stretch uses the Clock Control Special Function Register at SFR location 8Eh. The Stretch value is selected using bits CKCON.2-0. In the table, these bits are referred to as M2 through M0. The first Stretch (default) allows the use of common 120 nS RAMs without dramatically lengthening the memory access. See Table 4.
 Regarding the dual data pointers, the timing of block moves of data memory is faster using Dual Data Pointer (DPTR) 52. The standard 8051 DPTR is a 16-bit value that is used to address off-chip data RAM or peripherals. In preferred embodiments, this data pointer is called DPTR0, located at SFR addresses 82h and 83h. These are the original locations. Using DPTR0 requires no modification of standard code. The new DPTR at SFR 84h and 85h is called DPTR1. The DPTR Select bit (DPS) chooses the active pointer. Its location is the 1sb of the SFR location 86h. No other bits in register 86h have any effect and are 0. The user switches between data pointers by toggling the 1sb of register 86h. The increment (INC) instruction is the fastest way to accomplish this. All DPTR-related instructions use the currently selected DPTR for any activity. Therefore it takes only one instruction to switch from a source to a destination address. Using the Dual Data Pointer saves code from needing to save source and destination addresses when doing a block move. The software simply switches between DPTR0 and DPTR1 52 once software loads them. The relevant register locations are as follows:
 Regarding power management circuitry, along with the standard IDLE and power down (STOP) modes of the standard preferred embodiments, preferred embodiments provided a new Power Management Mode. This mode allows the processor to continue functioning, yet to save power compared with full operation. Preferred embodiments also feature several enhancements to STOP mode that make it more useful.
 Regarding the power management mode (PMM), power management mode offers a complete scheme of reduced internal clock speeds that allow the CPU to run software and use substantially less power. During default operation, preferred embodiments use 4 clocks per machine cycle. Thus the instruction cycle rate is Clock/4. At 33 MHz crystal speed, the instruction cycle speed is 8.25 MHz (33/4). In PMM, the microcontroller continues to operate but uses an internally divided version of the clock source. This creates a lower power state without external components. It offers a choice of two reduced instruction cycle speeds (and two clock sources—discussed below). The speeds are (Clock \ 64) and (Clock \ 1024).
 PMM is preferably invoked via software. Table 5 illustrates the instruction cycle rate in PMM for several common crystal frequencies. Since power consumption is a direct function of operating speed, PMM1 eliminates most of the power consumption while still allowing a reasonable speed of processing. PMM2 runs very slowly and provides the lowest power consumption without stopping the CPU. This is illustrated in Table 6.
 Note that PMM provides a lower power condition than IDLE mode. This is because in IDLE, all clocked functions such as timers run at a rate of crystal divided by 4. Since wake-up from PMM is as fast as or faster than from IDLE and PMM allows the CPU to operate (even if doing NOPs), there is little reason to use IDLE in new designs.
 Regarding Crystalless PMM, a major component of power consumption in PMM is the crystal amplifier circuit. Preferred embodiments allow the user to switch CPU operation to an internal ring oscillator and turn off the crystal amplifier. The CPU then has a clock source of approximately 4 MHz, divided by either 4, 64, or 1024. The ring is not accurate so software cannot perform precision timing. However, this mode allows an additional saving of between 0.5 and 6.0 mA depending on the actual crystal frequency. While this saving is of little use when running at 4 clocks per instruction cycle, it makes a major contribution when running in PMM1 or PMM2.
 Regarding PMM operation, software invokes the PMM by setting the appropriate bits in the SFR area. The basic choices are divider speed and clock source. There are three speeds (4, 64, 1024) and two clock sources (crystal, ring). Both the decisions and the controls are separate. Software will typically select the clock speed first. Then, it will perform the switch to ring operation if desired. Lastly, software can disable the crystal amplifier if desired.
 There are two ways of exiting PMM. Software can remove the condition by reversing the procedure that invoked PMM, or hardware can (optionally) remove it. To resume operation at a divide by 4 rate under software control, simply select 4 clocks per cycle, then crystal based operation if relevant. When disabling the crystal as the timebase in favor of the ring oscillator, there are timing restrictions associated with restarting the crystal operation. Details are described below.
 There are three registers containing bits that are concerned with PMM functions. They are Power Management Register 50 (PMR; C4h), Status (STAT; C5h), and External Interrupt Flag (EXIF; 91h).
 Regarding Clock Divider, software can select the instruction cycle rate by selecting bits CD1 (PMR.7) and CD0 (PMR.6) as follows:
 The selection of instruction cycle rate will take effect after a delay of one machine cycle. Note that the clock divider choice applies to all functions including timers. Since baud rates are altered, it will be difficult to conduct serial communication while in PMM. There are minor restrictions on accessing the clock selection bits. The processor must be running in a 4 clock state to select either 64 (PMM1) or 1024 (PMM2) clocks. This means software cannot go directly from PMM1 to PMM2 or vice versa. It must return to a 4 clock rate first.
 Regarding Switchback, to return to a 4 clock rate from PMM, software can simply select the CD1 and CD0 clock control bits to the 4 clocks per cycle state. However, preferred embodiments provide several hardware alternatives for automatic Switchback. If Switchback is enabled, then preferred embodiments will automatically return to a 4 clock per cycle speed when an interrupt occurs from an enabled, valid external interrupt source. A Switchback will also occur when a UART detects the beginning of a serial start bit if the serial receiver is enabled. Note the beginning of a start bit does not generate an interrupt; this occurs on reception of a complete serial word. The automatic Switchback on detection of a start bit allows hardware to correct baud rates in time for a proper serial reception.
 Switchback is enabled by setting the SWB bit (PMR.5) to a 1 in software. For an external interrupt, Switchback will occur only if the interrupt source could really generate the interrupt. For example, if INTO\ is enabled but has a low priority setting, then Switchback will not occur on INTO\ if the CPU is servicing a high priority Interrupt. A serial Switchback will occur only if the serial receiver function is enabled (REN=1).
 When SWB=1, the user software will not be able to select a reduced clock mode if the UART is active. For example, the processor will prohibit the PMM by not allowing a write to CD1 and CD0 if a serial start bit arrived and SWB=1. Since the reception of a serial start bit or an interrupt priority lockout is normally undetectable by software in an 8051, the Status register features several new flags that are useful. These are described below.
 Regarding the Status, information in the Status register assists decisions about switching into PMM. This register contains information about the level of active interrupts and the activity on the serial ports.
 Preferred embodiments support three levels of Interrupt priority. These levels are Power-fail, High, and Low. Bits STAT.7-5 indicate the service status of each level. If PIP (Power-fail Interrupt Priority; STAT.7) is a 1, then the processor is servicing this level. If either HIP (High Interrupt Priority; STAT. 6) or LIP (Low Interrupt Priority; STAT.5) is high, then the corresponding level is in service.
 Referring now to FIG. 3, software should not depend on a lower priority level interrupt source to remove PMM (Switchback) when the higher level is in service. Check the current priority service level before entering PMM. If the current service level locks out a desired Switchback source, then it would be advisable to wait until this condition clears before entering PMM.
 Alternately, software can prevent an undesired exit from PMM by entering a low priority interrupt service level before entering PMM. This will prevent other low priority interrupts from causing a Switchback. See steps S10 and S12.
 Status also contains information about the state of the serial ports. Serial Port Zero Receive Activity (SPRA0; STAT.0) indicates a serial word is being received on Serial Port 0 when this bit is set to a 1. Serial Port Zero Transmit Activity (SPTA0; STAT.1) indicates that the serial port is still shifting out a serial transmission. STAT.2 and STAT.3 provide the same information for Serial Port 1, respectively. While one of these bits is set, hardware prohibits software from entering PMM (CD1 and CD0 are write protected) since this would corrupt the corresponding serial transmissions. Thus, in steps S14 and S16, the status is checked and impending activity is cleared.
 Regarding the Crystal/Ring Operation, preferred embodiments allow software to choose the clock source as an independent selection from the machine cycle rate. The user can select crystal-based or ring oscillator-based operation under software control. FIG. 2 indicates connections for a crystal and the oscillator/ring oscillator block circuitry 54. Power-on reset default is the crystal (or external clock) source. The ring may save power depending on the actual crystal speed. To save still more power, software can then disable the crystal amplifier. This process requires two steps. Reversing the process also requires two steps. In FIG. 3 at step S18 PMM is invoked and the clock speed is selected.
 Referring to steps S20 through S30, the XT/RG bit (EXIF.3) selects the crystal or ring as the clock source. Setting XT/RG=1 selects the crystal. Setting XT/RG=0 selects the ring, step S24. The RGMD (EXIF.2) bit serves as a status bit by indicating the active clock source. RGMD=0 indicates the CPU is running from the crystal. RGMD=1 indicates it is running from the ring. When operating from the ring, disable the crystal amplifier by setting the XTOFF bit (PMR.3) to a 1. This can only be done when XT/RG=0.
 When changing the clock source, the selection will take effect after a one machine cycle delay. This applies to changes from crystal to ring and vice versa. However, this assumes that the crystal amplifier is running. In most cases, when the ring is active, software previously disabled the crystal to save power. If ring operation is being used and the system must switch to crystal operation, the crystal must first be enabled. Set the XTOFF bit to a 0. At this time, the crystal oscillation will begin. Preferred embodiments then provide a warm-up delay to make certain that the frequency is stable. Hardware will set the XTUP bit (STAT.4) to a 1 when the crystal is ready for use. Then software should write XT/RG to a 1 to begin operating from the crystal. Hardware prevents writing XT/RG to a 1 before XTUP=1. The delay between XTOFF=0 and XTUP=1 will be 65,536 crystal clocks. FIG. 3 flow charts also indicate an exemplary exit from PMM.
 Switchback has no effect on the clock source. If software selects a reduced clock divider and enables the ring, a Switchback will only restore the divider speed. The ring will remain as the timebase until altered by software. If there is serial activity, Switchback usually occurs with enough time to create proper baud rates. This is not true if the crystal is off and the CPU is running from the ring. If sending a serial character that wakes the system from crystaless PMM, then it should be a dummy character of no importance with a subsequent delay for crystal startup.
 Regarding the IDLE mode, setting the 1sb of a Power Control register (PCON; 87h) invokes the IDLE mode. IDLE will leave internal clocks, serial ports and timers running. Power consumption drops because the memory is not being accessed. Since clocks are running, the IDLE power consumption is a function of crystal frequency. It should be approximately ½ of the power-on-power at a given frequency. The CPU can exit the IDLE state with any interrupt or a reset. IDLE is available for backward software compatibility. The system can now reduce power consumption to below IDLE levels by using PMM.
 Regarding STOP mode enhancements, setting bit 1 of the Power Control register (PCON; 87h) invokes the STOP mode. STOP mode is the lowest power state since it turns off all internal clocking. The Icc of a standard STOP mode is approximately 1 uA. The exemplary CPU will exit STOP mode by an external interrupt or a reset condition. Internally generated interrupts (timer, serial port, watchdog) are not useful since they require clocking activity.
 Preferred embodiments provide two enhancements to the STOP mode. As documented below, preferred embodiments provide a band-gap reference to determine Power-fail Interrupt and Reset thresholds. The default state is that the band-gap reference is off while in STOP mode. This allows the extremely low power state mentioned above. A user can optionally choose to have the band-gap enabled during STOP mode. With the band-gap reference enabled, PFI and Power-fail reset are functional and are valid means for leaving STOP mode. This allows software to detect and compensate for a brown-out or power supply sag, even when in STOP mode.
 In STOP mode with the band-gap enabled, Icc will be approximately 100 uA computed with 1 uA with the band-gap off. If a user does not require a Power-fail Reset or Interrupt while in STOP mode, the band-gap can remain disabled. Only the most power sensitive applications should turn off the band-gap, as this results in an uncontrolled power down condition.
 The second feature allows an additional power savings option while also making STOP easier to use. This is the ability to start instantly when exiting STOP mode. It is the internal ring oscillator that provides this feature. This ring can be a clock source when exiting STOP mode in response to an interrupt. The benefit of the ring oscillator is as follows.
 Entering STOP mode turns off the crystal oscillator and all internal clocks to save power. This requires that the oscillator be restarted when exiting STOP mode. Actual start-up time is crystal dependent, but is normally at least 4 mS. A common recommendation is 10 mS. In an application that will wake-up, perform a short operation, then return to sleep, the crystal start-up can be longer than the real transaction. However, the ring oscillator will start instantly. Running from the ring, the user can perform a single operation and return to sleep before the crystal has even started. If a user selects the ring to provide the start-up clock and the processor remains running, hardware will automatically switch to the crystal once a power-on reset interval (65536 clocks) has expired. Hardware uses this value to assure proper crystal start even though power is not being cycled.
 The ring oscillator runs at approximately 4 MHz but will not be a precise value. Real-time precision operations (including serial communication) should not be conducted during a ring period. FIG. 4 provides a timing diagram comparing the time to initiate STOP mode with a crystal oscillator start-up 400 v. a ring oscillator start-up 402. Note that in the time it takes for the crystal oscillator to become stable in chart 400, the ring oscillator could have started performed the necessary timing clocks and stopped 402. The default state is to exit STOP mode without using the ring oscillator.
 The RGSL—Ring Select bit at EXIF.1 (EXIF; 91h) controls this ring oscillator select function. When RGSL=1, the CPU will use the ring oscillator to exit STOP mode quickly. As mentioned above, the processor will automatically switch from the ring to the crystal after a delay of 65,536 crystal clocks. For a 3.57 MHz crystal, this is approximately 18 mS. The processor sets a flag called RGMD—Ring Mode, located at EXIF.2, that tells software that the ring is being used. The bit will be a logic 1 when the ring is in use. Attempt no serial communication or precision timing while this bit is set, since the operating frequency is not precise.
 Preferred embodiments of the exemplary microcontroller provide several of the most commonly needed peripheral functions in microcomputer-based systems. These new functions include a second serial port, Power-fail Reset, Power-fail Interrupt, and a programmable watchdog Timer. These are described below.
 Regarding serial ports, preferred exemplary microcontrollers provide a serial port (UART). In addition, a preferred microcontroller includes a second hardware serial port. This second port optionally uses pins P1.2 (RXD1) and P1.3 (TXD1). It has control functions that are included in new SFR locations.
 Both ports can operate simultaneously, but can operate at different baud rates or in different modes. The second serial port has similar control registers (SCON1 at C0h, SBUF1 at C1h) like the first port. The second serial port can only use Timer 1 for timer generated baud rates.
 Regarding timer rate control, there is one important difference between preferred embodiments and a standard 8051 regarding timers. The standard 8051 uses 12 clocks per cycle for timers as well as for machine cycles. The preferred embodiment's architecture normally uses 4 clocks per machine cycle. However, in the area of timers and serial ports, a preferred embodiment will default to 12 clocks per cycle on reset. This allows existing code with real-time dependencies, such as baud rates, to operate properly.
 If an application needs higher speed timers or serial baud rates, the user can select individual timers to run at the 4 clocks per cycle rate. The Clock Control register (CKCON; 8Eh) controls these timer speeds. When the relevant CKCON bit is a logic 1, a preferred embodiment uses 4 clocks per cycle to generate timer speeds. When the bit is a 0, a preferred embodiment uses 12 clocks for timer speeds. The reset condition is a 0. CKCON.5 selects the speed of Timer 2. CKCON.4 selects Timer 1 and CKCON.3 selects Timer 0. Note that unless a user desires very fast timing, it is unnecessary to alter these bits. Note that the timer controls are independent.
 Regarding power-fail reset, a preferred embodiment uses a precision band-gap voltage reference to decide if VCC is out of tolerance. While powering up, an Internal monitor circuit (56, FIG. 2) maintains a reset state until VCC rises above the VRST level. Once above this level, the monitor enables the crystal oscillator and counts 65,536 clocks. It then exits the reset state. This power-on reset (POR) interval allows time for the oscillator to stabilize.
 A system needs no external components to generate a power-related reset. Anytime VCC drops below VRST, as in power failure or a power drop, the monitor 56 will generate and hold a reset. It occurs automatically, needing no action from the software.
 Regarding the power-fail interrupt function, the voltage reference that sets a precise reset threshold also generates an optional early warning Power-fail Interrupt (PFI). When enabled by software, the processor will vector to RAM address 0033h if VCC drops below VPFW. PFI has the highest priority. The PFI enable is in the Watchdog Control SFR (WDCON-D8h) (60 FIG. 2). Setting WDCON.5 to a logic 1 will enable the PFI. Application software can also read the PFI flag at WDCON.4. A PFI condition sets this bit to a 1. The flag is independent of the interrupt enable and software must manually clear it.
 Regarding the Watchdog timer 58, to prevent software from losing control, preferred embodiments include a programmable Watchdog Timer 58. The Watchdog timer 58 is a free running timer that sets a flag if allowed to reach a preselected time-out. It can be (re)started by software.
 A typical application is to select the flag as a reset source. When the Watchdog times out, it sets its flag which generates a reset. Software must restart the timer before it reaches its time-out or the processor is reset.
 Software can select one of four time-out values. Then, it restarts the timer and enables the reset function. After enabling the reset function, software must then restart the timer before its expiration or hardware will reset the CPU. Both the Watchdog Reset Enable and the Watchdog Restart control bits are protected by a “Timed Access” circuit 62. This prevents errant software from accidentally clearing the the PFI flag at WDCON.4. A PFI condition sets this bit to a 1. The flag is independent of the interrupt enable and software must manually clear it.
 Regarding the Watchdog timer 58, to prevent software from losing control, preferred embodiments include a programmable Watchdog Timer 58. The Watchdog timer 58 is a free running timer that sets a flag if allowed to reach a preselected time-out. It can be (re)started by software.
 A typical application is to select the flag as a reset source. When the Watchdog times out, it sets its flag which generates a reset. Software must restart the timer before it reaches its time-out or the processor is reset.
 Software can select one of four time-out values. Then, it restarts the timer and enables the reset function. After enabling the reset function, software must then restart the timer before its expiration or hardware will reset the CPU. Both the Watchdog Reset Enable and the Watchdog Restart control bits are protected by a “Timed Access” circuit 62. This prevents errant software from accidentally clearing the Watchdog timer 58. Time-out values are precise since they are a function of the crystal frequency as shown below in TABLE 8. The time periods at 33 MHz also are shown.
 The Watchdog timer 58 also provides a useful option for systems that do not require a reset circuit. The Watchdog timer 58 will set an interrupt flag 512 clocks before setting the reset flag. Software can optionally enable this interrupt source. The interrupt is independent of the reset. A common use of the interrupt is during debug, to show developers where the Watchdog times out. This indicates where the Watchdog must be restarted by software. The interrupt also can serve as a convenient time-base generator or can wake-up the processor.
 The Watchdog function is controlled by the Clock Control (CKCON-8Eh), Watchdog Control (WDCON-D8h), and Extended Interrupt Enable (EIE-E8h) SFRs. CKCON.7 and CKCON.6 are WD1 and WD0 respectively and they select the Watchdog time-out period as shown in TABLE 8.
 As shown above, the Watchdog Timer 58 uses the crystal frequency as a timebase. A user selects one of four counter values to determine the time-out. These clock counter lengths are 217=131, 072 clocks; 220=1,048,576 clocks; 223=8,388,606 clocks; and 226=67,108,864 clocks. The times shown in TABLE 8 above are for a 33 MHz crystal frequency. Once the counter chain has completed a full interrupt count, hardware will set an interrupt flag. Regardless of whether the user enables this interrupt, there are then 512 clocks left until the reset flag is set. Software can enable the interrupt and reset individually. Note that the Watchdog timer 58 is a free running timer and does not require an enable. There are five control bits in special function registers that affect the Watchdog Timer and two status flags that report to the user. One interrupt flag is set at timer termination when there are 512 clocks remaining until the reset flag is set. Another flag is set when the timer has completely timed out. This flag is normally associated with a CPU reset and allows software to determine the reset source. One control bit is the enable for the Watchdog timer reset function. A second control bit is for software used to restart the Watchdog Timer 58. Setting this second bit restarts the timer for another full interval. Application software must set this bit before the time-out. Both of these bits are protected by Timed Access 62. Two more bits select the time-out. Finally, a fifth bit enables the Watchdog Interrupt.
 Regarding interrupts, preferred embodiments provide 13 interrupt sources with three priority levels. The Power-fail Interrupt (PFI) has the highest priority. Software can assign high or low priority to other sources. All interrupts that are new to the 8051 family, except for the PFI, have a lower natural priority than the standard 8051 interrupts.
 Regarding timed access functions 62 (FIG. 2), it is useful to protect certain SFR bits from an accidental write operation. The Timed Access procedure stops an errant CPU from accidentally changing these bits. It requires that the following instructions precede a write of a protected bit.
MOV 0C7h, #0AAh
MOV 0C7h, #55h
 In an exemplary embodiment, writing an AAh then a 55h to the Timed Access register (location C7h) opens a 2 cycle window for write access. The window allows software to modify a protected bit(s). If these instructions do not immediately precede the write operation, then the write will not take effect. The protected bits are:
 Regarding EPROM programming, preferred embodiments follow standards for a 16K byte EPROM version in the 8051 family. It is available in a UV erasable, ceramic windowed package and in plastic packages for one-time user-programmable versions. The part has unique signature information so EPROM programmers can support its specific EPROM options.
 The Signature bytes identify the product and programming revision to EPROM programmers. This information is at programming addresses 30h, 31h, and 60h. This information is as follows:
 Referring again to FIG. 2 , FIG. 5 is a functional/structural block circuit diagram showing a portion of the enhanced circuitry 20 in FIG. 2 in greater detail.
 The internal ring oscillator operates as follows. A register bit called “XTRG” located in “IN_RING” is generally selected as the control bit. If “XTRG” is set to be logic 1, an external crystal 70 of FIG. 5 will be the source to the system. Otherwise, if “XTRG” is set to be logic 0, internal ring oscillator 72 will be the source to the system. The default state is logic 1. That is, the system will use external crystal oscillator 70 as the main source clock when the system first powers up. In order to use internal ring oscillator 72, however, the user has to specify the address of “IN_RING” register, which is 91 HEX in preferred embodiments and place it onto the address bus 64 (FIG. 2), followed by the data the user wishes to write to the register and placed onto data bus 66. If the address on the DA corresponding to “IN_RING” register is present, an enable signal will be issued. Therefore, if a “write” operation is encountered, the data on data bus 66 will be written to “IN RING” on C4 clock. If a “read” operation is encountered, the data in “IN-RING” will be driven onto data bus 66.
 Bit 3 is also of interest. If the user has decided to use internal ring oscillator as the source clock, the user would have to set “XTRG” to logic 0. The switching from external crystal oscillator 70 to the internal ring oscillator 72 will not occur until one machine cycle later, which ensures the switching function is glitch free and occurs at the beginning of a machine cycle.
 “XTRG” bit is not affected by reset, but there are some conditions associated with this control bit. If the processor 10 is running at “divide by 2” (via “divide by 2” module 74 in FIG. 5) of external crystal 70, a signal called “ENDB2Z” will become active. This condition prevents the user from using the internal ring oscillator 72 as the main source clock. If the processor 10 has decided to disable external crystal 70, a signal called “IRG_ONZ” will become active. This signal prevents “XTRG” from changing from a logic 0 to logic 1 unless proper warm up time for the external crystal oscillator 70, 76 has elapsed.
 In order to guarantee glitch free switching function of various divide ratio clocks, a state machine is introduced to govern the function. A signal called “XTAL” is the actual clock source going to system clock generator. There are four system clocks: C1, C2, C3, and C4 clocks (see FIG. 5), all of which are non-overlapping clocks, so that no two or more system clocks will be active at any given time. There is some delay introduced between the rising edge of “XTAL” and the rising edge of system clocks. Consequently, it is not a good idea to use system clocks as the sampling clocks.
 Control bits, CD1 and CD0, are updated on every C1 cycle of each machine cycle. The control bits, CD1 and CD0 are used to select the output of one of the divide by circuits (÷2, ÷4, ÷64, ÷1024) (elements 74, 80, 82, 84, respectively) via the glitch free MUX 78. If a reset signal is received by the 1 of 4 select circuitry, the check is set to the default state. Another situation is the stop mode operation. When the processor 10 is to enter stop mode, a “HALT” signal will become active and trigger similar operations as a reset.
 Regarding the software control of either an external crystal oscillator or an on-chip internal ring oscillator, preferred embodiments, as described and shown in the FIGURES and described above, the user can choose whether to use external crystal oscillator or internal ring oscillator as the main source clock to the system. More specifically, preferred embodiments have a plurality (e.g., four) of machine system clocks in one machine cycle: C1, C2, C3, C4. The internal address in preferred embodiments is updated on every C4 cycle. The “write” to the register occurs on C4 of last machine cycle of the “write” instruction. The “read” from the register occurs on C2 of last machine cycle of the “read” instruction. There are two data buses associated with the “write” and “read” operations: address bus 64 and data bus 66, both of them consist of eight data bus lines. The address bus 64 is normally used as a register address and data bus 66 is used as the data to or from the register.
 Regarding a ring oscillator control circuit 90 of FIG. 6, a register bit called “XTRG” located in “IN_RING”0 has been selected as the control bit. If “XTRG” is set to be logic 1, the external crystal 70 will be the source oscillation to the system. Otherwise, if “XTRG” 92 is set to be logic 0, internal ring oscillator 72 will be the source to the system. The default state is logic 1. That is, the system will use external crystal oscillator 70 as the main source clock when the system 10 first powers up. In order to use internal ring oscillator 72, however, the user has to specify the address of XTRG register and place it onto the address bus, followed by the data the user wishes to write to the register and placed onto data bus. If the address on the address bus corresponding to XTRG register, an enable signal will be issued. Therefore, if a “write” operation is encountered, the data on the data bus will be written to XTRG. If a “read” operation is encountered, the data in XTRG will be driven onto the data bus.
 The bit of interest interested is bit 3 (See FIG. 6). If the user has decided to use the internal ring oscillator 72 as the source clock, he would have to set “XTRG” to logic 0. The switching from external crystal oscillator to internal ring oscillator will not occur until one machine cycle later. This is to insure the switching function is glitch free and occurs at the beginning of a machine cycle.
 The “XTRG” bit is not affected by reset. There are some conditions associated with this control bit. If the processor is running at “divide by 2” of external crystal, a signal called “ENDB2Z” will be active. This condition is to prevent the user from using internal ring oscillator as the main source clock. If the processor has been running from internal ring oscillator and the user has decided to disable external crystal, the signal called “IRG_ONZ” will become active. This signal is to prevent “XTRG” to change from logic 0 to logic 1 unless proper warm up time for external crystal oscillator has elapsed. “XTRG” will be accessible by the user.
 Regarding the operation of the crystal oscillator 76, the state of internal ring oscillator is set at logic 0. As long as “XTRG” is asserted, a clear signal will have no effect. However, if the user has deserted “XTRG”, then the falling edge of ring will clear a latch and the ring oscillator will stop.
 Preferred embodiments also provide for software control to disable/enable the external oscillator while running from the internal ring oscillator, so that the user has the ability to disable external oscillator to reduce current consumption tremendously. A bit called “XTOFF” (crystal off) has been designated to control whether the external crystal will be on or off. In order to access “XTOFF” bit, certain conditions have to be met before hand. One of which is to make sure the processor is running from internal ring oscillator, “XTRG” (crystal or ring) is set to logic 0. Otherwise “XTOFF” is stuck at logic 0, always.
 If the user has specified to set “XTRG” logic 0 and “XTOFF” logic 1, then a “KILL” signal is issued and sent to “AGC” (automatic gain controller). Therefore, the on-chip crystal amplifier will be disabled. The processor will use less power and conserve energy. This is especially important in battery operations.
 “XTRG” is not permitted to change from logic 0 to logic 1 while “XTOFF” is set to logic 1. The reason is that external crystal oscillator needs to have some warm-up time period before it becomes stable to use as clock source to the processor once it has been disabled by the user.
 If “XTOFF” is deasserted, the signal will trigger internal watch dog to count for about 2.6 ms and then issue “XTUP” (crystal up) signal. “XTUP” is the indicator to the processor that external crystal is now available for use. Only at this time, the user will gain access to “XTRG”.
 Preferred embodiments provide for the software control to divide the main system clock (ring or external crystal oscillator) to provide lower operating current, which allows the user to change system clock divide ratio to lower operating current. More specifically, referring to SFR_PRR module, Two control bits, CD1 and CD0, are associated with this operation. They are located in “SFR_PRR” register bit 7 and bit 6 with address of C4 HEX. The default state when the processor first powers up is that CD1 is at logic 0 and CD1 is at logic 1. These two bits are affected by reset.
 There are some restrictions associated with CD1 and CD0 bits. At any given time, if the state of the control bits is not at the default state (01; CD1=0, CD0=1), no access to these bits will be granted without going through 01 state. For example, if CD1 and CD0 is at 10 state, a signal called “BLKZ” (block) will be active, then a “write” has occurred on C4 to change to 11 state, the 11 state will be latched to “master” latches on C4. However, the updated values are not permitted to propagate through on the following C1. The values in “master” latches will be overwritten by the values in “slave” latches on the following C2. As long as the state is at 10 or 11, “BLKZ” is active, always. Preferably, when the state has been changed to 01, a signal called “CLRZ” (clear) will be active and cause “BLKZ” to be inactive. Then the state of the control bits will be accessible once again. This mechanism is to insure proper divide ratio has been initiated from the default state. Another condition that will affect the control bits state is the stop mode operation. Whatever the control bit state is, if the stop mode has been initiated, a signal called “HALT” will be active to force CD1 and CD0 back to the default state (01).
 In order to guarantee glitch free switching function of various divide ratio clocks, a state machine is introduced to govern the function. A signal called “XTAL” is the actual clock source going to system clock generator. There are four system clocks; C1, C2, C3, and C4. All four of them are non-overlapping clocks. That is no two or more system clocks will be active at any given time. And there is some delay introduced between the rising edge of “XTAL” and the rising edge of system clocks. Because of this nature, it is not a good idea to use system clocks as the sampling clocks. Therefore, a state machine is introduced to generate “system clock like” clocks.
 EXTERNAL INTERRUPT FLAG REGISTER (EXIF; Special Function Address 91 Hex)
 EXIF3: XT/RG Crystal Oscillator/Ring Oscillator Select: The XT/RG bit allows the processor to operate from either the External Oscillator (Crystal or external source) or the onboard Ring Oscillator. When XT/RG is set to a “1” the processor will operate from the external oscillator. When cleared to a “0” the processor will operate from the ring oscillator. In specific cases, the XT/RG bit is locked and cannot be altered due to the states that may exist on the XTOFF, or CD1/CD0 bits. These conditions are listed below. XT/RG is set to a “1” by a Power-On Reset and is unaffected by all other Reset functions.
 A. XT/RG is not allowed to change from a “1” to a “0” if the CD1 & CD0 bits are set to the divide by 2 mode.
 The reason is that the divide by 2 option in the clock control circuit is not supported for the ring oscillator.
 B. XT/RG cannot be changed from a “0” to a “1” until both XTOFF (PMR.3) and XTUP (STAT.4) are cleared to a “0”.
 The reason is that the external oscillator can only be selected after it has been enabled to run and the 65,536 cycle crystal oscillator start-up period has elapsed.
 EXIF.2: RGMD Ring Oscillator Mode:
 RGMD=1 indicates that the ring oscillator is providing the system clock as controlled by either XT/RG or RGSL.
 RGMD=0 indicates that the crystal is providing the system clock.
 EXIF.1: RGSL Ring Oscillator Select:
 When programmed to a “1” RGSL will enable the ring oscillator to begin clocking the system following interrupt generated STOP mode removals. Once the ring is started it will run uninterrupted (even in the event of a RESET) until the completion of the crystal startup time. At this time the system will be automatically switched to the external crystal oscillator to continue running. When programmed to a “0” the system will not use the ring and will wait until the crystal startup time has been satisfied before the system will begin running from the crystal oscillator. Reset only on Power On Reset. Note that when a STOP mode is issued while running from the ring as programmed by the XT/RG control in bit 3, the system will not automatically restart the crystal oscillator or automatically switch to the external crystal oscillator. When the ring is selected as programmed via the XT/RG bit the processor will remain on the ring until either programmed to change or externally issued a Reset.
 POWER MANAGEMENT REGISTER (PMR; Special Function Address C4 Hex)
 PMR. 7: CD1 Clock Divide Control Bit 1:
 PMR. 6: CD0 Clock Divide Control Bit 0:
 The Clock Divide Control bits establish the number of clocks required by the crystal oscillator input (Xtal 1) to generate one machine cycle. A default value of 4 is selected after all Resets and STOP exits. Note that the basic divide by 12 mode for the Timers (TXM=0) as well as the divide by 33 and 64 for Mode 2 on the Serial Ports, has been maintained when running the processor with either 2 or 4 oscillator cycles per machine cycle. Serial Port Mode 0 tracks the oscillator cycles per machine cycle, as does the Timers and Serial Port Mode 2 when the higher divide ratios of 64 and 1024 are selected. Automatic Switch-Back functions and hardware blocks to the write function of the Clock Divide Control bits are outlined below.
FIG. 7 is a state diagram corresponding power management register and the allowed state flow for CD1 and CD0. When changing the Clock Divide Control Bits (CD1 & CD0) certain restrictions must be observed. The default state of the divide by four mode 700 acts as the only state that any other divide ratio can be changed to or from, as outlined by the diagram in FIG. 7. As an example, attempting to change from a divide by 64 to a divide by 1024 will result in the CD1 and CD0 bit remaining set at the divide by 64 mode. The divide by 2 mode is only available when the processor is running from an external crystal or clock source, as programmed by the XT/RG bit. The XT/RG bit can only be cleared for ring operation if the divide by 2 mode is not selected by the CD1 & CD0 bits. Once the ring is 1024 L64 selected (XT/RG=0) the CD1 & CD0 bits are disabled from being programmed to a 00 Hex. The divide by 2 circuit is also disabled to conserve power when the ring oscillator is selected by the XT/RG bit and the crystal oscillator is disabled via the XTOFF bit. When the Automatic Switch-Back is enabled, and a respective Switch-Back source has been properly programmed, it will be impossible to change the Clock Divider Control bits to either a divide by 64 or 1024 until all respective sources are not active (see Switch-Back Enable). Movement between the divide by 2 and divide by 4 is not affected by the Switch-Back relationship.
 PMR.5: SWB Switch-Back Enable:
 Set to a “1”, SWB will allow mask enabled external interrupts INT0-INT5 as well as enabled serial port receive functions to force the Clock Divide Control bits (when programmed 64 or 1024 cycles per machine cycle) to the Reset default state (divide by 4). When set to a “0” (Reset default state) SWB will disable the Switch-Back mode.
FIG. 8 is a state diagram corresponding to the switch-back enable. Switch back paths supported by external interrupts or serial port activity. Switch-Back paths are supported from either the divide by 64 or 1024 modes (800, 802). The first Switch-Back condition is initiated by the detection of a low (programmed as either edge or level detect) on either INT0\ or INT1\, detection of a low on INT3\ or INT5\ or a high on INT2 or INT4 when the respective pin has been program enabled to issue an interrupt. Although INT0\ through INT5\ are defined normally or programmed as edge generated interrupts, the Switch-Back mode senses all of these pins in a level detection scheme to improve the response time normally required due to the slower clocks used to test for edge relationships. Note that the Switch-Back interrupt relationship requires that the respective external interrupt source will be allowed to actually generate an interrupt as defined by the priority of the interrupt and the state of nested interrupts, before the Switch-Back will actually occur. The second Switch-Back condition will occur when either serial port is enabled to receive data and is found to have an active low start bit on the respective receive input pin. Serial Port transmit activity will also force a Switch-Back if the SWB is set. Note that the Serial Port activity, as related to the Switch-Back is independent of the Serial Port Interrupt relationship. The automatic Switch-Back is only enabled when the Clock Divide Control bits have established either a divide by 64 or 1024 mode and the SWB bit is set to a “1”.
 PMR.4: DX2 Divide By 2 Clock Generator Enable
 The DX2 bit is cleared to a “0” on a Power-On Reset, and is unaffected by all other Reset functions. When programmed to a “0” the DX2 bit will disable the Divide by 2 Clock Generator to save energy and when programmed to a “1” the DX2 bit will enable the Divide by 2 Clock Generator. The Divide by 2 Clock Generator requires a start-up stabilization period equal to the standard start-up time of the crystal oscillator. Setting DX2 to a “1” from a previous “0” will automatically clear the XTUP bit in the status register and restart the crystal start-up time-out in the Watchdog Timer. During the Watchdog count of the required 65536 crystal clocks, the XTUP bit will remain cleared and the CD0, and CD1 clock controls will not be allowed to be set to the divide by 2 option. Setting RWT during the start-up period while XTUP is low will result in the Watchdog being cleared immediately following the start-up time-out. DX2 can not be changed from a “1” to a “0” while the divide by 2 option is selected via the CD0, and CD1 clock control bits. Although the DX2 bit is unaffected by normal Resets, it will be cleared if the crystal is stopped either via the XTOFF bit, by the external removal of the crystal or external clock, or by enabling the STOP mode (see function description of the Divide by 2 Generator).
 PMR.3 XTOFF Crystal Oscillator Enable:
 The XTOFF bit provides a means to disable the external crystal oscillator after the processor has been programmed to run from the on-board ring oscillator. When the XTOFF bit is set to a “1” the external oscillator will be disabled. When XTOFF is cleared to a “0” the crystal oscillator will be left to operate as normal. Note that even when not selected by the XT/RG bit the crystal oscillator can still be stopped through the use of the standard STOP mode bit in the PCON register. Setting the XTOFF bit to a “1” is only allowed when the XT/RG bit in the EXIF register has been cleared to a “0” (ring operation). Programming the XTOFF bit to a “0” ran be done at any time, independent of all other states. When changing the processor clock from the ring to the crystal oscillator (using the XT/RG bit), it is necessary that the proper start-up time be allowed before switching from the ring to the crystal. The status of the start-up time for the crystal is given in the XTUP bit in the STAT register. When the XTOFF bit is programmed from a “1” to a “0”, an internal count from the watchdog counter will count the standard 65,536 crystal oscillator cycles and indicate through the XTUP bit in the STAT register when the count is completed. Controls are provided to prevent the XT/RG bit from being set immediately after turning on the crystal oscillator, (XTOFF=>1). The lock-out of the XT/RG bit allows the standard oscillator start-up period to first elapse (Note: XTUP STAT.4) before switching back to the crystal oscillator. Setting RWT during the start-up period while XTUP is low will result in the Watchdog being cleared immediately following the start-up time-out.
 STATUS REGISTER (STAT; Special Function Address C5 Hex)
 STAT. 4: XTUP Crystal Oscillator Warm Up Status:
 The XTUP bit indicates the status of the 65,536 clock period delay used to establish the crystal oscillator or Divide by 2 Clock Generator warm-up period. When XTUP is set to “0”, the counter for the 65,653 clocks is still counting. When XTUP is cleared to a “1”, the count has been completed.
 This status bit is cleared each time the crystal oscillator is restarted following a period of being disabled via a STOP mode or the setting of the XTOFF bit in the PMR register. Once the XTUP is set, all lock-outs on the XT/RG bit are removed to allow the processor to use the crystal oscillator clock source.
 The XTUP bit is also cleared each time the DX2 bit (PMR.4) is changed from a low to a high to start the Divide by 2 Clock Generator. Once the XTUP is set, all lock-outs on the divide by 2 option via CD0, and CD1 bit are removed to allow the processor to use the Divide by 2 Generator as a system clock source.
 Note that XTUP functions differs from that of the RGMD bit in the EXIF register. The XTUP bit is used to monitor the crystal oscillator (or Divide by 2 Clock Generator) warm-up time and the RGMD is used to establish which clock (Ring or Crystal) is being used to clock the processor. When the system uses the XT/RG (EXIF.3) aid XTOFF (PMR.3), control bits to change and control the processor clocks, the two bits change and function independent of each other. When the system is programmed to exit a STOP mode with the ring oscillator and to automatically return to the crystal oscillator after the warm-up period (RGSL=1, XT/RG=1) the two bits again act independently, but will appear to change at the same time. When the ring is selected to act as the primary system clock via the XT/RG=0, the RGSL bit will become a don't care condition.
 Although the invention has been described with reference to a specific embodiment, this description is not meant to be construed in a limiting sense. As described above, various modifications of the disclosed embodiment as well as alternate embodiments of the invention will become apparent to persons skilled in the art upon reference to the description of the invention. While it is clear from the above discussion, that preferred embodiments implement the disclosed circuitry in an integrated circuit on a monolithic semiconductor substrate (e.g., silicon) portions of the circuitry may be moved “off-chip” depending upon the application and design requirements. Accordingly, it should be understood that the modifications and variations suggested above are not intended to be exhaustive.