The interfacing of serial communication (UART) with 8051 micro controller, with the baud rate of 9600bps.
Code:
#include <reg51.h>
#include <stdio.h>
unsigned char c;
void Serial_Init()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;
TI = 1;
RI = 0;
}
void delay(unsigned int i)
{
unsigned int j,k;
for(j=0;j<=i;j++)
{
for(k=0;k<256;k++);
}
}
void main(void)
{
Serial_Init();
printf("Hello World \n");
while(1)
{
delay(5);
c = getchar();
delay(5);
//putchar(c);
delay(5);
}
}
Design Proteus:
Code:
#include <reg51.h>
#include <stdio.h>
unsigned char c;
void Serial_Init()
{
TMOD = 0x20;
SCON = 0x50;
TH1 = 0xFD;
TR1 = 1;
TI = 1;
RI = 0;
}
void delay(unsigned int i)
{
unsigned int j,k;
for(j=0;j<=i;j++)
{
for(k=0;k<256;k++);
}
}
void main(void)
{
Serial_Init();
printf("Hello World \n");
while(1)
{
delay(5);
c = getchar();
delay(5);
//putchar(c);
delay(5);
}
}
Design Proteus:
This comment has been removed by the author.
ReplyDelete