;****************************************************************
;* Started 18/6/2009
;2 Digit UP / Down Counter with FastCount after 2secs
;Port B drives 7 segment display
;Up sw on RA2 Down on RA3
;Units drive on RA0 Tens drive on RA1 *
;* *
;****************************************************************
list P = 16F628 ;microcontroller
include ;registers for F628
__Config _cp_off & _lvp_off & _pwrte_on
& _wdt_off & _intRC_osc_noclkout & _mclre_off
;code protection - off
;low-voltage programming - off
;power-up timer - on
;watchdog timer - off
;use internal RC for 4MHz - all pins for in-out
;****************************************************************
; variables - names and files
;****************************************************************
;files for F628 start at 20h
temp1 equ 20h ;for delay
temp2 equ 21h ;for delay
SwUp equ 22h ;
SwDwn equ 23h ;
units equ 24h ;
tens equ 25h ;
Sw_Flag equ 26h ;
FastCount equ 27h ;
;****************************************************************
;Equates
;****************************************************************
status equ 0x03
cmcon equ 0x1F
rp1 equ 0x06
rp0 equ 0x05
portA equ 0x05
portB equ 0x06
;****************************************************************
;Beginning of program
;****************************************************************
reset org 00 ;reset vector address
goto SetUp ;goto SetUp
table addwf PCL,F ;02h,1 add W to program counter
retlw b'00111111' ; "0" -|F|E|D|C|B|A
retlw b'00000110' ; "1" -|-|-|-|C|B|-
retlw b'01011011' ; "2" G|-|E|D|-|B|A
retlw b'01001111' ; "3" G|-|-|D|C|B|A
retlw b'01100110' ; "4" G|F|-|-|C|B|-
retlw b'01101101' ; "5" G|F|-|D|C|-|A
retlw b'01111101' ; "6" G|F|E|D|C|-|A
retlw b'00000111' ; "7" -|-|-|-|C|B|A
retlw b'01111111' ; "8" G|F|E|D|C|B|A
retlw b'01101111' ; "9" G|F|-|D|C|B|A
;****************************************************************
;* port A and B initialisation *
;****************************************************************
SetUp bsf status,rp0
movlw b'00001100' ;Make RA0,1 out RA2,3 in
movwf 05h ;trisA
clrf 06h ;trisB Make all RB output
bcf status,rp0 ;select programming area - bank0
movlw b'10000000' ;Turn off T0CKI, prescale for TMR0=1
movwf option_reg
clrf portB ;Clear Port B of junk
clrf units ;zero the units file
clrf tens ;zero the tens file
clrf Sw_Flag
movlw 07h ;turn comparators off and enable
movwf cmcon ; pins for I/O functions
goto Main
;****************************************************************
;* Delay 10mS 10 x 1,000uS *
;****************************************************************
D_10mS movlw 0Ah
movwf temp2
D_a nop
decfsz temp1,f
goto D_a
decfsz temp2,f
goto D_a
retlw 00
FastUp btfss Sw_Flag,2 ;First time through loop?
goto FU_2 ;yes
btfsc Sw_Flag,7 ;Has 5Hz bit been set?
goto FU_3
FU_1 incfsz FastCount,f ;Increment FastCount
movlw d'100'
xorwf FastCount,w
btfss status,2 ;reached 100 loops?
retlw 00
clrf FastCount
bsf Sw_Flag,7 ;set bit for 5Hz incrementing
FU_2 bsf Sw_Flag,2 ;Up button has been pressed
incf units,f
movlw 0Ah ;put 10 into w
xorwf units,w ;compare units file with 10
btfss status3,2 ;zero flag in status file. Set if units is 10
retlw 00
clrf units
incf tens,f
movlw 0Ah ;put 10 into w
xorwf tens,w ;compare units file with 10
btfsc status,2 ;zero flag in status file. Set if tens is 10
clrf tens
retlw 00 ;display passes 99 but not below 0
FU_3 incfsz FastCount,f ;Increment FastCount
movlw d'5'
xorwf FastCount,w
btfss status,2 ;reached 5 loops?
retlw 00
clrf FastCount
goto FU_2
Dwn btfsc Sw_Flag,3
retlw 00
bsf Sw_Flag,3
decf units,f
movlw 0FFh ;put FFh into w
xorwf units,w ;compare units file with FFh
btfss status,2 ;zero flag in status file. Set if units is 10
retlw 00
movlw 09
movwf units ;put 9 into units file
decf tens,f
movlw 0FFh ;put 0FFh into w
xorwf tens,w ;compare tens file with 0FFh
btfsc status,2 ;zero flag in status file. Set if tens is 0FFh
goto $+2 ;tens file is 0FFh
retlw 00
clrf tens
clrf units
retlw 00 ;display not below 0
;****************************************************************
;* Main *
;****************************************************************
Main btfss portA,2 ;test switch-press for UP
call FastUp ;UP switch pressed
btfss portA,3 ;test switch-press for Down
call Dwn ;Down switch pressed
movlw b'00000001' ;Make RA0 HIGH for units drive
movwf portA
movf units,w ;copy unit value into w
call table ;unit display value will return in w
movwf portB ;output units value
call D_10mS ;call delay
clrf portB ;clear display
movlw b'00000010' ;Make RA1 HIGH for tens drive
movwf portA
movf tens,w ;copy tens value into w
call table ;tens display value will return in w
movwf portB ;output tens value
call D_10mS ;call delay
clrf portB ;clear display
btfsc portA,3 ;bit will be zero when sw is pressed
bcf Sw_Flag,3 ;button not pressed. Clear down flag
btfss portA,2 ;bit will be zero when sw is pressed
goto Main
bcf Sw_Flag,2 ;button not pressed. Clear Up flag
bcf Sw_Flag,7 ;Clear Up repeat flag
clrf FastCount
goto Main
END
Thanks, my friends, for your answers.
I will try to implement the keys routine and will post here as soon as I have it working.
Firstly you have to convert all the wording to English.
Secondly you have to remove all the unnecessary instructions such as CALL TIMERSET
Thirdly you have to simplify a lot of the routines, such as removing the macros as they are only used once and remove clrw and put it in MAINCONTINUE
Then you have to supply a circuit diagram so we can see how you are multiplexing the displays and what you are really doing.
You have totally gone against everything I have ever taught.
The first thing you do is produce a routine to activate the displays. Then introduce one key and one LED.
During the time when the last display is illuminated you have time to do all sorts of "housekeeping."
This involves looking at the input port and dealing with the data, processing it and storing it.
This is a much simpler way of tackling your requirement and the program will be half the size. And you will be able to understand it.
What you are doing is very simple.
DECOD_DISPLAY_A:
MOVWF TEMP ; Put number in displacement variable
MOVLW LOW TABLE_A ; cop to W the 8 LSB bits of the TABLE address
ADDWF TEMP,F ; add the value to the displacement variable
MOVLW HIGH TABLE_A ; copy to W the upper 5 bits of the TABLE ddress
BTFSC STATUS,C ; Test to see if the sum activates the carry bit
ADDLW 0x01 ; if carry, sum 1 to W
MOVWF PCLATH ; sets PCLATH using the TABLE address
MOVF TEMP,W ; copy the displacement value to W
MOVWF PCL ; copy W to PCL
TABLE_A:
; A
; _______
; | |
; F | | B
; | G |
; -------
; | |
; E | | C
; |_______|
; D
; |7|6|5|4|3|2|1|0| - Bits PORTA
; |-|-|B|E|-|A|-|-|
RETLW B'00000000' ; |-|-|B|E|-|A|-|-| - 0
RETLW B'00010000' ; |-|-|B|X|-|A|-|-| - 1
RETLW B'00000000' ; |-|-|B|E|-|A|-|-| - 2
RETLW B'00010000' ; |-|-|B|X|-|A|-|-| - 3
RETLW B'00010100' ; |-|-|B|X|-|X|-|-| - 4
RETLW B'00011000' ; |-|-|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:
MOVWF TEMP ; Put number in displacement variable
MOVLW LOW TABLE_B ; cop to W the 8 LSB bits of the TABLE address
ADDWF TEMP,F ; add the value to the displacement variable
MOVLW HIGH TABLE_B ; copy to W the upper 5 bits of the TABLE ddress
BTFSC STATUS,C ; Test to see if the sum activates the carry bit
ADDLW 0x01 ; if carry, sum 1 to W
MOVWF PCLATH ; sets PCLATH using the TABLE address
MOVF TEMP,W ; copy the displacement value to W
MOVWF PCL ; copy W to PCL
TABLE_B:
;|7|6|5|4|3|2|1|0| - Bits PORTB
;|C|F|D|G|-|-|-|-| -
RETLW B'00000000' ; |C|F|D|G|-|-|-|-| - 0
RETLW B'11110000' ; |X|X|X|X|-|-|-|-| - 1
RETLW B'11000000' ; |X|X|D|G|-|-|-|-| - 2
RETLW B'01000000' ; |C|X|D|G|-|-|-|-| - 3
RETLW B'10100000' ; |X|F|X|G|-|-|-|-| - 4
RETLW B'10100000' ; |X|F|X|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
;**********************************************************************
; *
;**********************************************************************
; Filename: oven.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
;**********************************************************************
; Files Required: P16F677.INC *
; *
;**********************************************************************
; PIC 16F677 pinout: *
; |--\/--| *
; Vdd -|1 20|- Vss *
; RA5/T1CKI/OSC1/CLKIN -|2 19|- RA0/AN0/C1IN+/ICSPDAT/ULPWU *
; RA4/AN3/T1G/OSC2/CLKOUT -|3 18|- RA1/AN1/C12IN0-/VREF/ICSPCLK *
; RA3/MCLR/VPP -|4 17|- RA2/AN2/T0CKI/INT/C1OUT *
; RC5 -|5 16|- RC0/AN4/C2IN+ *
; RC4/C2OUT -|6 15|- RC1/AN5/C12IN1- *
; RC3/AN7C12IN3 -|7 14|- RC2/AN6/C12IN2- *
; RC6/AN8/SS -|8 13|- RB4/AN10/SDI/SDA *
; RC7/AN9/SDO -|9 12|- RB5/AN11 *
; RB7 -|10 11|- RB6/SCK/SCL *
; -------- *
; *
;**********************************************************************
;/****************************************************************************
;* DESCRIPTION: System definitions.
;* RETURN: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
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.
;* RETURN: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
TEMPER EQU 0x20 ; Store temperature
TEMP EQU 0x21 ; General use variable
W_TEMP EQU 0x22 ; Temporary W register
STATUS_TEMP EQU 0x23 ; Temporary STATUS register
UNITS EQU 0x24 ; UNITS
TENS EQU 0x25 ; TENS
HUNDREDS EQU 0x26 ; HUNDREDS
AUX EQU 0x27 ; GENERAL AUX. REGISTER
TEMPO0 EQU 0x28
TEMPO1 EQU 0x29
T1_CONTA EQU 0x2A ; Aux. Timer1 counter
TMR_1MS EQU 0x2B ; Counter for 1 ms period
TMR_100MS EQU 0x2C ; Counter for 100 ms period
; 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
; 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
;*****************************************************************************
ORG 0x0004
MOVWF W_TEMP ; save W content to W_TEMP
SWAPF STATUS,W ; put STATUS in W...
MOVWF STATUS_TEMP ; ... Then save it in STATUS_TEMP
BCF PIR1,TMR1IF ; Clear Timer1 Interrupt flag
MOVLW 0x18 ;
MOVWF TMR1L ;
MOVLW 0xFC ;
MOVWF TMR1H ; Init TIMER1 with decimal 64536 (interrupt every 1ms)
INCF TMR_1MS,F ; Increment TR_1MS (1 ms counter)
MOVLW D'100'
XORWF TMR_1MS,W ; Is TMR_1MS = 100?
BTFSC STATUS,Z ; No, skip if TMR_1MS < 100
GOTO INC100MS ; Yes, zero TMR_1MS and inc TMR_100MS
GOTO END_INT ; No, exit interrupt
INC100MS
MOVLW D'0' ;
MOVWF TMR_1MS ; Zero TMR_1MS
INCF TMR_100MS,F ; Increment TMR_100MS (100 ms counter)
MOVLW D'5' ; 500 ms?
XORWF TMR_100MS,W ; Is TMR_100MS = 5 (500ms)?
BTFSC STATUS,Z ; No, skip if TMR_100MS < 5
GOTO INCCONTA ; Yes, zero TMR_100MS and inc 0,5 seconds counter
GOTO END_INT ; No, Exit interrupt
INCCONTA:
MOVLW D'0' ;
MOVWF TMR_100MS ; Zero 100 ms counter (reached 500ms)
BSF STATUS,RP0 ; Bank 1
BCF STATUS,RP1 ;
BCF LED_ONOFF ; LED_ONOFF output
BCF STATUS,RP0 ; Bank 0
BCF STATUS,RP1 ;
MOVLW D'1' ; Verify if ...
XORWF T1_CONTA,W ; passed 1/2 second ...
BTFSC STATUS,Z ;
GOTO LEDON ; Led ONOFF is ON? Goto LEDON
LEDOFF:
BCF LED_ONOFF ; Turn OFF LEDON_OFF
GOTO LEDOUT ; ok, done...
LEDON:
BSF LED_ONOFF ; Turn ON LED_ONOFF
LEDOUT:
DECFSZ T1_CONTA,F ; Decrement the Counter rRegister
GOTO END_INT ; If diferent of zero, exit interrupt
MOVLW 2 ;
MOVWF T1_CONTA ; Restart Counter Register with 2
END_INT:
SWAPF STATUS_TEMP,W ; Restaure STATUS content...
MOVWF STATUS ; ... from STATUS_TEMP
SWAPF W_TEMP,F ; Restaure W content...
SWAPF W_TEMP,W ; ... from W_TEMP.
RETFIE ; Return from interrupt
;/****************************************************************************
;* DESCRIPTION: Decodes value in W register to display segments for PORTA.
;* RETURN: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
DECOD_DISPLAY_A:
MOVWF TEMP ; Put number in displacement variable
MOVLW LOW TABLE_A ; cop to W the 8 LSB bits of the TABLE address
ADDWF TEMP,F ; add the value to the displacement variable
MOVLW HIGH TABLE_A ; copy to W the upper 5 bits of the TABLE ddress
BTFSC STATUS,C ; Test to see if the sum activates the carry bit
ADDLW 0x01 ; if carry, sum 1 to W
MOVWF PCLATH ; sets PCLATH using the TABLE address
MOVF TEMP,W ; copy the displacement value to W
MOVWF PCL ; copy W to PCL
TABLE_A:
; A
; _______
; | |
; F | | B
; | G |
; -------
; | |
; E | | C
; |_______|
; D
; |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: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
DECOD_DISPLAY_B:
MOVWF TEMP ; Put number in displacement variable
MOVLW LOW TABLE_B ; cop to W the 8 LSB bits of the TABLE address
ADDWF TEMP,F ; add the value to the displacement variable
MOVLW HIGH TABLE_B ; copy to W the upper 5 bits of the TABLE ddress
BTFSC STATUS,C ; Test to see if the sum activates the carry bit
ADDLW 0x01 ; if carry, sum 1 to W
MOVWF PCLATH ; sets PCLATH using the TABLE address
MOVF TEMP,W ; copy the displacement value to W
MOVWF PCL ; copy W to PCL
TABLE_B:
; |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
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
DELAY_MS: ; 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: CENTENA - the hundreds digit of the BCD conversion
;* DEZENA - the tens digits of the BCD conversion
;* UNIDADE - the ones digits of the BCD conversion
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
BINARY_TO_BCD:
MOVWF AUX ; sve 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
;* RETURN: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
START:
BCF STATUS,RP0 ; Bank 2
BSF STATUS,RP1 ;
CLRF ANSEL ; digital I/O
CLRF ANSELH ; " " "
BCF STATUS,RP0 ; Bank 2
BSF STATUS,RP1 ;
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 2 ;
MOVWF T1_CONTA ;
; Init Timer1
MOVLW B'00000000' ; Configure TIMER1 for internal clock and prescaler 1:1
MOVWF T1CON ; Init Timer1
MOVLW 0x18 ;
MOVWF TMR1L ;
MOVLW 0xFC ;
MOVWF TMR1H ; Init TIMER1 with decimal 64536 (interrupt every 1ms)
BSF STATUS,RP0 ; Bank 1
BCF STATUS,RP1 ;
MOVLW B'00000001' ; Enable TIMER1 Overflow Interrupt
MOVWF PIE1
BCF STATUS,RP0 ; Bank 0
BCF STATUS,RP1 ;
CLRF PIR1 ; Clear Peripheral Interrupt Flags
BSF INTCON, PEIE ; Enable Peripheral Interrupts
BSF T1CON, TMR1ON ; Start TMR1
BSF INTCON, GIE ; Enable Global Interrupts
;/****************************************************************************
;* DESCRIPTION: Main Program
;* RETURN: none
;* ALGORITHM: none
;* NOTES: none
;*****************************************************************************/
MAIN_LOOP:
MOVF TEMPER,W ; Put temperature in W
CALL BINARY_TO_BCD ; Decode Temperature to bcd
BSF LED_CMN ; Leds off
MOVF UNITS,W ; copy units to W
;MOVLW D'0'
CALL DECOD_DISPLAY_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF UNITS,W ; copy units to W
;MOVLW D'0'
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
MOVF TENS,W ; copy tens to W
;MOVLW D'0'
CALL DECOD_DISPLAY_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF TENS,W ; copy tens to W
;MOVLW D'0'
CALL DECOD_DISPLAY_B ; convert
MOVWF PORTB ; put it in PORTA
BCF DISP2 ; display 1 on
MOVLW D'2' ;
CALL DELAY_MS ; delay 2 ms
BSF DISP2 ; display 1 off
MOVF HUNDREDS,W ; copy hundeds to W
;MOVLW D'0'
CALL DECOD_DISPLAY_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF HUNDREDS,W ; copy hundeds to W
;MOVLW D'0'
CALL DECOD_DISPLAY_B ; convert
MOVWF PORTB ; put it in PORTA
BCF DISP3 ; display 1 on
MOVLW D'2' ;
CALL DELAY_MS ; delay 2 ms
BSF DISP3 ; display 1 off
BCF LED_UP ; led UP ON
BCF LED_DWN ; led DWN ON
BCF LED_TEMP ; led TEMP ON
BSF LED_TIMER ; led TIMER OFF
BSF LED_LIGHT ; led LIGHT OFF
BSF LED_TOASTER ; led TOASTER OFF
BCF LED_CMN ; Leds on
MOVLW D'2' ;
CALL DELAY_MS ; delay 2 ms
BSF LED_CMN ; Leds off
GOTO MAIN_LOOP ; Back to main loop
END
1 - Use lower case for nmemonics
2. Have you cleared: units, tens, and hundreds before starting?
3. You don't need interrupts. It just makes things more complex.
4. Put the tables in the first page Page0 and go to them. This will simplify the code to:
movf units,w
goto tableA
Here is a very short delay routine
del_2mS
movlw 02
movwf temp1
nop
decfsz temp2
goto $-2
retlw 00
each unit put into temp1 will produce 1mS delay. temp2 will be 00 at start of second and further calls to this delay.
DELAY_MS: ; 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
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?