;gr_tim02.asm ;Grill timer ; ;Jeff Thorssell Ocean Pines, MD 2009 ;RB 7, 6, 5, 4, 3, 2 are 1, 2, 3, 4, 5, 10 minutes ;RB0 is a set switch ;RB1 is a "GO" switch ; ; list p=16f87 ; list directive to define processor #include ; processor specific variable definitions errorlevel -302 ; suppress message 302 from list file ;Program Configuration Register 1 __CONFIG _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_CLKOUT ;Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF FiveMSec equ D'100' ;TMR0 delay for 5 ms OneSecTime equ D'200' ;5 ms cycles to get one second LEDOff equ 3 ;cycles for the ONLED to remain off ;Registers cblock 0x20 ;RAM Starts higher on newer stuff SecCnt MinCnt TimeCnt LEDCnt Temp01 Temp02 Temp03 Temp04 Count0 Count1 MyFlags Set_Time Old_B endc ;individual bits in MyFlags #define Flag01 MyFlags, 0 #define Flag02 MyFlags, 1 #define SW01 PORTB, 0 ;Set Time #define SW02 PORTB, 1 ;Run #define MOTOR PORTA, 2 #define BEEPER PORTA, 1 ;---------------------------------------------------------------------- ; Program Memory ;---------------------------------------------------------------------- ; Program Memory Organization (Section 2.1) ORG 0x000 ; RESET Vector nop ; for ICD use goto RESET ORG 0x004 ; Interrupt Vector return ;No IRQs on this RESET bcf INTCON, GIE ;Stop IRQs Call Init_1 Call LightsOff clrf Set_Time bcf MOTOR ;motor off bcf BEEPER ;alarm off ;movlw D'4' ;Call BlinkLED3 movlw LEDOff ;Reset the number of passes until turn on again movwf LEDCnt ;And store it in LEDCnt Call OneSec Call LightsOff clrf MyFlags Loop btfss SW01 goto Switch1 btfss SW02 goto Switch2 goto Loop Switch1 movlw D'25' xorwf Set_Time, W btfsc STATUS, Z clrf Set_Time ;clear if would be over 25. Next will increment to one incf Set_Time, F skip_inc Call Debounce01 Call Up_Display goto Loop Switch2 Call Time_It Call Run_Motor ;goto Loop bcf PORTB, 7 ;Light #1 at end to know it's on bsf PORTB, 6 bsf PORTB, 5 bsf PORTB, 4 bsf PORTB, 3 bsf PORTB, 2 sleep Up_Display movfw Set_Time Call Light_Table movwf Old_B ;Save for blinking later Movwf PORTB ;Call BlinkLED3 Return Light_Table addwf PCL, F ;Add W to get jump retlw B'11111111' retlw B'01111111' retlw B'10111111' retlw B'11011111' retlw B'11101111' retlw B'11110111' retlw B'01110111' retlw B'10110111' retlw B'11010111' retlw B'11100111' retlw B'11111011' retlw B'01111011' retlw B'10111011' retlw B'11011011' retlw B'11101011' retlw B'11110011' retlw B'01110011' retlw B'10110011' retlw B'11010011' retlw B'11100011' retlw B'01100011' retlw B'10100011' retlw B'11000011' retlw B'01000011' retlw B'10000011' retlw B'00000011' Blink_Lights movfw PORTB movwf Old_B ;Save port comf PORTB, F Call Delay movfw Old_B movwf PORTB return Run_Motor bsf MOTOR bsf BEEPER call OneSec bcf MOTOR bcf BEEPER call OneSec bsf MOTOR bsf BEEPER call OneSec bcf MOTOR bcf BEEPER call OneSec bsf MOTOR bsf BEEPER call OneSec bcf MOTOR bcf BEEPER Return ;------------------------------------------------------------------- ;One second delay OneSec decfsz LEDCnt, F ;Check and see if LEDs should be blinked. Only blink every X times through here. goto RestOfSec ;No, go ahead and do the time. movfw Old_B movwf PORTB movlw LEDOff ;Reset the number of passes until turn on again movwf LEDCnt ;And store it in LEDCnt RestOfSec movlw OneSecTime ;Get a second amount movwf SecCnt ;And store it temporarily OneSec1 Movlw FiveMSec ;Get the number for 5 ms movwf TMR0 ;And put in the TMR0 OneSec2 movf TMR0, W ;Start checking TMR0 for going all the way up btfss STATUS, Z ; Status reg, Zero flag. goto OneSec2 ; and go back until it fills decfsz SecCnt, F ;Decrement temp register and keep going until the time is up goto OneSec1 movlw B'11111111' ;lights off movwf PORTB return ;End One second delay ;------------------------------------------------------------------- ;------------------------------------------------------------------- ;OneMin ;Calls OneSec 60 times OneMin movlw D'59' ;Changed. Timed with watch and was about 1 sec per minute over. movwf MinCnt OM2 Call OneSec decfsz MinCnt, F goto OM2 return ;----------------------------------------------------------------- ;Time_It ;Calls OneMin for each minute in Set_Time Time_It movfw Set_Time movwf TimeCnt TI2 Call OneMin decfsz TimeCnt, F goto TI2 return ;------------------------------------------------------------------- ;Init_1 ;Initial settings of ports etc. Init_1 ;Turn off IRQs while initial testing bcf INTCON, GIE bsf STATUS, RP0 ; ---- Select Bank 1 ----- bcf OPTION_REG, NOT_RBPU ; GPIO pull-ups: enabled bcf OPTION_REG, T0CS ; TMR0 Clock Source: internal instruction cycle (CLKOUT) bcf OPTION_REG, T0SE ; TMR0 Source Edge: increment low-to-high transition on GP2/T0CKI pin bcf OPTION_REG, PSA ; Prescaler Assignment: assigned to TIMER0 ; TMR0 Prescaler Rate: 1:4 bsf OPTION_REG, PS2 ; Prescaler Rate Select bit 2 ;set this one only for /32 bcf OPTION_REG, PS1 ; Prescaler Rate Select bit 1 bcf OPTION_REG, PS0 ; Prescaler Rate Select bit 0 bcf STATUS, RP0 ;---- Select Bank 0 ----- ;End Option ------------------------------------------------------------------ ;---------------------------------------- ;INTCON register ;Disabled GIE before calling this routine bcf INTCON, RBIE ;Disable PORTB line change IRQs bcf INTCON, INTE ;Disable the RB0 IRQs bcf INTCON, TMR0IE ;Disable TMR0 IRQs bcf INTCON, PEIE ;Disable Peripheral Interrupt Enable bit clrf PIR2 clrf PIR1 bsf STATUS, RP0 ; ---- Select Bank 1 ----- clrf PIE2 clrf PIE1 bcf STATUS, RP0 ; ---- Select Bank 0 ----- ;---------------------------------------- ;END INTCON ;---------------------------------------- bsf STATUS, RP0 ; ---- Select Bank 1 ----- movlw B'01100010' ;Osc control to 4Mhz movwf OSCCON bcf STATUS, RP0 ;---- Select Bank 0 ----- movlw 0 ;clear some spaces and registers to start with a clean slate clrf SecCnt clrf MyFlags bsf STATUS, RP0 ; ---- Select Bank 1 ----- movlw B'00000000' ;PORTA as all outputs movwf TRISA movlw B'00000011' ;and B 0, 1, as inputs and rest outputs movwf TRISB ; Want to use the pullups for SWs bcf STATUS, RP0 ;---- Select Bank 0 ----- EndInit Return ;End Init_1 ;------------------------------------------------------------------- LightsOff bsf PORTB, 7 bsf PORTB, 6 bsf PORTB, 5 bsf PORTB, 4 bsf PORTB, 3 bsf PORTB, 2 return ;-------------------------------------------------------------------------- ;MiniDel ;20 ms delay for switch debounce ; MiniDel movlw D'5' movwf Count0 movlw D'30' movwf Count1 MDL02 decfsz Count0, f goto MDL02 decfsz Count1, f goto MDL02 return Debounce01 Call MiniDel btfss SW01 goto Debounce01 Return Debounce02 Call MiniDel btfss SW02 goto Debounce02 Return Toggle01 btfss Flag01 Goto Turn01On ;Need to trun it off bsf PORTB, 7 bcf Flag01 Return Turn01On bcf PORTB, 7 bsf Flag01 Return Toggle02 btfss Flag02 Goto Turn02On ;Need to trun it off bsf PORTB, 6 bcf Flag02 Return Turn02On bcf PORTB, 6 bsf Flag02 Return ;------------------------------------------------------------------- ;Blink an LED (for debugging) - Have digit in W entering here ;Connect an LED between + and RA0 ;Needs REGS: ;Temp04 ;Count0 ;Count1 ; BlinkLED3 movwf Temp04 ;Store W bsf PORTB, 7 ;start with the LED off call Delay ;delay a couple BL2 bcf PORTB, 7 ;Turn LED on call Delay bsf PORTB, 7 ;LED off call Delay decfsz Temp04, F goto BL2 return Delay clrf Count0 clrf Count1 DL02 decfsz Count0, f goto DL02 decfsz Count1, f goto DL02 return ;movlw 0x05 ;;Jeff ;Call BlinkLED3 ;sleep ;---------------------------------------------------------------------- end ; end of program directive ;----------------------------------------------------------------------