4. Put the tables in the first page Page0 and go to them. This will simplify the code to:
movf units,w
goto tableA
.
ORG 0x0000
GOTO START
ORG 0x0004
GOTO TIMER1_ISR ; just case we need it in future...
DECOD_DISPLAY_A:
ADDWF PCL,F ; compute the jump value
; |7|6|5|4|3|2|1|0| - Bits PORTA
; |-|-|B|E|-|A|-|-|
RETLW B'00000000' ; |-|-|B|E|-|A|-|-| - 0
RETLW B'00010100' ; |-|-|B|X|-|X|-|-| - 1
RETLW B'00000000' ; |-|-|B|E|-|A|-|-| - 2
RETLW B'00010000' ; |-|-|B|X|-|A|-|-| - 3
RETLW B'00010100' ; |-|-|B|X|-|X|-|-| - 4
RETLW B'00110000' ; |-|-|X|X|-|A|-|-| - 5
RETLW B'00100000' ; |-|-|X|E|-|A|-|-| - 6
RETLW B'00010000' ; |-|-|B|X|-|A|-|-| - 7
RETLW B'00000000' ; |-|-|B|E|-|A|-|-| - 8
RETLW B'00010000' ; |-|-|B|X|-|A|-|-| - 9
DECOD_DISPLAY_B:
ADDWF PCL,F ; compute the jump value
; |7|6|5|4|3|2|1|0| - Bits PORTB
; |C|F|D|G|-|-|-|-| -
RETLW B'00010000' ; |C|F|D|X|-|-|-|-| - 0
RETLW B'01110000' ; |C|X|X|X|-|-|-|-| - 1
RETLW B'11000000' ; |X|X|D|G|-|-|-|-| - 2
RETLW B'01000000' ; |C|X|D|G|-|-|-|-| - 3
RETLW B'00100000' ; |C|F|X|G|-|-|-|-| - 4
RETLW B'00000000' ; |C|F|D|G|-|-|-|-| - 5
RETLW B'00000000' ; |C|F|D|G|-|-|-|-| - 6
RETLW B'01110000' ; |C|X|X|X|-|-|-|-| - 7
RETLW B'00000000' ; |C|F|D|G|-|-|-|-| - 8
RETLW B'00000000' ; |C|F|D|G|-|-|-|-| - 9
DISPSHOW:
BSF LED_CMN ; Leds off
MOVF UNITS,W ; copy units to W
CALL DECOD_DISPLAY_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF UNITS,W ; copy units to W
CALL DECOD_DISPLAY_B ; convert
MOVWF PORTB ; put it in PORTA
BCF DISP1 ; display 1 on
MOVLW D'2' ;
CALL DELAY_MS ; delay 2 ms
BSF DISP1 ; display 1 off
;/****************************************************************************
;* DESCRIPTION: System definitions.
;*****************************************************************************/
ERRORLEVEL -302 ;remove message about using proper bank
LIST P=16F677
INCLUDE <P16F677.INC>
__CONFIG _BOR_OFF & _FCMEN_OFF & _IESO_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTOSCIO
;/****************************************************************************
;* DESCRIPTION: Program variables and constant definitions.
;*****************************************************************************/
TEMPER EQU 0x20 ; Store temperature
UNITS EQU 0x24 ; UNITS
TENS EQU 0x25 ; TENS
HUNDREDS EQU 0x26 ; HUNDREDS
AUX EQU 0x27 ; GENERAL AUX. REGISTER
TEMPO0 EQU 0x28
TEMPO1 EQU 0x29
FLAGS EQU 0x2B ; General use flags
TIMER EQU 0x2D ; Timer register
; Leds
#DEFINE LED_CMN PORTC,2 ; Leds Anodes
#DEFINE LED_UP PORTA,4 ; Led UP
#DEFINE LED_TIMER PORTB,6 ; Led TIMER
#DEFINE LED_TEMP PORTB,5 ; Led TEMP
#DEFINE LED_DWN PORTA,2 ; Led DWN
#DEFINE LED_LIGHT PORTB,4 ; Led LIGHT
#DEFINE LED_TOASTER PORTA,5 ; Led TOASTER
#DEFINE LED_ONOFF PORTC,6 ; Led ONOFF
#DEFINE TRIS_LED_ONOFF TRISC,6 ; Led ONOFF TRIS
; Displays
#DEFINE DISP1 PORTC,3 ; Anode display DIS0
#DEFINE DISP2 PORTC,4 ; Anode display DIS1
#DEFINE DISP3 PORTC,5 ; Anode display DIS2
;/****************************************************************************
;* DESCRIPTION: Got Start of program.
;* return: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************
ORG 0x0000
goto START
;/****************************************************************************
;* DESCRIPTION: Decodes value in W register to display segments for PORTA.
;* return: result in W
;*****************************************************************************/
DECDISP_A:
addwf PCL,F ; compute the jump value
; |7|6|5|4|3|2|1|0| - Bits PORTA
; |-|-|B|E|-|A|-|-|
retlw B'00000000' ; |-|-|B|E|-|A|-|-| - 0
retlw B'00010100' ; |-|-|B|X|-|X|-|-| - 1
retlw B'00000000' ; |-|-|B|E|-|A|-|-| - 2
retlw B'00010000' ; |-|-|B|X|-|A|-|-| - 3
retlw B'00010100' ; |-|-|B|X|-|X|-|-| - 4
retlw B'00110000' ; |-|-|X|X|-|A|-|-| - 5
retlw B'00100000' ; |-|-|X|E|-|A|-|-| - 6
retlw B'00010000' ; |-|-|B|X|-|A|-|-| - 7
retlw B'00000000' ; |-|-|B|E|-|A|-|-| - 8
retlw B'00010000' ; |-|-|B|X|-|A|-|-| - 9
;/****************************************************************************
;* DESCRIPTION: Decodes value in W register to display segments, for PORTB.
;* return: result in W
;*****************************************************************************/
DECDISP_B:
addwf PCL,F ; compute the jump value
; |7|6|5|4|3|2|1|0| - Bits PORTB
; |C|F|D|G|-|-|-|-| -
retlw B'00010000' ; |C|F|D|X|-|-|-|-| - 0
retlw B'01110000' ; |C|X|X|X|-|-|-|-| - 1
retlw B'11000000' ; |X|X|D|G|-|-|-|-| - 2
retlw B'01000000' ; |C|X|D|G|-|-|-|-| - 3
retlw B'00100000' ; |C|F|X|G|-|-|-|-| - 4
retlw B'00000000' ; |C|F|D|G|-|-|-|-| - 5
retlw B'00000000' ; |C|F|D|G|-|-|-|-| - 6
retlw B'01110000' ; |C|X|X|X|-|-|-|-| - 7
retlw B'00000000' ; |C|F|D|G|-|-|-|-| - 8
retlw B'00000000' ; |C|F|D|G|-|-|-|-| - 9
;/****************************************************************************
;* DESCRIPTION: Little Delay to let display show digit.
;* return: none
;*****************************************************************************/
H_keeping: ; Delay routine - W is the number of ms of delay.
movwf TEMPO1 ; put w in temp variable
movlw D'250'
movwf TEMPO0
decfsz TEMPO0,F
goto $-1
decfsz TEMPO1,F
goto $-5
return
;/****************************************************************************
;* DESCRIPTION: binary_to_bcd - 8-bits
;* INPUT: TEMPER - 8-bit binary number
;* return: HUNDREDS - the hundreds digit of the BCD conversion
;* TENS - the tens digits of the BCD conversion
;* UNITS - the ones digits of the BCD conversion
;*****************************************************************************/
BIN2BCD:
movwf AUX ; save the value to convert in AUX
clrf UNITS ;
clrf TENS ;
clrf HUNDREDS ; RESET variables
movf AUX,F ;
btfsc STATUS,Z ; Is the value to convert = 0?
return ; Yes - Return
; No
incf UNITS,F ; Increment unit
movf UNITS,W ;
xorlw 0X0A ;
btfss STATUS,Z ; unit = 10d ?
goto $+3 ; No
; yes
clrf UNITS ; Reset unit
incf TENS,F ; Increment tens
movf TENS,W ;
xorlw 0X0A ;
btfss STATUS,Z ; Tens = 10d ?
goto $+3 ; No
; Yes
clrf TENS ; Reset tens
incf HUNDREDS,F ; Increment hundreds
decfsz AUX,F ; End of conertion ?
goto $-.14 ; No - go back to continue the convertion
return ; Yes
;/****************************************************************************
;* DESCRIPTION: Program Initialization
;*****************************************************************************/
START:
bcf STATUS,RP0 ; Bank 2
bsf STATUS,RP1 ;
clrf ANSEL ; digital I/O
clrf ANSELH ; " " "
movlw B'00000000'
movwf CM1CON0 ; disable comparator
movlw B'00000000' ; Not necessary?
movwf CM2CON0 ; disable 2nd comparator
movlw B'00000000' ; Not necessary?
movwf CM2CON1 ; disable 3rd comparator
bsf STATUS,RP0 ; Bank 1
bcf STATUS,RP1 ;
movlw B'00001000' ;
movwf TRISA ;
movlw B'00000000' ;
movwf TRISB ;
movlw B'10000010' ;
movwf TRISC ;
bcf STATUS,RP0 ; Bank 0
bcf STATUS,RP1 ;
bcf SSPCON,SSPEN ; Disable Synchronous Serial Port
; Turn off all reles, displays and leds
bsf LED_CMN ; Leds off
bsf DISP1 ; Display1 off
bsf DISP2 ; Display2 off
bsf DISP3 ; Display3 off
movlw D'180' ; Init temperature with 180 degrees Celsius
movwf TEMPER ;
movlw D'40' ; Start TIMER with 40 minutes
movwf TIMER ;
clrf UNITS
clrf TENS
clrf HUNDREDS
;/****************************************************************************
;* DESCRIPTION: Main Program
;*****************************************************************************/
MAIN_LOOP:
movf TEMPER,W ; Put temperature in W
call BIN2BCD ; Decode Temperature to bcd
bsf LED_CMN ; Leds off
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
movlw D'2' ;
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
movlw D'2' ;
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
movlw D'2' ;
call H_keeping ; delay 2 ms
bsf DISP3 ; display 3 off
; Leds code:
bsf LED_UP ; led UP ON
bsf LED_DWN ; led DWN ON
bsf LED_TEMP ; led TEMP ON
bsf LED_TIMER ; led TIMER ON
bsf LED_LIGHT ; led LIGHT ON
bsf LED_TOASTER ; led TOASTER ON
bsf LED_CMN ; Leds on
movlw D'2' ;
call H_keeping ; delay 2 ms
bsf LED_CMN ; Leds off
goto MAIN_LOOP ; Back to main loop
END
You mean to put, in the main, just a call to subroutines which will take care of displays and leds?Main will simply consist of turning on a digit and calling delay - three times - then the LEDs and calling delay.
BEEP:
movwf BEEPCNT
BEEP0:
bsf BUZZER ; beepctl bit
movlw 4
call udelay
bcf BUZZER ; beepctl bit
movlw 4
call udelay
decfsz BEEPCNT, F
goto BEEP0
udelay ; delay W * 100 usec
movwf DCNT0
udelay0
movlw 26
movwf DCNT1
udelay1
decfsz DCNT1,F
goto udelay1
decfsz DCNT0, F
goto udelay0
return
bsf buz ; piezo on
movlw .170
movwf buz_file
decfsz buz_file,f
goto $-1
bcf buz ; piezo off
movlw .170
movwf buz_file
decfsz buz_file,f
goto $-1
bcf buz ; piezo off
decf buz_length ; this is a file that you have previously set to 0ffh to create 250mS tone
retlw 00
buz_file EQU 0x2E ; Buzzer file
buz_length EQU 0x2F ; Buzzer length
; Buzzer
#define buz PORTC,0 ; Buzzer
H_keeping:
movlw D'255'
movwf buz_length
bsf buz ; piezo on
movlw .170
movwf buz_file
decfsz buz_file,f
goto $-1
bcf buz ; piezo off
movlw .170
movwf buz_file
decfsz buz_file,f
goto $-1
bcf buz ; piezo off
decf buz_length,F ;
retlw 00
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?