AN0582 low power real time clock

26 289 0
AN0582   low power real time clock

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

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 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 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 OPERATION Figure 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 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 is a list of the components and their part numbers 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), 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 PIC16CXXX RB7 VCC VCC VSS VSS RB5 MCLR RB3 RB2 RB1 RB0 3x100Ω RB6 S2 S3 S1 100Ω S4 T1OSO 32 kHz T1OSI RA2 RA1 OSC1 OSC2 RA0 14 13 12 11 10 kΩ 330Ω MHz 22 pF  1997 Microchip Technology Inc 22 pF 10 LCD Module DS00582B-page 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 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 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) Alternative 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 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 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 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 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: 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 TABLE 1: LIST OF COMPONENTS† Description Part Number Manufacturer Quantity LCD Module (2 x 20 Characters) LM032L Hitachi Switches EVQPADO4M Panasonic Microcontroller PIC16C64 / 74 Microchip 32.768 kHz Crystal NC26 / NC38 FOX MHz Crystal ECS-40-20-1 ECS † Most components available from DigiKey DS00582B-page  1997 Microchip Technology Inc 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 shows the program resource requirements TABLE 2: PROGRAM RESOURCE REQUIREMENTS Resource Initialization Program Memory Clock Operation Data Memory (1) (2) Increment Time WC Key Input WC Words / Bytes Cycles 61 61 106 35 + Display 35 + Display Time Display(2) 208 526(1) Variables N.A Scratch RAM N.A Dependent on LCD Module (re; BUSY_CHECK subroutine) Assumes worst case (WC) numbers and best case response from LCD module  1997 Microchip Technology Inc DS00582B-page APPENDIX A: SOURCE CODE LISTING (CLOCK_01.LST) MPASM 01.40 Released LOC OBJECT CODE VALUE  1997 Microchip Technology Inc 00000000 00000001 CLOCK.ASM 1-16-1997 17:05:59 PAGE LINE SOURCE TEXT 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, n = 66 ERRORLEVEL -302 ; ;****************************************************************************** ; ; This program implements a real time clock using the TMR1 module of the ; PIC16CXXX family A LCD display module is used to display (update) the time ; every second Three keys are used to set the time ; ; Program = CLOCK.ASM ; Revision Date: 5-15-94 ; 1-15-97 Compatibility with MPASMWIN 1.40 ; ;****************************************************************************** ; ; ; HARDWARE SETUP ; LCD Control Lines ; RA0 = E (Enable) ; RA1 = RW (Read/Write) ; RA2 = RS (Register Select) ; LCD Data Lines ; RB ; Switch Inputs ; RB7 = Select Hour / Minute / Off ; RB6 = Increment Hour / Minute ; RB5 = Reset Minutes to 00 ; INCLUDE LIST ; P16C74.INC Standard Header File, Version 1.00 Microchip Technology, Inc LIST FALSE TRUE EQU EQU AN582 DS00582B-page Please check the Microchip BBS for the latest version of the source code Microchip’s Worldwide Web Address: www.microchip.com; Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required)  1997 Microchip Technology Inc 00000006 00000086 00000005 00000000 00000000 00000001 0000 0000 0001 0002 0003 1683 188E 290C 295E 0004 0004 1283 180C 2843 1C0B 28D0 0009 0009 000A 000B 000C 000D 000E 000F 0010 0806 39E0 00B5 3002 08B3 01B4 0BB4 280F INCLUDE list ; LCD_DATA EQU PORTB ; The LCD data is on the lower 4-bits LCD_DATA_TRIS EQU TRISB ; The TRIS register for the LCD data LCD_CNTL EQU PORTA ; Three control lines ; PICMaster EQU FALSE ; A Debugging Flag Debug EQU FALSE ; A Debugging Flag Debug_PU EQU TRUE ; A Debugging Flag ; ; ; Reset address Determine type of RESET ; org RESET_V ; RESET vector location RESET BSF STATUS, RP0 ; Bank BTFSC PCON, NOT_POR ; Power-up reset? GOTO START ; YES GOTO OTHER_RESET ; NO, a WDT or MCLR reset ; ; This is the Periperal Interrupt routine Need to determine the type ; of interrupt that occurred The following interrupts are enabled: ; PORTB Change (RBIF) ; TMR1 Overflow Interrupt (T1IF) page org ISR_V ; Interrupt vector location PER_INT_V if ( Debug ) bsf PORTD, ; Set high, use to measure total endif ; time in Int Service Routine ; BCF STATUS, RP0 ; Bank BTFSC PIR1, TMR1IF ; Timer overflowed? GOTO T1_OVRFL ; YES, Service the Timer1 Overflow Interrupt BTFSS INTCON, RBIF ; NO, Did PORTB change? GOTO ERROR1 ; NO, Error Condition - Unknown Interrupt ; PORTB_FLAG ; Are any of PORTB's inputs active? MOVF PORTB, W ; ANDLW 0xE0 ; Keep only the switch values DEBOUNCE MOVWF TEMP ; MOVLW DB_HI_BYTE ; This is the debounce delay MOVF MSD, F ; CLRF LSD ; KB_D_LP1 DECFSZ LSD, F ; GOTO KB_D_LP1 ; AN582 DS00582B-page 0004 0005 0006 0007 0008 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 0BB3 280F 0806 39E0 02B5 1D03 0017 280B 0018 00B5 0019 001A 001B 001C 3080 008F 018E 100C 001D 001E 001F 0020 0021 0022 1FB5 2826 1F35 282B 1EB5 2835 0023 0023 0886 0024 100B 0025 0009  1997 Microchip Technology Inc 0026 0026 0027 0028 0029 002A 30FF 00C0 0AA0 1620 2875 002B 002B 002C 002D 002E 002F 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 KEY_MATCH ; DECFSZ GOTO MOVF ANDLW SUBWF BTFSS MSD, F KB_D_LP1 PORTB, W 0xE0 TEMP, F STATUS, Z GOTO MOVWF DEBOUNCE TEMP ; ; ; ; ; ; ; ; ; MOVLW MOVWF CLRF BCF 0x80 TMR1H TMR1L PIR1, TMR1IF ; Since doing key inputs, clear TMR1 ; for sec overflow ; ; Clear Timer Interrupt Flag BTFSS GOTO BTFSS GOTO BTFSS GOTO TEMP, HR_MIN_SW SELECT_UNITS TEMP, INC_SW INC_UNIT TEMP, CLR_MIN_SW CLR_MIN ; ; No key match occured, ; CLR_RB MOVF BCF if ( Debug ) bcf endif RETFIE Keep only the switch values Is the Zero bit set? (switches were the same on reads) NO, Try another read YES, need to see which is depressed ; ; ; ; ; ; Is the hour-min-off switch depressed? YES, specify the units selected Is the inc switch depressed? YES, Increment the selected Units Is the clear minute switch depressed? YES, clear the minutes or finished with PortB interrupt and need to clear interrupt condition PORTB, F INTCON, RBIF PORTD, ; No RB keys are depressed (rising edge Int.) ; Clear the PORTB mismatch condition ; Clear the PORTB Int Flag ; Set low, use to measure total ; time in Int Service Routine ; Return / Enable Global Interrupts ; page SELECT_UNITS MOVLW MOVWF INCF BSF GOTO ; INC_UNIT CLRF BTFSC GOTO BTFSS GOTO 0xFF ; WAIT_CNTR ; WAIT_CNTR has LSb set after each SELECT UNIT key press FLAG_REG, F ; Increment the pointer to the MIN_UNIT:HR_UNIT FLAG_REG, KEY_INPUT ; DISPLAY ; Flash the Display of the selected unit WAIT_CNTR FLAG_REG, HR_UNIT INC_HRS FLAG_REG, MIN_UNIT CLR_RB ; ; ; ; ; WAIT_CNTR is cleared to zero after each key press Are the hour units selected? YES, Increment the hour units Are the minute units selected? NO, Not a valid key Clear flags AN582 DS00582B-page 0011 0012 0013 0014 0015 0016  1997 Microchip Technology Inc 0030 0031 0032 0033 0034 0AB1 303C 0231 1D03 2875 0035 0036 0037 0038 0039 003A 003B 003C 003D 003E 003F 0040 0041 0042 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 3080 008F 0AB2 1F32 2875 3004 00B2 0AB1 ; CLR_MIN INCF MOVLW SUBWF BTFSS GOTO MIN, F 0x3C MIN, W STATUS, Z DISPLAY MIN 0x04 SECS 0x80 TMR1H TMR1L PIR1, TMR1IF WAIT_CNTR TEMP, CLR_MIN_SW DISPLAY FLAG_REG, MIN_UNIT FLAG_REG, HR_UNIT FLAG_REG, KEY_INPUT DISPLAY ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; YES, Increment the minute units This is Decimal 60 MIN - 60 = ? MIN = 60? NO, display time YES, MIN = (use code from CLR_MIN) MIN = Clear the seconds Initial Second count = Clear Timer 1, for sec overflow CLRF MOVLW MOVWF MOVLW MOVWF CLRF BCF CLRF BTFSC GOTO BCF BCF BCF GOTO BCF BTFSS GOTO INCF MOVLW SUBWF BTFSS GOTO CLRF BCF BCF BCF PIR1, TMR1IF FLAG_REG, KEY_INPUT INC_TIME WAIT_CNTR, F 0x0A WAIT_CNTR, W STATUS, Z DISPLAY WAIT_CNTR FLAG_REG, KEY_INPUT FLAG_REG, HR_UNIT FLAG_REG, MIN_UNIT ; ; ; ; ; ; ; ; ; ; ; ; Clear Timer Interrupt Flag Are we using the key inputs? NO, Need to Increment the time YES, 10 counts x seconds Has the 10 Sec wait for key expired? Is the result 0? NO, Display value YES, Clear WAIT_CNTR Clear the TMR1 overflow interrupt WAIT_CNTR is cleared to zero after each key press Is the clear minute switch depressed? NO Rollover from increment key YES, Clear ALL relevant flags ; page ; T1_OVRFL ; ; INC_TIME MOVLW MOVWF INCF BTFSS GOTO MOVLW MOVWF INCF 0x80 TMR1H SECS, F SECS, DISPLAY 0x04 SECS MIN, F ; ; Second Overflow ; ; ; ; ; ; AN582 DS00582B-page 004F 0050 0051 0052 0053 0054 0055 0056 100C 1E20 284F 0AC0 300A 0240 1D03 2875 01C0 1220 1020 10A0 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 303C 0231 1D03 2875 01B1 0AB0 005D 005E 005F 0060 0061 0062 0063 0064 0065 0066 300C 0230 1D03 2867 1FA0 2865 13A0 2875 17A0 2875 0067 0068 0069 006A 006B 006C 006D 300D 0230 1D03 2875 01B0 0AB0 2875  1997 Microchip Technology Inc 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 SET_AM CK_13 AN582 DS00582B-page 0057 0058 0059 005A 005B 005C MOVLW SUBWF BTFSS GOTO CLRF INCF 0x3C MIN, W STATUS, Z DISPLAY MIN HRS, F ; W = 60d ; ; ; ; ; MOVLW SUBWF BTFSS GOTO BTFSS GOTO BCF GOTO BSF GOTO 0x0C HRS, W STATUS, Z CK_13 FLAG_REG, AM SET_AM FLAG_REG, AM DISPLAY FLAG_REG, AM DISPLAY ; ; ; ; ; ; ; ; ; ; MOVLW SUBWF BTFSS GOTO CLRF INCF GOTO 0x0D HRS, W STATUS, Z DISPLAY HRS HRS, F DISPLAY ; Check if HRS = 13 ; ; ; ; ; ; MOVLW CALL MOVLW CALL MOVLW CALL RETURN DISP_ON SEND_CMD CLR_DISP SEND_CMD ENTRY_INC SEND_CMD ; ; ; ; ; ; MOVLW CALL DD_RAM_ADDR SEND_CMD ; ; BTFSC GOTO CALL CALL CALL GOTO FLAG_REG, KEY_INPUT FLASH_UNITS LOAD_HRS LOAD_COLON LOAD_MIN LOAD_AM ; Do we need to flash the selected units? ; YES, we need to flash selected units ; NO, a normal display ; ; ; It is now 12:00, Toggle AM / PM Need to check if HRS = 13 Was it AM or PM Was PM, Needs to be AM It is PM It is AM ; page INIT_DISPLAY Display On, Cursor On Send This command to the Display Module Clear the Display Send This command to the Display Module Set Entry Mode Inc., No shift Send This command to the Display Module ; DISPLAY ; ;  1997 Microchip Technology Inc 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 288D 3020 20D4 3020 20D4 008F 0090 0091 0092 303A 20D4 20B2 28BB 0093 0093 0094 0095 0096 20A4 303A 20D4 1C40 1C40 20A4 0097 289C 0098 3020 0099 20D4 AN582 DS00582B-page 0088 0089 008A 008B 008C 008D 008D 008E 00221 FLASH_UNITS 00222 CLRF PCLATH ; This clears PCLATH, This table in 1st 00223 MOVF FLAG_REG, W ; 256 bytes of program memory 00224 ANDLW 0x03 ; only HR_UNIT and MIN_UNIT bit can be non-zero 00225 UNIT_TBL 00226 ADDWF PCL, F ; HR_UNIT:MIN_UNIT 00227 GOTO NO_UNITS ; 0 - Display everything 00228 GOTO HR_UNITS ; - Flash the hour units 00229 GOTO MIN_UNITS ; - Flash the minute units 00230 UNIT_TBL_END 00231 MOVLW 0xFC ; 1 - Need to clear FLAG_REG 00232 ANDWF FLAG_REG, F ; 00233 GOTO NO_UNITS ; 0 - Display everything 00234 ; 00235 if ( (UNIT_TBL & 0x0FF) >= (UNIT_TBL_END & 0x0FF) ) 00236 MESSG "Warning: Table UNIT_TBL crosses page boundry in computed jump" 00237 endif 00238 ; 00239 ; 00240 HR_UNITS 00241 BTFSS WAIT_CNTR, ; If WAIT_CNTR is odd, 00242 ; hour digits are displayed as blank 00243 GOTO SKIP_BLK_HRS ; 00244 MOVLW ' ' ; 00245 CALL SEND_CHAR ; 00246 MOVLW ' ' ; 00247 CALL SEND_CHAR ; 00248 SKIP_BLK_HRS 00249 BTFSS WAIT_CNTR, ; WAIT_CNTR was even, display hour digits 00250 CALL LOAD_HRS ; 00251 ; 00252 MOVLW ':' ; : always on, display all other character 00253 CALL SEND_CHAR ; 00254 CALL LOAD_MIN ; 00255 GOTO LOAD_AM ; 00256 ; 00257 page 00258 MIN_UNITS 00259 CALL LOAD_HRS ; Display hours 00260 MOVLW ':' ; : always on 00261 CALL SEND_CHAR ; 00262 BTFSS WAIT_CNTR, ; If WAIT_CNTR is odd, 00263 ; minute digits are displayed as blank 00264 GOTO SKIP_BLK_MIN ; 00265 MOVLW ' ' ; 00266 CALL SEND_CHAR ; 009F 009F 00A0 00A1 00A2 00A3 3020 20D4 1C40 20B2 28BB 20A4 303A 20D4 20B2 28BB 00A4 00A4 00A5 00A6 00A7 00A8 0830 20C7 0833 2400 20D4 00A9 00AA 00AB 00AC 0834 2400 20D4 0008 00AD 3020 00AE 1832 00AF 3E1A 00B0 20D4 00B1 0008  1997 Microchip Technology Inc 00B2 00B2 00B3 00B4 00B5 00B6 0831 20C7 0833 2400 20D4 00B7 00B8 00B9 00BA 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 ' ' SEND_CHAR ; ; BTFSS CALL GOTO WAIT_CNTR, LOAD_MIN LOAD_AM ; WAIT_CNTR was even, display minute digits ; ; CALL MOVLW CALL CALL GOTO LOAD_HRS ':' SEND_CHAR LOAD_MIN LOAD_AM ; Display all character ; ; ; ; MOVF CALL MOVF CALL CALL HRS, W BIN_2_BCD MSD, W NUM_TABLE SEND_CHAR ; ; ; ; ; MOVF CALL CALL RETURN LSD, W NUM_TABLE SEND_CHAR ; Load the LSD value into the Wreg ; Get the ASCII code ; Send this Character to the Display MOVLW BTFSC ADDLW ' ' SECS, ':' - ' ' CALL RETURN SEND_CHAR ; ; ; ; ; 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 MOVF CALL MOVF CALL CALL MIN, W BIN_2_BCD MSD, W NUM_TABLE SEND_CHAR ; ; ; ; ; 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 MOVF CALL CALL RETURN LSD, W NUM_TABLE SEND_CHAR ; Load the LSD value into the Wreg ; Get the ASCII code ; Send this Character to the Display MOVLW ' ' ; ASCII value for a Blank space SKIP_BLK_MIN ; NO_UNITS ; LOAD_HRS 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_COLON ; LOAD_MIN ; ; page LOAD_AM AN582 DS00582B-page 10 009A 009B 009C 009C 009D 009E  1997 Microchip Technology Inc 00E3 00E3 00E4 00E5 00E6 00E7 00E8 00E9 00EA 00EB 00EC 00ED 00EE 00EF 00F0 00F1 00B6 20F2 0E36 390F 0086 1085 1505 1405 1005 0836 390F 0086 1405 1005 0008 00B6 20F2 0E36 390F 0086 1085 1105 1405 1005 0836 390F 0086 1405 1005 0008 ;* SendChar - Sends character to LCD * ;* This routine splits the character into the upper and lower * ;* nibbles and sends them to the LCD, upper nibble first * ;* The data is transmitted on the PORT pins * ;******************************************************************* SEND_CHAR MOVWF CALL SWAPF ANDLW MOVWF BCF BSF BSF BCF MOVF ANDLW MOVWF BSF BCF RETURN CHAR BUSY_CHECK CHAR, W 0x0F LCD_DATA LCD_CNTL, RW LCD_CNTL, RS LCD_CNTL, E LCD_CNTL, E CHAR, W 0x0F LCD_DATA LCD_CNTL, E LCD_CNTL, E ; Character to be sent is in W ; Wait for LCD to be ready ; ; ; ; ; Get upper nibble Send data to LCD Set LCD to read Set LCD to data mode toggle E for LCD ; Get lower nibble ; Send data to LCD ; toggle E for LCD ;******************************************************************* ;* SendCmd - Sends command to LCD * ;* This routine splits the command into the upper and lower * ;* nibbles and sends them to the LCD, upper nibble first * ;* The data is transmitted on the PORT pins * ;******************************************************************* SEND_CMD MOVWF CALL SWAPF ANDLW MOVWF BCF BCF BSF BCF MOVF ANDLW MOVWF BSF BCF RETURN page CHAR BUSY_CHECK CHAR, W 0x0F LCD_DATA LCD_CNTL, RW LCD_CNTL, RS LCD_CNTL, E LCD_CNTL, E CHAR, W 0x0F LCD_DATA LCD_CNTL, E LCD_CNTL, E ; Character to be sent is in W ; Wait for LCD to be ready ; ; ; ; ; Get upper nibble Send data to LCD Set LCD to read Set LCD to command mode toggle E for LCD ; Get lower nibble ; Send data to LCD ; toggle E for LCD AN582 DS00582B-page 12 00D4 00D4 00D5 00D6 00D7 00D8 00D9 00DA 00DB 00DC 00DD 00DE 00DF 00E0 00E1 00E2 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  1997 Microchip Technology Inc 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 ;******************************************************************* ;* This routine checks the busy flag, returns when not busy * ;* Affects: * ;* TEMP - Returned with busy/address * ;******************************************************************* BUSY_CHECK ; if ( Debug ) BSF PORTD, BCF PORTD, endif CLRF LCD_DATA ;** Have PORTB output low BSF STATUS, RP0 ; Bank BSF OPTION_REG, NOT_RBPU ; Turn off PORTB Pull-up MOVLW 0xFF ; Set PortB for input MOVWF LCD_DATA_TRIS BCF STATUS, RP0 ; Bank BCF LCD_CNTL, RS ; Set LCD for Command mode BSF LCD_CNTL, RW ; Setup to read busy flag BSF LCD_CNTL, E ; Set E high BCF LCD_CNTL, E ; Set E low SWAPF LCD_DATA, W ; Read upper nibble busy flag, DDRam address ANDLW 0xF0 ; Mask out lower nibble MOVWF TEMP ; BSF LCD_CNTL, E ; Toggle E to get lower nibble BCF LCD_CNTL, E MOVF LCD_DATA, W ; Read lower nibble busy flag, DDRam address ANDLW 0x0F ; Mask out upper nibble IORWF TEMP, F ; Combine nibbles BTFSC TEMP, ; Check busy flag, high = busy GOTO BUSY_CHECK ; If busy, check again BCF LCD_CNTL, RW BSF STATUS, RP0 ; Bank MOVLW 0xF0 ; MOVWF LCD_DATA_TRIS ; RB7 - = inputs, RB3 - = output BCF STATUS, RP0 ; Bank RETURN ; page ; ;****************************************************************************** ;***** Start program here, Power-On Reset occurred ;****************************************************************************** ; START ; POWER_ON Reset (Beginning of program) BCF STATUS, RP0 ; Bank AN582 DS00582B-page 13 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 300C 00B0 01B1 3000 00A0 3004 00B2 0114 3080 0115 008F 0116 018E 0117 0117 0118 0119 011A 011B 011C 011D 011E 011F 0120 0121 0122 0123 0124 0125 0126  1997 Microchip Technology Inc 0127 0128 0129 012A 012B 012C 012D 012E 012F 0130 0131 0132 0133 0183 018B 018C 1683 3000 0081 018C 30FF 009F 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 0x0C HRS MIN 0x00 FLAG_REG 0x04 SECS MOVLW MOVWF CLRF 0x80 TMR1H TMR1L CLRF CLRF CLRF BSF MOVLW MOVWF CLRF MOVLW MOVWF STATUS INTCON PIR1 STATUS, RP0 0x00 OPTION_REG PIE1 0xFF ADCON1 BCF CLRF CLRF CLRF CLRF CLRF BCF STATUS, RP0 PORTA PORTB PORTC PORTD PORTE T1CON, TMR1ON BSF CLRF MOVLW MOVWF CLRF BSF CLRF CLRF BSF BCF BCF MOVF BCF STATUS, RP0 ; Select Bank TRISA ; RA5 - outputs 0xF0 ; TRISB ; RB7 - inputs, RB3 - outputs TRISC ; RC Port are outputs TRISC, T1OSO ; RC0 needs to be input for the oscillator to function TRISD ; RD Port are outputs TRISE ; RE Port are outputs PIE1, TMR1IE ; Enable TMR1 Interrupt OPTION_REG, NOT_RBPU ; Enable PORTB pull-ups STATUS, RP0 ; Select Bank PORTB, F ; Need to clear 1st RBIF, due to INTCON, RBIF ; set up of PORTB ; MCLR_RESET ; ; ; ; ; ; ; ; ; ; ; Decimal 12 HOURS = 12 MIN = 00 PM light is on Initial value of seconds (64d - 60d) This allows a simple bit test to see if 60 secs has elapsed TIM1H:TMR1L = 0x8000 gives second overflow, at 32 KHz ; A Master Clear Reset ; Do initialization (Bank 0) ; Bank ; The LCD module does not like to work w/ weak pull-ups ; ; Disable all peripheral interrupts ; ; Port A is Digital (for 16C7x devices) ; ; ; Bank ; ALL PORT output should output Low ; Timer is NOT incrementing ; ; page AN582 DS00582B-page 14 010D 010E 010F 0110 0111 0112 0113  1997 Microchip Technology Inc 0134 0185 0135 0135 0136 0137 0138 3002 0086 1405 1005 3006 00B3 01B4 0BB4 293C 0BB3 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 293C ; ; Initilize the LCD Display Module ; CLRF LCD_CNTL ; ALL PORT output should output Low DISPLAY_INIT MOVLW 0x02 ; Command for 4-bit interface MOVWF LCD_DATA ; BSF LCD_CNTL, E ; BCF LCD_CNTL, E ; ; ; This routine takes the calculated times that the delay loop needs to ; be executed, based on the LCD_INIT_DELAY EQUate that includes the ; frequency of operation It uses registers before they are needed to ; store the time ; LCD_DELAY MOVLW LCD_INIT_DELAY ; MOVWF MSD ; Use MSD and LSD Registers to Initialize LCD CLRF LSD ; LOOP2 DECFSZ LSD, F ; Delay time = MSD * ((3 * 256) + 3) * Tcy GOTO LOOP2 ; DECFSZ MSD, F ; END_LCD_DELAY GOTO LOOP2 ; ; ; Command sequence for lines of 5x7 characters ; CMD_SEQ MOVLW 0X02 MOVWF LCD_DATA BSF LCD_CNTL, E ; BCF LCD_CNTL, E ; MOVLW 0x08 ; MOVWF LCD_DATA ; BSF LCD_CNTL, E ; BCF LCD_CNTL, E ; ; ; Busy Flag should be valid after this point ; MOVLW DISP_ON ; CALL SEND_CMD ; MOVLW CLR_DISP ; CALL SEND_CMD ; MOVLW ENTRY_INC ; CALL SEND_CMD ; MOVLW DD_RAM_ADDR ; CALL SEND_CMD ; ; AN582 DS00582B-page 15 0139 013A 013B 013C 013D 013E 013F 013F 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 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  1997 Microchip Technology Inc 0400 0400 00B5 page ; ; Initialize the Special Function Registers (SFR) interrupts ; CLRF PIR1 ; MOVLW 0x0E MOVWF T1CON ; RC1 is overridden by TCKO BSF INTCON, PEIE ; Enable Peripheral Interrupts BSF INTCON, RBIE ; Disable PORTB Change Interrupts BSF INTCON, GIE ; Enable all Interrupts ; CALL INIT_DISPLAY ; CALL DISPLAY ; ; MOVLW 0x0E MOVWF T1CON ; Enable T1 Oscillator, Ext Clock, Async, prescaler = BSF T1CON, TMR1ON ; Turn Timer ON ; if ( PICMaster ) lzz goto lzz ; Loop waiting for interrupts (for use with PICMASTER) else ; SLEEP_LP SLEEP ; Wait for Change on PORTB interrupt or TMR1 timeout NOP ; GOTO SLEEP_LP ; ; endif ; ; Here is where you things depending on the type of RESET (Not a Power-On Reset) ; OTHER_RESET BTFSS STATUS,NOT_TO ; WDT Time-out? WDT_TIMEOUT GOTO ERROR1 ; YES, This is error condition if ( Debug_PU ) goto START ; MCLR reset, Goto START else GOTO MCLR_RESET ; MCLR reset, Goto MCLR_RESET endif ; if (Debug ) END_START NOP ; END label for debug endif ; page ; org TABLE_ADDR ; NUM_TABLE MOVWF TEMP ; Store value to TEMP register AN582 DS00582B-page 16 0150 0151 0152 0153 0154 0155 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  1997 Microchip Technology Inc 0401 0402 0403 0404 0405 0406 0407 0408 0409 040A 040B 040C 040D 040E 040F 3004 008A 0835 390F 0782 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 0410 0411 0412 0413 0414 0415 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 XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX RETLW RETLW RETLW RETLW RETLW RETLW 'E' 'E' 'E' 'E' 'E' 'E' ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 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 end '-' = Unused) XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXX - XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX X - XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX -X AN582 DS00582B-page 17 : : : : : : : : HIGH (TABLE_ADDR) PCLATH TEMP, W 0x0F PCL, F '0' '1' '2' '3' '4' '5' '6' '7' '8' '9' NUM_TBL_END ; if ( (NUM_TBL & 0xFF00) != (NUM_TBL_END & 0xFF00) ) MESSG "Warning: Table NUM_TBL crosses page boundry in computed jump" endif ; ; org PMEM_END ; End of Program Memory GOTO ERROR1 ; If you get here your program was lost MEMORY USAGE MAP ('X' = Used, 0000 0040 0080 00C0 0100 0140 0400 07C0 MOVLW MOVWF MOVF ANDLW ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW Program Memory Words Used: Program Memory Words Free: Errors : Warnings : Messages : 0 reported, reported, 376 3720 suppressed 16 suppressed AN582 DS00582B-page 18 All other memory blocks unused  1997 Microchip Technology Inc AN582 Please check the Microchip BBS for the latest version of the source code Microchip’s Worldwide Web Address: www.microchip.com; Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required) APPENDIX B: CLOCK_01.H INCLUDE FILE nolist ;****************************************************************************** ; ; This is the custom Header File for the real time clock application note ; PROGRAM: CLOCK.H ; Revision:5-10-94 ; ;****************************************************************************** ; This is used for the ASSEMBLER to recalculate certain frequency ; dependant variables The value of Dev_Freq must be changed to ; reflect the frequency that the device actually operates at ; Dev_Freq EQU D’4000000’ ; Device Frequency is MHz DB_HI_BYTE EQU (HIGH ((( Dev_Freq / ) * / D’1000’ ) / ) ) + LCD_INIT_DELAY EQU (HIGH ((( Dev_Freq / ) * D’46’ / D’10000’ ) / ) ) + INNER_CNTR EQU 40 RAM Location OUTER_CNTR EQU 41 ; RAM Location ; T1OSO EQU ; The RC0 / T1OSO / T1CKI ; RESET_V EQU 0x0000 ; Address of RESET Vector ISR_V EQU 0x0004 ; Address of Interrupt Vector PMEM_END EQU 0x07FF ; Last address in Program Memory TABLE_ADDR EQU 0x0400 ; Address where to start Tables ; HR_MIN_SW EQU 0x7 ; The switch to select the units INC_SW EQU 0x6 ; The switch to increment the selected units CLR_MIN_SW EQU 0x5 ; The switch to clear the minutes and seconds ; FLAG_REG EQU 0x020 ; Register which contains flag bits ; ; + + -+ -+ -+ -+ -+ + -+ ; | AM | - | - | KEY_INPUT | - | - | MIN_UNIT | HR_UNIT | ; + + -+ -+ -+ -+ -+ + -+ ; AM EQU 0x07 ; Flag to specify if AM or PM ; KEY_INPUT EQU 0x04 ; Flag to specify if doing key inputs ; MIN_UNIT EQU 0x01 ; Flags to specify which units to operate on HR_UNIT EQU 0x00 ; (HRS, MIN, or none) ; HRS EQU 0x030 ; Holds counter value for HOURS MIN EQU 0x031 ; Holds counter value for MINUTES SECS EQU 0x032 ; Holds counter value for SECONDS MSD EQU 0x033 ; Temporary register, Holds MSD of BIN to BCD conversion LSD EQU 0x034 ; Temporary register, Holds LSD of BIN to BCD conversion TEMP EQU 0x035 ; Temporary register CHAR EQU 0x036 ; Temporary register, Holds value to send to LCD module ; WAIT_CNTR EQU 0x040 ; Counter that holds wait time for key inputs ; ; ; LCD Display Commands and Control Signal names ; E EQU ; LCD Enable control line R_W EQU ; LCD Read/Write control line RS EQU ; LCD Register Select control line ; ; ; LCD Module commands ;  1997 Microchip Technology Inc DS00582B-page 19 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 ; EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU 0x00C 0x00E 0x00F 0x008 0x001 0x006 0x007 0x004 0x005 0x080 0x080 ; ; ; ; ; ; ; ; ; ; ; Display on Display on, Cursor on Display on, Cursor on, Blink cursor Display off Clear the Display Least Significant 7-bit are for address Upper Left corner of the Display list DS00582B-page 20  1997 Microchip Technology Inc AN582 Please check the Microchip BBS for the latest version of the source code Microchip’s Worldwide Web Address: www.microchip.com; Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required) APPENDIX C: C74_REG.H INCLUDE FILE NOLIST ; ; File = C64_reg.h ; Rev History: 08-04-93 by MP ; 10-18-93 by MP to make Page ok ; 11-15-93 by MP to have correct pages for SFR ; ; EQUates for Special Function Registers ; ; 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 ; ;********************************************** ;************ Bit Definitions ************  1997 Microchip Technology Inc DS00582B-page 21 AN582 ;********************************************** ; ; STATUS register (Address 03/83) ; IRP EQU RP1 EQU RP0 EQU TO EQU PD EQU Z EQU DC EQU C EQU ; ; INTCON register (Address 0B/8B) ; GI EQU PEIE EQU T0IE EQU INTE EQU RBIE EQU T0IF EQU INTF EQU RBIF EQU ; ; PIR1 register (Address 0C) ; PSPIF EQU SSPIF EQU CCP1IF EQU TMR2IF EQU TMR1IF EQU ; ; PIE1 register (Address 8C) ; PSPIE EQU SSPIE EQU CCP1IE EQU TMR2IE EQU TMR1IE EQU ; ; OPTION register (Address 81) ; RBPU EQU INTEDG EQU T0CS EQU T0SE EQU PSA EQU PS2 EQU PS1 EQU PS0 EQU ; ; PCON register (Address 8E) ; POR EQU ; ; TRISE register (Address 89) ; IBF EQU OBF EQU IBOV EQU PSPMODE EQU TRISE2 EQU TRISE1 EQU TRISE0 EQU ; ; T1CON register (Address 10) DS00582B-page 22  1997 Microchip Technology Inc AN582 ; T1CKPS1 EQU T1CKPS0 EQU T1OSCEN EQU T1INSYNC EQU TMR1CS EQU TMR1ON EQU ; ; T2CON register (Address 12) ; TOUTPS3 EQU TOUTPS2 EQU TOUTPS1 EQU TOUTPS0 EQU TMR2ON EQU T2CKPS1 EQU T2CKPS0 EQU ; ; SSPCON register (Address 14) ; WCOL EQU SSPOV EQU SSPEN EQU CKP EQU SSPM3 EQU SSPM2 EQU SSPM1 EQU SSPM0 EQU ; ; SSPSTAT register (Address 94) ; DA EQU P EQU S EQU RW EQU UA EQU BF EQU ; ; CCP1CON register (Address 17) ; CCP1X EQU CCP1Y EQU CCP1M3 EQU CCP1M2 EQU CCP1M1 EQU CCP1M0 EQU ; ; RCSTA register (Address 18) ; SPEN EQU RC89 EQU SREN EQU CREN EQU FERR EQU OERR EQU RCD8 EQU ; ; TXSTA register (Address 98) ; CSRC EQU TX89 EQU TXEN EQU SYNC EQU BRGH EQU TRMT EQU TXD8 EQU  1997 Microchip Technology Inc DS00582B-page 23 AN582 ; ; CCP2CON register (Address 1D) ; CCP2X EQU CCP2Y EQU CCP2M3 EQU CCP2M2 EQU CCP2M1 EQU CCP2M0 EQU ; ; ADCON0 register (Address 1F) ; ADCS1 EQU ADCS0 EQU CHS2 EQU CHS1 EQU CHS0 EQU GO EQU DONE EQU ADON EQU ; ; ADCON1 register (Address 9F) ; PCFG2 EQU PCFG1 EQU PCFG0 EQU ; ;*********************************************** ;**** Bits for destination control ;**** W = W register is destination ;**** F = File register is destination ;*********************************************** ; W EQU F EQU ; FALSE EQU TRUE EQU LIST DS00582B-page 24  1997 Microchip Technology Inc 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 Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates It is your responsibility to ensure that your application meets with your specifications 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, or infringement of patents or other intellectual property rights arising from such use or otherwise Use of Microchip’s products as critical components in life support systems is not authorized except with express written approval by Microchip No licenses are conveyed, implicitly or otherwise, under any intellectual property rights Trademarks The Microchip name and logo, the Microchip logo, FilterLab, KEELOQ, microID, MPLAB, PIC, PICmicro, PICMASTER, PICSTART, PRO MATE, SEEVAL and The Embedded Control Solutions Company are registered trademarks of Microchip Technology Incorporated in the U.S.A and other countries dsPIC, ECONOMONITOR, FanSense, FlexROM, fuzzyLAB, In-Circuit Serial Programming, ICSP, ICEPIC, microPort, Migratable Memory, MPASM, MPLIB, MPLINK, MPSIM, MXDEV, PICC, PICDEM, PICDEM.net, rfPIC, Select Mode and Total Endurance are trademarks of Microchip Technology Incorporated in the U.S.A Serialized Quick Turn Programming (SQTP) is a service mark of Microchip Technology Incorporated in the U.S.A All other trademarks mentioned herein are property of their respective companies © 2002, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved Printed on recycled paper Microchip received QS-9000 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona in July 1999 The Company’s quality system processes and procedures are QS-9000 compliant for its PICmicro® 8-bit MCUs, KEELOQ® code hopping devices, Serial EEPROMs and microperipheral products In addition, Microchip’s quality system for the design and manufacture of development systems is ISO 9001 certified  2002 Microchip Technology Inc M WORLDWIDE SALES AND SERVICE AMERICAS ASIA/PACIFIC Japan Corporate Office Australia 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 Microchip Technology Australia Pty Ltd Suite 22, 41 Rawson Street Epping 2121, NSW Australia Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 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 China - Beijing 2355 West Chandler Blvd Chandler, AZ 85224-6199 Tel: 480-792-7966 Fax: 480-792-7456 Microchip Technology Consulting (Shanghai) Co., Ltd., Beijing Liaison Office Unit 915 Bei Hai Wan Tai Bldg No Chaoyangmen Beidajie Beijing, 100027, No China Tel: 86-10-85282100 Fax: 86-10-85282104 Atlanta 500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307 Boston Lan Drive, Suite 120 Westford, MA 01886 Tel: 978-692-3848 Fax: 978-692-3821 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 Detroit Tri-Atria Office Building 32255 Northwestern Highway, Suite 190 Farmington Hills, MI 48334 Tel: 248-538-2250 Fax: 248-538-2260 Kokomo 2767 S Albright Road Kokomo, Indiana 46902 Tel: 765-864-8360 Fax: 765-864-8387 Los Angeles 18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 949-263-1888 Fax: 949-263-1338 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 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 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 China - Shenzhen 150 Motor Parkway, Suite 202 Hauppauge, NY 11788 Tel: 631-273-5305 Fax: 631-273-5335 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 San Jose Hong Kong Microchip Technology Inc 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408-436-7950 Fax: 408-436-7955 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 New York Toronto 6285 Northam Drive, Suite 108 Mississauga, Ontario L4V 1X5, Canada Tel: 905-673-0699 Fax: 905-673-6509 India Microchip Technology Inc India Liaison Office Divyasree Chambers Floor, Wing A (A3/A4) No 11, O’Shaugnessey Road Bangalore, 560 025, India Tel: 91-80-2290061 Fax: 91-80-2290062 Korea Microchip Technology Korea 168-1, Youngbo Bldg Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934 Singapore Microchip Technology Singapore Pte Ltd 200 Middle Road #07-02 Prime Centre Singapore, 188980 Tel: 65-334-8870 Fax: 65-334-8850 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 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 France Microchip Technology SARL Parc d’Activite du Moulin de Massy 43 Rue du Saule Trapu Batiment A - ler Etage 91300 Massy, France Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany Microchip Technology GmbH Gustav-Heinemann Ring 125 D-81739 Munich, Germany Tel: 49-89-627-144 Fax: 49-89-627-144-44 Italy Microchip Technology SRL Centro Direzionale Colleoni Palazzo Taurus V Le Colleoni 20041 Agrate Brianza Milan, Italy Tel: 39-039-65791-1 Fax: 39-039-6899883 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 01/18/02  2002 Microchip Technology Inc [...]... Ext Clock, Async, prescaler = 1 BSF T1CON, TMR1ON ; Turn Timer 1 ON ; if ( PICMaster ) lzz goto lzz ; Loop waiting for interrupts (for use with PICMASTER) else ; SLEEP_LP SLEEP ; Wait for Change on PORTB interrupt or TMR1 timeout NOP ; GOTO SLEEP_LP ; ; endif ; ; Here is where you do things depending on the type of RESET (Not a Power- On Reset) ; OTHER_RESET BTFSS STATUS,NOT_TO ; WDT Time- out? WDT_TIMEOUT... www.microchip.com; Bulletin Board Support: MCHIPBBS using CompuServe® (CompuServe membership not required) APPENDIX B: CLOCK_ 01.H INCLUDE FILE nolist ;****************************************************************************** ; ; This is the custom Header File for the real time clock application note ; PROGRAM: CLOCK. H ; Revision:5-10-94 ; ;******************************************************************************... seconds (64d - 60d) This allows a simple bit test to see if 60 secs has elapsed TIM1H:TMR1L = 0x8000 gives 1 second overflow, at 32 KHz ; 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) ; ; ; Bank 0 ; ALL PORT output should output Low ; Timer 1 is NOT incrementing... output low BSF STATUS, RP0 ; Bank 1 BSF OPTION_REG, NOT_RBPU ; Turn off PORTB Pull-up MOVLW 0xFF ; Set PortB for input MOVWF LCD_DATA_TRIS BCF STATUS, RP0 ; Bank 0 BCF LCD_CNTL, RS ; Set LCD for Command mode BSF LCD_CNTL, RW ; Setup to read busy flag BSF LCD_CNTL, E ; Set E high BCF LCD_CNTL, E ; Set E low SWAPF LCD_DATA, W ; Read upper nibble busy flag, DDRam address ANDLW 0xF0 ; Mask out lower nibble... LCD_CNTL ; ALL PORT output should output Low DISPLAY_INIT MOVLW 0x02 ; Command for 4-bit interface MOVWF LCD_DATA ; BSF LCD_CNTL, E ; BCF LCD_CNTL, E ; ; ; This routine takes the calculated times that the delay loop needs to ; be executed, based on the LCD_INIT_DELAY EQUate that includes the ; frequency of operation It uses registers before they are needed to ; store the time ; LCD_DELAY MOVLW LCD_INIT_DELAY... ; Get upper nibble Send data to LCD Set LCD to read Set LCD to data mode toggle E for LCD ; Get lower nibble ; Send data to LCD ; toggle E for LCD ;******************************************************************* ;* SendCmd - Sends command to LCD * ;* This routine splits the command into the upper and lower * ;* nibbles and sends them to the LCD, upper nibble first * ;* The data is transmitted on... PORTB Pull-up ; Bank 0 ; You've displayed the time, Clear RBIF ; ; ;****************************************************************************** ; The BIN_2_BCD routine converts the binary number, in the W register, to a ; binary coded decimal (BCD) munber This BCD number is stored MSD:LSD This ; routine is used by the DISPLAY subroutine, to convert the time values ;******************************************************************************... high BCF LCD_CNTL, E ; Set E low SWAPF LCD_DATA, W ; Read upper nibble busy flag, DDRam address ANDLW 0xF0 ; Mask out lower nibble MOVWF TEMP ; BSF LCD_CNTL, E ; Toggle E to get lower nibble BCF LCD_CNTL, E MOVF LCD_DATA, W ; Read lower nibble busy flag, DDRam address ANDLW 0x0F ; Mask out upper nibble IORWF TEMP, F ; Combine nibbles BTFSC TEMP, 7 ; Check busy flag, high = busy GOTO BUSY_CHECK ; If busy,... STATUS, RP0 ; Bank 0 RETURN ; page ; ;****************************************************************************** ;***** Start program here, Power- On Reset occurred ;****************************************************************************** ; START ; POWER_ ON Reset (Beginning of program) BCF STATUS, RP0 ; Bank 0 AN582 DS00582B-page 13 010C 010C 1283 00408 00409 00410 00411 00412 00413 00414 00415... operation It uses registers before they are needed to ; store the time ; LCD_DELAY MOVLW LCD_INIT_DELAY ; MOVWF MSD ; Use MSD and LSD Registers to Initialize LCD CLRF LSD ; LOOP2 DECFSZ LSD, F ; Delay time = MSD * ((3 * 256) + 3) * Tcy GOTO LOOP2 ; DECFSZ MSD, F ; END_LCD_DELAY GOTO LOOP2 ; ; ; Command sequence for 2 lines of 5x7 characters ; CMD_SEQ MOVLW 0X02 MOVWF LCD_DATA BSF LCD_CNTL, E ; BCF LCD_CNTL, ... This 800 µs operation is out of the 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... 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... a real time clock using the TMR1 module of the ; PIC16CXXX family A LCD display module is used to display (update) the time ; every second Three keys are used to set the time ; ; Program = CLOCK. ASM

Ngày đăng: 11/01/2016, 11:52

Từ khóa liên quan

Mục lục

  • Introduction

  • Operation

  • Conclusion

  • Appendix A: source code listing (clock_01.lst)

  • Appendix B: clock_01.h include file

  • Appendix C: c74_reg.h include file

  • Worldwide Sales & Service

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan