M

Author:

AN582
Low-Power Real-Time Clock
the selected units values are displayed. Upon key release, the Timer counts out one second and begins flashing the selected units. The CLR_MIN Key (S3) clears the minutes and seconds. CLR_MIN is useful for exactly setting the time to the “top of the hour” as announced in radio broadcasts. After the INC or SELECT_UNITS keys are depressed, the user has ten seconds to depress the next key. If no keypress is detected within ten seconds, the unit returns to the clock mode. To simplify the design time and minimize cost, a standard Hitachi LCD display module is used. Most applications that require LCDs use a custom LCD display. The LCD interface software would need to be modified to suit the specific LCD display driver being used. Figure 1 is a block diagram of the design. The RA2:RA0 pins are the control signals to the LCD display, RB3:RB0 acts as a 4-bit data bus, and RB7:RB5 are the input switches. The OSC1 pin is connected to an RC network, which generates an approximate 4 MHz device frequency. Because Timer1 operates asynchronously to the device, the device's oscillator can be configured for RC mode. RC oscillator mode is the least expensive and has the quickest start-up time. Timer1 is where an accurate frequency is required. Timer1’s crystal is connected to the T1OSI and T1OSO pins. A good choice for a crystal is a 32.786 kHz (watch) crystal. Table 1 is a list of the components and their part numbers.

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
Upon power-up, the device is initialized with the display starting at 12:00 PM, and Timer1 is configured to generate an interrupt (every second). The Timer1 overflow interrupt wakes the device from sleep. This causes the time registers (HRS, MIN, SECS) to be updated. If the SECS register contains an even value (SECS<0> = 0), the colon (":") is not displayed. This gives a visual indication for each second. Then the device returns to sleep. There are three keys for the setting of the clock. The SELECT_UNITS Key (S1) selects which units are to be modified (hours, minutes, off). The selected units are blanked for a second then flashed for one second. The INC Key (S2) increments the selected units. While incrementing,

FIGURE 1:

CLOCK BLOCK DIAGRAM

VCC VSS 100Ω

VCC VSS

PIC16CXXX RB7 RB6 RB5

3x100Ω

S3 14 13 12 11 4 5 6

S2

S1

MCLR S4 T1OSO 32 kHz T1OSI

RB3 RB2 RB1 RB0

2

RA2 RA1 OSC1 OSC2 RA0

1 10 kΩ 3 10 9 8 LCD Module 7 330Ω

4 MHz 22 pF 22 pF

© 1997 Microchip Technology Inc.

DS00582B-page 1

AN582
Relative to most microelectronics, LCD’s are slow devices. A good portion of the time spent in the Interrupt Service Routine, is talking to and updating the LCD module. To minimize power consumption, the device should be in SLEEP mode as much as possible. By using the conditional assembly, if a flag (called Debug) is true, the total time spent in the subroutine can be seen on the PORTD<0> pin (the high time). Measuring this time on an oscilloscope displayed a typical time of 800 µs that the device is awake. This 800 µs operation is out of the 1 second time that the device needs to service the interrupt (a Timer1 overflow). The accuracy of a real-time clock using Timer1 depends on the accuracy of the crystal being used. The more accurate the crystal, the higher the cost. So as always there is a cost / performance trade-off to be made. A crystal rated with an accuracy of 20 PPM (parts per million), could cause an error of about 1.7 seconds per day. For many applications, this should be adequate (said from someone who doesn’t wear a watch). The program written for this application note shows one method for a real-time clock. Trade-offs between code size, current consumption and desired operation have been made. Some possible alternative implementations are: 1. 2. 3. When displaying the time, update only the characters that changed. Turn off the display during sleep LCD module data interface of 8-bits, as-opposed-to the 4-bit interface. Alternative 1 can reduce the time awake by keeping track of which characters need to be updated. The majority of the time it will be only the position which contains either the “:” or the “ “. Next would be the ones place of the minutes, then the tens place of the minutes, etc. The display would only need to be completely updated 2 times every 24 hours. This would reduce the amount of time talking with the LCD display at the cost of some program / data memory. Depending on the requirements of the application and the characteristics of the display, Alternative 2 could be implemented by turning the power off and on (at a given rate) to the display. This technique may lead to a lower system current consumption. Evaluation of the desired display / display driver is recommended. Alternative 3 uses the LCD module in an 8-bit mode, which will reduce the size of the display routines (save about 20 words of program memory) at the cost of four additional I/O lines. For some applications this may be a good trade-off to get the additional program memory space. The percentage of operating time saved is slight and should not give substantial power savings.

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

© 1997 Microchip Technology Inc.

AN582 CONCLUSION The Timer1 module allows many applications to include a real-time clock at minimal system cost. Table 2 shows the program resource requirements. Program Memory Clock Operation Display(2) Data Memory (1) (2) Variables Scratch RAM Dependent on LCD Module (re. N. Assumes worst case (WC) numbers and best case response from LCD module. © 1997 Microchip Technology Inc.A.A. This time function can be useful in consumer applications (display time) as well as in industrial applications (data time stamp). 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. DS00582B-page 3 . The accuracy of the time is strictly dependent on the accuracy of the crystal. BUSY_CHECK subroutine).

RB<3:0> . Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required). LCD Control Lines . Version 1. . RA2 = RS (Register Select) .com. every second. This program implements a real time clock using the TMR1 module of the .INC Standard Header File. PIC16CXXX family. Three keys are used to set the time. Program = CLOCK. RA1 = RW (Read/Write) . . . . n = 66 ERRORLEVEL -302 . P16C74.40 Released CLOCK. A LCD display module is used to display (update) the time . APPENDIX A: SOURCE CODE LISTING (CLOCK_01. .****************************************************************************** . RA0 = E (Enable) . INCLUDE <p16c74.ASM .inc> LIST . RB6 = Increment Hour / Minute .00 Microchip Technology. AN582 Please check the Microchip BBS for the latest version of the source code.LST) MPASM 01. RB7 = Select Hour / Minute / Off . LIST FALSE TRUE EQU EQU 0 1 .microchip. RB5 = Reset Minutes to 00 . Switch Inputs . 1-15-97 Compatibility with MPASMWIN 1. Microchip’s Worldwide Web Address: www. Revision Date: 5-15-94 .DS00582B-page 4 © 1997 Microchip Technology Inc. HARDWARE SETUP . LCD Data Lines .****************************************************************************** . . . Inc.40 .ASM 1-16-1997 17:05:59 PAGE 1 LOC OBJECT CODE VALUE LINE SOURCE TEXT 00000000 00000001 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00001 00002 00318 00030 00031 00032 LIST P = 16C74.

