• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

change in display

Status
Not open for further replies.
;******************************************************************************
; PROJECT : DIGITAL TIMER FOR 100 hr
; ORGANISATION: SECTRA SALES CORPORATION
; NAME OF FILE: TIMER WTCH
; SOFT : MPLAB IDE from Microchip.Inc
; MCU : PIC16F877A @4Mhz
; DATE : 25/01/2010
;PROGRAMMER :Mr.jimmy varghese
;******************************************************************************
;Preprocessor Directives


LIST P = PIC16F877A

#INCLUDE "P16F877A.INC"


__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _LVP_OFF

cblock 20h
hibyte
lowbyte
temp
IRWaitCnt
msb,lsb,ones,tens,hund,thus,ss,sp,rr,tmp,tmp1,tmp5,tmp3,STORE,blink,hunds,tmp2,timer,ee,ff,Timer,tmp4,gg,dd,bb,temp3,temp4
temp5,temp6,temp7,temp8,temp9,temp0,uu,tmr,tmr1,go,set0,tem,temp1,tt,ad,cb,rs,temp2,aa,sim
endc


ORG 0X00
MOVLW 00H
MOVWF PCLATH
CLRF STATUS
GOTO main
;****************************************************************************************************
org 04h
; bcf INTCON,T0IF ;clearing the timer 0 flag
bcf PIR1,TMR1IF ;clearing the timer 1 flag
movwf temp ;store w reg to temp
swapf STATUS,W ;swap and store status reg in to STORE
movwf STORE
clrf STATUS
goto ISR ;goto interrupt

;****************************************************************************************************
lookup

addwf PCL,F ;digit to be displayed
retlw b'00111111' ;'0'
retlw b'00000110' ;'1'
retlw b'01011011' ;'2'
retlw b'01001111' ;'3'
retlw b'01100110' ;'4'
retlw b'01101101' ;'5'
retlw b'01111101' ;'6'
retlw b'00000111' ;'7'
retlw b'01111111' ;'8'
retlw b'01101111' ;'9'




;****************************************************************************************************************************************************************************

initport
bsf STATUS,RP0 ;bank1
bcf TRISC,1 ;enable the led and latch as output
bcf TRISC,0
movlw 0x06 ;prescale value
movwf OPTION_REG
movlw b'00000000' ;port as output
movwf TRISD
bsf TRISA,4 ;portA,4 as input
bcf TRISB,5 ;disable buzzer
bsf TRISC,5
bsf TRISC,2
movlw b'11010000' ;portB as input/output
movwf TRISB
bsf PIE1,TMR1IE ;enable tmr1 enable bit
bcf STATUS,RP0 ;bank0
bcf PIR1,TMR1IF ;clr tmr1 flag
bsf INTCON,GIE ;set glble intrpt enbl bit
bsf INTCON,PEIE ;set peripheral intrpt enble bit
bsf T1CON,0 ;start tmr1
bcf T1CON,2
bcf T1CON,1 ;synchroized extrnl clck pulse
clrf TMR0 ;reset timer
clrf TMR1L ;load tmr values
clrf TMR1H
movlw 0xff
movwf TMR1L
movlw 0xef
movwf TMR1H
bcf PORTC,0 ;disable led and latch
bcf PORTC,1
clrf PORTA
clrf PORTB
clrf PORTC
clrf PORTD
clrf ee

clrf ff
bsf PORTC,0
bcf PORTC,0
clrf tmp
bsf tmp,0
movlw 0x00 ;load default value
movwf ones
movlw 0x00
movwf tens
movlw 0x00
movwf hunds
movlw 0x00
movwf thus
clrf sim
clrf tmp4
clrf tmp5
clrf gg
clrf tt
clrf go
clrf dd
clrf temp
clrf blink
bsf PORTD,4
return

;******************************************************************************************************************************************************************



mainline

btfsc go,0 ;which is used for unlock the cascade key..
goto hh
btfss PORTC,5 ;2nd key
goto mainline
hh btfss PORTA,4
goto mainline ;1st key
bsf go,0
incf tmp5,1 ;delay(debounce)
movfw tmp5
sublw 0x01
btfss STATUS,Z
goto mainline
clrf tmp5 ;debounce
btfss gg,7
goto mainline
clrf gg
incf tmp4,1 ;;for blinking ones?(digits0)
movfw tmp4
sublw 0x01
btfss STATUS,Z
goto chk1

clrf ff
clrf ee
bsf blink,0
bsf tt,0
clrf temp3
clrf temp4
goto mainline
return
;**********************************************************************************************************************************************************************************
chk1

