You are on page 1of 14

AN590

A Clock Design Using the PIC16C54 for LED Displays and Switch Inputs
Author: Dan Matthews Microchip Technology Inc.

OPERATION
Switches
When no buttons are pressed, the circuit will display the current time, starting at 12:00 on reset. Pressing SW1 will cause seconds to be displayed. The time is set by pressing SW2 to advance minutes, and SW3 to advance hours. Since each of the segments are tied together across all displays, only one display should be turned on at a time, or all displays turned on would display duplicate data. The displays are turned on right to left, with each display's value being output in its turn. This is done fast enough so that there is no perceived icker. The switches are read between display cycles.

INTRODUCTION
The purpose of this application note is to design a clock while multiplexing the features as much as possible, allowing the circuit to use the 18-pin PIC16C54. Other devices in the Microchip line expand on this part, making it a good starting point for learning the basics. This design is useful because it utilizes every pin for output and switches some of them to inputs briey to read the keys. For a more extensive clock design, consult application note AN529.

THE DESIGN
This design is a simple time-of-day clock incorporating four seven-segment LED displays and three input switches. There is also an additional reset switch that would not normally be incorporated into the nal design. The schematic is illustrated in Figure 1.

Timing
The PIC16C5X prescaler is assigned to TMR0 as a 1:16 divide. The T0CKI pin is tied low since it is not used. The OPTION Register is loaded with 03h to initialize this prescaler setup. The software is written with timing based on a 4.000 MHz crystal. The instruction clock is 1.000 MHz after the internal divide by four. The 8-bit TMR0 register rolls over every 256 cycles, for a nal frequency of 244.1406 Hz. (exactly a 4.096 ms period) A variable named sec_nth is used to count 244 roll-overs of TMR0 for one second. The benet of keeping time with a nth variable is that it can be written to as needed to adjust time in "nths" of a second, allowing almost any odd crystal frequency to be used. Simply determine the best prescale and "nth" divider, and compute the "nth" adjustment needed for each minute, hour, twelve hour roll-over. Time can be kept accurately to two "nths" a day (an "nth" is 1/244 of a second in this case). In this circuit, 9 "nths" are subtracted each minute, 34 "nths" are added each hour, and 6 "nths" subtracted every twelve hour roll-over. This leaves a computed error of 1.5 seconds/year except for crystal frequency drift. Another possible solution is to initialize TMR0 to some value that causes a roll-over at a predetermined time interval. Writing to TMR0 causes two clock cycles to be missed while clock edges realign, which would have to be accounted for. This is described in the Microchip Data Book.

CONNECTIONS
The individual segments of each display are connected together, A-A-A-A, B-B-B-B, etc. The displays are numbered from the right, or least signicant digit. The second display from the right is ipped upside down to align its decimal with the third display, creating the center clock colon. Therefore the segments are not tied together evenly straight across on the board, but must compensate for the change in one display's orientation. The common cathode for each display is turned on with transistors connected to the four I/O lines of PORTA. The connections are RA0-CC4/Digit4, RA1-CC3/Digit3, RA2-CC2/Digit2, RA3-CC1/Digit1. A low output turns on the PNP transistor for the selected display. The PORTB pins activate the LED segments. For this design only the center colon decimal points were connected. The connections are RB0-dp, RB1-A, RB2-B, RB3-C...RB7-G. The switches are also connected to PORTB I/O pins. PORTB pins RB1, RB2, and RB3 are pulled low with 10 k resistors. This value is high enough to not draw current away from the LEDs when they are being driven on. Inputs are detected by pulling the pins high with a switch to VDD through 820 resistors. This value is low enough to pull the pin high quickly when the outputs have been turned off, and to create a 90% of VDD high input.

1997 Microchip Technology Inc.

DS00590C-page 1

AN590
Displays
The program contains portions of code that act as a display driver. A variable exists for each of the four displays. A hex value from 0 to 9 can be written to these variables and they will be converted to display code and output to the displays. Only one display is actually on at a time, and its code is output into it in its turn. Another section of code takes the seconds, minutes, or hours value and separates it into the two digits needed for each display. In other words, 48 seconds would be separated into a "4" and an "8" and written to the appropriate display variable. The displays used were common cathode and turned on with transistors to avoid trying to sink too much current into the PIC16C5X. A display is enabled with a zero at the appropriate pin. 100 resistors were used in series with the segments to obtain the desired brightness. Different values may be required if different displays are used. Since each display is on less than one fourth of the time, the resistor value must be low enough to compensate for the needed forward current.