h> list . PORTB_FLAG . A Debugging Flag . The LCD data is on the lower 4-bits LCD_DATA_TRIS EQU TRISB . BCF STATUS. Error Condition . 0 . Power-up reset? GOTO START . DS00582B-page 5 00000006 00000086 00000005 00000000 00000000 00000001 0000 0000 0001 0002 0003 1683 188E 290C 295E 0004 0004 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 00033 00034 00076 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 INCLUDE <CLOCK. Service the Timer1 Overflow Interrupt BTFSS INTCON. MOVLW DB_HI_BYTE . Bank 1 BTFSC PCON. 2. F . a WDT or MCLR reset . . Set high. RBIF . A Debugging Flag Debug_PU EQU TRUE . GOTO KB_D_LP1 . Need to determine the type . Bank 0 BTFSC PIR1. A Debugging Flag Debug EQU FALSE .© 1997 Microchip Technology Inc. PORTB Change (RBIF) . W . TMR1IF . org RESET_V . LCD_DATA EQU PORTB . RP0 . Timer 1 overflowed? GOTO T1_OVRFL . PICMaster EQU FALSE . . CLRF LSD . This is the Periperal Interrupt routine.Unknown Interrupt . Interrupt vector location PER_INT_V if ( Debug ) bsf PORTD. The TRIS register for the LCD data LCD_CNTL EQU PORTA . AN582 . NO. Determine type of RESET . Three control lines . use to measure total endif . YES GOTO OTHER_RESET . ANDLW 0xE0 . RESET vector location RESET BSF STATUS. TMR1 Overflow Interrupt (T1IF) page org ISR_V . NOT_POR . Did PORTB change? GOTO ERROR1 . RP0 . NO. This is the debounce delay MOVF MSD. Are any of PORTB's inputs active? MOVF PORTB. time in Int Service Routine . NO. YES. of interrupt that occurred. The following interrupts are enabled: . . F . KB_D_LP1 DECFSZ LSD. Reset address. Keep only the 3 switch values DEBOUNCE MOVWF TEMP . 1.

