gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ; $Id: clock.asm,v 1.13 2001/05/13 21:45:11 dogcow Exp dogcow $ 00002 ; 00003 ; General notes: this is dervied from the 99 minute timer code, but I've 00004 ; whacked close to every single line of code there, so it's MINE! MINE! 00005 ; 00006 ; The "check 8 seconds" doesn't get triggered on second 00; this reduces the 00007 ; maximum number of ticks/minute to 7. (This can be fixed by moving the 00008 ; incf halfseconds, f to 'chkforminute' instead of right at 'checkseconds'.) 00009 ; 00010 list p=16f84a, r=dec 00001 LIST 00002 ; P16F84A.INC Standard Header File, Version 2.00 Microchip Technology, Inc. 00134 LIST 00011 include "p16f84a.inc" 00012 0000 00013 org 0 0000 282D 00014 goto init ;power-on-reset 0001 2830 00015 goto start ;interrupt vector (shouldn't be called) 00016 00000006 00017 numticksperminute equ 6 ; how many ticks occur in a minute? 00018 0000000C 00019 regbase equ 0ch ; vars start at 0ch on the 16C84. 0000000C 00020 oldkey equ regbase+0 0000000D 00021 newkey equ regbase+1 0000000E 00022 counter_4ms equ regbase+2 ;incremented every 4 msec 0000000F 00023 counter_100ms equ regbase+3 ;incremented every 100 msec 00000010 00024 halfseconds equ regbase+4 00000011 00025 minutes equ regbase+5 00000012 00026 hours equ regbase+6 00000013 00027 minuteticks equ regbase+7 00000014 00028 hourticks equ regbase+8 00000015 00029 tmr_comp equ regbase+9 ;tmr0 comparator register 00000016 00030 scrtch0 equ regbase+10 00000017 00031 led1 equ regbase+11 00000018 00032 led2 equ regbase+12 00033 00034 ; pin assignments: 00035 ; output: 00036 ; ra1,2,3 - minute/hour/ageofman outputs (to power Q's/solenoids) 00037 ; rb0,1,2,3 - minute/tenminute/hour/resettozero inputs (from pushbuttons) 00038 ; rb4,5,6 - strobe,clock,data outputs (to 4094s) 00039 ; ra0, rb7: unused 00040 ; 00041 ; bit positions inside digit_inc and newkey 00000000 00042 minute_inc equ 0 ;aka rb0 00000001 00043 tenminute_inc equ 1 ;aka rb1 XXX NOT CURRENTLY IMPLEMENTED XXX 00000002 00044 hour_inc equ 2 ;aka rb2 00000003 00045 reset_minutes equ 3 ;aka rb3 00000006 00046 button_PORT equ PORTB 0000000F 00047 keymask equ 0fh ; mask for lower keys 00048 00049 ; the 4094 8-bit shift registers 00000004 00050 strobe_4094 equ 4 ;aka rb4 00000005 00051 clock_4094 equ 5 ;aka rb5 gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00000006 00052 data_4094 equ 6 ;aka rb6 00000006 00053 shiftreg_PORT equ PORTB 00054 00055 ; the solenoids that kick the escapements 00056 ; note that since the output solenoids are on their own PORT, we can do 00057 ; bcf/bsfs without hitting a read latch we care about. 00000001 00058 minute_sol equ 1 ;aka ra1 00000002 00059 hour_sol equ 2 ;aka ra2 00000003 00060 aom_sol equ 3 ;aka ra3 (age of man relay) 00000005 00061 solenoid_PORT equ PORTA 00062 00063 ;7 segments decoded data. lo is segment on & hi is segment off 0002 0782 00064 get_seg addwf PCL, f 00065 ; ABCDEFGPb Error clock.asm 66 : 157 Illegal character 'b' in numeric constant 0003 340B 00066 retlw 00000011b ;0 Error clock.asm 67 : 157 Illegal character 'b' in numeric constant 0004 34E7 00067 retlw 10011111b ;1 Error clock.asm 68 : 157 Illegal character 'b' in numeric constant 0005 3405 00068 retlw 00100101b ;2 Error clock.asm 69 : 157 Illegal character 'b' in numeric constant 0006 344D 00069 retlw 00001101b ;3 Error clock.asm 70 : 157 Illegal character 'b' in numeric constant 0007 3479 00070 retlw 10011001b ;4 Error clock.asm 71 : 157 Illegal character 'b' in numeric constant 0008 3429 00071 retlw 01001001b ;5 Error clock.asm 72 : 157 Illegal character 'b' in numeric constant 0009 3441 00072 retlw 01000001b ;6 Error clock.asm 73 : 157 Illegal character 'b' in numeric constant 000A 3467 00073 retlw 00011111b ;7 Error clock.asm 74 : 157 Illegal character 'b' in numeric constant 000B 3401 00074 retlw 00000001b ;8 Error clock.asm 75 : 157 Illegal character 'b' in numeric constant 000C 34F9 00075 retlw 00011001b ;9 Error clock.asm 76 : 157 Illegal character 'b' in numeric constant 000D 3411 00076 retlw 00010001b ;A Error clock.asm 77 : 157 Illegal character 'b' in numeric constant 000E 34C1 00077 retlw 11000001b ;b Error clock.asm 78 : 157 Illegal character 'b' in numeric constant 000F 34EB 00078 retlw 01100011b ;C Error clock.asm 79 : 157 Illegal character 'b' in numeric constant 0010 34E5 00079 retlw 10000101b ;d Error clock.asm 80 : 157 Illegal character 'b' in numeric constant 0011 34E1 00080 retlw 01100001b ;E Error clock.asm 81 : 157 Illegal character 'b' in numeric constant 0012 34D9 00081 retlw 01111001b ;F Error clock.asm 82 : 157 Illegal character 'b' in numeric constant 00A98AC6 00082 dec_pt equ 11111110b ;decimal point bit 00083 0013 0812 00084 getticksperhour movf hours, w 0014 0782 00085 addwf PCL, f 0015 3405 00086 retlw 5 ;00 0016 3404 00087 retlw 4 ;01 0017 3403 00088 retlw 3 ;02 gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0018 3404 00089 retlw 4 ;03 0019 3402 00090 retlw 2 ;04 001A 3402 00091 retlw 2 ;05 001B 3402 00092 retlw 2 ;06 001C 3402 00093 retlw 2 ;07 001D 3402 00094 retlw 2 ;08 001E 3402 00095 retlw 2 ;09 001F 3404 00096 retlw 4 ;10 0020 3404 00097 retlw 4 ;11 0021 3404 00098 retlw 4 ;12 0022 3403 00099 retlw 3 ;13 0023 3403 00100 retlw 3 ;14 0024 3401 00101 retlw 1 ;15 0025 3402 00102 retlw 2 ;16 0026 3402 00103 retlw 2 ;17 0027 3403 00104 retlw 3 ;18 0028 3403 00105 retlw 3 ;19 0029 3402 00106 retlw 2 ;20 002A 3404 00107 retlw 4 ;21 002B 3404 00108 retlw 4 ;22 002C 3405 00109 retlw 5 ;23 00110 00111 ; clear vars, 00112 ; set the ports to the proper impedence/io states, 00113 ; and frob prescaler to make timer0 run more slowly. 00114 ; 002D 0192 00115 init clrf hours 002E 0191 00116 clrf minutes 002F 0190 00117 clrf halfseconds 0030 018C 00118 start clrf oldkey 0031 018D 00119 clrf newkey 0032 018E 00120 clrf counter_4ms 0033 018F 00121 clrf counter_100ms 00122 ; set up the TRIS flags properly - have to bank-switch to proper region 0034 1683 00123 bsf STATUS, RP0 00124 ; 0035 0185 00125 clrf TRISA ;lazy way "all ports are out" Error clock.asm 126 : 157 Illegal character 'b' in numeric constant 0036 3057 00126 movlw 00001111b ;ports 0-3 are pb input 0037 0086 00127 movwf TRISB 00128 ; Error clock.asm 129 : 157 Illegal character 'b' in numeric constant 0038 30CB 00129 movlw 11000011b ;tmr0 enable with 1:16 prescaler 0039 0081 00130 movwf OPTION_REG ;see 2.2.2.2 in 16f84a datasheet 003A 018B 00131 clrf INTCON ;we don't want no steenking interrupts! 00132 ; 003B 1283 00133 bcf STATUS, RP0 ;bank-switch back 00134 00135 ; and now, the timer bits 003C 0181 00136 clrf TMR0 00137 ; why 250? each isn takes 4 cycles, so with a 4mhz processor, 1m isn/sec. 00138 ; with 1:16 prescaler, 16 * 250 / 1e6 Hz = 4e-3 seconds 003D 30FA 00139 movlw 250 003E 0095 00140 movwf tmr_comp gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 003F 288C 00141 goto resetticks ;have to populate ticks/hour&min 00142 ; 00143 ; and now, the main main time-wasting loop 00144 ; 0040 0815 00145 main movf tmr_comp, w ;is tmr0 = tmr_comp (4 msec over?) 0041 0601 00146 xorwf TMR0, w 0042 1D03 00147 btfss STATUS, Z ;skip if = 250 0043 2840 00148 goto main 0044 30FA 00149 movlw 250 0045 0795 00150 addwf tmr_comp, f ;update 4 msec compare register 0046 0A8E 00151 incf counter_4ms, f 0047 3019 00152 movlw 25 0048 060E 00153 xorwf counter_4ms, w ;is 4ms * 25 = 100ms over ? 0049 1D03 00154 btfss STATUS, Z ;skip if = 100ms 004A 2840 00155 goto main 004B 018E 00156 clrf counter_4ms 00157 ; 100ms over - time to check the status of the buttons! 00158 ; 00159 ; in order for a button to register, the key has to have been pressed 00160 ; for two successive 100ms intervals. We invert the active-low 00161 ; bits to positive so we can just AND oldkey and newkey together. 00162 ; 004C 080D 00163 check_buttons movf newkey, w 004D 008C 00164 movwf oldkey ; save old key 004E 0906 00165 comf button_PORT, w ; invert keys, since active low 004F 008D 00166 movwf newkey ; save now active-high key 00167 ; clrf keyaction 0050 058C 00168 andwf oldkey, f ; and AND'em to oldkey in place 00169 ; movlw keymask 00170 ; andwf oldkey, f ; just in case we pick up spurious bits 00171 ; (I hope this ain't really needed) 00172 ; 00173 ; and back to the horribly important business of keeping the counters up 0051 0A8F 00174 incf counter_100ms, f 0052 3005 00175 movlw 5 0053 060F 00176 xorwf counter_100ms, w ;is 500ms done? 0054 1D03 00177 btfss STATUS, Z 0055 2840 00178 goto main ;nope, 500ms ain't done. 00179 ; 00180 ; huzzah! welcome to 500ms. 00181 ; all sorts of crap gets done here: 00182 ; turn off solenoids if it's an odd halfsecond; 00183 ; do clock ticks on multiples of 8 seconds ; 00184 ; do minute->hour rollover and stuff if needed; 00185 ; and finally, display the time on the LEDs. 00186 ; 0056 018F 00187 clrf counter_100ms ;half a second over! 00188 0057 080C 00189 movf oldkey, w ;have buttons been pressed? 0058 1903 00190 btfsc STATUS, Z 0059 2868 00191 goto checkseconds ; nope. 00192 ; so, we got button presses. buttons are active high. 005A 1C0C 00193 btfss oldkey, minute_inc 005B 285F 00194 goto chkhourbutton ; advance the minute! gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 005C 0190 00195 clrf halfseconds 005D 0A91 00196 incf minutes, f 005E 2883 00197 goto chkminuterollover 005F 1D0C 00198 chkhourbutton btfss oldkey, hour_inc 0060 2863 00199 goto chkresetbutton 0061 0A92 00200 incf hours, f ; inc hours, don't reset minute/hsec 0062 2888 00201 goto chkhourrollover 0063 1D8C 00202 chkresetbutton btfss oldkey, reset_minutes 0064 2868 00203 goto checkseconds 0065 0190 00204 clrf halfseconds 0066 0191 00205 clrf minutes 0067 2888 00206 goto chkhourrollover ; and this'll fall into 00207 0068 0A90 00208 checkseconds incf halfseconds, f 00209 ; if it's a odd half-second, turn off solenoids 0069 3001 00210 movlw 1 006A 0510 00211 andwf halfseconds, w 006B 1903 00212 btfsc STATUS,Z 006C 286F 00213 goto check8secs 00214 ; actually turn off the solenoids 006D 1085 00215 bcf solenoid_PORT, minute_sol 006E 1105 00216 bcf solenoid_PORT, hour_sol 00217 ; check and see if a multiple of 8 seconds has elapsed 006F 300F 00218 check8secs movlw 15 0070 0510 00219 andwf halfseconds, w 0071 1D03 00220 btfss STATUS, Z 0072 287D 00221 goto chkforminute ; nope, don't worry about tocking 00222 ; tick if need be... 0073 0893 00223 movf minuteticks, f 0074 1903 00224 btfsc STATUS, Z 0075 2878 00225 goto checkhourticks ;nope, no minute ticks needed 0076 1485 00226 bsf solenoid_PORT, minute_sol 0077 0393 00227 decf minuteticks, f 0078 0894 00228 checkhourticks movf hourticks, f 0079 1903 00229 btfsc STATUS, Z 007A 287D 00230 goto chkforminute ;nope, no hour ticks needed 007B 1505 00231 bsf solenoid_PORT, hour_sol 007C 0394 00232 decf hourticks, f 00233 ; 007D 3078 00234 chkforminute movlw 120 007E 0610 00235 xorwf halfseconds, w ;is 1 minute over ? 007F 1D03 00236 btfss STATUS, Z 0080 2890 00237 goto displaytime ;nope. 00238 ; roll over minutes, and possibly hours 0081 0190 00239 clrf halfseconds 0082 0A91 00240 incf minutes, f 0083 303C 00241 chkminuterollover movlw 60 0084 0611 00242 xorwf minutes, w ;is 60 minutes over? 0085 1D03 00243 btfss STATUS, Z 0086 288C 00244 goto resetticks ;reset minutetick & hourtick 00245 ; update hours 0087 0A92 00246 incf hours, f 0088 3018 00247 chkhourrollover movlw 24 0089 0612 00248 xorwf hours, w gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 008A 1903 00249 btfsc STATUS, Z 008B 0192 00250 clrf hours 008C 2013 00251 resetticks call getticksperhour 008D 0094 00252 movwf hourticks 008E 3006 00253 movlw numticksperminute 008F 0093 00254 movwf minuteticks 00255 ; and fall through to "display the time on the LEDs" 0090 30FF 00256 displaytime movlw 255 ;all segs off 0091 0097 00257 movwf led1 0092 0812 00258 movf hours, w 0093 2002 00259 call get_seg 0094 0098 00260 movwf led2 0095 3001 00261 movlw 1 0096 0510 00262 andwf halfseconds, w 0097 1D03 00263 btfss STATUS,Z 0098 28A1 00264 goto xmittoleds 0099 300F 00265 movlw 15 009A 0511 00266 andwf minutes, w 009B 2002 00267 call get_seg 009C 0098 00268 movwf led2 009D 0E11 00269 swapf minutes, w 009E 390F 00270 andlw 15 009F 2002 00271 call get_seg 00A0 0097 00272 movwf led1 00273 ;transmit data from scrtch1 thr scrtch1 to display circuit (msb first). 00A1 3010 00274 xmittoleds movlw 16 ;no of bit to tx 00A2 0096 00275 movwf scrtch0 00A3 0D98 00276 xmitloop rlf led2, f 00A4 0D97 00277 rlf led1, f 00A5 1803 00278 btfsc STATUS, C ;data hi if cy=1 else lo 00A6 28A9 00279 goto toggle_hi 00A7 1306 00280 bcf shiftreg_PORT, data_4094 00A8 28AA 00281 goto toggle_clock 00A9 1706 00282 toggle_hi bsf shiftreg_PORT, data_4094 00AA 0000 00283 toggle_clock nop ;delay 00AB 0000 00284 nop 00AC 1686 00285 bsf shiftreg_PORT, clock_4094 00AD 0000 00286 nop 00AE 0000 00287 nop 00AF 1286 00288 bcf shiftreg_PORT, clock_4094 00B0 0000 00289 nop 00B1 0000 00290 nop 00B2 0B96 00291 decfsz scrtch0, f ;next bit 00B3 28A3 00292 goto xmitloop 00B4 1606 00293 bsf shiftreg_PORT, strobe_4094 00B5 0000 00294 nop 00B6 1206 00295 bcf shiftreg_PORT, strobe_4094 00B7 1306 00296 bcf shiftreg_PORT, data_4094 00B8 2840 00297 goto main 00298 ; 002007 3FF3 00299 __CONFIG _RC_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 7 SYMBOL TABLE LABEL VALUE C 00000000 DC 00000001 EEADR 00000009 EECON1 00000088 EECON2 00000089 EEDATA 00000008 EEIE 00000006 EEIF 00000004 F 00000001 FSR 00000004 GIE 00000007 INDF 00000000 INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 IRP 00000007 NOT_PD 00000003 NOT_RBPU 00000007 NOT_TO 00000004 OPTION_REG 00000081 PCL 00000002 PCLATH 0000000A PORTA 00000005 PORTB 00000006 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 RBIE 00000003 RBIF 00000000 RD 00000000 RP0 00000005 RP1 00000006 STATUS 00000003 T0CS 00000005 T0IE 00000005 T0IF 00000002 T0SE 00000004 TMR0 00000001 TRISA 00000085 TRISB 00000086 W 00000000 WR 00000001 WREN 00000002 WRERR 00000003 Z 00000002 _CP_OFF 00003FFF _CP_ON 0000000F _HS_OSC 00003FFE _LP_OSC 00003FFC _PWRTE_OFF 00003FFF _PWRTE_ON 00003FF7 gpasm-0.9.4 alpha clock.asm 5-14-2001 19:08:11 PAGE 8 LOC OBJECT CODE LINE SOURCE TEXT VALUE _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _XT_OSC 00003FFD aom_sol 00000003 button_PORT 00000006 check8secs 0000006F check_buttons 0000004C checkhourticks 00000078 checkseconds 00000068 chkforminute 0000007D chkhourbutton 0000005F chkhourrollover 00000088 chkminuterollover 00000083 chkresetbutton 00000063 clock_4094 00000005 counter_100ms 0000000F counter_4ms 0000000E data_4094 00000006 dec_pt 00A98AC6 displaytime 00000090 get_seg 00000002 getticksperhour 00000013 halfseconds 00000010 hour_inc 00000002 hour_sol 00000002 hours 00000012 hourticks 00000014 init 0000002D keymask 0000000F led1 00000017 led2 00000018 main 00000040 minute_inc 00000000 minute_sol 00000001 minutes 00000011 minuteticks 00000013 newkey 0000000D numticksperminute 00000006 oldkey 0000000C regbase 0000000C reset_minutes 00000003 resetticks 0000008C scrtch0 00000016 shiftreg_PORT 00000006 solenoid_PORT 00000005 start 00000030 strobe_4094 00000004 tenminute_inc 00000001 tmr_comp 00000015 toggle_clock 000000AA toggle_hi 000000A9 xmitloop 000000A3 xmittoleds 000000A1 Errors : 19 Warnings : 0 reported, 0 suppressed Messages : 0 reported, 0 suppressed