'----------------------------------------------- ' DEMONSTARTION OF A 100THS OF A SECOND TIMER ' COUNTING UP TO 255 DAYS ' ' ' FIDDLE WITH FUDGE FACTOR TO IMPROVE ACCURACY ' ' BY TIM BOX NOV 03 '----------------------------------------------- DEVICE 16F628 REMARKS ON REMINDERS OFF CONFIG HS_OSC,PWRTE_ON,CP_OFF,WDT_OFF,LVP_OFF,MCLRE_OFF,BODEN_ON REMINDERS ON ON_INTERRUPT Horloge ALL_DIGITAL ON DECLARE XTAL=20 DECLARE LCD_INTERFACE 4 DECLARE LCD_LINES 2 DECLARE LCD_DTPIN PORTB.0 DECLARE LCD_ENPIN PORTA.4 DECLARE LCD_RSPIN PORTA.3 SYMBOL GIE = INTCON.7 SYMBOL T0IF = INTCON.2 SYMBOL T0IE = INTCON.5 SYMBOL TMR1IF = PIR1.0 SYMBOL TMR1IE = PIE1.0 SYMBOL TMR2IF = PIR1.1 SYMBOL TMR2IE = PIE1.1 SYMBOL PS0 = OPTION_REG.0 SYMBOL PS1 = OPTION_REG.1 SYMBOL PS2 = OPTION_REG.2 SYMBOL PSA = OPTION_REG.3 SYMBOL T0SE= OPTION_REG.4 SYMBOL T0CS= OPTION_REG.5 SYMBOL T1CKPS0 = T1CON.4 SYMBOL T1CKPS1 = T1CON.5 SYMBOL T1OSCEN = T1CON.3 SYMBOL T1SYNC = T1CON.2 SYMBOL TMR1CS = T1CON.1 SYMBOL TMR1ON = T1CON.0 SYMBOL TOUTPS3 = T2CON.6 SYMBOL TOUTPS2 = T2CON.5 SYMBOL TOUTPS1 = T2CON.4 SYMBOL TOUTPS0 = T2CON.3 SYMBOL TMR2ON = T2CON.2 SYMBOL T2CKPS1 = T2CON.1 SYMBOL T2CKPS0 = T2CON.0 DIM _100THS ' DECLARE ALL VARS AS BYTES DIM SECS DIM MINS DIM HOURS DIM DAYS DIM TEMP_100THS DIM TEMP_SECS DIM TEMP_MINS DIM TEMP_HOURS DIM TEMP_DAYS DIM TIMER1REG AS TMR1L.WORD ' MAKE THE TIMER VAR INTO A WORD SYMBOL FUDGE_FACTOR = 7 ' FIDDLE WITH TO IMPROVE ACCURACY SYMBOL TMR1_VAL =((65536)-(XTAL*2500))+FUDGE_FACTOR ' CALCULATE OSC OFFSET VALUES FOR 100HZ INTERRUPT ON_INTERRUPT INTERRUPT_ROUTINE ' WHERE TO GO ON AN INTERRUPT GOTO START ' JUMP THE INTERRUPT CODE INTERRUPT_ROUTINE: CLEAR T1CON.0 ' STOP TMR1 TIMER1REG = TIMER1REG + TMR1_VAL ' LOAD TMR1 SET T1CON.0 ' START TMR1 INC _100THS IF _100THS = 100 THEN ' UP 100TS CLEAR _100THS INC SECS ' UP SECONDS IF SECS = 60 THEN CLEAR SECS INC MINS ' UP MINS IF MINS = 60 THEN CLEAR MINS INC HOURS IF HOURS = 24 THEN ' UP HOURS CLEAR HOURS INC DAYS ENDIF ENDIF ENDIF ENDIF CLEAR PIR1.0 ' CLEAR TMR1 INTERRUPT FLAG CONTEXT RESTORE ' END INTERRUPT ROUTINE START: CLEAR ' CLEAR ALL VARS T1CON = %00000000 ' SET UP TMR1 TO HAVE 1:1 PRESCALER AND ACT AS A TIMER PIR1.0 = 0 ' CLEAR TMR1 INTERRUPT FLAG INTCON = %11000000 ' GLOBAL AND PERIPHERAL INTERRUPTS ON PIE1.0 = 1 ' ENABLE TMR1 AS PERIPHERAL INTERRUPT SOURCE T1CON.0 = 1 ' SET TIMER1 RUNNING CLS ' CLEAR THE LCD WHILE 1 = 1 ' MAKE AN ENDLESS LOOP GIE = 0 ' TURN OFF GLOBAL INTERRUPTS WHILE GIE = 1 : GIE = 0 : WEND ' AND MAKE SURE THEY ARE OFF TEMP_100THS = _100THS ' MAKE A COPY OF THE VARS TEMP_SECS = SECS TEMP_MINS = MINS TEMP_HOURS = HOURS TEMP_DAYS = DAYS GIE = 1 ' TURN THE INTERRUPTS BACK ON PRINT AT 1,1,DEC2 TEMP_DAYS,":",DEC2 TEMP_HOURS,":",DEC2 TEMP_MINS,":",DEC2 TEMP_SECS,":",DEC2 TEMP_100THS DELAYMS 100 ' SMALL DELAU WEND ' ROUND AND ROUND WE GO STOP