AN108 IMPLEMENTING A REALTIME CLOCK. Relevant Devices. Introduction. Key Points. Overview

Similar documents
AN116. Power Management Techniques and Calculation. Introduction. Key Points. Power Saving Methods. Reducing System Clock Frequency

QSG144: CP2615-EK2 Quick-Start Guide

SMBus. Target Bootloader Firmware. Master Programmer Firmware. Figure 1. Firmware Update Setup

EFM8 Laser Bee Family QSG110: EFM8LB1-SLSTK2030A Quick Start Guide

AN999: WT32i Current Consumption

QSG123: CP2102N Evaluation Kit Quick- Start Guide

EFM8 Universal Bee Family EFM8UB2 Errata

QSG114: CPT007B SLEX8007A Kit Quick- Start Guide

EFM32 Pearl Gecko Family QSG118: EFM32PG1 SLSTK3401A Quick- Start Guide

2. Key Points. F93x F92x F91x F90x. Figure 1. C8051F93x-C8051F90x MCU Family Memory Size Options

AN125 INTEGRATING RAISONANCE 8051 TOOLS INTO THE S ILICON LABS IDE. 4. Configure the Tool Chain Integration Dialog. 1. Introduction. 2.

Translate HCSL to LVPECL, LVDS or CML levels Reduce Power Consumption Simplify BOM AVL. silabs.com Building a more connected world. Rev. 0.

AN976: CP2101/2/3/4/9 to CP2102N Porting Guide

8-Bit MCU C8051F85x/86x Errata

Figure 1. CP2108 USB-to-Quad UART Bridge Controller Evaluation Board

EFM8 Universal Bee Family EFM8UB1 Errata

CP2104-EK CP2104 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup USBXpress Driver Development Kit

UG271: CP2615-EK2 User's Guide

CP2103-EK CP2103 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup USBXpress Driver Development Kit

EFM8 Busy Bee Family EFM8BB2-SLSTK2021A Quick Start Guide

EFM32 Happy Gecko Family EFM32HG-SLSTK3400A Quick-Start Guide

CP2105-EK CP2105 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup USBXpress Driver Development Kit

CP2110-EK CP2110 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Relevant Documentation. 3. Software Setup

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup using a USB Debug Adapter

Figure 1. Precision32 AppBuilder

EFM8 Busy Bee EFM8BB1 Errata

UG345: Si72xx Eval Kit User's Guide

EFM32 Zero Gecko EFM32ZG Errata

AN719 PRECISION32 IDE AND APPBUILDER DETAILED TUTORIAL AND WALKTHROUGH. 1. Introduction. Figure 1. Precision32 IDE and AppBuilder Walkthrough Overview

EFR32 Mighty Gecko Family EFR32MG1 with Integrated Serial Flash Errata History

WT12 EVALUATION KIT DATA SHEET. Monday, 09 September Version 1.7

UDP UPPI Card UG UDP UPPI CARD USER S GUIDE. 1. Introduction. Figure 1. UPPI Cards with and without Radio

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup Using a USB Debug Adapter

AN324 ADVANCED ENCRYPTION STANDARD RELEVANT DEVICES. 1. Introduction. 2. Implementation Potential Applications Firmware Organization

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup Using a USB Debug Adapter

AN1139: CP2615 I/O Protocol

AN1095: What to Do When the I2C Master Does Not Support Clock Stretching

CP2114 Family CP2114 Errata

AN1160: Project Collaboration with Simplicity Studio

8-bit MCU Family C8051F93x/92x Errata

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup using a USB Debug Adapter

UG254: CP2102N-MINIEK Kit User's Guide

QSG119: Wizard Gecko WSTK Quick-Start Guide

C8051F00x/01x-DK C8051F00X/01X DEVELOPMENT KIT USER S GUIDE. 1. Kit Contents. 2. Hardware Setup using a USB Debug Adapter

Date CET Initials Name Justification

C8051F411-EK C8051F411 EVALUATION KIT USER S GUIDE. 1. Kit Contents. 2. Kit Overview. 3. Evaluation Board Interface LCD User Interface

Humidity/Temp/Optical EVB UG