clear the minutes. . Z DEBOUNCE TEMP 0x80 TMR1H TMR1L PIR1. DISPLAY . F STATUS. . . time in Int Service Routine . . KEY_INPUT . Is the hour-min-off switch depressed? YES. . INC_SW INC_UNIT TEMP. Set low. INC_UNIT CLRF BTFSC GOTO BTFSS GOTO or finished with PortB interrupt and need to clear interrupt condition. CLR_RB MOVF BCF if ( Debug ) bcf endif RETFIE . . WAIT_CNTR . Not a valid key. 0 0xFF . . Clear the PORTB mismatch condition . TMR1IF TEMP. . Since doing key inputs. Increment the hour units Are the minute units selected? NO. clear TMR1 . . Return / Enable Global Interrupts PORTB.) . F INTCON. . . . . specify the units selected Is the inc switch depressed? YES. AN582 0011 0012 0013 0014 0015 0016 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 0025 0009 0026 0026 0027 0028 0029 002A 002B 002B 002C 002D 002E 002F 30FF 00C0 0AA0 1620 2875 01C0 1820 285C 1CA0 2823 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 END_DELAY DECFSZ GOTO MOVF ANDLW SUBWF BTFSS GOTO MOVWF MOVLW MOVWF CLRF BCF BTFSS GOTO BTFSS GOTO BTFSS GOTO MSD. for 1 sec overflow. Increment the selected Units Is the clear minute switch depressed? YES. . WAIT_CNTR has LSb set after each SELECT UNIT key press. Flash the Display of the selected unit WAIT_CNTR FLAG_REG.DS00582B-page 6 © 1997 Microchip Technology Inc. No RB<7:5> keys are depressed (rising edge Int. MIN_UNIT CLR_RB . . RBIF PORTD. . W 0xE0 TEMP. need to see which is depressed. No key match occured. . page SELECT_UNITS MOVLW MOVWF INCF BSF GOTO . Clear flags . Clear the PORTB Int Flag . . use to measure total . Are the hour units selected? YES. HR_UNIT INC_HRS FLAG_REG. WAIT_CNTR is cleared to zero after each key press. . . . Keep only the 3 switch values Is the Zero bit set? (switches were the same on 2 reads) NO. . F KB_D_LP1 PORTB. F . HR_MIN_SW SELECT_UNITS TEMP. CLR_MIN_SW CLR_MIN KEY_MATCH . . Try another read YES. Increment the pointer to the MIN_UNIT:HR_UNIT FLAG_REG. . . FLAG_REG. Clear Timer 1 Interrupt Flag .

HR_UNIT FLAG_REG. Rollover from increment key YES. Need to Increment the time YES. page . . Display value YES. . . . . 6 DISPLAY 0x04 SECS MIN. Clear WAIT_CNTR MOVLW MOVWF INCF BTFSS GOTO MOVLW MOVWF INCF 0x80 TMR1H SECS. MIN = 0 (use code from CLR_MIN) MIN = 0 Clear the seconds Initial Second count = 4 Clear Timer 1. . . . AN582 . F . . . YES. . MIN_UNIT . . . CLR_MIN_SW DISPLAY FLAG_REG. .© 1997 Microchip Technology Inc. . Z DISPLAY MIN 0x04 SECS 0x80 TMR1H TMR1L PIR1. . . KEY_INPUT INC_TIME WAIT_CNTR. W STATUS. . KEY_INPUT FLAG_REG. display time YES. . MIN_UNIT FLAG_REG. TMR1IF WAIT_CNTR TEMP. F 0x0A WAIT_CNTR. F SECS. . T1_OVRFL BCF BTFSS GOTO INCF MOVLW SUBWF BTFSS GOTO CLRF BCF BCF BCF . . . . for 1 sec overflow Clear the TMR1 overflow interrupt. HR_UNIT FLAG_REG. KEY_INPUT DISPLAY . Clear Timer 1 Interrupt Flag Are we using the key inputs? NO. . Is the clear minute switch depressed? NO. . . . .60 = ? MIN = 60? NO. Clear ALL relevant flags . . INC_TIME PIR1. DS00582B-page 7 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 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 . TMR1IF FLAG_REG. . . F 0x3C MIN. 1 Second Overflow . 10 counts x 1 seconds Has the 10 Sec wait for key expired? Is the result 0? NO. . Increment the minute units This is Decimal 60 MIN . . WAIT_CNTR is cleared to zero after each key press. . Z DISPLAY WAIT_CNTR FLAG_REG. INCF MOVLW SUBWF BTFSS GOTO CLR_MIN CLRF MOVLW MOVWF MOVLW MOVWF CLRF BCF CLRF BTFSC GOTO BCF BCF BCF GOTO MIN. W STATUS. . . .

. we need to flash selected units . . Cursor On Send This command to the Display Module Clear the Display Send This command to the Display Module Set Entry Mode Inc. . DISPLAY MOVLW CALL . . AM DISPLAY FLAG_REG. NO. . Toggle AM / PM Need to check if HRS = 13 Was it AM or PM Was PM. . . W STATUS. AM DISPLAY 0x0D HRS. YES. Z CK_13 FLAG_REG. . .. 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 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 INC_HRS MOVLW SUBWF BTFSS GOTO CLRF INCF MOVLW SUBWF BTFSS GOTO BTFSS GOTO BCF GOTO BSF GOTO MOVLW SUBWF BTFSS GOTO CLRF INCF GOTO 0x3C MIN.DS00582B-page 8 © 1997 Microchip Technology Inc. . . F 0x0C HRS. Needs to be AM It is PM It is AM SET_AM CK_13 . . KEY_INPUT FLASH_UNITS LOAD_HRS LOAD_COLON LOAD_MIN LOAD_AM . FLAG_REG. W STATUS. F DISPLAY . . . . . . . Z DISPLAY MIN HRS. . DISP_ON SEND_CMD CLR_DISP SEND_CMD ENTRY_INC SEND_CMD . . Do we need to flash the selected units? . . . W STATUS. page INIT_DISPLAY MOVLW CALL MOVLW CALL MOVLW CALL RETURN . Check if HRS = 13 . Display On. W = 60d . . . It is now 12:00. DD_RAM_ADDR SEND_CMD . AM SET_AM FLAG_REG. . No shift Send This command to the Display Module . do a normal display . . . BTFSC GOTO CALL CALL CALL GOTO . Z DISPLAY HRS HRS. .

0 . 256 bytes of program memory 00224 ANDLW 0x03 . 0 0 . : always on. 00263 .Need to clear FLAG_REG<HR_UNIT:MIN_UN IT> 00232 ANDWF FLAG_REG. Display hours 00260 MOVLW ':' .Flash the minute units 00230 UNIT_TBL_END 00231 MOVLW 0xFC . 00252 MOVLW ':' . 00262 BTFSS WAIT_CNTR.Display everything. W . minute digits are displayed as blank 00264 GOTO SKIP_BLK_MIN . This table in 1st 00223 MOVF FLAG_REG. 1 1 . 00265 MOVLW ' ' . If WAIT_CNTR is odd. 00234 . 0 . F .Display everything. If WAIT_CNTR is odd. 00246 MOVLW ' ' . only HR_UNIT and MIN_UNIT bit can be non-zero 00225 UNIT_TBL 00226 ADDWF PCL. : always on 00261 CALL SEND_CHAR . HR_UNIT:MIN_UNIT 00227 GOTO NO_UNITS . 0 1 . 00228 GOTO HR_UNITS . This clears PCLATH. 00255 GOTO LOAD_AM . 00239 . 0 . 00256 . WAIT_CNTR was even. 00245 CALL SEND_CHAR . 00242 . 00251 . 00247 CALL SEND_CHAR . 00254 CALL LOAD_MIN . 00257 page 00258 MIN_UNITS 00259 CALL LOAD_HRS . 00244 MOVLW ' ' . 00266 CALL SEND_CHAR . DS00582B-page 9 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 0093 0093 0094 0095 0096 20A4 303A 20D4 1C40 0097 289C 0098 3020 0099 20D4 00221 FLASH_UNITS 00222 CLRF PCLATH . hour digits are displayed as blank 00243 GOTO SKIP_BLK_HRS .Flash the hour units 00229 GOTO MIN_UNITS . display all other character 00253 CALL SEND_CHAR . 00233 GOTO NO_UNITS . 00235 if ( (UNIT_TBL & 0x0FF) >= (UNIT_TBL_END & 0x0FF) ) 00236 MESSG "Warning: Table UNIT_TBL crosses page boundry in computed jump" 00237 endif 00238 . 1 0 . 0 0 . 00248 SKIP_BLK_HRS 00249 BTFSS WAIT_CNTR. display hour digits 00250 CALL LOAD_HRS . 00240 HR_UNITS 00241 BTFSS WAIT_CNTR.© 1997 Microchip Technology Inc. AN582 . F .

0 LOAD_MIN LOAD_AM . WAIT_CNTR was even. . . LOAD_MIN MOVF CALL MOVF CALL CALL . . ASCII value for a Blank space . LOAD_HRS MOVF CALL MOVF CALL CALL . 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 . page LOAD_AM MOVLW ' ' SEND_CHAR WAIT_CNTR. . . 0 ':' . . display minute digits . W BIN_2_BCD MSD. . HRS. . Load the LSD value into the Wreg . . W NUM_TABLE SEND_CHAR LSD. Load the LSD value into the Wreg . . Display all character . . . . . 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 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 MOVLW CALL SKIP_BLK_MIN BTFSS CALL GOTO . . . LOAD_COLON MOVLW BTFSC ADDLW CALL RETURN . MOVF CALL CALL RETURN .DS00582B-page 10 © 1997 Microchip Technology Inc. Send this Character to the Display ' ' SECS. W BIN_2_BCD MSD. Get the ASCII code . Get the ASCII code . W NUM_TABLE SEND_CHAR LSD.' ' SEND_CHAR . Send this Character to the Display ' ' . MOVF CALL CALL RETURN . 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 . . Add delta offset of ASCII Characters Send this Character to the Display MIN. ASCII value for a Blank space Is it an EVEN or ODD second Is ODD. Second colon is ON. W NUM_TABLE SEND_CHAR . LOAD_HRS ':' SEND_CHAR LOAD_MIN LOAD_AM . . NO_UNITS CALL MOVLW CALL CALL GOTO . W NUM_TABLE SEND_CHAR .

binary coded decimal (BCD) munber. . Send this Character to the Display . Add delta offset of ASCII Characters Send this Character to the Display . routine is used by the DISPLAY subroutine.10 . Did this subtract cause a Negative Result? RETLW 0 . Bank 1 . 1 BCF PORTD. Should NEVER get here . RP0 OPTION_REG.'A' SEND_CHAR 'M' SEND_CHAR STATUS. 1 else BSF PORTC. Increment the most significat digit GOTO TENS_SUB . A decimal 10 SUBWF LSD. to convert the time values. YES. This value contain the 1's digit value TENS_SUB MOVLW . C . Clear RBIF . Return from this Routine MOVWF LSD . . .****************************************************************************** . Bank 0 . ERROR1 BCF STATUS. . DS00582B-page 11 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 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 CALL MOVLW BTFSS ADDLW CALL MOVLW CALL . RP0 CLR_RB . BIN_2_BCD CLRF MSD .© 1997 Microchip Technology Inc. This . . W . This BCD number is stored MSD:LSD. page . RP0 . . . AM 'P' . No. 0 endif GOTO ERROR1 . move the result into LSD INCF MSD. . Send this Character to the Display ASCII value for a Blank space Is it AM or PM Is PM. You've displayed the time. if ( Debug ) BSF PORTD. BSF BCF BCF GOTO SEND_CHAR 'A' FLAG_REG. BTFSS STATUS. This value contain the 10's digit value MOVWF LSD . to a . in the W register.****************************************************************************** . NOT_RBPU STATUS. Bank 0 . 0 BCF PORTC. Turn on PORTB Pull-up .******************************************************************* AN582 . . . . F . The BIN_2_BCD routine converts the binary number.

.* This routine splits the command into the upper and lower * . E CHAR. * . RW LCD_CNTL. E LCD_CNTL.* SendChar . . Wait for LCD to be ready . * . RW LCD_CNTL. E LCD_CNTL.DS00582B-page 12 © 1997 Microchip Technology Inc. E CHAR.Sends command to LCD * .* This routine splits the character into the upper and lower * .******************************************************************* SEND_CHAR MOVWF CALL SWAPF ANDLW MOVWF BCF BSF BSF BCF MOVF ANDLW MOVWF BSF BCF RETURN CHAR BUSY_CHECK CHAR. Send data to LCD . . E . E LCD_CNTL.******************************************************************* . Get upper nibble Send data to LCD Set LCD to read Set LCD to command mode toggle E for LCD . Character to be sent is in W . Get lower nibble . upper nibble first.Sends character to LCD * . upper nibble first.* The data is transmitted on the PORT<3:0> pins * . . . RS LCD_CNTL. W 0x0F LCD_DATA LCD_CNTL. toggle E for LCD . Character to be sent is in W . W 0x0F LCD_DATA LCD_CNTL. E . . 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 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 .******************************************************************* SEND_CMD MOVWF CALL SWAPF ANDLW MOVWF BCF BCF BSF BCF MOVF ANDLW MOVWF BSF BCF RETURN page CHAR BUSY_CHECK CHAR. . .* The data is transmitted on the PORT<3:0> pins * . Wait for LCD to be ready . toggle E for LCD . Send data to LCD .* nibbles and sends them to the LCD.* SendCmd . Get upper nibble Send data to LCD Set LCD to read Set LCD to data mode toggle E for LCD .* nibbles and sends them to the LCD. RS LCD_CNTL. W 0x0F LCD_DATA LCD_CNTL. W 0x0F LCD_DATA LCD_CNTL. E LCD_CNTL. Get lower nibble .

Read lower nibble busy flag.****************************************************************************** . RP0 . POWER_ON Reset (Beginning of program) BCF STATUS. Set PortB for input MOVWF LCD_DATA_TRIS BCF STATUS. E . RW BSF STATUS. Mask out upper nibble IORWF TEMP. RS .* This routine checks the busy flag. E . RP0 . MOVWF LCD_DATA_TRIS . Set LCD for Command mode BSF LCD_CNTL. returns when not busy * . DDRam address ANDLW 0x0F . DS00582B-page 13 00F2 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 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 . if ( Debug ) BSF PORTD. 7 .© 1997 Microchip Technology Inc. Set E high BCF LCD_CNTL. Bank 0 RETURN .******************************************************************* BUSY_CHECK .****************************************************************************** . . DDRam address ANDLW 0xF0 . F . W . high = busy GOTO BUSY_CHECK . RP0 . Set E low SWAPF LCD_DATA. Check busy flag. page . Bank 0 AN582 . Turn off PORTB Pull-up MOVLW 0xFF . E . RP0 . 3 BCF PORTD. W .* TEMP .4 = inputs. E MOVF LCD_DATA. RW .* Affects: * . RB7 . Combine nibbles BTFSC TEMP. check again BCF LCD_CNTL. Bank 1 MOVLW 0xF0 . Power-On Reset occurred. Setup to read busy flag BSF LCD_CNTL. Toggle E to get lower nibble BCF LCD_CNTL. START . 3 endif CLRF LCD_DATA . NOT_RBPU . Mask out lower nibble MOVWF TEMP .******************************************************************* .***** Start program here. RB3 .** Have PORTB<3:0> output low BSF STATUS. .0 = output BCF STATUS. RP0 . Read upper nibble busy flag. Bank 0 BCF LCD_CNTL. BSF LCD_CNTL.Returned with busy/address * . If busy. Bank 1 BSF OPTION_REG.

BCF CLRF CLRF CLRF CLRF CLRF BCF . TIM1H:TMR1L = 0x8000 gives 1 second overflow. Do initialization (Bank 0) .4 inputs. . . . STATUS INTCON PIR1 STATUS. TMR1ON . ALL PORT output should output Low. set up of PORTB . RB3 . F . MCLR_RESET CLRF CLRF CLRF BSF MOVLW MOVWF CLRF MOVLW MOVWF . RP0 0x00 OPTION_REG PIE1 0xFF ADCON1 . Enable PORTB pull-ups STATUS. .60d) This allows a simple bit test to see if 60 secs has elapsed. RC Port are outputs TRISC. 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 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 00481 00482 00483 00484 00485 00486 00487 00488 00489 00490 00491 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 MOVLW MOVWF CLRF MOVLW MOVWF MOVLW MOVWF MOVLW MOVWF CLRF . . . STATUS.0 outputs 0xF0 . . RD Port are outputs TRISE . A Master Clear Reset . . . RBIF . TMR1IE . Select Bank 1 TRISA . . RB7 . Need to clear 1st RBIF. . Enable TMR1 Interrupt OPTION_REG. BSF CLRF MOVLW MOVWF CLRF BSF CLRF CLRF BSF BCF BCF MOVF BCF .0 outputs TRISC . . RC0 needs to be input for the oscillator to function TRISD . RP0 . Bank 1 . . Timer 1 is NOT incrementing STATUS. Select Bank 0 PORTB. RP0 PORTA PORTB PORTC PORTD PORTE T1CON. Decimal 12 HOURS = 12 MIN = 00 PM light is on Initial value of seconds (64d . Bank 0 . TRISB . The LCD module does not like to work w/ weak pull-ups . NOT_RBPU . page 0x0C HRS MIN 0x00 FLAG_REG 0x04 SECS 0x80 TMR1H TMR1L . RA5 . . T1OSO . Disable all peripheral interrupts . Port A is Digital (for 16C7x devices). RE Port are outputs PIE1. RP0 . due to INTCON. at 32 KHz.DS00582B-page 14 © 1997 Microchip Technology Inc.

Command for 4-bit interface MOVWF LCD_DATA . . ALL PORT output should output Low. CALL SEND_CMD . . BCF LCD_CNTL. E . F . CMD_SEQ MOVLW 0X02 MOVWF LCD_DATA BSF LCD_CNTL. . It uses registers before they are needed to . . LCD_DELAY MOVLW LCD_INIT_DELAY . based on the LCD_INIT_DELAY EQUate that includes the . BSF LCD_CNTL. . DECFSZ MSD. . CALL SEND_CMD . MOVLW ENTRY_INC . MOVLW 0x08 . . AN582 . be executed. Use MSD and LSD Registers to Initialize LCD CLRF LSD . DISPLAY_INIT MOVLW 0x02 . E . LOOP2 DECFSZ LSD. Initilize the LCD Display Module . CALL SEND_CMD . . MOVWF MSD . F . DS00582B-page 15 0134 0185 0135 0135 0136 0137 0138 3002 0086 1405 1005 0139 013A 013B 013C 013D 013E 013F 013F 3006 00B3 01B4 0BB4 293C 0BB3 293C 0140 0141 0142 0143 0144 0145 0146 0147 3002 0086 1405 1005 3008 0086 1405 1005 0148 0149 014A 014B 014C 014D 014E 014F 300C 20E3 3001 20E3 3006 20E3 3080 20E3 00502 00503 00504 00505 00506 00507 00508 00509 00510 00511 00512 00513 00514 00515 00516 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 00528 00529 00530 00531 00532 00533 00534 00535 00536 00537 00538 00539 00540 00541 00542 00543 00544 00545 00546 00547 00548 . BSF LCD_CNTL. store the time. MOVLW DD_RAM_ADDR . E . BCF LCD_CNTL. . CALL SEND_CMD . E . E . Command sequence for 2 lines of 5x7 characters . MOVLW DISP_ON . END_LCD_DELAY GOTO LOOP2 . Busy Flag should be valid after this point . MOVLW CLR_DISP . frequency of operation.© 1997 Microchip Technology Inc. CLRF LCD_CNTL . This routine takes the calculated times that the delay loop needs to . Delay time = MSD * ((3 * 256) + 3) * Tcy GOTO LOOP2 . BCF LCD_CNTL. E . MOVWF LCD_DATA .

Disable PORTB<7:4> Change Interrupts BSF INTCON. AN582 0150 0151 0152 0153 0154 0155 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 00549 00550 00551 00552 00553 00554 00555 00556 00557 00558 00559 00560 00561 00562 00563 00564 00565 00566 00567 00568 00569 00570 00571 00572 00573 00574 00575 00576 00577 00578 00579 00580 00581 00582 00583 00584 00585 00586 00587 00588 00589 00590 00591 00592 00593 00594 00595 page . Goto START else GOTO MCLR_RESET . page . Enable all Interrupts . Here is where you do things depending on the type of RESET (Not a Power-On Reset). RBIE . prescaler = 1 BSF T1CON. . YES. Enable T1 Oscillator. Goto MCLR_RESET endif . NUM_TABLE MOVWF TEMP . CALL DISPLAY . MOVLW 0x0E MOVWF T1CON . WDT Time-out? WDT_TIMEOUT GOTO ERROR1 . Turn Timer 1 ON . Store value to TEMP register . Async.NOT_TO . MCLR reset. or TMR1 timeout NOP . END label for debug endif . . org TABLE_ADDR . Wait for Change on PORTB interrupt. GOTO SLEEP_LP . TMR1ON . CLRF PIR1 . Enable Peripheral Interrupts BSF INTCON. MCLR reset. .DS00582B-page 16 © 1997 Microchip Technology Inc. if (Debug ) END_START NOP . Ext Clock. Loop waiting for interrupts (for use with PICMASTER) else . Initialize the Special Function Registers (SFR) interrupts . if ( PICMaster ) lzz goto lzz . This is error condition if ( Debug_PU ) goto START . PEIE . OTHER_RESET BTFSS STATUS. SLEEP_LP SLEEP . . RC1 is overridden by TCKO BSF INTCON. endif . MOVLW 0x0E MOVWF T1CON . CALL INIT_DISPLAY . GIE . .

W 0x0F PCL. . F '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' 'E' 'E' 'E' 'E' 'E' 'E' NUM_TBL_END .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 MEMORY USAGE MAP ('X' = Used. DS00582B-page 17 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 00596 00597 00598 00599 00600 00601 00602 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 00621 00622 00623 00624 00625 00626 00627 NUM_TBL MOVLW MOVWF MOVF ANDLW ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW HIGH (TABLE_ADDR) PCLATH TEMP. . . . . . if ( (NUM_TBL & 0xFF00) != (NUM_TBL_END & 0xFF00) ) MESSG "Warning: Table NUM_TBL crosses page boundry in computed jump" endif . . . . org PMEM_END . . . . '-' = Unused) 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 . . If you get here your program was lost end . .© 1997 Microchip Technology Inc. . Ensure that PCLATH high has the correct value Value into table Mask to 4-bits (00 . . End of Program Memory GOTO ERROR1 . . . . . . .

DS00582B-page 18 © 1997 Microchip Technology Inc. AN582 All other memory blocks unused. 0 suppressed 16 suppressed . Program Memory Words Used: Program Memory Words Free: 376 3720 Errors : Warnings : Messages : 0 0 reported. 0 reported.

AN582 Please check the Microchip BBS for the latest version of the source code. RAM Location . PROGRAM: CLOCK. The switch to clear the minutes and seconds .H INCLUDE FILE nolist . AM EQU 0x07 . Counter that holds wait time for key inputs .com. KEY_INPUT EQU 0x04 . LCD Enable control line R_W EQU 1 . Temporary register. Last address in Program Memory TABLE_ADDR EQU 0x0400 . .H . The value of Dev_Freq must be changed to . DS00582B-page 19 . E EQU 0 . Flag to specify if AM or PM . | AM | --. Holds value to send to LCD module. Address where to start Tables . . LCD Register Select control line .| MIN_UNIT | HR_UNIT | . . FLAG_REG EQU 0x020 .microchip. MIN. . (HRS. +------+-------+-------+-----------+-------+-------+----------+---------+ .| KEY_INPUT | --. . Register which contains flag bits . T1OSO EQU 0 . APPENDIX B: CLOCK_01. . +------+-------+-------+-----------+-------+-------+----------+---------+ . Holds counter value for SECONDS MSD EQU 0x033 . Address of RESET Vector ISR_V EQU 0x0004 . RESET_V EQU 0x0000 . Temporary register. Dev_Freq EQU D’4000000’ . Holds LSD of BIN to BCD conversion TEMP EQU 0x035 . Holds MSD of BIN to BCD conversion LSD EQU 0x034 . LCD Display Commands and Control Signal names. Microchip’s Worldwide Web Address: www. Address of Interrupt Vector PMEM_END EQU 0x07FF . Holds counter value for HOURS MIN EQU 0x031 . The switch to increment the selected units CLR_MIN_SW EQU 0x5 . . Device Frequency is 4 MHz DB_HI_BYTE EQU (HIGH ((( Dev_Freq / 4 ) * 1 / D’1000’ ) / 3 ) ) + 1 LCD_INIT_DELAY EQU (HIGH ((( Dev_Freq / 4 ) * D’46’ / D’10000’ ) / 3 ) ) + 1 INNER_CNTR EQU 40 RAM Location OUTER_CNTR EQU 41 . HR_MIN_SW EQU 0x7 .| --. This is used for the ASSEMBLER to recalculate certain frequency . The RC0 / T1OSO / T1CKI . MIN_UNIT EQU 0x01 . . HRS EQU 0x030 . reflect the frequency that the device actually operates at. This is the custom Header File for the real time clock application note . LCD Module commands .****************************************************************************** . or none) . Temporary register CHAR EQU 0x036 . Holds counter value for MINUTES SECS EQU 0x032 . Flags to specify which units to operate on HR_UNIT EQU 0x00 . © 1997 Microchip Technology Inc. Temporary register. Revision:5-10-94 . Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required). LCD Read/Write control line RS EQU 2 . The switch to select the units INC_SW EQU 0x6 . . dependant variables. Flag to specify if doing key inputs . WAIT_CNTR EQU 0x040 .| --. .****************************************************************************** .

list EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU 0x00C 0x00E 0x00F 0x008 0x001 0x006 0x007 0x004 0x005 0x080 0x080 . . . . Cursor on Display on. Display on Display on. . Blink cursor Display off Clear the Display Least Significant 7-bit are for address Upper Left corner of the Display DS00582B-page 20 © 1997 Microchip Technology Inc. . . . . . .AN582 DISP_ON DISP_ON_C DISP_ON_B DISP_OFF CLR_DISP ENTRY_INC ENTRY_INC_S ENTRY_DEC ENTRY_DEC_S DD_RAM_ADDR DD_RAM_UL . Cursor on. .

EQUates for Special Function Registers .h . . File = C64_reg.************ Bit Definitions ************ © 1997 Microchip Technology Inc. 10-18-93 by MP to make Page ok . Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required). 11-15-93 by MP to have correct pages for SFR .microchip.H INCLUDE FILE NOLIST .com. APPENDIX C: C74_REG. Microchip’s Worldwide Web Address: www. INDF EQU 00 TMR0 EQU 01 OPTION_R EQU 81 PCL EQU 02 STATUS EQU 03 FSR EQU 04 PORTA EQU 05 TRISA EQU 85 PORTB EQU 06 TRISB EQU 86 PORTC EQU 07 TRISC EQU 87 PORTD EQU 08 TRISD EQU 88 PORTE EQU 09 TRISE EQU 89 PCLATH EQU 0A INTCON EQU 0B PIR1 EQU 0C PIE1 EQU 8C TMR1L EQU 0E PCON EQU 8E TMR1H EQU 0F T1CON EQU 10 TMR2 EQU 11 T2CON EQU 12 PR2 EQU 92 SSPBUF EQU 13 SSPADD EQU 93 SSPCON EQU 14 SSPSTAT EQU 94 CCPR1L EQU 15 CCPR1H EQU 16 CCP1CON EQU 17 RCSTA EQU 18 TXSTA EQU 98 TXREG EQU 19 SPBRG EQU 99 RCREG EQU 1A CCPR2L EQU 1B CCPR2H EQU 1C CCP2CON EQU 1D ADRES EQU 1E ADCON0 EQU 1F ADCON1 EQU 9F .AN582 Please check the Microchip BBS for the latest version of the source code. DS00582B-page 21 . . .********************************************** . Rev. History: 08-04-93 by MP . .