CONCLUSION
The instruction execution speed of the PIC16C54 (and the rest of the PICmicro series) allows many functions to be implemented with only a few pins, by multiplexing them in software. User inputs, Timer0 Counter, and multiple LED displays are all accommodated with little or no sacrice in functionality.

FIGURE 1:

TIME OF DAY CLOCK USING A PIC16C54


sw1-displays seconds sw2-advances minutes sw3-advances hours

5 VDC

820 1 RA2 CC1 RA3 T0CKI MCLR VSS RB0 dp A RB1 B RB2 C RB3
CC2

10 k
sw1 sw2 sw3

RA1 RA0 OSC1 OSC2 Vdd RB7 RB6 RB5 RB4

CC3 CC4 4.000 MHz xtal or osc circuit as needed G F E D

4 x 1 k

Reset

100 10 k

dp A B C

D E FG

2N5401

CC4

CC3

CC2 dp

All of the same display segments are linked together (A-A-A-A, B-B-B-B, etc.) and are individually selected by turning on only the desired display.

A F G E D C
dp (nc)

A B F G E D C
dp

A B G F

Common Cathode 1 Digit 1

B G

E D

E D

C
dp (nc)

HP part# HDSP7503

DS00590C-page 2

1997 Microchip Technology Inc.

1997 Microchip Technology Inc. DS00590C-page 3

Please check the Microchip BBS for the latest version of the source code. Microchips Worldwide Web Address: www.microchip.com; Bulletin Board Support: MCHIPBBS using CompuServe (CompuServe membership not required).

APPENDIX A: CLOCK54.ASM
MPASM 01.40 Released CLOCK54.ASM 1-16-1997 17:23:58 PAGE 1

LOC OBJECT CODE VALUE

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 00030 00031 00032 00033 00034 00035 00036

; ;******************************************************************** LIST P = 16C54, n = 66 ; ; Clock ;********************************************************************* ; ; PROGRAM DESCRIPTION ; ; This program runs on a PIC16C54. ; ; Hardware Description ; ; DISPLAYS ; Four 7 segment displays are multiplexed. The segments are tied together, with ; the common cathode pins broken out separately. The display appears as a clock ; with a center semicolon ( 88:88 ). The segments are assigned to Port B, with the ; semicolon being RB0, and segments A through F assigned as RB1 to RB7 respectively. ; The four common cathodes are attached to the four Port A pins through transistors. ; RA0 for LED0, RA1/LED1... through LED3. The center semicolon is made from the decimals ; of LED 2 and 3. LED display 2 is turned upside down to put its decimal into position, ; but it is wired with a corrected A-F assignment to compensate. Both decimals ; are tied together at RB0, but the display cathodes are still separate. ; ; SWITCHES ; Because all twelve I/O pins are already used for the muxed displays, the four ; switches must be switched in alternatingly through software. The switches ; lie across Port B pins, which wil be changed to inputs momentarily during read ; and changed back to outputs during display. ; ; ; ; Program: CLOCK54.ASM ; Revision Date: ; 1-16-97 Compatibility with MPASMWIN 1.40 ;

AN590

DS00590C-page 4 1997 Microchip Technology Inc.

AN590

000001FF 000003FF 00000000 00000001 00000002 00000003 00000004 00000005 00000006

00000000 00000000 00000001 00000001 00000002 00000002 00000003 00000003 00000004 00000004 00000005 00000006 00000007 0000007E 0000000C 000000B6 0000009E 000000CC 000000DA 000000FA 0000000E 000000FE 000000CE 00000001 000000F0 00000000 0000000C 000000C4

00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083

; ;************************** ; ; PIC54 equ H01FF PIC56 equ H03FF ; POINTER equ H00 TMR0 equ H01 PC equ H02 STATUS equ H03 FSR equ H04 ; PORT_A equ H05 PORT_B equ H06 ; CARRY C DCARRY DC Z_bit Z P_DOWN PD T_OUT TO PA0 PA1 PA2 ; ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE COLON T BLANK ; MAXNTHS MAXSECS equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ equ 0 0 1 1 2 2 3 3 4 4 5 6 7 H7E H0C HB6 H9E HCC HDA HFA H0E HFE HCE H01 HF0 H00 D12 D196