Software Release Note

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup Using a USB Debug Adapter

Wireless Development Suite (WDS) is a software utility used to configure and test the Silicon Labs line of ISM band RFICs.

UG313: Thunderboard Sense 2 Bluetooth Low Energy Demo User's Guide

C8051F36x-DK. C8051F36x DEVELOPMENT KIT USER S GUIDE. 1. Relevant Devices. 2. Kit Contents. 3. Hardware Setup Using a USB Debug Adapter

UG369: Wireless Xpress BGX13P SLEXP8027A Kit User's Guide

UG294: CPT213B SLEXP8019A Kit User's Guide

USBXpress Family CP2102N Errata

UG352: Si5391A-A Evaluation Board User's Guide

TS9004 Demo Board FEATURES ORDERING INFORMATION

QSG159: EFM32TG11-SLSTK3301A Quick- Start Guide

QSG153: Micrium s μc/probe Tool Quick- Start Guide

QSG155: Using the Silicon Labs Dynamic Multiprotocol Demonstration Applications

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup Using a USB Debug Adapter

AN1106: Optimizing Jitter in 10G/40G Data Center Applications

AN0821: Simplicity Studio C8051F85x Walkthrough

Termination Options for Any-Frequency Si51x XOs, VCXOs

UG365: GATT Configurator User s Guide

EFM32 Pearl Gecko Family EFM32PG1 Errata

Figure 1. Traditional Biasing and Termination for LVPECL Output Buffers

QSG107: SLWSTK6101A/B Quick-Start Guide

The Si50122-Ax-EVB is used to evaluate the Si50122-Ax. Table 1 shows the device part number and corresponding evaluation board part number.

UG322: Isolated CAN Expansion Board User Guide

Date CET Initials Name Justification

The process also requires the use of the following files found in the Micriµm Quick Start Package for the FRDM-KL46Z:

µc/probe on the Freescale FRDM-KL05Z without an RTOS

EFR32MG13, EFR32BG13 & EFR32FG13 Revision C and Data Sheet Revision 1.0

AN0018.0: Supply Voltage Monitoring

QSG107: SLWSTK6101A Quick-Start Guide

BRD4300B Reference Manual MGM111 Mighty Gecko Module

AN1143: Using Micrium OS with Silicon Labs Thread

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup Using a USB Debug Adapter

AN1083: Creating and Using a Secure CoAP Connection with ARM s mbed TLS

AN888: EZR32 Quick Start Guide

AN0059.1: UART Flow Control

EFM32 EFM32GG11 Giant Gecko Family QSG149: EFM32GG11-SLSTK3701A Quick-Start Guide

Si7005USB-DONGLE. EVALUATION DONGLE KIT FOR THE Si7005 TEMPERATURE AND HUMIDITY SENSOR. 1. Introduction. 2. Evaluation Kit Description

Router-E and Router-E-PA Wireless Router PRODUCT MANUAL

Si1146 UVIRSlider2EK Demo Kit

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

USB Debug. Adapter USB DEBUG ADAPTER. J4 Silicon Laboratories. Stop Power. Run AC/DC. Adapter. Figure 1. Hardware Setup Using a USB Debug Adapter

UG274: Isolated USB Expansion Board User Guide

AN0018.1: Supply Voltage Monitoring

Also available for purchase separately are socket daughter boards for the QFN-11 and QFN-10 packages.

FBOUT DDR0T_SDRAM0 DDR0C_SDRAM1 DDR1T_SDRAM2 DDR1C_SDRAM3 DDR2T_SDRAM4 DDR2C_SDRAM5 DDR3T_SDRAM6 DDR3C_SDRAM7 DDR4T_SDRAM8 DDR4C_SDRAM9 DDR5T_SDRAM10

QSG107: SLWSTK6101A/B Quick-Start Guide

UG334: Si5394 Evaluation Board User's Guide

AN1083: Creating and Using a Secure CoAP Connection with ARM s mbed TLS

AN1117: Migrating the Zigbee HA Profile to Zigbee 3.0

QSG126: Bluetooth Developer Studio Quick-Start Guide

Bluegiga WF111 Software Driver Release Notes

UG232: Si88xxxISO-EVB User's Guide

UG366: Bluetooth Mesh Node Configuration User s Guide

Transcription:

IMPLEMENTING A REALTIME CLOCK Relevant Devices This application note applies to the following devices: C8051F000, C8051F001, C8051F002, C8051F005, C8051F006, C8051F007, C8051F010, C8051F011, and C8051F012. Introduction The purpose of this note is to provide an example of how to add a real-time clock (RTC) feature to a C8051F00x or C8051F01x device. Example software is included at the end of this note. Key Points The external oscillator can be used to drive a crystal for the RTC while the system clock uses the high-frequency internal oscillator. The system clock can be derived from the internal or external oscillator, and can change sources without compromising the accuracy of the RTC. The RTC uses Timer 2, which is configured to increment on falling edges of an external input. Comparator 0 is used to convert the crystal waveform to a square wave. This application note describes how to implement the function of a real-time clock inexpensively by using a C8051Fxxx device, a small 32 khz watch crystal, and a few passive components. Because the CPU overhead and resource requirements of the RTC are very small, this functionality can easily be added to an existing 8051-based system. In this design, a 32 khz watch crystal is connected to the external oscillator of the C8051 device. The output signal from the crystal oscillator is conditioned by one of the internal analog comparators and fed into a timer input. The timer is configured in auto-reload mode to generate an interrupt at a periodic rate, one-tenth second in this example. The interrupt service routine for the timer updates a series of counters for seconds, minutes, hours, and days. Overview Real-time clocks are used in many embedded applications to record the time at which an event occured, a pressure sensor was activated, or an ADC reading was taken, for example. Currently there are off-the-shelf components that contain a small crystal time base coupled with simple logic that have standardized interfaces for connecting to the I2C, SPI, or parallel port of a microcontroller. Rev. 1.2 12/03 Copyright 2003 by Silicon Laboratories AN108

Hardware Description A schematic of the hardware is shown in Figure 1. This design uses an external 32kHz watch crystal as the time base for the RTC. This crystal is connected between the XTAL1 and XTAL2 pins of the device. Note that the external oscillator s crystal driver can be enabled while the CPU core is operating from the internal oscillator. The XTAL2 output is fed into the (+) input of an on-chip analog comparator (Comparator 0). A lowpass filtered version of the XTAL2 signal is fed to the (-) input of the comparator to provide the DC bias level at which to detect the transitions of the oscillating signal. The corner frequency of this filter, where R = 1 M and C = 0.022 F, is substantially below the frequency of oscillation. The output of the on-chip comparator is routed to an external GPIO pin (CP0, determined by the crossbar) and connected to the input signal of Timer 2 (T2, also determined by the crossbar). Timer 2 increments once for each falling edge detected at the T2 input. Timer 2 is configured in 16-bit auto-reload mode to generate an interrupt every 3200 counts, or once every tenth of a second. The interrupt handler for Timer 2 updates a series of counters for tenths of seconds, seconds, minutes, hours, and days. The default mode of the RTC implementation assumes that the CPU system clock (SYSCLK) is derived from the high-speed internal oscillator. When the system clock is changed to use the external 32kHz source, for example to save power, Timer 2 is switched by the software to use SYSCLK as its time base. Synchronizing the clock CRYSTAL XTAL1 XTAL2 Input Circuit OSC CP0+ XTAL2 R LPF C CP0- CP0 P0.0 Digital Crossbar P0.1 Timer 2 Figure 1. Connection Diagram 2 Rev. 1.2