. . T1CON register (Address 10) DS00582B-page 22 © 1997 Microchip Technology Inc. STATUS register (Address 03/83) . PSPIF EQU 7 SSPIF EQU 3 CCP1IF EQU 2 TMR2IF EQU 1 TMR1IF EQU 0 . . OPTION register (Address 81) . GI EQU 7 PEIE EQU 6 T0IE EQU 5 INTE EQU 4 RBIE EQU 3 T0IF EQU 2 INTF EQU 1 RBIF EQU 0 . POR EQU 1 . TRISE register (Address 89) . . . . IRP EQU 7 RP1 EQU 6 RP0 EQU 5 TO EQU 4 PD EQU 3 Z EQU 2 DC EQU 1 C EQU 0 . PSPIE EQU 7 SSPIE EQU 3 CCP1IE EQU 2 TMR2IE EQU 1 TMR1IE EQU 0 . . PIR1 register (Address 0C) . PIE1 register (Address 8C) . . . RBPU EQU 7 INTEDG EQU 6 T0CS EQU 5 T0SE EQU 4 PSA EQU 3 PS2 EQU 2 PS1 EQU 1 PS0 EQU 0 . INTCON register (Address 0B/8B) . IBF EQU 7 OBF EQU 6 IBOV EQU 5 PSPMODE EQU 4 TRISE2 EQU 2 TRISE1 EQU 1 TRISE0 EQU 0 .AN582 .********************************************** . PCON register (Address 8E) .

