Menu

BTFSS Command

Help
MBB
2011-04-17
2013-05-30
  • MBB

    MBB - 2011-04-17

    I'm using a 16F627 and wrote this code:

    BitClk:
    Lcnt = Lcnt + 1
    BTFSS INTCON, T0IF ;Check if T0IF=1
    Goto Pt2
    Goto BitClk
    Pt2:
    Print Lcnt

    I believe the "BTFSS INTCON, T0IF " should monitor the Timer 0 Interrupt bit and SKIP the next instruction (Goto Pt2) and perform the  "Goto BitClk" command as long as Timer 0 has not overflowed.

    If Timer0 overflows then  "BTFSS INTCON, T0IF " should equal1 and the "Goto Pt2" command should be performed.

    I'm feeding a frequency into the RA4/T0CKI pin but the Lcnt never increments.  I've tried frequencies between 10 Hz and 10 MHz but Lcnt always equals 1.  I've even grounded this pin.

    Anyone know why this happens?

     
  • Hugh Considine

    Hugh Considine - 2011-04-17

    I think what is happening there is that once the timer overflows, the T0IF bit goes high and stays high. This will mean that the PIC sits in an infinite loop, doing nothing other than incrementing Lcnt. This means that once the timer overflows, the PIC will never escape the loop and get to the Print statement. Try putting in a Set (or bcf) command to clear T0IF before the Goto BitClk command.

     
  • MBB

    MBB - 2011-04-18

    Thanks for your response.

    The PIC is escaping the loop.  It does generate the Print statement but it always gives a value of 1 for Lcnt.

     
  • Nobody/Anonymous

    Shouldn't it be "BTFSC INTCON, T0IF " so that it skips the goto Pt2 while T0IF is clear then when its set it executes the goto Pt2.

    Alternatively you could replace the bit of assembly with a basic control structure like -

    do
        Lcnt = Lcnt + 1
    loop until INTCON.T0IF on
    Print Lcnt
    
     
  • MBB

    MBB - 2011-04-19

    Thanks!  Your BTFSC instead of BTFSS comment makes sense.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.