8051 assembly timer program

Discussion in 'Embedded Systems and Microcontrollers' started by antiantianti, Sep 3, 2017.

  1. antiantianti

    Thread Starter Member

    Aug 4, 2016
    45
    0
    Hi
    My problem is tat when I debug this program
    Everything works fine step by step until I come to the instruction JNB TF0,$ and the program stays there and doesnt move to the next instruction
    Code (ASM):
    1.  
    2. main:
    3.         clr tf0
    4.         clr tr0
    5.         mov p4,#11110000b
    6.         mov p2,#1
    7.         mov P3,#6H
    8.         lcall delay    
    9.         ljmp main  
    10.         DELAY:
    11.        MOV TH0,#0ffh
    12.        MOV TL0,#0feh
    13. MOV TMOD,#1      
    14.        SETB TR0
    15. JNB TF0,$
    16.     clr tf0
    17.     clr tr0
    18.     ret
    19.     end
     
  2. MrChips

    Moderator

    Oct 2, 2009
    19,051
    6,121
    What do you expect to happen when the instruction JNB TF0,$ is executed?
     
  3. antiantianti

    Thread Starter Member

    Aug 4, 2016
    45
    0
    Hi
    I am expecting to get counted two times and then move to the next instruction I mean when the timer overflows the flag tf0 is set to one and then it is suppose to move to the next instruction
     
  4. MrChips

    Moderator

    Oct 2, 2009
    19,051
    6,121
    What is make and model number of the 8051 chip?
    Or is this a simulator?
     
  5. antiantianti

    Thread Starter Member

    Aug 4, 2016
    45
    0
    No Actually I am using silicon laboratories c8051f340 looks like i cant change the title
     
  6. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,667
    745
    The program does not know where to jump to.

    Can you explain why you are using dollar sign as an operand?

    The code example in my textbook uses label for the destination of the jump.
     
  7. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    4,225
    6,354
    The $ is a literal constant that means "this", or the address of the first byte of the assembled instruction opcode for that line of code.

    A jump to $ is an infinite loop.
     
  8. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    4,225
    6,354
    In what way is it failing to work? What do you expect?

    edit: Wait, you're not OP. Those questions are addressed to him.
     
  9. shteii01

    AAC Fanatic!

    Feb 19, 2010
    4,667
    745
    I deleted my earlier post. I guess it would confuse people.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    19,051
    6,121
    While in debug, examine the contents of TH0 and TL0 and confirm that the counter registers are incrementing.
    Examine the contents of TCON and check that TF0 is being set when the counter overflows from FFFFh to 0000h.
     
  11. antiantianti

    Thread Starter Member

    Aug 4, 2016
    45
    0
    tf0 doesnt get set to one the timer doesnt overflow in the first place

    when I write the same code in generic 8051 it works , it only doesnt work when I change it to silicon laboratories c8051f340
     
    Last edited: Sep 10, 2017
Loading...