. . TOUTPS3 EQU 6 TOUTPS2 EQU 5 TOUTPS1 EQU 4 TOUTPS0 EQU 3 TMR2ON EQU 2 T2CKPS1 EQU 1 T2CKPS0 EQU 0 .AN582 . DS00582B-page 23 . CCP1X EQU 5 CCP1Y EQU 4 CCP1M3 EQU 3 CCP1M2 EQU 2 CCP1M1 EQU 1 CCP1M0 EQU 0 . . SPEN EQU 7 RC89 EQU 6 SREN EQU 5 CREN EQU 4 FERR EQU 2 OERR EQU 1 RCD8 EQU 0 . . WCOL EQU 7 SSPOV EQU 6 SSPEN EQU 5 CKP EQU 4 SSPM3 EQU 3 SSPM2 EQU 2 SSPM1 EQU 1 SSPM0 EQU 0 . T2CON register (Address 12) . DA EQU 5 P EQU 4 S EQU 3 RW EQU 2 UA EQU 1 BF EQU 0 . T1CKPS1 EQU 5 T1CKPS0 EQU 4 T1OSCEN EQU 3 T1INSYNC EQU 2 TMR1CS EQU 1 TMR1ON EQU 0 . . SSPSTAT register (Address 94) . CSRC EQU 7 TX89 EQU 6 TXEN EQU 5 SYNC EQU 4 BRGH EQU 2 TRMT EQU 1 TXD8 EQU 0 © 1997 Microchip Technology Inc. RCSTA register (Address 18) . TXSTA register (Address 98) . SSPCON register (Address 14) . CCP1CON register (Address 17) . .

