;---------------------------------------------------------------------------; ; ; ; ; ; AUTHOR: EDWIN TUGANO JR. ; ; DATE; AUGUST 02, 2005 ; ; EMAIL ADD: archjet3@hotmail.com ; ; ADDRESS: MANDAUE CITY CEBU, PHILIPPINES 6014 ; ; TEL NO.: 0915-9476778 ; ; TITLE: REALTIME CLOCK WITH HOUR AND MINUITE BUTTON ; ; ; ;---------------------------------------------------------------------------; #include "p16f676.inc" __CONFIG _WDT_OFF & _XT_OSC & _CP_OFF & _MCLRE_OFF temp EQU 0x20 w_temp EQU 0x21 ; variable used for context saving status_temp EQU 0x22 ; variable used for context saving ORG 0 GOTO Start ORG 0x004 ; interrupt vector location movwf w_temp ; save off current W register contents movf STATUS,w ; move status register into W register movwf status_temp ; save off contents of STATUS register ; isr code can go here or be located as a call subroutine elsewhere incf ms,F movlw .225 xorwf ms,w btfss STATUS,Z goto $+3 clrf ms incf count,F bcf INTCON,T0IF movf status_temp,w ; retrieve copy of STATUS register movwf STATUS ; restore pre-isr STATUS register contents swapf w_temp,f swapf w_temp,w ; restore pre-isr W register contents retfie ; return from interrupt cblock 0x23 d1 d2 d3 d4 temp1 digit1 digit2 digit3 digit4 digit5 digit6 tempA count secdigit1 secdigit2 c1 c2 c3 ms second endc ;---------------------------------------------------------------------- Initialize bcf STATUS,RP0 movlw B'00000111' ;to make RA0,RA1,RA2 ;not comparator movwf CMCON clrf PORTA bsf STATUS,RP0 movlw B'00111000' movwf TRISA bcf STATUS,RP0 clrf PORTC bsf STATUS,RP0 movlw B'00000000' movwf TRISC bcf OPTION_REG,T0CS ;configure the TMR0 bcf OPTION_REG,PSA bsf OPTION_REG,0 bsf OPTION_REG,1 bcf OPTION_REG,2 bsf INTCON,T0IE bsf INTCON,GIE bcf STATUS,RP0 ;end return ;------------------------------------------------------------------- increment_digits incf secdigit1,f movlw .10 xorwf secdigit1,w btfss STATUS,Z return clrf secdigit1 incf secdigit2,f movlw .6 xorwf secdigit2,w btfss STATUS,Z return clrf secdigit2 increment_min incf digit1,f movlw .10 xorwf digit1,w btfss STATUS,Z return clrf digit1 incf digit2,f movlw .6 xorwf digit2,w btfss STATUS,Z return clrf digit2 increment_hour incf digit3,f movlw .1 xorwf digit4,w btfsc STATUS,Z goto check_12hour movlw .10 xorwf digit3,w btfss STATUS,Z return clrf digit3 incf digit4,f return check_12hour movlw .3 xorwf digit3,w btfss STATUS,Z return movlw 1h movwf digit3 clrf digit4 return ;--------------------------------------------------------------- dec_digits movlw 0x00 xorwf digit1,w btfsc STATUS,Z goto $+3 decf digit1,f return movlw 0x00 xorwf digit2,w btfsc STATUS,Z return decf digit2,f movlw 0x09 movwf digit1 return ;------------------------------------------------------------ delay1ms movlw 3h movwf d1 movlw 1h movwf d2 loopd2 decfsz d2,f goto loopd2 decfsz d1,f goto loopd2 return ;--------------------------------------------------------------- Display_out movlw B'00000100' andwf PORTA,F movlw B'00000000' iorwf PORTA,F bsf PORTC,5 ;digit1 bcf PORTC,4 ;digit2 movlw B'11110000' andwf PORTC,F movf digit1,w iorwf PORTC,f call check_button call delay1ms movlw B'00000100' andwf PORTA,F movlw B'00000000' iorwf PORTA,F bcf PORTC,5 ;digit1 bsf PORTC,4 ;digit2 movlw B'11110000' andwf PORTC,F movf digit2,w iorwf PORTC,f call check_button call delay1ms movlw B'00000100' andwf PORTA,F movlw B'00000010' iorwf PORTA,F bcf PORTC,5 ;digit1 bcf PORTC,4 ;digit2 movlw B'11110000' andwf PORTC,F movf digit3,w iorwf PORTC,f call delay1ms movlw B'00000100' andwf PORTA,F movlw B'00000001' iorwf PORTA,F bcf PORTC,5 ;digit1 bcf PORTC,4 ;digit2 movlw B'11110000' andwf PORTC,F movf digit4,w iorwf PORTC,f call delay1ms display_RA2 movf tempA,w iorwf PORTA,F call delay1ms return ;---------------------------------------------------------------------- check_increment movlw 1h xorwf count,w btfss STATUS,Z return clrf count call increment_digits return ;---------------------------------------------------------------------- second_check movlw .112 subwf ms,w btfss STATUS,C goto $+3 bcf tempA,2 return bsf tempA,2 return ;--------------------------------------------------------------- check_button btfsc PORTA,3 return call delay1ms btfsc PORTA,3 return call delay1ms btfss PORTC,4 goto check_min call delay1ms btfss PORTC,4 goto check_min call delay1ms bcf INTCON,GIE call increment_hour loop_increment_hour btfss PORTA,3 goto loop_increment_hour call delay1ms btfss PORTA,3 goto loop_increment_hour call delay1ms clrf count bsf INTCON,GIE return check_min btfss PORTC,5 return call delay1ms btfss PORTC,5 return call delay1ms bcf INTCON,GIE call increment_min loop_increment_min btfss PORTA,3 goto loop_increment_min call delay1ms btfss PORTA,3 goto loop_increment_min call delay1ms clrf count bsf INTCON,GIE return ;--------------------------------------------------------------- Start call Initialize clrf digit1 clrf digit2 clrf digit3 clrf digit4 clrf ms clrf tempA clrf count clrf secdigit1 clrf secdigit2 main call check_increment call second_check call Display_out goto main END