EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies /  #include “reg51.h”  void

 #include “reg51.h”  void

|

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);
}
}
}
 

RSS Recent Posts

  • Faulty heat air gun (dc motor) - problem to locate fault due to Intermittent fault July 19, 2025
  • Does US electric code allow branching ? July 19, 2025
  • Fun with AI and swordfish basic July 19, 2025
  • Sump pit water alarm - Kicad 9 July 19, 2025
  • turbo jet fan - feedback appreciated. July 19, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise