Description:
The serial port
of 8051 is
full duplex, i.e., it can transmit and
receives simultaneously. The register SBUF is used to hold the data.
One is, write-only and is used to hold data to be transmitted out
of the8051 via
TXD. The other is, read-only and holds the received data from
external sources via RXD. Virtual Terminal connected on the TXD to
the port RXD and vice versa. The transmitted data display on the
virtual terminal.
Code:
#include<reg51.h>
#include<TX.h>
void
main()
{
while(1)
{
ini();
transmit('M');
display("
Rajeev");
while(1);
}
}
*/---------------------------------------TX.h----------------------------------------------------*/
void
ini();
void
transmit(char x);
void
delay(int n);
void
display(char *s);
void
ini() //
Initialize Timer 1 for serial communication
{
TMOD=0x20;
//Timer1, mode 2, baud rate 9600 bps
TH1=0XFD;
SCON=0x50;
TR1=1;
}
void
transmit(char x) //
Funtion to transmit serial data
{
SBUF=x;
TR1=1;
while(TI==0);
delay(10);
TI=0;
TR1=0;
}
void
delay(int n) //Delay
loop
{
int
i,j;
for(i=0;i<n;i++)
{
for(j=0;j<10;j++);
}
}
void
display(char *s) //to
convert string to char
{
while(*s!='\0')
{
transmit(*s);
s++;
}
}
Circuit
Diagram:
No comments:
Post a Comment