; VERSION 1.1, 2009/09/24 ; http://avtanski.net/projects/timer #include __config (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF) ; Uncomment the line below if you want to use RB7 to control the LEDs ;#define RB7_LED_CONTROL ; Uncomment the line below if you want the timer to remember its initial value ;#define REMEMBER_INITIAL_VALUE ; Rate Adjustments #ifdef RB7_LED_CONTROL #define TMR_LO 0xBF #define TMR_HI 0xEE #else #define TMR_LO 0xBE #define TMR_HI 0xEE #endif #define INTERRUPTS_PER_SECOND .200 #define TIMER_DEFAULT_VALUE 0 ; use packed decimal notation here - i.e. a hex where ; the two nibbles correspond to the two decimal digits ; (for example, use the hex "15" for 15 units of time) #define TIMER_DIVIDER .01 ; seconds per tick; set to: ; .1 to count seconds ; .60 to count minutes ; .3600 to count hours #define ROUGH_ADJUSTMENT .10 ; how much to increase/decrease timer when the rough ; adjustments buttons are used #define BTN_REPEAT_START 0x0200 #define BTN_REPEAT_REINIT 0x01C0 #define F_RUNNING 0 ; timer is running #define F_TICK 1 ; timer tick (after division) #define F_DIGIT 2 ; which digit LED display is ON #define F_BLINKING 3 ; display blinking #define F_BTN_READY 4 ; no button pressed on last check, ready for new button #define F_BTN_REPEAT 5 ; set if latest button is set through a repeat action #define F_RESET_ON_START 6 ; everything should be reset on start #define F_FAN_RUNNING 7 ; current status of the fan #define B_START 0 ; Start button #define B_RST 1 ; Reset button #define B_INC 2 ; Increase button #define B_DEC 3 ; Decrease button #define B_INC10 4 ; Increase by 10 button #define B_DEC10 5 ; Decrease by 10 button #define B_INVALID 7 ; Invalid - more than one buttons pressed cblock 0x20 FLAGS OLD_COUNTER TIMER TIMER_INITIAL DISPLAY DIVIDER_L DIVIDER_H LOOKUP TMP BTN BTN_DOWN BTN_DOWN_COUNTER_L BTN_DOWN_COUNTER_H BLINK_COUNTER endc ; interrupt registers in shared space cblock 0x78 INT_W INT_STATUS INT_PCLATH INT_FSR INT_PULSECTR INT_COUNTER endc org 0x00 goto Start org 0x04 nop ; interrupt code follows - avoid potential paging issues Interrupt movwf INT_W swapf STATUS,w clrf STATUS movwf INT_STATUS movf PCLATH,w movwf INT_PCLATH clrf PCLATH movf FSR,w movwf INT_FSR banksel T1CON ; stop timer bcf T1CON,TMR1ON banksel TMR1H ; set TMR1 counter movlw TMR_LO movwf TMR1L movlw TMR_HI movwf TMR1H banksel INT_PULSECTR decf INT_PULSECTR,f btfss STATUS,Z goto Interrupt_display incf INT_COUNTER,f movlw INTERRUPTS_PER_SECOND movwf INT_PULSECTR Interrupt_display movlw 0x01<