Header *************************

; F3 Reg is STATUS Reg.

; 7 segment Display Common Cathodes ; Center Colon and Muxed Display Segments (Switches when inputs) ; STATUS REG. Bits ; Carry Bit is Bit.0 of F3

; Bit 2 of F3 is Zero Bit

;16C5X Status bits ;16C5X Status bits ;16C5X Status bits

; Mapping of segments for display (PORT_B)

; constants for timer variable count up ; variables roll over in HEX at time roll over, see variable

1997 Microchip Technology Inc. DS00590C-page 5

000000C4 000000F4 000000F3 00000009 00000022 00000003 000000FE 000000FD 000000FB 000000F7 000000FF 0000000E

00000000 00000001 00000002 00000003 00000004 00000005 00000006 00000007

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 00127 00128 00129

MAXMINS MAXHRS MINHRS ADJMIN ADJHR ADJDAY ; DISP1 DISP2 DISP3 DISP4 DISPOFF SWITCH ; ; Flag SEC MIN HRS CHG

equ equ equ equ equ equ equ equ equ equ equ equ

D196 D244 D243 D9 D34 D3 B11111110 B11111101 B11111011 B11110111 HFF B00001110

explanation

; number of nths that need to be subtracted each minute ; nths added each hour for accurate time ; nths subtracted each 1/2 day rollover

; Mapping of Active Display Selection (PORT_A)

; Activate RB1-3 for switch inputs

bit assignments equ H0 equ H1 equ H2 equ H3

; update time display values for sec, min, or hours

; a change has occurred on a switch or to a potentially displayed value

00000008 00000009 0000000B 0000000C 0000000D 0000000E 0000000F

00000010 00000011 00000012 00000013 00000014 00000015 00000016

SW1 equ H4 ; Flag bit assignments - switches that are on = 1 SW2 equ H5 ; SW1 is Seconds-minutes, SW2-hours, SW3-mode SW3 equ H6 SW_ON equ H7 ; a switch has been pressed ; ; VARIABLES keys equ H08 ; variable location - which keys are pressed? bit0/sw1... flags equ H09 ; bit flags; 0-SEC, 1-MIN, 2-HRS, 3-CHG, 4-SW1, 5-SW2, 6-SW3 ; equ H0A ; Not Used display equ H0B ; variable location - which display to update digit1 equ H0C ; Rightmost display value digit2 equ H0D ; Second display from right digit3 equ H0E ; Third digit4 equ H0F ; Fourth (and Leftmost) ; ; timer variables start at a number that allows rollover in sync with time rollover, ; i.e. seconds starts at decimal 195 so that sixty 1-second increments causes 0. sec_nth equ H10 ; seconds, fractional place seconds equ H11 ; seconds minutes equ H12 ; minutes hours equ H13 ; hours var equ H14 ; variable for misc math computations count equ H15 ; loop counter variable count2 equ H16 ; 2nd loop counter for nested loops ; ;********************************************************************************

AN590

DS00590C-page 6 1997 Microchip Technology Inc.

AN590

0000 0C03 0001 0002 0002 0003 0004 0005 0006 0007 0008 0C00 0005 0006 0C00 0026 04C3 04A3

0009 000A 000B 000C 000D 000E 000F 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 001A 001B

0C01 0021 0CFE 002B 0C00 002C 002D 002E 002F 0C0C 0030 0CC4 0031 0CC4 0032 0CFF 0033 0C00 0029

001C

001C 001C 0201 001D 0743 001E 0A1C 001F 03F0 0020 0A52

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 00174 00175 00176

