Continue to Site

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.

  • 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.

digital timer,manual setting

Status
Not open for further replies.
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,tmr,tmr1,ll,vv,go,set0,temp1,tt,ad,cb,aa,cc,jj,ii,temp2,tem,tem3,tem4,rs,pp,dj
endc


ORG 0X00

MOVLW 00H
MOVWF PCLATH
CLRF STATUS
GOTO main
;****************************************************************************************************
org 04h
bcf PIR1,TMR1IF
movwf temp
swapf STATUS,W
movwf STORE
clrf STATUS
btfss timer,0
goto ISR
goto ISR1


;****************************************************************************************************
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'
; retlw b'01110111' ;'a'



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




initport
bsf STATUS,RP0 ;bank1
bcf TRISC,1
bcf TRISC,0
movlw 0x06
movwf OPTION_REG
movlw b'00000000'
movwf TRISD
bsf TRISA,4
bsf TRISC,5

bcf TRISB,5
movlw b'11010000'
movwf TRISB
bsf PIE1,TMR1IE
bcf STATUS,RP0 ;bank0
bcf PIR1,TMR1IF
bsf INTCON,GIE
bsf INTCON,PEIE
bsf T1CON,0
bcf T1CON,2
bcf T1CON,1
clrf TMR0
clrf TMR1L
clrf TMR1H
movlw 0xff
movwf TMR1L
movlw 0xef
movwf TMR1H
bcf PORTC,0
bcf PORTC,1
clrf PORTB
clrf PORTD
bsf PORTC,0
bcf PORTC,0
movlw 0x5f
movwf ss
clrf tmp
bsf tmp,0
clrf tmp1
bsf tmp1,0
movlw 0x00
movwf ones
movlw 0x00
movwf tens
movlw 0x02
movwf hunds
movlw 0x01
movwf thus
clrf blink
clrf tmp1
clrf dj
clrf go
bsf PORTD,4
clrf ee
clrf gg
clrf ff
clrf tt
clrf aa
clrf bb
clrf cc
clrf jj
clrf vv
clrf ll
clrf dd
clrf tem
clrf timer
clrf tmp4
clrf tmp5
bsf dj,0
clrf temp1
clrf temp2
clrf tem3
clrf tem4
clrf pp

return


;************************************************************************************
;main program
;************************************************************************************

mainline


btfsc go,0 ;removing the cascade key.
goto hh
btfsc timer,0 ;checking the timer start
goto setup
btfss PORTC,5 ;start button
goto mainline
hh btfss PORTA,4 ;key for increment and select the blinking.
goto mainline
bsf go,0
incf tmp5,1 ;delay for blink select
movfw tmp5
sublw 0x04
btfss STATUS,Z
goto mainline
clrf tmp5
btfss ff,7 ;delay for debounce
goto mainline
clrf ff
incf tmp4,1 ;for selecting the blink bit
movfw tmp4
sublw 0x01
btfss STATUS,Z
goto chk1
bsf blink,0 ;set the blink,0 bit
bsf tt,0
clrf temp3
clrf temp4
clrf ee
clrf gg
clrf ll
clrf vv
goto mainline
return

chk1

movfw tmp4
sublw 0x02
btfss STATUS,Z
goto chk2
bcf blink,0
bcf tt,0
bsf blink,1 ;set the blink,1 bit
bsf tt,1
clrf temp5
clrf temp6
clrf ee
clrf gg
clrf ff
clrf ll
clrf vv
goto mainline
return
chk2
movfw tmp4
sublw 0x03
btfss STATUS,Z
goto chk3
bcf tt,0
bcf tt,1
bcf blink,0
bcf blink,1
bsf blink,2 ;set the blink,2 bit
bsf tt,2
clrf temp7
clrf temp8
clrf ee
clrf gg
clrf ff
clrf ll
clrf vv
goto mainline
return

chk3

movfw tmp4
sublw 0x04
btfss STATUS,Z
goto chk4

bcf tt,2 ;set the blink,2 bit
bcf blink,0
bcf blink,1
bcf blink,2
bsf blink,3
bsf tt,3
clrf temp9
clrf temp0
clrf ee
clrf ff
clrf ll
clrf vv
clrf gg
goto mainline
return
;************************************************************************************************
chk4


clrf gg
clrf tt
clrf ff
clrf ee ;clrf all reg
clrf dd
clrf ll
clrf vv
clrf tmp4
clrf blink
clrf temp3
clrf temp4
clrf temp5
clrf temp6
clrf temp7
clrf temp8
clrf temp9
clrf temp0
goto mainline
return
;*************************************************************************
add

clrf dd ;clear the delay
btfss tt,0 ;check the blink condition
goto ret
incf aa,1 ;delay for debouncing
movfw aa
sublw .2
btfss STATUS,Z
goto ret
clrf aa
bcf PORTD,4 ;key for incrementing the digits
bsf PORTD,6
btfss PORTC,2
goto ret
incf ones,1 ;incrementing the ones
movfw ones
sublw 0x0a
btfss STATUS,Z
goto add
clrf ones
goto ret
return

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

