ssaguiar
New Member
OK.
This is the code.
For the main loop:
for the housekeeping:
Now, with the correct paging for the WPUB register, the value in display continues to update while the key up is pressed, without problems.
The flashing rate is increased (almost twice a seond, because there were the timming inside the beep routine which is gone) and we are at the limit for the counter in Led_blink file.
Another thing: while the key is pressed and the display is being updated, the leds which were suposed to be off , blinks.
This is the code.
For the main loop:
Code:
main_loop:
movf temper,W ; Put temperature in W
call bin2bcd ; Decode Temperature to bcd
movf units,W ; copy units to W
call decdisp_a ; convert
bsf LED_CMN ; Leds off
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 H_keeping ; delay 2 ms
movf tens,W ; copy tens to W
call decdisp_a ; convert
bsf DISP1 ; display 1 off
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 H_keeping ; delay 2 ms
movf hundreds,W ; copy hundeds to W
call decdisp_a ; convert
bsf DISP2 ; display 2 off
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 H_keeping ; delay 2 ms
bsf DISP3 ; display 3 off
; Leds code:
bsf LEDS_ON ; Flag leds on
bcf LED_CMN ; Leds on
call H_keeping ; delay 2 ms
goto main_loop ; Back to main loop
for the housekeeping:
Code:
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 ; not enabled ; No, get out!
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
;notenabled:
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
bsf leds_s,6 ; Led on/off in on
goto contled
setledoff:
bcf leds_s,6 ; Led on/off in off
contled:
btfss LEDS_ON
goto endleds
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
endleds:
bcf LEDS_ON
; Test_Keys (k_pressed):
; 7 6 5 4 3 2 1 0
; X up timer onoff light toast temp down
bsf STATUS,RP0 ; Bank 1
;bcf STATUS,RP1 ; " "
bcf OPTION_REG,NOT_RABPU ; Activate pull-up resistors - Clear RABPU flag
movlw B'00111100' ;
movwf TRISA ; Make RA2, RA4, RA3 and RA5 inputs (RA3 is a sensor)
movlw B'11110000' ;
movwf TRISB ; Make RB4, RB5, RB6 and RB7 inputs
movlw B'00110100' ;
movwf WPUA ; Enable RA2, RA4 and RA5 pull-up internal resistors
bcf STATUS,RP0 ; Bank 2
bsf STATUS,RP1 ; " "
movlw B'11110000'
movwf WPUB ; Enable RB4, RB5, RB6 and RB7 pull-up internal resistors
bsf STATUS,RP0 ; Back to Bank 1
bcf STATUS,RP1 ; " "
bsf OPTION_REG,7 ; Set RABPU flag
bcf STATUS,RP0 ; Bank 0
btfss KEY_UP ; KEY_UP pressed?
incf temper,F ; Yes
btfsc KEY_UP ; Key Up pressed?
goto $+3 ; No
bsf k_pressed,6 ; Yes, set flag
goto $+2 ; Exit
bcf k_pressed,6 ; No, reset flag
btfsc KEY_timer ;
goto $+3 ;
bsf k_pressed,5 ;
goto $+2 ;
bcf k_pressed,5 ;
btfsc KEY_ONOFF ;
goto $+3 ;
bsf k_pressed,4 ;
goto $+2 ;
bcf k_pressed,4 ;
btfsc KEY_LIGHT ;
goto $+3 ;
bsf k_pressed,3 ;
goto $+2 ;
bcf k_pressed,3 ;
btfsc KEY_TOASTER ;
goto $+3 ;
bsf k_pressed,2 ;
goto $+2 ;
bcf k_pressed,2 ;
btfsc KEY_TEMP ;
goto $+3 ;
bsf k_pressed,1 ;
goto $+2 ;
bcf k_pressed,1 ;
btfsc KEY_DWN ;
goto $+3 ;
bsf k_pressed,0 ;
goto $+2 ;
bcf k_pressed,0 ;
bsf STATUS,RP0 ; Bank 1
bcf WPUA,7
bcf WPUB,7
bcf OPTION_REG,7 ; Set RABPU flag
movlw B'00001000' ;
movwf TRISA ;
movlw B'00000000' ;
movwf TRISB ;
bcf STATUS,RP0 ; Bank 0
retlw 00
Now, with the correct paging for the WPUB register, the value in display continues to update while the key up is pressed, without problems.
The flashing rate is increased (almost twice a seond, because there were the timming inside the beep routine which is gone) and we are at the limit for the counter in Led_blink file.
Another thing: while the key is pressed and the display is being updated, the leds which were suposed to be off , blinks.
Last edited: