list p=pic16f873 include p16f873.inc __config _hs_osc & _wdt_off & _pwrte_on & _lvp_off ;**************** Label Definition ******************** cblock h'20' count ;Clock counter disp_p ;Disply position disp_pw ;Disply position work disp_data ;Disply data save area disp_h10w ;Tens of hour work disp_h10 ;Tens of hour disp_h1 ;Units of hour disp_m10 ;Tens of minute disp_m1 ;Units of minute disp_s10 ;Tens of second disp_s1 ;Units of second mode ;Mode (0:Adjust 1:Clock) rb6ll ;0 sec adjust Last look rb7ll ;Time adjust Last look rb7count ;Time adj guard counter digit_posi ;Adj digit position data digit_posiw ;Adj digit position work digit_save ;Previous adj data save digit_blink ;Digit blink counter blink_cont ;Blink (0:ON 1:OFF) change_st ;Digit change status change_wk ;Digit change work seg7_ha ;7 segLED table head adr seg70 ;Pattern 0 set adr seg71 ;Pattern 1 set adr seg72 ;Pattern 2 set adr seg73 ;Pattern 3 set adr seg74 ;Pattern 4 set adr seg75 ;Pattern 5 set adr seg76 ;Pattern 6 set adr seg77 ;Pattern 7 set adr seg78 ;Pattern 8 set adr seg79 ;Pattern 9 set adr seg7a ;Pattern A set adr seg7b ;Pattern B set adr endc ra1 equ h'01' ;RA1 port designation ra2 equ h'02' ;RA2 port designation ra3 equ h'03' ;RA3 port designation rb1 equ h'01' ;RB1 port designation rb4 equ h'04' ;RB4 port designation rb5 equ h'05' ;RB5 port designation rb6 equ h'06' ;RB6 port designation rb7 equ h'07' ;RB7 port designation seg7_0 equ b'01000000' ;-gfedcba Pattern 0 seg7_1 equ b'01111001' ; Pattern 1 seg7_2 equ b'00100100' ; Pattern 2 seg7_3 equ b'00110000' ; Pattern 3 seg7_4 equ b'00011001' ; Pattern 4 seg7_5 equ b'00010010' ; Pattern 5 seg7_6 equ b'00000010' ; Pattern 6 seg7_7 equ b'01111000' ; Pattern 7 seg7_8 equ b'00000000' ; Pattern 8 seg7_9 equ b'00010000' ; Pattern 9 seg7_a equ b'01111111' ; LED off seg7_b equ b'00100011' ; Illegal int ;**************** Program Start *********************** org 0 ;Reset Vector goto init org 4 ;Interrupt Vector goto int ;**************** Initial Process ********************* init ;*** Port mode initializing bsf status,rp0 ;Change to Bank1 movlw b'00000110' ;RA port to digital mode movwf adcon1 ;Set ADCON1 register movlw b'00000000' ;RA port to output mode movwf trisa ;Set TRISA register movlw b'11111101' ;RB1:output,OTHER:input movwf trisb ;Set TRISB register movlw b'00000000' ;RC port to output mode movwf trisc ;Set TRISC register ;*** LED disply interval initializing (Timer0) movlw b'00000010' ;PBPU=on,PSA=0,PS=1:8 movwf option_reg ;Set OPTION_REG register bcf status,rp0 ;Change to Bank0 movlw d'131' ;(256-131)x8=1000usec movwf tmr0 ;Set TMR0 register ;*** Port initializing clrf porta ;Clear PORTA clrf portb ;Clear PORTB movlw b'11111111' ;Set LED off data movwf portc ;Set PORTC ;*** Work area initializing clrf count ;Clear Clock counter movlw d'6' ;Disply position = 6 movwf disp_p ;Set disply position clrf disp_h10 ;Clear Tens of hour clrf disp_h1 ;Clear Units of hour clrf disp_m10 ;Clear Tens of minute clrf disp_m1 ;Clear Units of minute clrf disp_s10 ;Clear Tens of second clrf disp_s1 ;Clear Units of second clrf mode ;Set Adjust mode clrf rb6ll ;Clear 0 sec Last look clrf rb7ll ;Clear Time adj Last look clrf rb7count ;Clear Time adj guard clrf digit_posi ;Clear Adj digit position clrf digit_blink ;Clear Digit blink count clrf blink_cont ;Set Blink on clrf change_st ;Clear Change status movlw seg70 ;Set 7seg head address movwf seg7_ha ;Save 7seg head address movlw seg7_0 ;Set 7segment pattern 0 movwf seg70 ;Save pattern 0 movlw seg7_1 ;Set 7segment pattern 1 movwf seg71 ;Save pattern 1 movlw seg7_2 ;Set 7segment pattern 2 movwf seg72 ;Save pattern 2 movlw seg7_3 ;Set 7segment pattern 3 movwf seg73 ;Save pattern 3 movlw seg7_4 ;Set 7segment pattern 4 movwf seg74 ;Save pattern 4 movlw seg7_5 ;Set 7segment pattern 5 movwf seg75 ;Save pattern 5 movlw seg7_6 ;Set 7segment pattern 6 movwf seg76 ;Save pattern 6 movlw seg7_7 ;Set 7segment pattern 7 movwf seg77 ;Save pattern 7 movlw seg7_8 ;Set 7segment pattern 8 movwf seg78 ;Save pattern 8 movlw seg7_9 ;Set 7segment pattern 9 movwf seg79 ;Save pattern 9 movlw seg7_a ;Set 7segment pattern A movwf seg7a ;Save pattern A movlw seg7_b ;Set 7segment pattern B movwf seg7b ;Save pattern B ;*** Interruption control movlw b'10111000' ;GIE&T0IE&INTE&RBIE=ON movwf intcon ;Set INTCON register wait goto $ ;Interruption wait ;*************** Interruption Process ***************** int movf intcon,w ;Read INTCON register btfsc intcon,intf ;RB0/INT interrupt ? goto clock ;Yes. "Clock" btfsc intcon,t0if ;TMR0 overflow ? goto led_disp ;Yes. "LED disply" btfsc intcon,rbif ;RB Port Change ? goto digit_change ;Yes. "Digit change" ;*************** Illegal interruption ***************** illegal movlw h'0b' ;Set Illegal disp digit addwf seg7_ha,w ;Seg7 H.Adr + digit movwf fsr ;Set FSR register movf indf,w ;Read seg7 data movwf portc ;Set LED data movlw b'00000101' ;Set sec1 select data movwf porta ;Write digit select data goto $ ;Stop ;************ END of Interruption Process ************** int_end retfie ;********* LED disply Process (1msec interval) ********* led_disp bcf intcon,t0if ;Clear T0IF movlw d'131' ;Set Time value (1msec) movwf tmr0 ;Write TMR0 register movlw b'11111111' ;LED off data movwf portc ;Clear disply movf disp_p,w ;Read disply position movwf disp_pw ;Save position data decfsz disp_pw,f ;Units of second ? goto led_disp0 ;No. Next ;*** Control UNITS of SECOND movlw b'00000101' ;Set units of second movwf porta ;Write PORTA register movf disp_s1,w ;Read units of sec data movwf disp_data ;Save data goto led_disp8 ;Jump to LED control led_disp0 decfsz disp_pw,f ;Tens of second ? goto led_disp1 ;No. Next ;*** Control TENS of SECOND movlw b'00000100' ;Set tens of second movwf porta ;Write PORTA register movf disp_s10,w ;Read tens of sec data movwf disp_data ;Save data goto led_disp8 ;Jump to LED control led_disp1 decfsz disp_pw,f ;Units of minute ? goto led_disp2 ;No. Next ;*** Control UNITS of MINUTE movlw b'00000011' ;Set units of minute movwf porta ;Write PORTA register movf disp_m1,w ;Read units of min data movwf disp_data ;Save data goto led_disp8 ;Jump to LED control led_disp2 decfsz disp_pw,f ;Tens of minute ? goto led_disp3 ;No. Next ;*** Control TENS of MINUTE movlw b'00000010' ;Set tens of minute movwf porta ;Write PORTA register movf disp_m10,w ;Read tens of min data movwf disp_data ;Save data goto led_disp8 ;Jump to LED control led_disp3 decfsz disp_pw,f ;Units of hour ? goto led_disp4 ;No. Next ;*** Control UNITS of HOUR movlw b'00000001' ;Set units of hour movwf porta ;Write PORTA register movf disp_h1,w ;Read units of hour data movwf disp_data ;Save data goto led_disp8 ;Jump to LED control ;*** Control TENS of HOUR led_disp4 movlw b'00000000' ;Set tens of hour movwf porta ;Write PORTA register movlw h'0a' ;Set off data movwf disp_data ;Save data subwf disp_h10,w ;H10 - off data btfsc status,z ;H10 = off data ? goto led_disp8 ;Jump to LED control movf disp_h10,w ;Read tens of hour data movwf disp_h10w ;Save tens of hour data btfss status,z ;AM 0x o'clock ? goto led_disp5 ;No. Next movlw b'11111110' ;PM=off,Tens=off,AM=on goto led_disp9 ;Jump to PORTC write led_disp5 decfsz disp_h10w,f ;AM 1x o'clock ? goto led_disp6 ;No. Next movlw b'11111000' ;PM=off,Tens=1,AM=on goto led_disp9 ;Jump to PORTC write led_disp6 decfsz disp_h10w,f ;PM 0x o'clock ? goto led_disp7 ;No. Next movlw b'11110111' ;PM=on,Tens=off,AM=off goto led_disp9 ;Jump to PORTC write led_disp7 movlw b'11110001' ;PM=on,Tens=1,AM=off goto led_disp9 ;Jump to PORTC write led_disp8 movf disp_data,w ;Read disply digit data addwf seg7_ha,w ;Seg7 H.Adr + digit movwf fsr ;Set FSR register movf indf,w ;Read seg7 data led_disp9 movwf portc ;Write LED data led_dispe decfsz disp_p,f ;End of cycle ? goto int_end ;Jump to END of interrupt movlw d'6' ;Set initial value movwf disp_p ;Write disply position goto int_end ;Jump to END of interrupt ;****** Clock count up Process (20msec interval) ******* clock bcf intcon,intf ;Clear INTF ;*** Time adjust mode check movf mode,w ;Read time adj mode data btfsc status,z ;Time adjust mode ? goto adjust ;Yes. Jump to Adjust Proc ;*** 0 second adjust check btfss portb,rb6 ;0 sec adjust ? goto check1 ;No. movf rb6ll,w ;Yes. Read RB6 last look btfss status,z ;Last look = 0 ? goto check2 ;No. Last look = 1 incf rb6ll,f ;Yes. Set last look clrf disp_s1 ;Clear units of second clrf disp_s10 ;Clear tens of second clrf count ;Clear clock counter goto check2 ;Jump to time adj check check1 clrf rb6ll ;Clear RB6 last look ;*** Time adjust demand check check2 btfss portb,rb7 ;Time adjust ? goto check4 ;No. movlw d'100' ;Set guard (2sec) subwf rb7count,w ;Counter - Guard btfss status,c ;Counter >= Guard ? goto check3 ;No. Counter < Guard clrf digit_posi ;Set position to H10 movf disp_h10,w ;Read tens of hour movwf digit_save ;Save previous adj data clrf disp_s1 ;Clear units of second clrf disp_s10 ;Clear tens of second clrf count ;Clear clock counter incf rb7ll,f ;Set RB7 last look bsf intcon,rbie ;Set RBIE bit clrf mode ;Set time adjust mode goto adjust ;Jump to Adjust process check3 incf rb7count,f ;Counter + 1 goto clock1 ;Jump to clock count up check4 clrf rb7count ;Clear counter clrf rb7ll ;Clear RB7 last look ;*** Timer count up clock1 movlw d'49' ;Set 1 sec data subwf count,w ;Counter - 1 sec btfsc status,c ;Counter >= 1 sec ? goto clock_1sec ;Yes. Counter >= 1 sec incf count,f ;No. Counter + 1 goto int_end ;Jump to END of interrupt clock_1sec clrf count ;Clear 1 second counter movlw d'9' ;Set check data subwf disp_s1,w ;S1 - 9 btfsc status,c ;S1 >= 9 sec ? goto clock_10sec ;Yes. S1 >= 9 sec incf disp_s1,f ;No. S1 + 1 bcf portb,rb1 ;Clear time signal goto int_end ;Jump to END of interrupt clock_10sec clrf disp_s1 ;Set xx:xx:x0 movlw d'5' ;Set check data subwf disp_s10,w ;S10 - 5 btfsc status,c ;S10 >= 5x sec ? goto clock_1min ;Yes. S10 >= 5x sec incf disp_s10,f ;No. S10 + 1 goto int_end ;Jump to END of interrupt clock_1min clrf disp_s10 ;Set xx:xx:0x movlw d'9' ;Set check data subwf disp_m1,w ;M1 - 9 btfsc status,c ;M1 >= 9 min ? goto clock_10min ;Yes. M1 >= 9 min incf disp_m1,f ;No. M1 + 1 goto int_end ;Jump to END of interrupt clock_10min clrf disp_m1 ;Set xx:x0:xx movlw d'5' ;Set check data subwf disp_m10,w ;M10 - 5 btfsc status,c ;M10 >= 5x min ? goto clock_1hour ;Yes. M10 >= 5x min incf disp_m10,f ;No. M10 + 1 goto int_end ;Jump to END of interrupt clock_1hour clrf disp_m10 ;Set xx:0x:xx movf disp_h10,w ;Read tens of hour data movwf disp_h10w ;Save tens of hour data btfss status,z ;AM 0x o'clock ? goto hour1 ;No. Next ;*** AM 0x movlw d'9' ;Set check data subwf disp_h1,w ;H1 - 9 btfsc status,c ;H1 >= 9 hour ? goto am09 ;Yes. H1 >= 9 hour incf disp_h1,f ;No. H1 + 1 goto time_check ;Jump to Time Check am09 clrf disp_h1 ;Set x0:xx:xx incf disp_h10,f ;Set AM10:00:00 goto time_check ;Jump to Time Check hour1 decfsz disp_h10w,f ;AM 1x o'clock ? goto hour2 ;No. Next ;*** AM 1x decfsz disp_h1,w ;AM 11 o'clock ? goto am10 ;No. AM 10 o'clock goto am11 ;Yes. AM 11 o'clock am10 incf disp_h1,f ;H1 + 1 goto time_check ;Jump to Time Check am11 incf disp_h1,f ;Set x2:xx:xx movlw d'3' ;Set PM 1x movwf disp_h10 ;Set PM12:00:00 goto time_check ;Jump to Time Check hour2 decfsz disp_h10w,f ;PM 0x o'clock ? goto hour3 ;No. Next ;*** PM 0x movlw d'9' ;Set check data subwf disp_h1,w ;H1 - 9 btfsc status,c ;H1 >= 9 hour ? goto pm09 ;Yes. H1 >= 9 hour incf disp_h1,f ;No. H1 + 1 goto time_check ;Jump to Time Check pm09 clrf disp_h1 ;Set x0:xx:xx incf disp_h10,f ;Set PM10:00:00 goto time_check ;Jump to Time Check ;*** PM 1x hour3 movlw d'1' ;Set check data subwf disp_h1,w ;H1 - 1 btfsc status,z ;H1 = 1 hour ? goto pm11 ;Yes. PM 11 o'clock movlw d'2' ;Set check data subwf disp_h1,w ;H1 - 2 btfsc status,c ;H1 >= 2 hour ? goto pm12 ;Yes. PM 12 o'clock incf disp_h1,f ;No. H1 + 1 goto time_check ;Jump to Time Check pm11 clrf disp_h1 ;Set 0 o'clock clrf disp_h10 ;Set AM00:00:00 goto time_check ;Jump to Time Check pm12 movlw d'1' ;Set data movwf disp_h1 ;Set 1 o'clock movlw d'2' ;Set data movwf disp_h10 ;Set PM01:00:00 goto time_check ;Jump to Time Check ;*** Time signal check time_check btfsc disp_h10,1 ;AM ? goto tck4 ;No. PM movlw d'7' ;Set AM 7:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;AM 7:00 ? goto tck1 ;No. Next goto time_signal ;Yes. Jump to time signal tck1 movlw d'8' ;Set AM 8:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;AM 8:00 ? goto tck2 ;No. Next goto time_signal ;Yes. Jump to time signal tck2 movlw d'9' ;Set AM 9:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;AM 9:00 ? goto tck3 ;No. Next goto time_signal ;Yes. Jump to time signal tck3 btfss disp_h10,0 ;AM 1x ? goto no_signal ;No. End of signal check movf disp_h1,w ;Read H1 btfss status,z ;AM 10:00 ? goto no_signal ;No. End of signal check goto time_signal ;Yes. Jump to time signal tck4 movlw d'6' ;Set PM 6:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;PM 6:00 ? goto tck5 ;No. Next goto time_signal ;Yes. Jump to time signal tck5 movlw d'7' ;Set PM 7:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;PM 7:00 ? goto tck6 ;No. Next goto time_signal ;Yes. Jump to time signal tck6 movlw d'8' ;Set PM 8:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;PM 8:00 ? goto tck7 ;No. Next goto time_signal ;Yes. Jump to time signal tck7 movlw d'9' ;Set PM 9:00 data subwf disp_h1,w ;H1 - check data btfss status,z ;PM 9:00 ? goto no_signal ;No. End of signal check goto time_signal ;Yes. Jump to time signal time_signal bsf portb,rb1 ;Time signal ON no_signal goto int_end ;Jump to END of interrupt ;****** Time adjust mode Process (20msec interval) ****** adjust ;*** Adjust end check btfss portb,rb6 ;0 sec adjust SW = ON ? goto adjust1 ;No. Next process movf digit_posi,w ;Yes. Read digit position movwf digit_posiw ;Save digit position btfss status,z ;Position = H10 ? goto adj_end1 ;No. Next movf digit_save,w ;Yes. Read saved digit movwf disp_h10 ;Recover digit goto adj_end4 ;Jump to adj mode end adj_end1 decfsz digit_posiw,f ;Position = H1 ? goto adj_end2 ;No. Next movf digit_save,w ;Yes. Read saved digit movwf disp_h1 ;Recover digit goto adj_end4 ;Jump to adj mode end adj_end2 decfsz digit_posiw,f ;Position = M10 ? goto adj_end3 ;No. Next movf digit_save,w ;Yes. Read saved digit movwf disp_m10 ;Recover digit goto adj_end4 ;Jump to adj mode end adj_end3 movf digit_save,w ;Read saved digit movwf disp_m1 ;Recover digit adj_end4 incf rb6ll,f ;Set last look ON bcf intcon,rbie ;Clear RBIE bit incf mode,f ;Set clock mode goto int_end ;Jump to END of interrupt ;*** Adjust position check adjust1 btfss portb,rb7 ;Position SW = ON ? goto adj_posi10 ;No. SW = OFF movf rb7ll,w ;Yes. Read RB7 last look btfss status,z ;Last look = 0 ? goto adjust2 ;No. Last look = 1 incf rb7ll,f ;Yes. Set last look incf digit_posi,f ;Change position movlw d'4' ;Set check data subwf digit_posi,w ;Position data - 4 btfss status,c ;Position over ? goto adj_posi1 ;No. digit proc clrf digit_posi ;Set position to H10 adj_posi1 movf digit_posi,w ;Read digit position movwf digit_posiw ;Save digit position btfss status,z ;Position = H10 ? goto adj_posi3 ;No. Next movf blink_cont,w ;Read blink control btfsc status,z ;LED OFF ? goto adj_posi2 ;No. LED ON movf digit_save,w ;Yes. Read saved digit movwf disp_m1 ;Set M1 digit adj_posi2 movf disp_h10,w ;Read digit goto adj_posi9 ;Jump to digit save adj_posi3 decfsz digit_posiw,f ;Position = H1 ? goto adj_posi5 ;No. Next movf blink_cont,w ;Read blink control btfsc status,z ;LED OFF ? goto adj_posi4 ;No. LED ON movf digit_save,w ;Yes. Read saved digit movwf disp_h10 ;Set H10 digit adj_posi4 movf disp_h1,w ;Read digit goto adj_posi9 ;Jump to digit save adj_posi5 decfsz digit_posiw,f ;Position = M10 ? goto adj_posi7 ;No. Next movf blink_cont,w ;Read blink control btfsc status,z ;LED OFF ? goto adj_posi6 ;No. LED ON movf digit_save,w ;Yes. Read saved digit movwf disp_h1 ;Set H1 digit adj_posi6 movf disp_m10,w ;Yes. Read digit goto adj_posi9 ;Jump to digit save adj_posi7 movf blink_cont,w ;Read blink control btfsc status,z ;LED OFF ? goto adj_posi8 ;No. LED ON movf digit_save,w ;Yes. Read saved digit movwf disp_m10 ;Set M10 digit adj_posi8 movf disp_m1,w ;Read digit adj_posi9 movwf digit_save ;Save digit goto adjust2 adj_posi10 clrf rb7ll ;Clear RB7 last look ;*** Adjust digit blink process adjust2 movlw d'10' ;Set 200 msec data subwf digit_blink,w ;Counter - 200 msec btfsc status,c ;Counter >= 200 msec ? goto adj_blk1 ;Yes. Counter >= 200 msec incf digit_blink,f ;No. Counter + 1 goto int_end ;Jump to END of interrupt adj_blk1 clrf digit_blink ;Clear Blink counter btfsc blink_cont,0 ;Blink ON ? goto adj_blk5 ;No. Jump to ON process ;*** LED OFF process incf blink_cont,f ;Set Blink OFF data movf digit_posi,w ;Read digit position movwf digit_posiw ;Save digit position btfss status,z ;Position = H10 ? goto adj_blk2 ;No. Next movlw h'0a' ;Yes. Set LED off digit movwf disp_h10 ;LED off goto adj_blke ;Jump to blink end adj_blk2 decfsz digit_posiw,f ;Position = H1 ? goto adj_blk3 ;No. Next movlw h'0a' ;Yes. Set LED off digit movwf disp_h1 ;LED off goto adj_blke ;Jump to blink end adj_blk3 decfsz digit_posiw,f ;Position = M10 ? goto adj_blk4 ;No. Next movlw h'0a' ;Yes. Set LED off digit movwf disp_m10 ;LED off goto adj_blke ;Jump to blink end adj_blk4 movlw h'0a' ;Yes. Set LED off digit movwf disp_m1 ;LED off goto adj_blke ;Jump to blink end ;*** LED ON process adj_blk5 clrf blink_cont ;Set Blink ON data movf digit_posi,w ;Read digit position movwf digit_posiw ;Save digit position btfss status,z ;Position = H10 ? goto adj_blk6 ;No. Next movf digit_save,w ;Read saved digit movwf disp_h10 ;Set H10 digit goto adj_blke ;Jump to blink end adj_blk6 decfsz digit_posiw,f ;Position = H1 ? goto adj_blk7 ;No. Next movf digit_save,w ;Read saved digit movwf disp_h1 ;Set H1 digit goto adj_blke ;Jump to blink end adj_blk7 decfsz digit_posiw,f ;Position = M10 ? goto adj_blk8 ;No. Next movf digit_save,w ;Read saved digit movwf disp_m10 ;Set M10 digit goto adj_blke ;Jump to blink end adj_blk8 movf digit_save,w ;Read saved digit movwf disp_m1 ;Set M1 digit adj_blke goto int_end ;Jump to END of interrupt ;**************** Digit change process ****************** digit_change bcf intcon,rbif ;Clear RBIF movf portb,w ;Read PORTB andlw b'00110000' ;Pick up RB4 and RB5 movwf change_wk ;Save RB4/RB5 condition movf change_st,w ;Read Digit change status btfss status,z ;Status = "0" ? goto change2 ;No. Next movf change_wk,w ;Read RB4/RB5 condition xorlw b'00100000' ;Check RB4/RB5 condition btfss status,z ;RB5(B)=1 RB4(A)=0 ? goto change1 ;No. next movlw d'1' ;Set status to "1" movwf change_st ;Write status goto int_end ;Jump to END of interrupt change1 movf change_wk,w ;Read RB4/RB5 condition xorlw b'00110000' ;Check RB4/RB5 condition btfss status,z ;RB5(B)=1 RB4(A)=1 ? goto int_end ;Jump to END of interrupt ;*** Count up process movlw d'2' ;Set status to "2" movwf change_st ;Write status movf digit_posi,w ;Read digit position movwf digit_posiw ;Save digit position btfss status,z ;Position = H10 ? goto count_up2 ;No. Next movlw d'3' ;Set check data subwf digit_save,w ;H10 - check data btfss status,z ;H10 = 3 ? goto count_up1 ;No. clrf digit_save ;Set H10 = 0 goto count_h10 ;Jump to save check count_up1 incf digit_save,f ;H10 + 1 goto count_h10 ;Jump to save check count_up2 decfsz digit_posiw,f ;Position = H1 ? goto count_up8 ;No. Next movf disp_h10,w ;Read H10 digit andlw b'00000001' ;Pick up 0x/1x btfss status,z ;H10 = AM 0x or PM 0x ? goto count_up4 ;No. AM 1x or PM 1x movlw d'9' ;Set check data subwf digit_save,w ;H1 - check data btfss status,z ;H1 = 9 ? goto count_up3 ;No. clrf digit_save ;Set H1 = 0 goto count_h1 ;Jump to save check count_up3 incf digit_save,f ;H1 + 1 goto count_h1 ;Jump to save check count_up4 movf disp_h10,w ;Read H10 digit andlw b'00000010' ;Pick up AM/PM btfss status,z ;H10 = AM ? goto count_up6 ;No. PM movf digit_save,w ;Read H1 digit btfss status,z ;H1 = 0 ? goto count_up5 ;No. H1 > 1 incf digit_save,f ;H1 = 1 goto count_h1 ;Jump to save check count_up5 clrf digit_save ;H1 = 0 goto count_h1 ;Jump to save check count_up6 movlw d'2' ;Set check data subwf digit_save,w ;H1 - check data btfss status,c ;H1 >= 2 ? goto count_up7 ;No. clrf digit_save ;Set H1 = 0 goto count_h1 ;Jump to save check count_up7 incf digit_save,f ;H1 + 1 goto count_h1 ;Jump to save check count_up8 decfsz digit_posiw,f ;Position = M10 ? goto count_up10 ;No. Next movlw d'5' ;Set check data subwf digit_save,w ;M10 - check data btfss status,z ;M10 = 5 ? goto count_up9 ;No. clrf digit_save ;Set M10 = 0 goto count_m10 ;Jump to save check count_up9 incf digit_save,f ;M10 + 1 goto count_m10 ;Jump to save check count_up10 movlw d'9' ;Set check data subwf digit_save,w ;M1 - check data btfss status,z ;M1 = 9 ? goto count_up11 ;No. clrf digit_save ;Set M1 = 0 goto count_m1 ;Jump to save check count_up11 incf digit_save,f ;M1 + 1 goto count_m1 ;Jump to save check change2 movlw d'1' ;Set check data subwf change_st,w ;Status - check data btfss status,z ;Status = "1" ? goto change4 ;No. Next movf change_wk,w ;Read RB4/RB5 condition xorlw b'00010000' ;Check RB4/RB5 condition btfss status,z ;RB5(B)=0 RB4(A)=1 ? goto change3 ;No. next clrf change_st ;Set status to "0" goto int_end ;Jump to END of interrupt change3 movf change_wk,w ;Read RB4/RB5 condition xorlw b'00110000' ;Check RB4/RB5 condition btfss status,z ;RB5(B)=1 RB4(A)=1 ? goto int_end ;Jump to END of interrupt ;*** Count down process movlw d'2' ;Set status to "2" movwf change_st ;Write status movf digit_posi,w ;Read digit position movwf digit_posiw ;Save digit position btfss status,z ;Position = H10 ? goto count_down2 ;No. Next movf digit_save,w ;Read H10 btfss status,z ;H10 = 0 ? goto count_down1 ;No. movlw d'3' ;Set data movwf digit_save ;Set H10 = 3 goto count_h10 ;Jump to save check count_down1 decf digit_save,f ;H10 - 1 goto count_h10 ;Jump to save check count_down2 decfsz digit_posiw,f ;Position = H1 ? goto count_down9 ;No. Next movf disp_h10,w ;Read H10 digit andlw b'00000001' ;Pick up 0x/1x btfss status,z ;H10 = AM 0x or PM 0x ? goto count_down4 ;No. AM 1x or PM 1x movf digit_save,w ;Read H1 btfss status,z ;H1 = 0 ? goto count_down3 ;No. movlw d'9' ;Set data movwf digit_save ;Set H1 = 9 goto count_h1 ;Jump to save check count_down3 decf digit_save,f ;H1 - 1 goto count_h1 ;Jump to save check count_down4 movf disp_h10,w ;Read H10 digit andlw b'00000010' ;Pick up AM/PM btfss status,z ;H10 = AM ? goto count_down6 ;No. PM movf digit_save,w ;Read H1 digit btfss status,z ;H1 = 0 ? goto count_down5 ;No. H1 = 1 incf digit_save,f ;H1 = 1 goto count_h1 ;Jump to save check count_down5 clrf digit_save ;H1 = 0 goto count_h1 ;Jump to save check count_down6 movlw d'3' ;Set check data subwf digit_save,w ;H1 - check data btfsc status,c ;H1 >= 3 ? goto count_down7 ;Yes. movf digit_save,w ;read H1 btfss status,z ;H1 = 0 ? goto count_down8 ;No. count_down7 movlw d'2' ;Set data movwf digit_save ;Set H1 = 2 goto count_h1 ;Jump to save check count_down8 decf digit_save,f ;H1 - 1 goto count_h1 ;Jump to save check count_down9 decfsz digit_posiw,f ;Position = M10 ? goto count_down11 ;No. Next movf digit_save,w ;Read M10 btfss status,z ;M10 = 0 ? goto count_down10 ;No. movlw d'5' ;Set data movwf digit_save ;Set M10 = 5 goto count_m10 ;Jump to save check count_down10 decf digit_save,f ;M10 - 1 goto count_m10 ;Jump to save check count_down11 movf digit_save,w ;Read M1 btfss status,z ;M1 = 0 ? goto count_down12 ;No. movlw d'9' ;Set data movwf digit_save ;Set M1 = 9 goto count_m1 ;Jump to save check count_down12 decf digit_save,f ;M1 - 1 goto count_m1 ;Jump to save check count_h10 movf blink_cont,w ;Read blink control data btfss status,z ;Blink ON ? goto int_end ;Jump to END of interrupt movf digit_save,w ;Yes. Read H10 data movwf disp_h10 ;Set H10 data goto int_end ;Jump to END of interrupt count_h1 movf blink_cont,w ;Read blink control data btfss status,z ;Blink ON ? goto int_end ;Jump to END of interrupt movf digit_save,w ;Yes. Read H1 data movwf disp_h1 ;Set H1 data goto int_end ;Jump to END of interrupt count_m10 movf blink_cont,w ;Read blink control data btfss status,z ;Blink ON ? goto int_end ;Jump to END of interrupt movf digit_save,w ;Yes. Read M10 data movwf disp_m10 ;Set M10 data goto int_end ;Jump to END of interrupt count_m1 movf blink_cont,w ;Read blink control data btfss status,z ;Blink ON ? goto int_end ;Jump to END of interrupt movf digit_save,w ;Yes. Read M1 data movwf disp_m1 ;Set M1 data goto int_end ;Jump to END of interrupt change4 movf change_wk,w ;Read RB4/RB5 condition xorlw b'00000000' ;Check RB4/RB5 condition btfss status,z ;RB5(B)=0 RB4(A)=0 ? goto int_end ;No. END of interrupt clrf change_st ;Yes. Set status to "0" goto int_end ;Jump to END of interrupt ;******************************************************** ; END of Digital Clock ;******************************************************** end