8051 assembly timer program

Thread Starter

antiantianti

Joined Aug 4, 2016
45
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:
main:
        clr tf0
        clr tr0
        mov p4,#11110000b
        mov p2,#1
        mov P3,#6H
        lcall delay    
        ljmp main   
        DELAY: 
       MOV TH0,#0ffh
       MOV TL0,#0feh
MOV TMOD,#1      
       SETB TR0
JNB TF0,$
    clr tf0
    clr tr0
    ret
    end
 

MrChips

Joined Oct 2, 2009
30,808
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
What do you expect to happen when the instruction JNB TF0,$ is executed?
 

Thread Starter

antiantianti

Joined Aug 4, 2016
45
What do you expect to happen when the instruction JNB TF0,$ is executed?
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
 

shteii01

Joined Feb 19, 2010
4,644
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.
 

joeyd999

Joined Jun 6, 2011
5,283
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.
 

joeyd999

Joined Jun 6, 2011
5,283
Ok. I looked up JNB in the table of opcodes, it is 3 bytes, not 1 byte. Is that why that instruction line is failing to work?
In what way is it failing to work? What do you expect?

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

MrChips

Joined Oct 2, 2009
30,808
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.
 

Thread Starter

antiantianti

Joined Aug 4, 2016
45
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:
Top