; ; Initialize Ports all outputs, blank display ; START movlw H03 ; set option register, transition on clock, option ; Prescale TMR0, 1:16 ; movlw 0 tris PORT_A ; Set all port pins as outputs tris PORT_B movlw BLANK movwf PORT_B ; Blank the display bcf STATUS,PA1 bcf STATUS,PA0 ; ; initialize variables movlw H01 movwf TMR0 ; set TMR0 above zero so initial wait period occurs movlw HFE movwf display ; initializes display selected to first display. movlw BLANK ; put all displays to blank, no visible segments movwf digit1 movwf digit2 movwf digit3 movwf digit4 movlw MAXNTHS ; set timer variables to initial values movwf sec_nth movlw MAXSECS movwf seconds movlw MAXMINS movwf minutes movlw HFF ; hours start at 12 which is max at FF movwf hours movlw H00 movwf flags ; ;? call converts for minutes and hours to initialize display Variables ; MAIN ; ; wait for TMR0 to roll-over TMR0_FILL movf TMR0,0 btfss STATUS,Z ; note, TMR0 is left free running to not lose clock cycles on writes goto TMR0_FILL ; incfsz sec_nth,1 ; add 1 to nths, n X nths = 1 sec, n is based on prescaler goto TIME_DONE

1997 Microchip Technology Inc. DS00590C-page 7

0021 0C0C 0022 0030 0023 0023 0024 0025 0026 0027 0028 0029 002A 002B 002C 002D 002E 002F 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 003A 003A 003B 003C 003D 003E 003F 0040 0041 0042 0043 0044 0045 0046 0047

07E9 0A3A 0689 0A3A 0CC4 0031 0C7F 0030 07A9 0A33 0CAF 0030 03F2 0A33 0CC4 0032 06A9 0A5E 03F3 0A5E 0CF4 0033 0A5E

0509 0569 03F1 0A52 0CC4 0031 0529 0569 0C09 00B0 03F2 0A52 0CC4 0032

0048 0549

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 00221 00222 00223

movlw movwf ; CHECK_SW btfss goto btfsc goto movlw movwf movlw movwf btfss goto movlw movwf incfsz goto movlw movwf ; HOURSET btfsc goto incfsz goto movlw movwf goto ; SET_TIME bsf bsf incfsz goto movlw movwf ; bsf bsf movlw subwf incfsz goto movlw movwf ; bsf

MAXNTHS sec_nth

; restore sec_nths variable for next round

flags,SW_ON SET_TIME flags,SW1 SET_TIME MAXSECS seconds H7F sec_nth flags,SW2 HOURSET HAF sec_nth minutes,1 HOURSET MAXMINS minutes flags,SW2 CHECK_TIME hours,1 CHECK_TIME MAXHRS hours CHECK_TIME

; if no switches press, bypass this

; if seconds display is pressed, do not change time ; reset seconds to zero when setting clock ; advance second timer 1/2 second to speed time setting ; minutes do not need changing, check hours ; advances timer faster when setting minutes

; not changing hours

; since no timing is required, go to display changes

flags,SEC flags,CHG seconds,1 TIME_DONE MAXSECS seconds flags,MIN flags,CHG ADJMIN sec_nth,1 minutes,1 TIME_DONE MAXMINS minutes flags,HRS

; seconds, if displayed, should be updated ; a flag change was made. ; add 1 to seconds

; restore seconds variable for next round ; minutes, if displayed, should be updated

AN590

; subtraction needed adjustment for each minute ; add 1 to minutes

; restore minutes variable for next hour countdown

DS00590C-page 8 1997 Microchip Technology Inc.

AN590

0049 004A 004B 004C 004D 004E 004F 0050 0051

0569 0C22 01F0 03F3 0A52 0CF4 0033 0C03 00B0

0052 0052 0769 0053 0A8F

0054 0054 0055 0056 0057 0058 0059 005A 005B 005C 005D 005E 005E 005F 0060 0061 0062 0063 0064 0065 0066 0789 0A5E 0C00 002D 002E 002F 0CC4 0091 002C 0A67

0C00 002F 002D 0CF3 0093 002E 0CC4 0092 002C

0067 0067 0C02 0068 0035

00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270

; subtraction adjustment for each 1/2 day rollover ; TIME_DONE btfss flags,CHG ; if no switches or potentially dislayed numbers were goto CYCLE ; changed, then skip updating display variables ; ; CHECK_SECONDS ; if seconds is button was pushed and not mode display seconds btfss flags,SW1 goto CHECK_TIME movlw H00 movwf digit2 ; 3rd digit variable used to store temp hex value for hours display movwf digit3 movwf digit4 movlw MAXSECS subwf seconds,0 movwf digit1 ; 1st digit variable temporarily holds hex value for seconds display goto SPLIT_HEX ; CHECK_TIME movlw H00 movwf digit4 ; zero out tens places in case there is no tens increment movwf digit2 movlw MINHRS subwf hours,0 movwf digit3 ; 3rd digit variable temporarily holds hex value for hours movlw MAXMINS subwf minutes,0 movwf digit1 ; 1st digit temporarily holds hex value for minutes ; ; ; SPLIT_HEX ; split into two hex display variables and write ; movlw H02 movwf count ; loop to convert each number - seconds - or minutes and hours ;1st time through, FSR = digit1, 2nd time FSR = digit3