add1


clrf gg ;clr delay
btfss tt,1 ;check blink condition
goto ret1
incf bb,1
movfw bb ;debouncing
sublw .3
btfss STATUS,Z
goto ret1
clrf bb
bcf PORTD,4 ;incrementing key
bsf PORTD,6
btfss PORTC,2
goto ret1
incf tens,1
movfw tens
sublw 0x0a
btfss STATUS,Z
goto add1
clrf tens
goto ret1
return


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

add2

clrf vv ;clear the delay
btfss tt,2 ;select blink set
goto ret2
incf cc,1
movfw cc
sublw .2
btfss STATUS,Z
goto ret2
clrf cc
bcf PORTD,4 ; increment key
bsf PORTD,6
btfss PORTC,2
goto ret2
incf hunds,1
movfw hunds
sublw 0x0a
btfss STATUS,Z
goto add2
clrf hunds
goto ret2
return


;****************************************************************
add3

clrf ll
btfss tt,3
goto ret3
incf jj,1
movfw jj
sublw .3
btfss STATUS,Z
goto ret3
clrf jj
bcf PORTD,4
bsf PORTD,6
btfss PORTC,2
goto ret3
incf thus,1
movfw thus
sublw 0x0a
btfss STATUS,Z
goto add3
clrf thus
goto ret3
return




;************************************************************************************************
;ISR program for displaying the values
;************************************************************************************************
ISR

incf msb,1 ;making delay
incf ff,1
incf dd,1
incf gg,1
incf ll,1
incf vv,1
incf ee,1
call check ;checking the timer start
btfss tmp,0
goto one
bcf PORTB,3
movfw ones
movwf temp1
movfw ones
call lookup ;displaying ones(1st digits)
movwf PORTD
btfsc blink,0
btfsc ee,7
bsf PORTB,3 ;checking the increment condition
btfsc dd,7
goto add
ret incf temp3,1
btfsc temp3,7
incf temp4,1
btfsc temp4,7
bcf blink,0
rlf tmp,F
bcf tmp,0
GOTO finish
;.....................................................................
one
btfss tmp,1 ;displaying tens(2nd digits)
goto ten
bcf PORTB,3
movfw tens
movwf temp2
movfw tens
call lookup
movwf PORTD
btfsc blink,1
btfsc ee,7
bsf PORTB,2
btfsc gg,7
goto add1
ret1 incf temp5,1
btfsc temp5,7
incf temp6,1
btfsc temp6,7
bcf blink,1
rlf tmp,F
goto finish
;************************************************************************************************

ten btfss tmp,2
goto hund1
bcf PORTB,2
movfw hunds ;displaying hunds(3rd digits)
movwf tem3
movfw hunds
call lookup
movwf PORTD
bsf PORTD,7
btfsc msb,7
bcf PORTD,7
btfsc gg,7
bcf PORTD,7
btfsc blink,2
btfsc ee,7
bsf PORTB,1
btfsc vv,7
goto add2
ret2 incf temp7,1
btfsc temp7,7
incf temp8,1
btfsc temp8,7
bcf blink,2
rlf tmp,F
goto finish
;***************************************************************************************************

hund1 btfss tmp,3 ;displaying thus(4th digits)
goto thuds
bcf PORTB,1
movfw thus
movwf temp1
movfw thus
call lookup
movwf PORTD
btfsc blink,3
btfsc ee,7
bsf PORTB,0
btfsc ll,7
goto add3
ret3 incf temp9,1
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 ; interrupt restore values
movlw 0xff
movwf TMR1L
movlw 0xef
movwf TMR1H

; *** Restore Values ***
swapf STORE,W
movwf STATUS
swapf temp,F
swapf temp,w

retfie
;**********************************************************************************************

check
bcf PORTD,6 ;this switches are used for starting the timer function
bsf PORTD,4
btfss PORTA,4
return
btfss PORTC,2
return
bsf timer,0
return

;*********************************************************************************************
setup


movfw ones ;copy the values of ones,tens,hunds and thus
movwf temp1
movfw tens
movwf temp2
movfw hunds
movwf tem3
movfw thus
movwf tem4
;**************************************************************************************************
mainline1


call delay ;delay
incf dj,1
movfw dj
sublw 0x3c ;delay for 1 minute
btfss STATUS,Z
goto mainline1
chk btfsc tem,3 ;for checking the zero conditn of thousnd
goto load3
btfsc tem,2
goto load2
btfsc tem,1
goto load1
btfsc tem,0
goto load
clrf dj ;reset seconds countr
movfw temp1 ;combare the zero condtn of ones
sublw 0x00
btfsc STATUS,Z
goto next
decfsz temp1,1
goto mainline1
bsf tem,0
goto mainline1
return

