1. jimmyvarghese

    Thread Starter New Member

    Nov 25, 2009
    2
    0
    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,ee,ff
    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
    movlw 0xf0
    movwf TMR1L
    movlw 0xfe
    movwf TMR1H
    bcf PORTC,0
    bcf PORTC,1
    movlw b'11110000'
    andwf PORTB,F
    clrf ee
    clrf PORTD
    clrf ff
    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
    bsf blink,0
    return


    mainline:



    bcf INTCON,T0IF
    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 mainline

    incf ee,1
    btfsc ee,7
    incf ff,1

    ; bcf PIR1,TMR1IF
    btfss tmp,0
    goto one
    bcf PORTB,0
    movfw ones
    call lookup
    movwf PORTD
    btfsc blink,0
    btfss ff,7
    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 ff,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 ff,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 ff,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 temp,W
    bcf INTCON,T0IF
    bcf PIR1,TMR1IF
    movlw 0x0c
    movwf TMR1L
    movlw 0xff
    movwf TMR1H
    ; *** Restore Values ***
    swapf STORE,W
    movwf STATUS
    swapf temp,F
    swapf temp,w
    retfie
    return


    convert:
    movf tmp,0
    movwf lsb
    ; btfsc tmp2,0
    ; goto aa
    ; btfsc tmp2,1
    ; goto bb
    ; btfsc tmp2,2
    ; goto cc
    ; btfsc tmp2,3
    ; goto dd
    ; clrf tmp2
    ; goto mainline
    ; return

    aa :
    movf lsb,0
    movwf ones
    bcf ones,7
    bcf ones,6
    bcf ones,5
    bcf ones,4
    call ISR
    return
    bb
    movf lsb,0
    movwf tens
    bcf tens,7
    bcf tens,6
    bcf tens,5
    bcf tens,4
    call ISR
    return

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

    dd
    movf lsb,0
    movwf thus
    bcf thus,7
    bcf thus,6
    bcf thus,5
    bcf thus,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

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

    this s the program which is used for changing the 7segmnt display using remote....timer one i used for the display and the timer0 s used for the decoding of IR signal..now am geting the output bt my display s nt getting continuesly........wl u pls help??????
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I don't fully understand this program but I think it might be worth checking the ISR and the calls and gotos.
    The ISR seems to have one path where there is a RETFIE and saved registers are restored but it looks like if it branches to mainline that doesn't happen.
    There is a 'goto start' and also a 'call start'. I'm not sure if it is intended to be that way. It might be worth checking the other calls and gotos.
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
Loading...