bsf movlw addwf incfsz goto movlw movwf movlw subwf

flags,CHG ADJHR sec_nth,1 hours,1 TIME_DONE MAXHRS hours ADJDAY sec_nth,1

; add needed adjustment for each hour ; add 1 to hours

; restore hours variable for next round

1997 Microchip Technology Inc. DS00590C-page 9

0069 0C0C 006A 0024 006B 0A6E 006C 0C0E 006D 0024 006E 006E 006F 0070 0071 0072 0073 0074 0074 0075 0076 0077

0C0A 00A0 0603 0A74 01E0 0A78

02A4 02A0 00E4 0A6E

0078 0078 02F5 0079 0A6C 007A 007A 007B 007C 007D 007E 007E 007F 0080 0081 0082 0083 0084 0084 0085 0086 0087 0088 0089

0C0C 0024 0C04 0035 0200 09C0 0020 02A4 02F5 0A7E

0C7E 008F 0743 0A8A 0C00 002F

008A 0789

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 00314 00315 00316 00317

movlw movwf goto ; LOOP2 ; LOOP movlw subwf btfsc goto addwf goto movlw movwf

digit1 FSR LOOP digit3 FSR

; ; address of digit1 into File Select Register enables POINTER ; this loop is used to modify the minutes/seconds place

; this loop is used to modify the hours place

D10 POINTER,1 STATUS,C INCREMENT_10S POINTER,1 NEXT_DIGIT

; find out how many tens in number, ; was a borrow needed? ; if not, add 1 to tens position ; if so, do not increment tens place, add ten back on to get 1s

; INCREMENT_10S incf FSR,1 incf POINTER,1 decf FSR,1 goto LOOP ; NEXT_DIGIT decfsz count,1 goto LOOP2 ; CONVERT_HEX_TO_DISPLAY movlw digit1 movwf FSR movlw H04 movwf count NEXT_HEX movf POINTER,0 call RETURN_CODE movwf POINTER incf FSR,1 decfsz count,1 goto NEXT_HEX ; FIX_DISPLAY movlw ZERO subwf digit4,0 btfss STATUS,Z goto FIX_SEC movlw BLANK movwf digit4 FIX_SEC btfss flags,SW1

; ; ; ;

bump address pointed to from 1st position to 10s add 1 to 10s position as determined by previous subtract put POINTER value back to 1s place for next subtraction go back and keep subtracting until finished

; converts hex number in digit variables to decimal display code ; put the address of the first digit into the FSR to enable POINTER ; prepare count variable to loop for all four displays ; ; ; ; ; get the hex value of the current digit variable call for the hex to decimal display conversion put the returned display code back into the digit variable increment the pointer to the next digit variable address allow only count(4) times through loop

AN590

DS00590C-page 10 1997 Microchip Technology Inc.

AN590

008B 0A8D 008C 002E 008D 008D 0CF0 008E 0169 008F 008F 0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 009A 009B 009C 009D 009E 009F 00A0 00A1 00A2 00A3 00A4 00A5 00A6 00A7 00A8 00A9 00AA 00AB 00AC 0CFF 0025 0C0E 0006 0C0F 0169 0000 0000 0000 0206 0034 0734 0A9F 0569 0589 05E9 0754 0AA4 0569 05A9 05E9 0774 0AA9 0569 05C9 05E9 0C00 0006 0C00 0026

00AD 00AE 00AF 00B0 00B1

070B 020F 072B 020E 074B

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 00361 00362 00363 00364

goto movwf

CLEAR_FLAGS digit3