;***************************************************************************************************************
next
goto load
return

;***************************************************************************************************************
load

movfw temp2 ;chk tens as 0?
sublw 0x00
btfss STATUS,Z
goto adds
clrf dj
bcf tem,0
bsf tem,1
goto chk
return
adds
bcf tem,0 ;load 9 to ones
movlw .9
movwf temp1
clrf dj
decfsz temp2,1
goto mainline1
goto mainline1
return
;*******************************************************************************************************************

load1


movfw tem3 ;chk hunds as 0?
sublw 0x00
btfss STATUS,Z
goto adds1
bcf tem,0
bcf tem,1
bsf tem,2
clrf dj
goto chk
return
adds1
bcf tem,0 ;decrmnt hunds,load 5 to tens and 9 to hund
bcf tem,1
movlw .9
movwf temp1
movlw .5
movwf temp2
clrf dj
decfsz tem3,1
goto mainline1
goto mainline1
return

;**************************************************************************************************************
load2

movfw tem4 ;chk thus as?
sublw 0x00
btfss STATUS,Z
goto adds2
bcf tem,0
bcf tem,1
bcf tem,2
bsf tem,3
clrf dj
goto chk
return
adds2
bcf tem,0
bcf tem,1
bcf tem,2
movlw .9
movwf temp1 ;decrmt thus,load 9 to ones,5 to tens and 9 to hunds3
movlw .5
movwf temp2
movlw .9
movwf tem3
clrf dj

decfsz tem4,1
goto mainline1
goto mainline1
return
;**************************************************************************************************************


load3

movlw 0x00 ;clr ones,tens,hunds and thus
movwf temp1
movwf temp2
movwf tem3
movwf tem4
goto mainline1
return



;************************************************************************************************************************
ISR1

incf lsb,1
incf ff,1 ;making delay for displaying default and current value
btfsc ff,7
incf gg,1
btfsc gg,7
incf dd,1
btfsc dd,7
goto display ;displaying ones
; call search
bck btfss tmp,0
goto one11
movfw temp1
call lookup
movwf PORTD
bsf PORTB,3
rlf tmp,F
GOTO finish1

one11
btfss tmp,1 ;displaying tens
goto ten11
bcf PORTB,3
movfw temp2
call lookup
movwf PORTD
bsf PORTB,2
rlf tmp,F
goto finish1

ten11 btfss tmp,2 ;displaying hunds
goto hund12
bcf PORTB,2
movfw tem3
call lookup
movwf PORTD
bsf PORTD,7
btfsc lsb,7
BCF PORTD,7
bsf PORTB,1
rlf tmp,F
goto finish1

hund12 btfss tmp,3 ;displaying thus
goto thud12s
bcf PORTB,1
movfw tem4
call lookup
movwf PORTD
bsf PORTB,0
rlf tmp,1
goto finish1

thud12s btfss tmp,4
goto finish1
bcf PORTB,0
clrf tmp
bsf tmp,0
goto finish1

;-----------------------------------------------------------------------------
finish1

swapf temp,W ;reload status reg values
movlw 0xef
movwf TMR1L
movlw 0xef
movwf TMR1H

; *** Restore Values ***
swapf STORE,W
movwf STATUS
swapf temp,F
swapf temp,w
retfie


;*************************************************************************
search
bcf PORTD,7
bsf PORTD,4
btfss PORTA,4
return
btfss PORTC,5
return
clrf timer
goto mainline
return
;****************************************************************************************************************
;for displaying the default values
;****************************************************************************************************************
display


incf lsb,1
btfss tmp,0
goto one1
movfw ones
call lookup
movwf PORTD
bsf PORTB,3
rlf tmp,F
GOTO finish1

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

ten1 btfss tmp,2
goto hund11
bcf PORTB,2
movfw hunds
call lookup
movwf PORTD
bsf PORTD,7
btfsc lsb,7
bcf PORTD,7
bsf PORTB,1
rlf tmp,F
goto finish1

hund11 btfss tmp,3
goto thuds1
bcf PORTB,1
movfw thus
call lookup
movwf PORTD
bsf PORTB,0
rlf tmp,1
goto finish1
thuds1 btfss tmp,4
goto finish1
bcf PORTB,0
clrf tmp
bsf tmp,0
goto finish1
return
;***********************************************************************************************************
;DELAY PROGRAM
;************************************************************************************************************
delay
;delay for 1 sec
movlw 0x05
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

;*****************************************************************************************************
delay1
movlw .5
movwf rr
back21 movlw 0xff
movwf sp
back11 decfsz sp,1
goto back11
decfsz rr,1
goto back21
return

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

main


call initport
call mainline
end

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



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.my problem s that after selecting the number when we go to the timer program it is not working properly..when it is in default value it is working properly...pls chk the program...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top