Tran_buffer[9] = {\n,D,i,s,a,r,m,e,d};
.
.
.
void PC_LINK_O_Update(void)
{
if(Out_written_index_G < 9)
{
PC_LINK_O_Send_Char(Tran_buffer[Out_written_index_G]);
Out_written_index_G ++;
.
.
.
.
void PC_LINK_O_Send_Char(const char CHARACTER)
{
tLong Timeout1 = 0;
if(CHARACTER == '\n')
{
Timeout1 = 0;
while((++Timeout1) && (TI == 0)); // set (1) Transmit-Interrupt flag
if(Timeout1 == 0)
{
return;
}
TI = 0;
SBUF = 0x0D; // Output CR (Carriage Return),
}
Timeout1 = 0;
while((++Timeout1) && (TI == 0)); // count until 23d=17h (ETB = "End of Trans. Block")
if(Timeout1 == 0)
{
return;
}
TI = 0;
SBUF = CHARACTER;
}
Help said:Anyone can help me to explain the function PC_LINK_O_Send_Char??
Help said:Code:Timeout1 = 0; while((++Timeout1) && (TI == 0)); // count until 23d=17h (ETB = "End of Trans. Block")
Ace-X said:Help said:Anyone can help me to explain the function PC_LINK_O_Send_Char??
It just sends argument CHARACTER to on-chip UART. If it gets end-of-line symbol "\n", it sends only code 0xD instead of pair 0xD,0xA. Also, it introduces timeout delay: if UART tranciever is busy for long period of time, it returns - but this last function is implemented in very stupid way.
void PC_LINK_O_Send_Char(const char CHARACTER)
{
tLong Timeout1 = 0;
if(CHARACTER == '\n') // when CHARACTER = \n then mask the condition
{
Timeout1 = 0; // then set the to 0
while((++Timeout1) && (TI == 0)); // Q1) ???
if(Timeout1 == 0) // Q2) ??
{
return;
}
TI = 0; // Q3) ?
SBUF = 0x0D; // Q4) what the output carriage return for ??
}
Timeout1 = 0;
while((++Timeout1) && (TI == 0)); // Q5) why [i]Indi2go[/i] say wait until TI=1?
if(Timeout1 == 0) // Q6) what the condition make the Timeout1 become 0 ??
{
return;
}
TI = 0; // Q7) ??
SBUF = CHARACTER; // Q8) is it stoge every character inside the chip buffer ??
}
Help said:Ok.... Please can you explain inside the code what they doing?? Because i understand abit don't understand abit.. so very confuse now...
Ace-X said:Help said:Ok.... Please can you explain inside the code what they doing?? Because i understand abit don't understand abit.. so very confuse now...
Q1,Q5: wait until previous symbol has been sending by UART (TI - UART "transmit complete" flag) or until timeout timer expire (variable Timeoutl)
Q2,Q6: do nothing if we exit due to timeout
Q3,Q7: reset UART transmit flag
Q4: send only character 0xD instead of end-of-line double characters (0xD,0xA)
Q8: send new character to UART
if(CHARACTER == '\n') // when CHARACTER = \n then mask the condition
{
Timeout1 = 0; // then set the to 0
while((++Timeout1) && (TI == 0)); // Q1) ???
if(Timeout1 == 0) // Q2) ??
{
return;
}
TI = 0; // Q3) ?
SBUF = 0x0D; // Q4) what the output carriage return for ??
}
Timeout1 = 0;
while((++Timeout1) && (TI == 0)); // Q5) why [i]Indi2go[/i] say wait until TI=1?
if(Timeout1 == 0) // Q6) what the condition make the Timeout1 become 0 ??
{
return;
}
Help said:Q1,Q5: The Q1, what's you mean the previous symbol is it previous symbol for \n?
Help said:The Q5, if CHARACTER = \n that time, why the Timeout1 (at Q5) need to count until 0x23h
Help said:Q3,Q7. Every time sending each character we need to set (TI=1 'stop transmit') and reset (TI=0 'prepare to transmit') UART transmit flag is it??
Help said:Q4. Why need SBUF = 0x0D; and why need to send this character??
Which also mean that if function carry the CHARACTER is i=69h then the while((++Timeout1) && (TI == 0)); just sent the D=44h previous want is it..?Ace-X said:Yes. The symbol, that was sent to UART right before current symbol.
but why the author declare the Timeout1 is Long, 256 is for char is it.... or we need to change to char. What you mean compaerd with 0.Ace-X said:Timeout in your code always count till 256, because its size is limited by 1 byte and it is compared with 0.
The while((++Timeout1) && (TI == 0)); keep on counting 23 time then the TI will automatically set to 1. The TI is set by hardware, so the hardware must be set it on time is it... before the Timeout1 finish counting.Ace-X said:If during this timeout period UART transmitter didn't set TI flag, we just leave this function.
You mean when the TI=1 then after the while((++Timeout1) && (TI == 0)); then sent the character? Before the SBUF!!Ace-X said:No. TI is set to 1 automatically by UART transmitter every time when character that you write before to SBUF was sent outside.
If we choose the 0xA (SBUF = 0x0AAce-X said:End of line symbol ('\n') actually consist of 2 symbols: Carriage Return (ASCII code: 0xD) and Line Feed (ASCII code: 0xA). The author of program sends only first symbol.
Help said:Which also mean that if function carry the CHARACTER is i=69h then the while((++Timeout1) && (TI == 0)); just sent the D=44h previous want is it..?
Help said:but why the author declare the Timeout1 is Long, 256 is for char is it.... or we need to change to char. What you mean compaerd with 0.
Help said:The while((++Timeout1) && (TI == 0)); keep on counting 23 time then the TI will automatically set to 1.
Help said:You mean when the TI=1 then after the while((++Timeout1) && (TI == 0)); then sent the character? Before the SBUF!!
Help said:If we choose the 0xA (SBUF = 0x0Ais the same is it..?
Ace-X said:May I know where did you get this number "23"?
if(CHARACTER == '\n')
{
.
.
}
Timeout1 = 0;
while((++Timeout1) && (TI == 0));
Is it every time we send the string to PC terminal we need to send the 0xD first?? Then the PC will automatically know the 0xA.. am I right ??Ace-X said:If you want to make link with PC terminal, then stay on 0xD, because most of terminals can substitute full 0xD,0xA instead of one received 0xD.
void PC_LINK_O_Init_T1(const tWord BAUD_RATE)
{
.
.
TI = 1;
.
}
void PC_LINK_O_Send_Char(const char CHARACTER)
{
TI = 0; // reset UART transmit flag
SBUF = CHARACTER;
}
Help said:What you mean Then this is even more stupid then I thought before, because timeout of about 1 hour (for 12 Mhz freq.) is useless. is it the Timeout1 too long?
Help said:Why before we sent the string we need to send the \n first?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?