PIC16F887, timer accurate problem for assembly language

Discussion in 'Embedded Systems and Microcontrollers' started by zhengkoon8, Dec 11, 2011.

  1. zhengkoon8

    Thread Starter New Member

    Nov 28, 2011
    10
    0
    I have the problem of getting the exact 4 second for the code below and the the delay 3 second. can someone point out what is the problem? thank you very much.


    movlw b'10000011'
    movwf OPTION_REG


    DelayThreeSecond:
    clrf Time
    WaitThreeSecond
    clrf Mem
    OneSecondWait:
    clrf TMR0
    LoopTMR0:
    call CheckButton
    call NumberPress
    movf TMR0,w
    xorlw .250
    btfss STATUS,Z
    goto LoopTMR0
    incf Mem,f
    movlw .250
    xorwf Mem,w
    btfss STATUS,Z
    goto OneSecondWait
    incf Time,f
    movlw .3
    xorwf Time,w
    btfss STATUS,Z
    goto WaitThreeSecond
    return


    ; Function Delays for 4 Second
    DelayFourSecond:
    clrf Time
    WaitFourSecond
    clrf Mem
    OneSecondDelay:
    clrf TMR0
    WaitTMR0:
    movf TMR0,w
    xorlw .250
    btfss STATUS,Z
    goto WaitTMR0
    incf Mem,f
    movlw .250
    xorwf Mem,w
    btfss STATUS,Z
    goto OneSecondDelay
    incf Time,f
    movlw .4
    xorwf Time,w
    btfss STATUS,Z
    goto WaitFourSecond
    return

    NumberPress:
    btfss SwitchPressed,0
    return
    incf Memory
    clrf SwitchPressed
    return
    return
     
Loading...