Microcontroller › 8051 › 89c51 interfacing with rs232 as well as 16×2 LCD › #include “reg51.h” void
March 10, 2013 at 4:10 am
#9286
ronakpatel
Participant
#include “reg51.h”
void inici_serie (void)
{
PCON |= 0x80; // SMOD = 1; => transmition rate x2
SCON = 0x50; // Serial port in mode 1
TMOD |= 0x20; // Timer 1, in mode 2
// i. e., timer of 8 bits with autoreload
//TH1 = 256 – (((smod + 1) * f_xtal) / (384 * baud)); TH1 = 0xFA; // for baud = 9600
TL1 = TH0;
// Activa timer0
TR1 = 1;
}
char receive_char (void)
{
RI = 0;
return SBUF;
}
void send_char (char chr)
{
TI = 0;
SBUF = chr
while(!TI)
TI = 0;
}
void send_msg (char *msg)
{
TI = 0;
while(*msg)
{
SBUF = *(msg++);
while (!TI); TI = 0;
}
}
void main (void)
{
char chr;
inici_serie();
send_msg (“Hello!n ”);
while (1)
{
if (RI) // do echo of the character received
{
character = receive_char ();
send_char (chr);
}
}
}