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

program clarification

Thread starter #1
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,STORE,blink,hunds,tmp2,timer
endc


ORG 0X00

MOVLW 00H
MOVWF PCLATH
CLRF STATUS
GOTO main
;********************************************************************************
org 04h
movwf temp
swapf STATUS,W
movwf STORE
clrf STATUS
GOTO ISR
retfie
;********************************************************************************
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'
retlw b'01111100' ;'b'
retlw b'00111001' ;'c'
retlw b'01011110' ;'d'
retlw b'01111001' ;'e'
retlw b'01110001' ;'f'
retlw b'00000000'


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




initport:
bsf STATUS,RP0
bcf TRISC,1
bcf TRISC,0
movlw 0x06
movwf OPTION_REG
movlw b'00000000'
movwf TRISD
bcf TRISB,5
movlw b'11010000'
movwf TRISB
bsf PIE1,TMR1IE
bcf STATUS,RP0
bcf PIR1,TMR1IF
bsf INTCON,GIE
bsf INTCON,PEIE
bsf T1CON,0
bcf T1CON,2
bcf T1CON,1
clrf TMR0
clrf TMR1L
clrf TMR1H

bcf PORTC,0
bcf PORTC,1
movlw b'11110000'
andwf PORTB,F
clrf PORTD
bsf PORTC,0
bcf PORTC,0
movlw 0x5f
movwf ss
bsf tmp,0
movlw 0x01
movwf ones
movlw 0x02
movwf tens
movlw 0x03
movwf hunds
movlw 0x04
movwf thus
clrf blink
return





mainline:



bcf INTCON,T0IF
bcf PIR1,TMR1IF
nop
btfsc PORTB,4
goto mainline
call start
xorlw 0FFh
btfss STATUS,Z
goto mainline
movlw 0FFh
movwf PORTD
bsf PORTC,1
call delay
bcf PORTC,1
movfw lowbyte
movfw hibyte
movwf tmp1


movfw lowbyte
movwf tmp
xorlw .1
btfss STATUS,Z
goto next1
goto chkOvr

next1: movfw lowbyte
xorlw .2
btfss STATUS,Z
goto next2
goto chkOvr

next2: movfw lowbyte
xorlw .3
btfss STATUS,Z
goto next3
goto chkOvr

next3: movfw lowbyte
xorlw .4
btfss STATUS,Z
goto next4
goto chkOvr

next4: movfw lowbyte
xorlw .5
btfss STATUS,Z
goto next5
goto chkOvr

next5: movfw lowbyte
xorlw .6
btfss STATUS,Z
goto next6
goto chkOvr

next6: movfw lowbyte
xorlw .7
btfss STATUS,Z
goto next7
goto chkOvr

next7: movfw lowbyte
xorlw .8
btfss STATUS,Z
goto chkOvr
goto chkOvr

chkOvr:



call convert
clrf lowbyte
clrf hibyte
goto mainline

chk: clrf tmp1
retlw 0Fh

start :

nop
incf tmp1,f
movlw .45
subwf tmp1,w
skpc
goto start
clrf tmp1
clrf TMR0
movlw 0x06
movwf TMR0
bcf INTCON,T0IF
call Wlow
call Whigh
btfsc INTCON,T0IF
retlw 0x0F

movfw TMR0
clrf TMR0
movwf timer
movwf temp
clrc
rrf temp,f
clrc
rrf temp,f
movf temp,w
subwf timer,
movlw 0x0c
movwf temp
nextBit : movfw timer
subwf TMR0,w
skpz
goto nextBit
btfss PORTB,4
goto waitlow
call Whigh
setc
goto clock



waitlow: call Wlow
clrc
clock: clrf TMR0
btfsc INTCON,T0IF
retlw 0x00
rlf lowbyte,F
rlf hibyte,F
decfsz temp,f
goto nextBit
movfw lowbyte
movwf temp
rlf temp,f
rlf hibyte,F
rlf temp,f
rlf hibyte,F
movlw 0x3f
andwf hibyte,F
movlw 0x3f
andwf lowbyte,F
retlw 0xff



Wlow : btfsc INTCON,T0IF
return
btfss PORTB,4
goto Wlow
return



Whigh : btfsc INTCON,T0IF
return
btfsc PORTB,4
goto Whigh
return


;----------------------------------------------------------------------------------------------------------------------
ISR:

btfsc INTCON,T0IF
; goto finish
goto mainline
btfss tmp,0
goto one
bcf PORTB,0
movfw ones
call lookup
movwf PORTD
btfsc blink,0
btfsc ss,5
bsf PORTB,0
rlf tmp,F
GOTO finish

one:
btfss tmp,1
goto ten
bcf PORTB,0
movfw tens
call lookup
movwf PORTD
btfsc blink,1
btfsc ss,5
bsf PORTB,1
rlf tmp,F
goto finish

ten: btfss tmp,2
goto hund1
bcf PORTB,1
movfw hunds
call lookup
movwf PORTD
btfsc blink,2
btfsc ss,5
bsf PORTB,2
rlf tmp,F
goto finish

hund1: btfss tmp,3
goto thuds
bcf PORTB,2
movfw thus
call lookup
movwf PORTD
btfsc blink,3
btfsc ss,5
bsf PORTB,3
rlf tmp,1
goto finish

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

;-----------------------------------------------------------------------------
finish:


swapf STORE,W
movwf STATUS
swapf temp,F
swapf temp,W
bcf INTCON,T0IF
bcf PIR1,TMR1IF
clrf TMR1L
clrf TMR1H
movlw 0xf0
movwf TMR1L
movlw 0xee
movwf TMR1H
retfie
return



convert:

movf tmp,0
movwf lsb



movf lsb,0
movwf ones
bcf ones,7
bcf ones,6
bcf ones,5
bcf ones,4
call ISR
return


delay

movlw 0x05
movwf rr
back2: movlw 0xff
movwf sp
back decfsz sp,1
goto back
decfsz rr,1
goto back2
return


main
call initport
goto mainline
end
;***********************************************


hai,
this prrogram is mainly used for interfacing the remote controller and 7sedment dspy..i used timer1 for the display and timer0 for decoding the IR code...bt nw am facing a program that i didnt got the proper out...this projct s for changing the display using remote...wl u pls help me to getting the output?????
 
Last edited:

Latest threads

EE World Online Articles

Loading

 
Top