| |
Datasheet Home \ Datasheet Details
Download
PDF Abstract Text:
AN582
Low-Power Real-Time Clock
Author:
AN582
Low-Power Real-Time Clock
Mark Palmer Microchip Technology Inc.
INTRODUCTION
This application note uses the Timer1 module, from a mid-range PIC16CXXX microcontroller, to control a low-power real-time clock. Timer1 was chosen because it has its own crystal which allows the module to operate during sleep. The two events that will wake the device from sleep (for this application) are a keypress and a Timer1 overflow.
OPERATION
FIGURE 1:
CLOCK BLOCK DIAGRAM
VCC VSS 100
VCC VSS
PIC16CXXX RB7 RB6 RB5
3x100
MCLR S4 T1OSO 32 kHz T1OSI
RB3 RB2 RB1 RB0
RA2 RA1 OSC1 OSC2 RA0
DS00582B-page 1
AN582
TABLE 1:
LIST OF COMPONENTS
Description Part Number LM032L EVQPADO4M PIC16C64 / 74 NC26 / NC38 ECS-40-20-1 Manufacturer Hitachi Panasonic Microchip FOX ECS Quantity 1 4 1 1 1
LCD Module (2 x 20 Characters) Switches Microcontroller 32.768 kHz Crystal 4 MHz Crystal
Most components available from DigiKey.
DS00582B-page 2
AN582
CONCLUSION
The Timer1 module allows many applications to include a real-time clock at minimal system cost. This time function can be useful in consumer applications (display time) as well as in industrial applications (data time stamp). The accuracy of the time is strictly dependent on the accuracy of the crystal. Table 2 shows the program resource requirements.
TABLE 2:
PROGRAM RESOURCE REQUIREMENTS
Resource Initialization Words / Bytes 61 Increment Time WC Key Input WC 106 208 5 4 Cycles 61 35 + Display 35 + Display Time 526(1) N.A. N.A.
Program Memory Clock Operation Display(2) Data Memory
Variables Scratch RAM
DS00582B-page 3
AN582
MPASM 01.40 Released CLOCK.ASM 1-16-1997 17:05:59 PAGE 1
LOC OBJECT CODE VALUE
LINE SOURCE TEXT
1683 188E 290C 295E
0004 0005 0006 0007 0008 0009 0009 000A 000B 000C 000D 000E 000F 0010
1283 180C 2843 1C0B 28D0
0806 39E0 00B5 3002 08B3 01B4 0BB4 280F
AN582
0BB3 280F 0806 39E0 02B5 1D03
0017 280B 0018 00B5 0019 001A 001B 001C 001D 001E 001F 0020 0021 0022 3080 008F 018E 100C 1FB5 2826 1F35 282B 1EB5 2835
0023 0023 0886 0024 100B
0026 0026 0027 0028 0029 002A 002B 002B 002C 002D 002E 002F
30FF 00C0 0AA0 1620 2875
01C0 1820 285C 1CA0 2823
DECFSZ GOTO MOVF ANDLW SUBWF BTFSS GOTO MOVWF MOVLW MOVWF CLRF BCF BTFSS GOTO BTFSS GOTO BTFSS GOTO
PORTB, F INTCON, RBIF PORTD, 0
0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F 0040 0041 0042
0AB1 303C 0231 1D03 2875 01B1 3004 00B2 3080 008F 018E 100C 01C0 1AB5 2875 10A0 1020 1220 2875
0043 0043 0044 0045 0046 0047 0048 0049 004A 004B 004C 004D 004E
100C 1E20 284F 0AC0 300A 0240 1D03 2875 01C0 1220 1020 10A0
004F 0050 0051 0052 0053 0054 0055 0056
3080 008F 0AB2 1F32 2875 3004 00B2 0AB1
MOVLW MOVWF INCF BTFSS GOTO MOVLW MOVWF INCF
0x80 TMR1H SECS, F SECS, 6 DISPLAY 0x04 SECS MIN, F
AN582
0057 0058 0059 005A 005B 005C 005D 005E 005F 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 006A 006B 006C 006D
303C 0231 1D03 2875 01B1 0AB0 300C 0230 1D03 2867 1FA0 2865 13A0 2875 17A0 2875 300D 0230 1D03 2875 01B0 0AB0 2875
006E 006E 006F 0070 0071 0072 0073 0074
300C 20E3 3001 20E3 3006 20E3 0008
0075 0075 3080 0076 20E3 0077 0078 0079 007A 007B 007C 1A20 287D 20A4 20AD 20B2 28BB
MOVLW SUBWF BTFSS GOTO CLRF INCF MOVLW SUBWF BTFSS GOTO BTFSS GOTO BCF GOTO BSF GOTO MOVLW SUBWF BTFSS GOTO CLRF INCF GOTO
007D 007D 007E 007F 0080 0080 0081 0082 0083 0084 0084
018A 0820 3903 0782 289F 2887 2893 30FC
0085 05A0 0086 289F
0087 0087 1C40 0088 0089 008A 008B 008C 008D 008D 008E 008F 0090 0091 0092 288D 3020 20D4 3020 20D4 1C40 20A4 303A 20D4 20B2 28BB
20A4 303A 20D4 1C40
0097 289C 0098 3020 0099 20D4
AN582
009A 009B 009C 009C 009D 009E 009F 009F 00A0 00A1 00A2 00A3 00A4 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC
3020 20D4 1C40 20B2 28BB
20A4 303A 20D4 20B2 28BB
0830 20C7 0833 2400 20D4 0834 2400 20D4 0008
00AD 3020 00AE 1832 00AF 3E1A 00B0 20D4 00B1 0008 00B2 00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA
0831 20C7 0833 2400 20D4 0834 2400 20D4 0008
00BB 3020
Display all character
Load the Wreg with the value to convert to BCD Load the MSD value into the Wreg Get the ASCII code Send this Character to the Display
Load the LSD value into the Wreg Get the ASCII code Send this Character to the Display
ASCII value for a Blank space Is it an EVEN or ODD second Is ODD, Second colon is ON. Add delta offset of ASCII Characters Send this Character to the Display
Load the Wreg with the value to convert to BCD Load the MSD value into the Wreg Get the ASCII code Send this Character to the Display
Load the LSD value into the Wreg Get the ASCII code Send this Character to the Display
ASCII value for a Blank space
00BC 00BD 00BE 00BF 00C0 00C1 00C2 00C3 00C4 00C5 00C6
20D4 3041 1FA0 3E0F 20D4 304D 20D4 1683 1381 1283 2823
00C7 00C8 00C9 00CA 00CB 00CC 00CD 00CE 00CF
01B3 00B4 300A 0234 1C03 3400 00B4 0AB3 28C9
00D0 1283
00D1 1407 00D2 1007 00D3 28D0
CALL MOVLW BTFSS ADDLW CALL MOVLW CALL BSF BCF BCF GOTO
Send this Character to the Display ASCII value for a Blank space Is it AM or PM Is PM, Add delta offset of ASCII Characters Send this Character to the Display
AN582
00D4 00D4 00D5 00D6 00D7 00D8 00D9 00DA 00DB 00DC 00DD 00DE 00DF 00E0 00E1 00E2
00B6 20F2 0E36 390F 0086 1085 1505 1405 1005 0836 390F 0086 1405 1005 0008
00E3 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF 00F0 00F1
00B6 20F2 0E36 390F 0086 1085 1105 1405 1005 0836 390F 0086 1405 1005 0008
Get lower nibble Send data to LCD toggle E for LCD
00F2 00F3 00F4 00F5 00F6 00F7 00F8 00F9 00FA 00FB 00FC 00FD 00FE 00FF 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 010A 010B
0186 1683 1781 30FF 0086 1283 1105 1485 1405 1005 0E06 39F0 00B5 1405 1005 0806 390F 04B5 1BB5 28F2 1085 1683 30F0 0086 1283 0008
010C 010C 1283
AN582
010D 010E 010F 0110 0111 0112 0113
300C 00B0 01B1 3000 00A0 3004 00B2
0114 3080 0115 008F 0116 018E 0117 0117 0118 0119 011A 011B 011C 011D 011E 011F
0183 018B 018C 1683 3000 0081 018C 30FF 009F
0120 0121 0122 0123 0124 0125 0126 0127 0128 0129 012A 012B 012C 012D 012E 012F 0130 0131 0132 0133
1283 0185 0186 0187 0188 0189 1010 1683 0185 30F0 0086 0187 1407 0188 0189 140C 1381 1283 0886 100B
A Master Clear Reset Do initialization (Bank 0)
Bank 1 The LCD module does not like to work w / weak pull-ups Disable all peripheral interrupts Port A is Digital (for 16C7x devices).
STATUS, RP0 PORTA PORTB PORTC PORTD PORTE T1CON, TMR1ON
Bank 0 ALL PORT output should output Low.
Timer 1 is NOT incrementing
0139 013A 013B 013C 013D 013E 013F 013F
3006 00B3 01B4 0BB4 293C 0BB3 293C
0148 0149 014A 014B 014C 014D 014E 014F
300C 20E3 3001 20E3 3006 20E3 3080 20E3
ALL PORT output should output Low.
AN582
018C 300E 0090 170B 158B 178B
0156 206E 0157 2075 0158 300E 0159 0090 015A 1410
015B 0063 015C 0000 015D 295B
015E 1E03 015F 28D0 0160 290C
0400 0400 00B5
0401 0402 0403 0404 0405 0406 0407 0408 0409 040A 040B 040C 040D 040E 040F 0410 0411 0412 0413 0414 0415
3004 008A 0835 390F 0782 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3445 3445 3445 3445 3445 3445
07FF 07FF 28D0
MOVLW MOVWF MOVF ANDLW ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW
Ensure that PCLATH high has the correct value Value into table Mask to 4-bits (00 - 0Fh) Determine Offset into table ASCII value of "0" in W register ASCII value of "1" in W register ASCII value of "2" in W register ASCII value of "3" in W register ASCII value of "4" in W register ASCII value of "5" in W register ASCII value of "6" in W register ASCII value of "7" in W register ASCII value of "8" in W register ASCII value of "9" in W register Any enter after is in error (Display an E) ASCII value of "E" in W register ASCII value of "E" in W register ASCII value of "E" in W register ASCII value of "E" in W register ASCII value of "E" in W register ASCII value of "E" in W register
0000 0040 0080 00C0 0100 0140 0400 07C0
XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX --------
XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXX-------------
XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX X-----------------------
XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX -----------------------X
AN582
All other memory blocks unused. Program Memory Words Used: Program Memory Words Free: 376 3720
Errors : Warnings : Messages :
0 0 reported, 0 reported,
0 suppressed 16 suppressed
AN582
DS00582B-page 19
AN582
Least Significant 7-bit are for address Upper Left corner of the Display
DS00582B-page 20
AN582
DS00582B-page 21
AN582
STATUS register (Address 03 / 83) IRP EQU 7 RP1 EQU 6 RP0 EQU 5 TO EQU 4 PD EQU 3 Z EQU 2 DC EQU 1 C EQU 0 INTCON register (Address 0B / 8B) GI EQU 7 PEIE EQU 6 T0IE EQU 5 INTE EQU 4 RBIE EQU 3 T0IF EQU 2 INTF EQU 1 RBIF EQU 0 PIR1 register (Address 0C) PSPIF EQU 7 SSPIF EQU 3 CCP1IF EQU 2 TMR2IF EQU 1 TMR1IF EQU 0 PIE1 register (Address 8C) PSPIE EQU 7 SSPIE EQU 3 CCP1IE EQU 2 TMR2IE EQU 1 TMR1IE EQU 0 OPTION register (Address 81) RBPU EQU 7 INTEDG EQU 6 T0CS EQU 5 T0SE EQU 4 PSA EQU 3 PS2 EQU 2 PS1 EQU 1 PS0 EQU 0 PCON register (Address 8E) POR EQU 1 TRISE register (Address 89) IBF EQU 7 OBF EQU 6 IBOV EQU 5 PSPMODE EQU 4 TRISE2 EQU 2 TRISE1 EQU 1 TRISE0 EQU 0 T1CON register (Address 10)
DS00582B-page 22
AN582
T1CKPS1 EQU 5 T1CKPS0 EQU 4 T1OSCEN EQU 3 T1INSYNC EQU 2 TMR1CS EQU 1 TMR1ON EQU 0 T2CON register (Address 12) TOUTPS3 EQU 6 TOUTPS2 EQU 5 TOUTPS1 EQU 4 TOUTPS0 EQU 3 TMR2ON EQU 2 T2CKPS1 EQU 1 T2CKPS0 EQU 0 SSPCON register (Address 14) WCOL EQU 7 SSPOV EQU 6 SSPEN EQU 5 CKP EQU 4 SSPM3 EQU 3 SSPM2 EQU 2 SSPM1 EQU 1 SSPM0 EQU 0 SSPSTAT register (Address 94) DA EQU 5 P EQU 4 S EQU 3 RW EQU 2 UA EQU 1 BF EQU 0 CCP1CON register (Address 17) CCP1X EQU 5 CCP1Y EQU 4 CCP1M3 EQU 3 CCP1M2 EQU 2 CCP1M1 EQU 1 CCP1M0 EQU 0 RCSTA register (Address 18) SPEN EQU 7 RC89 EQU 6 SREN EQU 5 CREN EQU 4 FERR EQU 2 OERR EQU 1 RCD8 EQU 0 TXSTA register (Address 98) CSRC EQU 7 TX89 EQU 6 TXEN EQU 5 SYNC EQU 4 BRGH EQU 2 TRMT EQU 1 TXD8 EQU 0
DS00582B-page 23
AN582
DS00582B-page 24
Note the following details of the code protection feature on PICmicro® MCUs. · · · The PICmicro family meets the specifications contained in the Microchip Data Sheet. Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today, when used in the intended manner and under normal conditions. There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet. The person doing so may be engaged in theft of intellectual property. Microchip is willing to work with the customer who is concerned about the integrity of their code. Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as "unbreakable". Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our product.
If you have any further questions about this matter, please contact the local sales office nearest to you.
Printed on recycled paper.
2002 Microchip Technology Inc.
WORLDWIDE SALES AND SERVICE
AMERICAS
Corporate Office
2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: 480-792-7627 Web Address: http://www.microchip.com
ASIA / PACIFIC
Australia
Microchip Technology Australia Pty Ltd Suite 22, 41 Rawson Street Epping 2121, NSW Australia Tel: 61-2-9868-6733 Fax: 61-2-9868-6755
Japan
Microchip Technology Japan K.K. Benex S-1 6F 3-18-20, Shinyokohama Kohoku-Ku, Yokohama-shi Kanagawa, 222-0033, Japan Tel: 81-45-471- 6166 Fax: 81-45-471-6122
Rocky Mountain
2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7966 Fax: 480-792-7456
China - Beijing
Microchip Technology Consulting (Shanghai) Co., Ltd., Beijing Liaison Office Unit 915 Bei Hai Wan Tai Bldg. No. 6 Chaoyangmen Beidajie Beijing, 100027, No. China Tel: 86-10-85282100 Fax: 86-10-85282104
Korea
Microchip Technology Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934
Atlanta
500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307
Singapore
Microchip Technology Singapore Pte Ltd. 200 Middle Road #07-02 Prime Centre Singapore, 188980 Tel: 65-334-8870 Fax: 65-334-8850
Boston
2 Lan Drive, Suite 120 Westford, MA 01886 Tel: 978-692-3848 Fax: 978-692-3821
China - Chengdu
Microchip Technology Consulting (Shanghai) Co., Ltd., Chengdu Liaison Office Rm. 2401, 24th Floor, Ming Xing Financial Tower No. 88 TIDU Street Chengdu 610016, China Tel: 86-28-6766200 Fax: 86-28-6766599
Taiwan
Microchip Technology Taiwan 11F-3, No. 207 Tung Hua North Road Taipei, 105, Taiwan Tel: 886-2-2717-7175 Fax: 886-2-2545-0139
Chicago
333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 630-285-0071 Fax: 630-285-0075
Dallas
4570 Westgrove Drive, Suite 160 Addison, TX 75001 Tel: 972-818-7423 Fax: 972-818-2924
China - Fuzhou
Microchip Technology Consulting (Shanghai) Co., Ltd., Fuzhou Liaison Office Unit 28F, World Trade Plaza No. 71 Wusi Road Fuzhou 350001, China Tel: 86-591-7503506 Fax: 86-591-7503521
EUROPE
Denmark
Microchip Technology Nordic ApS Regus Business Centre Lautrup hoj 1-3 Ballerup DK-2750 Denmark Tel: 45 4420 9895 Fax: 45 4420 9910
Detroit
Tri-Atria Office Building 32255 Northwestern Highway, Suite 190 Farmington Hills, MI 48334 Tel: 248-538-2250 Fax: 248-538-2260
China - Shanghai
Microchip Technology Consulting (Shanghai) Co., Ltd. Room 701, Bldg. B Far East International Plaza No. 317 Xian Xia Road Shanghai, 200051 Tel: 86-21-6275-5700 Fax: 86-21-6275-5060
Kokomo
2767 S. Albright Road Kokomo, Indiana 46902 Tel: 765-864-8360 Fax: 765-864-8387
France
Los Angeles
18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 949-263-1888 Fax: 949-263-1338
China - Shenzhen
Microchip Technology Consulting (Shanghai) Co., Ltd., Shenzhen Liaison Office Rm. 1315, 13 / F, Shenzhen Kerry Centre, Renminnan Lu Shenzhen 518001, China Tel: 86-755-2350361 Fax: 86-755-2366086
New York
150 Motor Parkway, Suite 202 Hauppauge, NY 11788 Tel: 631-273-5305 Fax: 631-273-5335
Germany
Microchip Technology GmbH Gustav-Heinemann Ring 125 D-81739 Munich, Germany Tel: 49-89-627-144 0 Fax: 49-89-627-144-44
San Jose
Microchip Technology Inc. 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408-436-7950 Fax: 408-436-7955
Hong Kong
Microchip Technology Hongkong Ltd. Unit 901-6, Tower 2, Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431
Italy
Microchip Technology SRL Centro Direzionale Colleoni Palazzo Taurus 1 V. Le Colleoni 1 20041 Agrate Brianza Milan, Italy Tel: 39-039-65791-1 Fax: 39-039-6899883
Toronto
6285 Northam Drive, Suite 108 Mississauga, Ontario L4V 1X5, Canada Tel: 905-673-0699 Fax: 905-673-6509
India
United Kingdom
Arizona Microchip Technology Ltd. 505 Eskdale Road Winnersh Triangle Wokingham Berkshire, England RG41 5TU Tel: 44 118 921 5869 Fax: 44-118 921-5820
2002 Microchip Technology Inc.
|