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 / TRY THISMY WORKING

TRY THISMY WORKING

|

Microcontroller › 8051 › Help with serial communication › TRY THISMY WORKING

November 25, 2011 at 12:46 am #6877
Dexter
Participant

TRY THIS

MY WORKING CODE

 

 

#include………

…………..

…………

 

//  SERIAL COMMUNICATION
void serial_init        (void);                        //initialise serial communication
unsigned char recv_byte    (void);                        //recieves th ASCII value
void send_byte            (unsigned char);            //sends ASCII value to PC or microcontroller
void sendString            (unsigned char *str);
void enter(void);

 

 

void main()
{

unsigned char A;

serial_init();
sendString(“WELCOME TO RS232 COM1”);
enter();
sendString(“DEXTER8051”);
enter();

 

A=recv_byte()

…………………

………………

………………

}

 

 

/*SENDING THE ENTER CAMMAND*/
void enter()
{
    send_byte(0x0d);       //  <CR>
    send_byte(0x0a);        // <LF>
}

/*SERIAL ROUTINES*/
void serial_init()
{
    SCON=0x50;                        //mode 1 serial communication
    TMOD=0x20;                        //timer 1 auto reload mode
    TH1=0xfd;                        //9600 baudrate at 11.0592 MHz
    TR1=1;
    EA=1;
    EX0=1;
    IT0=1;
    IP=0x10;
}
/* RECIVING BIT FROM PC*/
unsigned char recv_byte()
{
    unsigned char c;
    while(!RI);                        //waits till a byte is recieved
    RI = 0;
    c = SBUF;
    return(c);
}
  /* SENDING BIT TO PC*/
void send_byte(unsigned char ch)
{
    TI = 0;
    SBUF = ch;
    while(!TI);
    del_1ms();
}
/* SENDING STRING BIT TO PC*/
void sendString(unsigned char *str)
{
    while(*str != ‘’)
    send_byte(*str++);
}

 

RSS Recent Posts

  • Sine wave distortion January 17, 2026
  • Micro mouse January 17, 2026
  • flexible copper cable January 16, 2026
  • Flip Flop for My Mirrors January 16, 2026
  • potenciometer attachment / screwdriver January 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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