movfw tmp4 ;for blinking tens(digits1)
sublw 0x02
btfss STATUS,Z
goto chk2
bcf blink,0
bcf tt,0
bsf blink,1
bsf tt,1
clrf gg
clrf ff
clrf ee
clrf dd
clrf temp5
clrf temp6
goto mainline
return
;****************************************************************************************************************************************************************************** *
chk2
movfw tmp4 ;for blinking hunds(digits2)
sublw 0x03
btfss STATUS,Z
goto chk3
bcf tt,0
bcf tt,1
bcf blink,0
bcf blink,1
bsf blink,2
bsf tt,2
clrf gg
clrf ff
clrf ee
clrf dd
clrf temp7
clrf temp8
goto mainline
return
;*************************************************************************************************************************************************************************************
chk3
;for blinking thus(digits3)
movfw tmp4
sublw 0x04
btfss STATUS,Z
goto chk4
bcf tt,0
bcf tt,1
bcf tt,2
bcf blink,0
bcf blink,1
bcf blink,2
bsf blink,3
bsf tt,3
clrf gg
clrf ff
clrf ee
clrf dd
clrf temp9
clrf temp0
goto mainline
return
;**********************************************************************************************************************************************************************************
chk4


clrf gg
clrf ff
clrf tt
clrf ee
clrf dd
clrf tmp4
clrf blink
clrf temp3
clrf temp4
clrf temp5
clrf temp6
clrf temp7
clrf temp8
clrf temp9
clrf temp0
goto mainline
return

;********************************************************************************************************************************************************************************
scor


bcf PIR1,TMR1IF ;for incrementing the ones(digits0)
btfss tt,0
goto ret1
bsf PORTD,7 ;increment key
btfss PORTC,2
goto ret1
incf ones,1
bck11 movfw ones
sublw 0x09
btfss STATUS,Z
goto scor
clrf gg
clrf dd
clrf ff
clrf ones
clrf sim
bsf PIR1,TMR1IF
goto ret1
return

;***********************************************************************************************************************************************************************************
scor1
; bcf PIR1,TMR1IF ;for incrementing the tens(digits1)
btfss tt,1
goto ret11
bsf PORTD,7 ;increment key
btfss PORTC,2
goto ret11
incf tens,1
bck111 movfw tens
sublw 0x09
btfss STATUS,Z
goto scor1
clrf tens
clrf gg
clrf ff
clrf tt
clrf ee
clrf dd
; bsf PIR1,TMR1IF
goto ret1
return
;***********************************************************************************************************************************************************************************

scor2

;for incrementing the hunds(digits2)
; bcf PIR1,TMR1IF
btfss tt,2
goto ret11
bsf PORTD,7 ;increment key
btfss PORTC,2
goto ret111
incf hunds,1
bck12 movfw hunds
sublw 0x09
btfss STATUS,Z
goto scor2
clrf gg
clrf dd
clrf ff
clrf hunds
; bsf PIR1,TMR1IF
goto ret1
return
;************************************************************************************************************************************************************************************

scor3

; bcf PIR1,TMR1IF ;for incrementing the thus(digits3)
btfss tt,3
goto ret111
bsf PORTD,7 ;increment key
btfss PORTC,2
goto ret1111
incf thus,1

bck13 movfw thus
sublw 0x09
btfss STATUS,Z
goto scor3
clrf thus
clrf gg
clrf ff
clrf tt
clrf ee
clrf dd
goto ret1
return


;************************************************************************************************************************
ISR
incf ee,1
incf ff,1 ;making delay for displaying current value
btfsc ff,7
incf gg,1
btfsc gg,7
incf dd,1
btfsc dd,7
incf uu,1
; btfsc dd,7
; goto display ;displaying ones
btfss tmp,0
goto one
movfw ones
call lookup
movwf PORTD
btfsc blink,0
btfsc ee,7
bsf PORTB,3
btfsc ff,7
goto scor
ret1 incf temp3,1 ;blink stop
btfsc temp3,7
incf temp4,1
btfsc temp4,7
bcf blink,0
rlf tmp,F
GOTO finish

one
btfss tmp,1 ;displaying tens
goto ten
bcf PORTB,3
movfw tens
call lookup
movwf PORTD
btfsc blink,1
btfsc ee,7
bsf PORTB,2
btfsc ff,7
goto scor1
ret11 incf temp5,1 ;blink stop
btfsc temp5,7
incf temp6,1
btfsc temp6,7
bcf blink,1
rlf tmp,F
goto finish

