;/****************************************************************************
;* DESCRIPTION: House keeping and delay routine.
;*****************************************************************************/
H_keeping:
; Leds:
; 7 6 5 4 3 2 1 0
; blink onoff up down light toast time temp
btfss leds_s,7 ; Is led blink enabled?
goto contled ; No, it's not enabled
btfsc leds_s,6 ; Is led on/off on?
goto $+3
bcf LED_ONOFF ; No - it's activated directly, not using LED_CMN
goto $+2
bsf LED_ONOFF ; Yes - it's activated directly, not using LED_CMN
decfsz Led_blink,F ; Blink control = 0?
goto contled ; No
movlw D'255' ; Value to preload to
movwf Led_blink ; Led blink time control
btfsc leds_s,6 ; Is led on/off on?
goto setledoff ; Yes, turn it off.
bsf leds_s,6 ; No, turn it on
goto contled ; Continue
setledoff:
bcf leds_s,6 ; Led on/off in off
contled:
btfsc leds_s,5 ; Is led up on?
goto $+3
bsf LED_UP ; No
goto $+2
bcf LED_UP ; Yes
btfsc leds_s,4 ; Is led down on?
goto $+3
bsf LED_DWN ; No
goto $+2
bcf LED_DWN ; Yes
btfsc leds_s,3 ; Is led light on?
goto $+3
bsf LED_LIGHT ; No
goto $+2
bcf LED_LIGHT ; Yes
btfsc leds_s,2 ; Is led toast on?
goto $+3
bsf LED_TOASTER ; No
goto $+2
bcf LED_TOASTER ; Yes
btfsc leds_s,1 ; Is led time on?
goto $+3
bsf LED_timer ; No
goto $+2
bcf LED_timer ; Yes
btfsc leds_s,0 ; Is led temp on?
goto $+3
bsf LED_TEMP ; No
goto $+2
bcf LED_TEMP ; YES
; Test_Keys (k_pressed):
; 7 6 5 4 3 2 1 0
; X up timer onoff light toast temp down
bsf STATUS,RP0 ; RP0 = 1 goto Bank 1
movlw B'00111100' ; 0 = output - 1 = input
movwf TRISA ; Make RA2, RA4, RA3 and RA5 inputs (RA3 is a sensor)
movlw B'11110000' ; 0 = output - 1 = input
movwf TRISB ; Make RB4, RB5, RB6 and RB7 inputs
movlw B'00110100' ; 1 = enable pull-up - 0 disable it.
movwf WPUA ; Enable RA2, RA4 and RA5 pull-up internal resistors
bcf STATUS,RP0 ; RP0 = 0 -> Bank 2
bsf STATUS,RP1 ; RP1 = 1 -> " "
movlw B'11110000' ; 1 = enable pull-up - 0 disable it.
movwf WPUB ; Enable RB4, RB5, RB6 and RB7 pull-up internal resistors
bsf STATUS,RP0 ; RP0 = 1 -> Back to Bank 1
bcf STATUS,RP1 ; RP1 = 0 -> " "
bsf OPTION_REG,7 ; Set RABPU flag
bcf STATUS,RP0 ; RP0 = 0 -> Back to Bank 0 (RP1 already = 0)
;==================================================================================
;This section has a number of sub-routines to detect a key press, set a flag and turn on a LED
;This routine detects if a key is pressed for the second
;time so that a LED can be turned off. It does this by detecting the
;key is pressed and looking to see if the "not-pressed" flag has been
;set to indicate the key has been released between detections.
btfsc KEY_UP ; When KEY_UP pressed, input=0
goto $+5 ; Not pressed, goto exit (l1)...
btfss k_not_pressed,6 ; key pressed - look to see if second pressing
goto $+3 ; (if k_not_pressed,6 is set, key has been released between detections)
bcf k_pressed,6 ; clear the KEY_UP flag
incf temper,F ; increment temperature
btfsc KEY_DWN ; When KEY_UP pressed, input=0
goto $+5 ; Not pressed, goto exit (l1)...
btfss k_not_pressed,0 ; key pressed - look to see if second pressing
goto $+3 ; (if k_not_pressed,6 is set, key has been released between detections)
bcf k_pressed,0 ; clear the KEY_UP flag
decf temper,F ; decrement temperature
;This routine detects if a key is released
btfss KEY_UP ; Was the key released? When KEY_UP not pressed, input=1
goto $+2 ; No, it's still being pressed...
bsf k_not_pressed,6 ; Key is not pressed, set flag "not pressed"
btfss KEY_DWN ; Was the key released? When KEY_UP not pressed, input=1
goto $+2 ; No, it's still being pressed...
bsf k_not_pressed,0 ; Key is not pressed, set flag "not pressed"
;This routine just detects if a key is pressed.
;If a key is pressed, it will set the corresponding flag
;Another routine will detect that the key has been released.
;and other routine will deal with doing something will the "key-pressed" flag.
;and another routine will deal with turning off the "key-pressed" flag.
;clear the flags file in start_up
btfsc KEY_UP ; Is KEY_UP pressed, then input=0
goto $+3 ; No, it's not pressed, exit...
bsf k_pressed,6 ; Yes, it's pressed, set flag
bcf k_not_pressed,6 ; Clear the flag which indicates the key as not pressed.
btfsc KEY_DWN ; Is KEY_UP pressed, then input=0
goto $+3 ; No, it's not pressed, exit...
bsf k_pressed,0 ; Yes, it's pressed, set flag
bcf k_not_pressed,0 ; Clear the flag which indicates the key as not pressed.
;==================================================================================
bsf STATUS,RP0 ; RP0 = 1 -> Goto Bank 1 (RP1 already = 0)
bcf WPUA,7
bcf WPUB,7
bcf OPTION_REG,7 ; Set RABPU flag
movlw B'00001000' ;
movwf TRISA ; Make A0,A1,A2,A4,A5,A6 and A7 outputs.
movlw B'00000000' ;
movwf TRISB ; Make all PORTB output.
bcf STATUS,RP0 ; RP0 = 0 -> Back to Bank 0 (RP1 already = 0)
retlw 00
;/****************************************************************************
;* DESCRIPTION: Main Program
;*****************************************************************************/
Main:
movf temper,W ; Put temperature in W
call bin2bcd ; Decode Temperature to bcd
movf units,W ; copy units to W
call decdisp_a ; convert
movwf PORTA ; put it in PORTA
movf units,W ; copy units to W
call decdisp_b ; convert
movwf PORTB ; put it in PORTA
bcf DISP1 ; display 1 on
call DelayAA ; delay
call H_keeping ; delay 2 ms
bsf DISP1 ; display 1 off
movf tens,W ; copy tens to W
call decdisp_a ; convert
movwf PORTA ; put it in PORTA
movf tens,W ; copy tens to W
call decdisp_b ; convert
movwf PORTB ; put it in PORTA
bcf DISP2 ; display 2 on
call DelayAA ; delay
call H_keeping ; delay 2 ms
bsf DISP2 ; display 2 off
movf hundreds,W ; copy hundeds to W
call decdisp_a ; convert
movwf PORTA ; put it in PORTA
movf hundreds,W ; copy hundeds to W
call decdisp_b ; convert
movwf PORTB ; put it in PORTA
bcf DISP3 ; display 3 on
call DelayAA ; delay
call H_keeping ; delay 2 ms
bsf DISP3 ; display 3 off
; Leds code:
call H_keeping ; delay 2 ms
bcf LED_CMN ; Turn on the leds anode (transistor Q6)
call DelayAA ; delay
bsf LED_CMN ; Turn off the leds
goto Main ; Back to main loop
END