switching inside the RTC interrupt handler ensures no loss of accuracy. Crossbar Configuration The connection between internal digital peripherals and the GPIO pins is handled by the crossbar. In this design, the crossbar routes the CP0 output and T2 input to GPIO pins P0.0 and P0.1, respectively. It is important to note that the specific port pins used will change if peripherals with a higher crossbar priority are enabled (see AN001). Crossbar setup is accomplished with the following statements: enable CP0 outpput mov XBR0, #80h enable T2 input mov XBR1, #20h enable crossbar and weak pull- ups mov XBR2, #40h Oscillator Configuration Refer to AN002 for details on configuring external oscillator. The following statement configures and enables the external oscillator for use with a 32 khz crystal. enable external oscillator in crystal mode XFCN = 001 for a 32kHz crystal mov OSCXCN, #61h Once configuration is complete, the external oscillator must be checked for stability before enabling the timer. The XTLVLD bit (OSCXN.7) is set when the crystal is running and stable. Software polls the XTLVLD bit before enabling Timer 2: wait until the external osc. is stable WAIT: mov ACC, OSCXCN jnb ACC.7, WAIT enable Timer 2 setb TR2 Comparator Configuration The Comparator 0 setup involves setting the positive and negative hysteresis and enabling the comparator. The comparator hysteresis can be configured in the comparator control register CPT0CN. Since the voltage of the XTAL2 signal will be fairly large (500 mv to 3 V), the CP0 hysteresis can be set high to provide noise immunity. The hysteresis is set and the comparator is enabled with the following statements: set CP0 hysteresis 10mV/10mV mov CPT0CN, #0Ah enable CP0 orl CPT0CN, #80h Timer Configuration When the CPU system clock (SYSCLK) is derived from the high-frequency internal oscillator, Timer 2 is configured in auto-reload mode to count falling edges on the external signal T2. Timer 2 is configured with the following statement: mov T2CON, #02h We must also set the initial and reload values for Timer 2. The initial value is the value loaded into Timer 2 before it is enabled, and the reload value, held in RCAP2H (high byte) and RCAP2L (low byte), is loaded into Timer 2 after an overflow. The initial and reload values, which are identical, are determined by the precision required of the realtime clock. This design implements precision of a tenth of a second therefore, Timer 2 is set to overflow every tenth of a second, or every 3200 counts of the 32 khz time base. We set the COUNT value to 3,200, and set the reload values in the RCAP2 registers with the following commands: set T2 reload high byte mov RCAP2H, #HIGH(-COUNT) set T2 reload low byte mov RCAP2L, #LOW(-COUNT) Rev. 1.2 3

When Timer 2 overflows, it will be reloaded to overflow in another 3200 counts, and it will generate an interrupt. The program will vector to the Timer 2 interrupt service routine every tenth of a second to increment the counters. Because the interrupt service routine is short and is only called once every tenth of a second, CPU utilization is remarkably low. Once Timer 2 is configured, its interrupt must be enabled with the following statement: enable Timer 2 interrupt setb ET2 Timer 2 is enabled after all other timer configuration is complete by setting its run bit: start Timer 2 setb TR2 System Clock Switching The default configuration of this RTC example assumes that the CPU system clock (SYSCLK) is derived from the high-speed internal oscillator. If SYSCLK is derived instead from the external oscillator, for power savings, the configuration for Timer 2 must be changed to use SYSCLK as the time base because signals at T2 can have a maximum frequency of SYSCLK / 4 in order to be properly detected. The process for changing the system clock is as follows: 1. Stop the timer (TR2 = 0 ). 2. Change timer time base. 3. Change SYSCLK time base. 4. Add correction factor to timer s counter. 5. Start the timer (TR2 = 1 ). In order to guarantee that no external clock edges are missed, the SYSCLK should be updated in the RTC s interrupt service routine. The system clock can be changed by setting either SET_EXT_OSC (to change to the external oscillator) or SET_INT_OSC (to change to the internal oscillator) to 1. These bits are used as flags in the Timer 2 ISR to permit changing of the system clock without sacrificing RTC accuracy. Details are given in the software description at the end of this report. Software Description This section contains a description of the software flow. The program listing begins on page 6. Main Function The MAIN function is used to configure the crossbar, external oscillator, comparator, and timer. First we setup the external crystal by enabling the external oscillator and setting the power factor bits. The crossbar setup and CP0 setup values described above are then loaded, and then each are enabled. The crystal must be settled before Timer 2 is enabled. When the crystal is settled, the XTLVLD bit is set by hardware, and the program moves past the WAIT loop. At the end of the MAIN function the RTC_INIT function is called, Timer 2 is enabled, and global interrupts enabled. RTC Initialization Function The RTC_INIT function is used to reset the counter values and to configure Timer 2. This function can be used as a reset for the RTC. After clearing the counter values, the initial value for Timer 2 is set to the COUNT value as described in the configuration section. The COUNT value is also loaded into the reload registers (RCAP2H & RCAP2L). Timer 2 is then set to increment on external input edges, and the Timer 2 interrupt is enabled. 4 Rev. 1.2