ten btfss tmp,2 ;displaying hunds
goto hund1
bcf PORTB,2
movfw hunds
call lookup
movwf PORTD
btfsc blink,2
btfsc ee,7
bsf PORTB,1
btfsc ff,7
goto scor1
ret111 incf temp7,1 ;blink stop
btfsc temp7,7
incf temp8,1
btfsc temp8,7
bcf blink,2
rlf tmp,F
goto finish

hund1 btfss tmp,3 ;displaying thus
goto thuds
bcf PORTB,1
movfw thus
call lookup
movwf PORTD
btfsc blink,3
btfsc ee,7
bsf PORTB,0
btfsc ff,7
goto scor1
ret1111 incf temp9,1 ;blink stop
btfsc temp9,7
incf temp0,1
btfsc temp0,7
bcf blink,3
rlf tmp,1
goto finish

thuds btfss tmp,4
goto finish
bcf PORTB,0
clrf tmp
bsf tmp,0
goto finish

;*************************************************************************************************************************************************************
finish

swapf temp,W ;reload status reg values
movlw 0xff
movwf TMR1L
movlw 0xef
movwf TMR1H
; *** Restore Values ***

swapf STORE,W
movwf STATUS
swapf temp,F
swapf temp,w

retfie

;****************************************************************************************************************

;for displaying the default values

;****************************************************************************************************************
display

; btfss aa,1 ;displaying ones
; goto bck
btfss tmp,0
goto one1
movfw temp1
call lookup
movwf PORTD
bsf PORTB,3
rlf tmp,F
GOTO finish

one1
btfss tmp,1 ;displaying tens
goto ten1
bcf PORTB,3
movfw temp2
call lookup
movwf PORTD
bsf PORTB,2
rlf tmp,F
goto finish

ten1
btfss tmp,2 displaying hunds
goto hund11
bcf PORTB,2
movfw temp3
call lookup
movwf PORTD
bsf PORTB,1
rlf tmp,F
goto finish

hund11
btfss tmp,3 displaying thus
goto thuds1
bcf PORTB,1
movfw temp4
call lookup
movwf PORTD
bsf PORTB,0
rlf tmp,1
goto finish

thuds1
btfss tmp,4
goto finish
bcf PORTB,0
clrf tmp
bsf tmp,0
goto finish
return


;************************************************************************************************************************************************

delay
movlw 0x05 ;delay...
movwf rs
back3
movlw 0xff
movwf rr
back2 movlw 0xff
movwf sp
back1 decfsz sp,1
goto back1
decfsz rr,1
goto back2
decfsz rs,1
goto back3
return

;***********************************************************************************************************************************************
main

call initport
call mainline
end

problem:

it is a display program,which is used to change the diplay using two push button..when we press two bus botton at a time the last digit wil blink.aftr press the first buttom v can select our desired digits..after selecting the digits if we press second key that will increment..like this all the four wil work...my problem is that after selecting the digits when we press the 2nd key it is not incrementing.some times it will increment but very fast..am already used debounce then also not getting proper increment...
 
Last edited:

Wp100

Well-Known Member
Hi,

Whats the question ?? - well before that think you need to look at your code in a bit more detail.

What crystal frequency are you using for Timer1 - you are preloading it in the ISR to 0xEF in both tmr1L and H ?


Think you need to read up on the ISR and the Context Saving - put simply you need to use the ISR to execute the minimum amount of code, within that section, and then return back to the main code.
You do not want to do most of your main processing in the ISR as you seem to be doing.
The most obvious reason is that your next interrupt may be missed becuase you are still processing the last one. but more importantly you will probably loose the ISR return location so the program will probably fail in some way.

Most of your code does not have any notation, so while you currently are very familiar with your code and its logic flow how can anyone else follow it ? - plus in a few months time will you be able to look back and follow it as easily ?
 

Wilksey

Member
That is quite painful to look at I must admit!

0xFF is being loaded into tmr1H isnt it?

Too many variables and not enough description of a circuit or what the problem is.

Wilksey
 
That is quite painful to look at I must admit!

0xFF is being loaded into tmr1H isnt it?

Too many variables and not enough description of a circuit or what the problem is.

Wilksey
it is a display program,which is used to change the diplay using two push button..when we press two bus botton at a time the last digit wil blink.aftr press the first buttom v can select our desired digits..after selecting the digits if we press second key that will increment..like this all the four wil work...my problem is that after selecting the digits when we press the 2nd key it is not incrementing.some times it will increment but very fast..am already used debounce then also not getting proper increment...
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top