.*********************************************** . PCFG2 EQU 2 PCFG1 EQU 1 PCFG0 EQU 0 . . ADCS1 EQU 7 ADCS0 EQU 6 CHS2 EQU 5 CHS1 EQU 4 CHS0 EQU 3 GO EQU 2 DONE EQU 2 ADON EQU 0 .*********************************************** . ADCON1 register (Address 9F) . . ADCON0 register (Address 1F) .**** Bits for destination control . W EQU 0 F EQU 1 . .AN582 . . FALSE EQU 0 TRUE EQU 1 LIST DS00582B-page 24 © 1997 Microchip Technology Inc.**** W = W register is destination .**** F = File register is destination . CCP2CON register (Address 1D) . CCP2X EQU 5 CCP2Y EQU 4 CCP2M3 EQU 3 CCP2M2 EQU 2 CCP2M1 EQU 1 CCP2M0 EQU 0 .

microPort. ECONOMONITOR.. microID. PRO MATE.A. SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U. Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Arizona in July 1999. . Trademarks The Microchip name and logo. ICEPIC. In-Circuit Serial Programming. • • • The PICmicro family meets the specifications contained in the Microchip Data Sheet. The person doing so may be engaged in theft of intellectual property. Serialized Quick Turn Programming (SQTP) is a service mark of Microchip Technology Incorporated in the U. dsPIC. FlexROM. PICMASTER.S. Microchip Technology Incorporated.net. Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates.A. Code protection is constantly evolving. • • • If you have any further questions about this matter. PICC. or infringement of patents or other intellectual property rights arising from such use or otherwise. No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information.Note the following details of the code protection feature on PICmicro® MCUs.S. MPLIB. Microchip believes that its family of PICmicro microcontrollers is one of the most secure products of its kind on the market today. All Rights Reserved.S. Use of Microchip’s products as critical components in life support systems is not authorized except with express written approval by Microchip. rfPIC. Code protection does not mean that we are guaranteeing the product as “unbreakable”. FanSense.A. All other trademarks mentioned herein are property of their respective companies. PIC. when used in the intended manner and under normal conditions. PICDEM. All of these methods. MPASM. We at Microchip are committed to continuously improving the code protection features of our product. to our knowledge. design and wafer fabrication facilities in Chandler and Tempe. Microchip is willing to work with the customer who is concerned about the integrity of their code. Serial EEPROMs and microperipheral products. MPLINK.S.A.  2002 Microchip Technology Inc. No licenses are conveyed. fuzzyLAB. PICmicro. There are dishonest and possibly illegal methods used to breach the code protection feature. PICDEM. Microchip’s quality system for the design and manufacture of development systems is ISO 9001 certified. MXDEV. Migratable Memory. KEELOQ. KEELOQ® code hopping devices. It is your responsibility to ensure that your application meets with your specifications. Microchip received QS-9000 quality system certification for its worldwide headquarters. In addition. The Company’s quality system processes and procedures are QS-9000 compliant for its PICmicro® 8-bit MCUs. Printed on recycled paper. the Microchip logo. ICSP. under any intellectual property rights. © 2002. and other countries. implicitly or otherwise. please contact the local sales office nearest to you. PICSTART. Select Mode and Total Endurance are trademarks of Microchip Technology Incorporated in the U. FilterLab. MPSIM. Printed in the U. MPLAB. require using the PICmicro microcontroller in a manner outside the operating specifications contained in the data sheet.