; CLEAR_FLAGS movlw HF0 andwf flags,1 ; clear the lower 4 flag bits to show update status ; CYCLE ; movlw DISPOFF movwf PORT_A ; Turn off LED Displays movlw SWITCH tris PORT_B ; Set some port B pins as switch inputs movlw H0F andwf flags,1 ; reset switch flags to zero nop ; nop may not be needed, allows old outputs to bleed nop ; off through 10k R before reading port pins nop movf PORT_B,0 movwf var btfss var,1 goto SWITCH2 bsf flags,CHG bsf flags,SW1 bsf flags,SW_ON SWITCH2 btfss var,2 goto SWITCH3 bsf flags,CHG bsf flags,SW2 bsf flags,SW_ON SWITCH3 btfss var,3 goto SETPORT bsf flags,CHG bsf flags,SW3 bsf flags,SW_ON ; SETPORT movlw H00 tris PORT_B movlw BLANK movwf PORT_B ; ; determine which display needs updating and cycle it on btfss display,0 ; if 1st display, get 1st digit movf digit4,0 btfss display,1 ; if 2nd display, get 2nd digit movf digit3,0 btfss display,2 ; if 3rd display, get 3rd digit

1997 Microchip Technology Inc. DS00590C-page 11

00B2 00B3 00B4 00B5 00B6 00B7 00B8 00B9 00BA 00BB 00BC 00BD 00BE

020D 076B 020C 0026 06F0 0506 020B 0025 002B 036B 050B 078B 040B

00BF 0A1C 00C0 00C0 00C1 00C2 00C3 00C4 00C5 00C6 00C7 00C8 00C9 00CA 01E2 087E 080C 08B6 089E 08CC 08DA 08FA 080E 08FE 08CE

01FF 01FF 0A00

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

movf btfss movf movwf btfsc bsf movf movwf movwf rlf bsf btfss bcf ; ; ; goto ; RETURN_CODE ; addwf retlw retlw retlw retlw retlw retlw retlw retlw retlw retlw ; ; org goto ; END

digit2,0 display,3 digit1,0 PORT_B sec_nth,7 PORT_B,0 display,0 PORT_A display display,1 display,0 display,4 display,0

; if 4th display, get 4th digit ; put the number out to display ; ; ; ; ; ; ; ; sets colon decimal on %50 duty using highest bit get display needing cycle on enables proper display returns old w if not done, new w if resetting display rotate display on bit to next position assures a 1 on lowest position since rotated carry is zero check if last display was already updated if it was, set display back to 1st (bit 0 set)

MAIN

PC,1 ZERO ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE

PIC54 START

MEMORY USAGE MAP (X = Used, 0000 0040 0080 00C0 01C0 : : : : : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXX--------------------

- = Unused)

AN590

XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX -------------------------------

XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX -------------------------------

XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX ------------------------------X

All other memory blocks unused.

DS00590C-page 12 1997 Microchip Technology Inc.

AN590

Program Memory Words Used: Program Memory Words Free:

204 308

Errors : Warnings : Messages :

0 0 reported, 0 reported,

0 suppressed 0 suppressed

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 Microchips 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 Companys 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, Microchips quality system for the design and manufacture of development systems is ISO 9001 certified.

2002 Microchip Technology Inc.

M
WORLDWIDE SALES AND SERVICE
AMERICAS
Corporate Office
2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: 480-792-7627 Web Address: http://www.microchip.com

ASIA/PACIFIC
Australia
Microchip Technology Australia Pty Ltd Suite 22, 41 Rawson Street Epping 2121, NSW Australia Tel: 61-2-9868-6733 Fax: 61-2-9868-6755

Japan
Microchip Technology Japan K.K. Benex S-1 6F 3-18-20, Shinyokohama Kohoku-Ku, Yokohama-shi Kanagawa, 222-0033, Japan Tel: 81-45-471- 6166 Fax: 81-45-471-6122

Rocky Mountain
2355 West Chandler Blvd. Chandler, AZ 85224-6199 Tel: 480-792-7966 Fax: 480-792-7456

China - Beijing
Microchip Technology Consulting (Shanghai) Co., Ltd., Beijing Liaison Office Unit 915 Bei Hai Wan Tai Bldg. No. 6 Chaoyangmen Beidajie Beijing, 100027, No. China Tel: 86-10-85282100 Fax: 86-10-85282104

Korea
Microchip Technology Korea 168-1, Youngbo Bldg. 3 Floor Samsung-Dong, Kangnam-Ku Seoul, Korea 135-882 Tel: 82-2-554-7200 Fax: 82-2-558-5934