Timer Interrupt Service Routine The Timer 2 ISR is called each time Timer 2 overflows (once every tenth of a second). When the ISR is called, it first clears the Timer 2 interrupt flag (TF2). The ISR then checks for overflows in all of the counters, starting with the tenths counter. If the tenths counter is at 9, it is reset to 0 and the seconds are checked for an overflow. Similarly, if the seconds are at 59, they are reset to 0, and the minutes are checked. The hours and days are checked in the same fashion. The counter is incremented, and then the oscillator selection bits (SET_EXT_OSC and SET_INT_OSC) are checked. Oscillator Selection If the SET_EXT_OSC bit is set, the bit is cleared, and the program jumps to the EXT_OSC label. First, OSCICN is checked--if the system clock is already using the external oscillator, the ISR exits. If not, Timer 2 is disabled to avoid any miscounts during the system clock switch. CKCON is setup so that the Timer 2 input clock is the system clock divided by one. Timer 2 is then set to increment on the system clock, and the Timer 2 counter register is updated to compensate for missed ticks during the SYSCLK transition. Between the system clock switch and the Timer 2 re-enable, Timer 2 misses 5 ticks. The correction value, EXT_COR, is set to 5 this value is added to the Timer 2 register before the system clock is switched to the external oscillator. After the switch, Timer 2 is enabled again, and the ISR exits. enabled. The ISR then exits to wait for another overflow. Counter Access The tenths/seconds/minutes/etc counters can be accessed by calling the SAVE routine. The SAVE routine first saves the current state of the Timer 2 interrupt flag in the Carry bit and then disables the Timer 2 interrupt so that no interrupts occur during the save. Disabling the interrupt does no harm here because the interrupt will be enabled again at the end of the SAVE routine. If an interrupt is generated during the SAVE routine, it will be serviced as soon as the Timer 2 interrupt is enabled again. After ET2 is cleared, each counter is saved (TENTHS into STORE_T, SECONDS into STORE_S, etc). The interrupt flag is restored, and the function returns to its caller. If the SET_INT_OSC bit is set, the bit is cleared and the program jumps to the INT_OSC label. OSCICN is checked first to make sure the system clock is not already using the internal oscillator. If it is not, Timer 2 is disabled for the clock switch. The internal oscillator is selected as the system clock, and then the correction value, COR_INT is added to the Timer 2 register. In this case, 3 ticks are missed during the switch. COR_INT, which is set to 3, is added to Timer 2. The external input pin is selected as the Timer 2 input, and Timer 2 is Rev. 1.2 5

Software Example CYGNAL, INC. FILE NAME : RTC_1.asm TARGET DEVICE : C8051F0xx DESCRIPTION : Software implementation of a real-time clock AUTHOR : JS Software implementation of a real-time clock using a 32KHz crystal oscillator. This program uses the crystal driver, XTAL2 to drive Comparator 0. The positive comparator input is from XTAL2, and the negative input is an averaged version of XTAL2. The averaging is done by a low pass filter. The output of Comparator 0 is routed to the Timer 2 input (T2). Timer 2 is configured in auto-reload mode, and is set to trigger on the external input pin connected to the Comparator 0 output. This code assumes the following: (1) An external oscillator is connected between XTAL1 and XTAL2 (2) A low pass averaging filter is connected bewteen XTAL2 and CP0- (3) XTAL2 is routed to CP0+ (4) CP0 output is routed to Timer 2 input through the port pins assigned by the crossbar For a 32KHz crystal, the low pass filter consists of a 0.022uF capacitor and a 1 Mohm resistor. EQUATES $MOD8F000 Count value: This value is used to define what is loaded into timer 2 after each overflow.the count value is 3200, meaning the timer will count 3200 ticks before an overflow. Used with the 32KHz crystal, this means the timer will overflow every tenth of a second. COUNT EQU 3200d count value Compensation factors for system clock switching used to update Timer 2 after a system clock change EXT_COMP EQU 5d INT_COMP EQU 3d VARIABLES DSEG 6 Rev. 1.2

BSEG org 30h TENTHS: DS 1 counts tenths of seconds SECONDS: DS 1 counts seconds MINUTES: DS 1 counts minutes HOURS: DS 1 counts hours DAYS: DS 1 counts days STORE_T: DS 1 storage byte for tenths, used by SAVE routine STORE_S: DS 1 storage byte for seconds STORE_M: DS 1 minutes STORE_H: DS 1 hours STORE_D: DS 1 days org 00h SET_EXT_OSC: DBIT 1 flag to change system clock to external osc SET_INT_OSC: DBIT 1 flag to change system clock to internal osc RESET and INTERRUPT VECTORS CSEG Reset Vector org 00h ljmp MAIN Timer 2 ISR Vector org 2Bh ljmp T2_ISR Timer 2 ISR MAIN PROGRAM org 0B3h MAIN: mov OSCXCN, #61h enable external oscillator in crystal mode for a 32kHz watch crystal mov WDTCN, #0DEh disable watchdog timer mov WDTCN, #0ADh Setup Crossbar mov XBR0, #80h enable CP0 output mov XBR1, #20h enable T2 input mov XBR2, #40h enable crossbar Setup Comparator 0 Rev. 1.2 7

WAIT: mov CPT0CN, #08h set positive hysteresis to 10mV orl CPT0CN, #02h set negative hysteresis to 10mV orl CPT0CN, #80h enable CP0 acall RTC_INIT Initialize RTC and Timer 2 mov ACC, OSCXCN wait until the external oscillator is steady jnb ACC.7, Wait by checking the XTLVLD bit in OSCXCN setb TR2 turn on Timer 2 (starts RTC) setb EA enable global interrupts jmp $ spin forever - Initialization Subroutine - RTC_INIT: Clear all counters mov TENTHS, #0 mov SECONDS, #0 mov MINUTES, #0 mov HOURS, #0 mov DAYS, #0 Setup Timer2 in auto-reload mode to count falling edges on external T2 mov TH2, #HIGH(-COUNT) set initial value for timer 2 mov TL2, #LOW(-COUNT) mov RCAP2H, #HIGH(-COUNT) set reload value for timer 2 mov RCAP2L, #LOW(-COUNT) mov T2CON, #02h configure Timer 2 to increment falling edges on T2 setb ET2 enable Timer 2 interrupt ret - Timer 2 ISR - T2_ISR: clr TF2 clear overflow interrupt flag push PSW preserve PSW (carry flag) push ACC preserve ACC Check for overflows mov A, TENTHS cjne A, #9d, INC_TEN if tenths less than 9, jump to increment mov TENTHS, #0 if tenths = 9, reset to zero, 8 Rev. 1.2

and check seconds mov A, SECONDS cjne A, #59d, INC_SEC if seconds less than 59, jump to increment mov SECONDS, #0 if seconds = 59, reset to zero, and check minutes mov A, MINUTES cjne A, #59d, INC_MIN if minutes less than 59, jump to increment mov MINUTES, #0 if minutes = 59, reset to zero, and check hours mov A, HOURS cjne A, #23d, INC_HOUR if hours less than 23, jump to increment mov HOURS, #0 if hours = 23, reset to zero, and check days inc DAYS DAYS will roll over after 255 jmp CHECK_OSC jump to check for oscillator change request Increment counters---------------------------------------------------------------- INC_TEN: inc TENTHS increment tenths counter jmp CHECK_OSC jump to check for oscillator change request INC_SEC: inc SECONDS increment seconds counter jmp CHECK_OSC jump to check for oscillator change request INC_MIN: inc MINUTES increment minutes counter jmp CHECK_OSC jump to check for oscillator change request INC_HOUR: inc HOURS increment hours counter jmp CHECK_OSC jump to check for oscillator change request Oscillator changes---------------------------------------------------------------- CHECK_OSC: jbc SET_EXT_OSC, EXT_OSC check for external oscillator select jbc SET_INT_OSC, INT_OSC check for internal oscillator select jmp END_ISR exit EXT_OSC: switch system clock to external oscillator mov ACC, OSCICN check current system clock Rev. 1.2 9

