I have written a program to transmit char value serially for AT89S51. Its is working perfectly.
Program is given below:-
#include<reg51.h>
void main()
{
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
while(1)
{
SBUF='A';
while(TI==0);
TI=0;
}
}
In above code char 'A' is transmitted.
Now I want to transmit an integer value and I have written a program for it.
Program is given below:-
#include<reg51.h>
void main()
{
int i=61;
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;
while(1)
{
SBUF=i;
while(TI==0);
TI=0;
}
}
Above program is transmitting ' = ' (i.e decimal 61 corresponds to ' = ' character in ASCII).
I want to know how I can transmit an integer value.
Please guide me in this regard.
SBUF
contains a single byte (i.e. char) to be transmitted. If you put 'A' there, that's what will be transmitted (in fact 0x41 will be transmitted, which corresponds to ASCII value of 'A'). When assigning a value of i
into SBUF
, it will be interpreted as byte regardless of type of i
. This byte can be interpreted in any way the receiving party desires - it can treat it as integer or as ASCII value, it's the same as far as transmission goes; the difference is in the way the data is treated.