Atlanta
500 Sugar Mill Road, Suite 200B Atlanta, GA 30350 Tel: 770-640-0034 Fax: 770-640-0307

Singapore
Microchip Technology Singapore Pte Ltd. 200 Middle Road #07-02 Prime Centre Singapore, 188980 Tel: 65-334-8870 Fax: 65-334-8850

Boston
2 Lan Drive, Suite 120 Westford, MA 01886 Tel: 978-692-3848 Fax: 978-692-3821

China - Chengdu
Microchip Technology Consulting (Shanghai) Co., Ltd., Chengdu Liaison Office Rm. 2401, 24th Floor, Ming Xing Financial Tower No. 88 TIDU Street Chengdu 610016, China Tel: 86-28-6766200 Fax: 86-28-6766599

Taiwan
Microchip Technology Taiwan 11F-3, No. 207 Tung Hua North Road Taipei, 105, Taiwan Tel: 886-2-2717-7175 Fax: 886-2-2545-0139

Chicago
333 Pierce Road, Suite 180 Itasca, IL 60143 Tel: 630-285-0071 Fax: 630-285-0075

Dallas
4570 Westgrove Drive, Suite 160 Addison, TX 75001 Tel: 972-818-7423 Fax: 972-818-2924

China - Fuzhou
Microchip Technology Consulting (Shanghai) Co., Ltd., Fuzhou Liaison Office Unit 28F, World Trade Plaza No. 71 Wusi Road Fuzhou 350001, China Tel: 86-591-7503506 Fax: 86-591-7503521

EUROPE
Denmark
Microchip Technology Nordic ApS Regus Business Centre Lautrup hoj 1-3 Ballerup DK-2750 Denmark Tel: 45 4420 9895 Fax: 45 4420 9910

Detroit
Tri-Atria Office Building 32255 Northwestern Highway, Suite 190 Farmington Hills, MI 48334 Tel: 248-538-2250 Fax: 248-538-2260

China - Shanghai
Microchip Technology Consulting (Shanghai) Co., Ltd. Room 701, Bldg. B Far East International Plaza No. 317 Xian Xia Road Shanghai, 200051 Tel: 86-21-6275-5700 Fax: 86-21-6275-5060

Kokomo
2767 S. Albright Road Kokomo, Indiana 46902 Tel: 765-864-8360 Fax: 765-864-8387

France
Microchip Technology SARL Parc dActivite 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

Los Angeles
18201 Von Karman, Suite 1090 Irvine, CA 92612 Tel: 949-263-1888 Fax: 949-263-1338

China - Shenzhen
Microchip Technology Consulting (Shanghai) Co., Ltd., Shenzhen Liaison Office Rm. 1315, 13/F, Shenzhen Kerry Centre, Renminnan Lu Shenzhen 518001, China Tel: 86-755-2350361 Fax: 86-755-2366086

New York
150 Motor Parkway, Suite 202 Hauppauge, NY 11788 Tel: 631-273-5305 Fax: 631-273-5335

Germany
Microchip Technology GmbH Gustav-Heinemann Ring 125 D-81739 Munich, Germany Tel: 49-89-627-144 0 Fax: 49-89-627-144-44

San Jose
Microchip Technology Inc. 2107 North First Street, Suite 590 San Jose, CA 95131 Tel: 408-436-7950 Fax: 408-436-7955

Hong Kong
Microchip Technology Hongkong Ltd. Unit 901-6, Tower 2, Metroplaza 223 Hing Fong Road Kwai Fong, N.T., Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431

Italy
Microchip Technology SRL Centro Direzionale Colleoni Palazzo Taurus 1 V. Le Colleoni 1 20041 Agrate Brianza Milan, Italy Tel: 39-039-65791-1 Fax: 39-039-6899883

Toronto
6285 Northam Drive, Suite 108 Mississauga, Ontario L4V 1X5, Canada Tel: 905-673-0699 Fax: 905-673-6509

India
Microchip Technology Inc. India Liaison Office Divyasree Chambers 1 Floor, Wing A (A3/A4) No. 11, OShaugnessey Road Bangalore, 560 025, India Tel: 91-80-2290061 Fax: 91-80-2290062

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.

You might also like