Wing A (A3/A4) No. Tower 2.. 207 Tung Hua North Road Taipei. TX 75001 Tel: 972-818-7423 Fax: 972-818-2924 China . GA 30350 Tel: 770-640-0034 Fax: 770-640-0307 Singapore Microchip Technology Singapore Pte Ltd. Germany Tel: 49-89-627-144 0 Fax: 49-89-627-144-44 San Jose Microchip Technology Inc. World Trade Plaza No. China Tel: 86-755-2350361 Fax: 86-755-2366086 New York 150 Motor Parkway. India Tel: 91-80-2290061 Fax: 91-80-2290062 United Kingdom Arizona Microchip Technology Ltd. MI 48334 Tel: 248-538-2250 Fax: 248-538-2260 China .Shenzhen Microchip Technology Consulting (Shanghai) Co. China Tel: 86-28-6766200 Fax: 86-28-6766599 Taiwan Microchip Technology Taiwan 11F-3. O’Shaugnessey Road Bangalore. 560 025. Ontario L4V 1X5. MA 01886 Tel: 978-692-3848 Fax: 978-692-3821 China . Kangnam-Ku Seoul. Shenzhen Kerry Centre. Suite 190 Farmington Hills. Chandler. NSW Australia Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 Japan Microchip Technology Japan K. France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Los Angeles 18201 Von Karman. Ltd. India Liaison Office Divyasree Chambers 1 Floor.T. 100027.ler Etage 91300 Massy. AZ 85224-6199 Tel: 480-792-7966 Fax: 480-792-7456 China . CA 92612 Tel: 949-263-1888 Fax: 949-263-1338 China . Suite 180 Itasca. Ltd. Metroplaza 223 Hing Fong Road Kwai Fong. Room 701. No. Taiwan Tel: 886-2-2717-7175 Fax: 886-2-2545-0139 Chicago 333 Pierce Road. Suite 160 Addison. Unit 901-6. 188980 Tel: 65-334-8870 Fax: 65-334-8850 Boston 2 Lan Drive. AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: 480-792-7627 Web Address: http://www. 24th Floor. Suite 1090 Irvine. No. 6 Chaoyangmen Beidajie Beijing. 2401.M WORLDWIDE SALES AND SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd. Benex S-1 6F 3-18-20. 200051 Tel: 86-21-6275-5700 Fax: 86-21-6275-5060 Kokomo 2767 S.6166 Fax: 81-45-471-6122 Rocky Mountain 2355 West Chandler Blvd. China Tel: 86-10-85282100 Fax: 86-10-85282104 Korea Microchip Technology Korea 168-1. 11. Canada Tel: 905-673-0699 Fax: 905-673-6509 India Microchip Technology Inc. Albright Road Kokomo. Suite 108 Mississauga. Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 Italy Microchip Technology SRL Centro Direzionale Colleoni Palazzo Taurus 1 V. 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. 505 Eskdale Road Winnersh Triangle Wokingham Berkshire. Ltd.. Fuzhou Liaison Office Unit 28F..com ASIA/PACIFIC Australia Microchip Technology Australia Pty Ltd Suite 22. 88 TIDU Street Chengdu 610016.Fuzhou Microchip Technology Consulting (Shanghai) Co. Bldg.K. Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934 Atlanta 500 Sugar Mill Road. IL 60143 Tel: 630-285-0071 Fax: 630-285-0075 Dallas 4570 Westgrove Drive. Indiana 46902 Tel: 765-864-8360 Fax: 765-864-8387 France Microchip Technology SARL Parc d’Activite du Moulin de Massy 43 Rue du Saule Trapu Batiment A . Le Colleoni 1 20041 Agrate Brianza Milan. 317 Xian Xia Road Shanghai. Shinyokohama Kohoku-Ku.Chengdu Microchip Technology Consulting (Shanghai) Co. 3 Floor Samsung-Dong.Shanghai Microchip Technology Consulting (Shanghai) Co. Youngbo Bldg. NY 11788 Tel: 631-273-5305 Fax: 631-273-5335 Germany Microchip Technology GmbH Gustav-Heinemann Ring 125 D-81739 Munich. No.. Suite 120 Westford. 71 Wusi Road Fuzhou 350001. 2107 North First Street. Shenzhen Liaison Office Rm... 13/F. 200 Middle Road #07-02 Prime Centre Singapore.microchip. Renminnan Lu Shenzhen 518001. Suite 202 Hauppauge.Beijing Microchip Technology Consulting (Shanghai) Co. Japan Tel: 81-45-471. Suite 590 San Jose. 105. Italy Tel: 39-039-65791-1 Fax: 39-039-6899883 Toronto 6285 Northam Drive. Beijing Liaison Office Unit 915 Bei Hai Wan Tai Bldg.. Yokohama-shi Kanagawa. Chandler. Ltd. Chengdu Liaison Office Rm. . B Far East International Plaza No. 1315. N. 222-0033. Ltd.. 41 Rawson Street Epping 2121.. Ming Xing Financial Tower No.. Suite 200B Atlanta. England RG41 5TU Tel: 44 118 921 5869 Fax: 44-118 921-5820 01/18/02  2002 Microchip Technology Inc. CA 95131 Tel: 408-436-7950 Fax: 408-436-7955 Hong Kong Microchip Technology Hongkong Ltd.

Sign up to vote on this title
UsefulNot useful