Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

why TI=1 before printf()?

Status
Not open for further replies.

hiclickme

Newbie level 6
Joined
Aug 25, 2004
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
160
Hi,
I used to write program in ASM lanuage. As it groups bigger, I get confused. Now I take the step to C.

Why?
...
TI=1
printf("why TI=1 before printf()?\n");
...

Thinking in ASM. I always "CLR TI" to make SBUF send. I think it should be
...
TI=0
printf("no matter what you type I print nothing cuz TI=0, haha...\n")
...
But it doens't work. Why? "TI=1" means it send done and it won't send as I think. Why?

Thanks alot!
 

I want to help you but not understand anythnig with your issue. Could you please explain in depth?
 

Hi, Free_Will. Sorry for my poor expression! I am learning C from assembly language.

If I want to send 'A' through TXD, I would write like this in ASM

MOV A,#'A'
CLR TI
MOV SBUF,A
JNB TI,$

TI will be setted 1 when a byte send done, and it stop send. So if I want it send, I need TI=0, in ASM language. But for printf() in C lanuage,

TI=1
printf("A");

it need TI=1 to send. Why?

in a word, why not?

TI=0
printf("A");
 

Salam,

Which is compiler you use ?

Bye
 

Hi,SphinX,
I use "Keil uVision2"
 

Hi,

Observe the asm codes that C compiler generated and compare it with yours.
 

Thanks Free_Will

Now I know why
C:0x040C 3099FD JNB TI(0x98.1),C:040C
C:0x040F C299 CLR TI(0x98.1)
C:0x0411 F599 MOV SBUF(0x99),A

The way to answer is always much more important than the answer
 

hiclickme said:
I used to write program in ASM lanuage. As it groups bigger, I get confused. Now I take the step to C.

Why?
...
TI=1
printf("why TI=1 before printf()?\n");

It has been 8 years since my last project for 8051 but if I remember correctly printf function is implemented by polling (and not interrupt driven). Basically, print first checks for char to be transmitted before new one is placed in SBUF. The char has been sent when TI is 1, so setting TI to 1 before printf signals that it can start sending given string immediately.

Tom
 

tom324 is right.
printf function call putchar and putchar checks TI first. Make sure no character is sending. It means TI must be 1 before send.
 

I met the same problem before.

Tom324 gave the right answer.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top