jb ACC.3, END_ISR exit if already using external oscillator orl CKCON, #20h select system clock (divide by 1) for Timer 2 clr TR2 disable Timer 2 during clock change clr CT2 select SYSCLK as Timer 2 input mov A, #LOW(EXT_COR) load correction value into accumulator add A, TL2 add correction value to Timer 2 counter register mov TL2, A store updated Timer 2 value orl OSCICN, #08h select external oscillator as system clock setb TR2 enable Timer 2 after clock change jmp END_ISR exit INT_OSC: switch system clock to internal oscillator mov ACC, OSCICN check current system clock jnb ACC.3, END_ISR exit if already using internal oscillator clr TR2 disable Timer 2 during clock change anl OSCICN, #0f7h select internal oscillator as system clock mov A, #LOW(INT_COR) load correction value into accumulator add A, TL2 add correction value to Timer 2 register mov TL2, A store updated Timer 2 value setb CT2 select external Timer 2 input setb TR2 enable Timer 2 after clock change jmp END_ISR exit END_ISR: pop ACC restore ACC pop PSW restore PSW reti - Counter Save Routine - SAVE: mov C, ET2 preserve ET2 in Carry clr ET2 disable Timer 2 interrupt during copy 10 Rev. 1.2

mov STORE_T, TENTHS copy all counters mov STORE_S, SECONDS mov STORE_M, MINUTES mov STORE_H, HOURS mov STORE_D, DAYS mov ET2, C restore ET2 ret --------------------------------------------------------------------------------- END Rev. 1.2 11

Simplicity Studio One-click access to MCU and wireless tools, documentation, software, source code libraries & more. Available for Windows, Mac and Linux! IoT Portfolio www.silabs.com/iot SW/HW Quality Support and Community www.silabs.com/simplicity www.silabs.com/quality community.silabs.com Disclaimer Silicon Labs intends to provide customers with the latest, accurate, and in-depth documentation of all peripherals and modules available for system and software implementers using or intending to use the Silicon Labs products. Characterization data, available modules and peripherals, memory sizes and memory addresses refer to each specific device, and "Typical" parameters provided can and do vary in different applications. Application examples described herein are for illustrative purposes only. Silicon Labs reserves the right to make changes without further notice and limitation to product information, specifications, and descriptions herein, and does not give warranties as to the accuracy or completeness of the included information. Silicon Labs shall have no liability for the consequences of use of the information supplied herein. This document does not imply or express copyright licenses granted hereunder to design or fabricate any integrated circuits. The products are not designed or authorized to be used within any Life Support System without the specific written consent of Silicon Labs. A "Life Support System" is any product or system intended to support or sustain life and/or health, which, if it fails, can be reasonably expected to result in significant personal injury or death. Silicon Labs products are not designed or authorized for military applications. Silicon Labs products shall under no circumstances be used in weapons of mass destruction including (but not limited to) nuclear, biological or chemical weapons, or missiles capable of delivering such weapons. Trademark Information Silicon Laboratories Inc., Silicon Laboratories, Silicon Labs, SiLabs and the Silicon Labs logo, Bluegiga, Bluegiga Logo, Clockbuilder, CMEMS, DSPLL, EFM, EFM32, EFR, Ember, Energy Micro, Energy Micro logo and combinations thereof, "the world s most energy friendly microcontrollers", Ember, EZLink, EZRadio, EZRadioPRO, Gecko, ISOmodem, Precision32, ProSLIC, Simplicity Studio, SiPHY, Telegesis, the Telegesis Logo, USBXpress and others are trademarks or registered trademarks of Silicon Labs. ARM, CORTEX, Cortex-M3 and THUMB are trademarks or registered trademarks of ARM Holdings. Keil is a registered trademark of ARM Limited. All other products or brand names mentioned herein are trademarks of their respective holders. Silicon Laboratories Inc. 400 West Cesar Chavez Austin, TX 78701 USA http://www.silabs.com