; VERSION 1.0, 2009/05/05 ; http://avtanski.net/projects/air_sampler #include __config (_XT_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF) ; Rate Adjustments #define TMR_LO 0xBE #define TMR_HI 0xEE #define INTERRUPTS_PER_SECOND .200 #define TIMER_DIVIDER .60 ; should be .60 #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 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<