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 / Topics / regarding interfacing!!!

regarding interfacing!!!

|

Microcontroller › 8051 › regarding interfacing!!!

  • This topic has 4 replies, 2 voices, and was last updated 14 years, 3 months ago by Dharmit.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • February 25, 2011 at 10:54 am #752
    Dharmit
    Participant

    hi guys,

     

    got a really big question,

     

    we got two microcontrollers and we need to send in the data from both of them to the PC, so can we just use one serial port or we need seperate ports for it?

     

    Thank you. 

    February 26, 2011 at 3:55 am #5620
    Anonymous
    Guest

    I think yes you can send the data, just connect the output of both the microcontroller to the same serial port. I am not sure whether this will work for sure but you will have to experiment.

     

    Alternatively why dont you send the data of second controller to first and from there send it to the serial port??? 

    February 28, 2011 at 5:23 pm #5640
    Dharmit
    Participant

    hey thanks for that,

     

    Can u please send me the code for sending the data frm one microcontroller to the other………and then to the serial port! 

    March 2, 2011 at 9:53 am #5650
    Anonymous
    Guest

    i dont have the direct code.. but thats so simple.. just connect the ports of one to the other. Make the port on first microcontroller as output and on the second as input.. 

    March 2, 2011 at 12:08 pm #5652
    Dharmit
    Participant

    hey I have a code for serial interfacing in C, and also a code for the stop watch design in C, so i want to know how to integrate both codes together in order to make a one hex file.

     

    here is the code for serial interfacing:

     

    #include<reg51.h>

    void ini()     // Initialize Timer 1 for serial communication
    {
    TMOD=0x20; //Timer1, mode 2, baud rate 9600 bps
    TH1=0XFD;
    SCON=0x50;
    TR1=1;
    }

    void recieve() //Function to receive serial data
    {
    unsigned char value;
    while(RI==0);
    SBUF=value;
    P1=SBUF;
    RI=0;
    }

    void transmit() // Funtion to transmit serial data
    {
    P2=P1-32;
    SBUF=P2;
    while(TI==0);
    TI=0;
    SBUF=P1;
    while(TI==0);
    TI=0;
    }

    void main()
    {
    while(1)
    {
    ini();
    recieve();
    transmit();
    } 

    And here is the code for stop watch timer in C:

     

    #include<reg51.h>

    #define msec 1

    unsigned int sec1,sec2;

    int sec1_1,sec1_2,sec2_1,sec2_2;

     

    unsigned int

    digi_val[10]={0x40,0xF9,0x24,0x30,0x19,0x12,0x02,0xF8,0x00,0x10};

    sbit dig_ctrl_1=P1^0;  

    sbit dig_ctrl_2=P1^1;

    sbit dig_ctrl_3=P1^2;

    sbit dig_ctrl_4=P1^3;

    sbit start_pin = P1^4; 

    sbit stop_pin = P1^5; 

    sbit reset_pin = P1^6; 

    int s,t;

     

    void mplex_delay(unsigned int time) 

    {

    int i,j;

    for (i=0;i<=time;i++)

      for(j=0;j<=50;j++);

    }

     

    void digi_out(unsigned int current_num)

    {

        P2=digi_val[current_num];

         mplex_delay(msec);

    }

     

    void display(unsigned int dig1,unsigned int dig2)

    {

        sec1_2=dig1%10;

    sec1_1=dig1/10;

    sec2_2=dig2%10;

    sec2_1=dig2/10;

    TMOD=0x01;  

    TL0=0xFF;

    TH0=0xDB;

    TR0=1;  

    while(TF0==0)

    {

      dig_ctrl_1 = 1;

      dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_4 = 0;

      digi_out(sec1_1);

      dig_ctrl_2 = 1;

      dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_4 = 0;

      digi_out(sec1_2);

      dig_ctrl_3 = 1;

      dig_ctrl_2 = dig_ctrl_1 = dig_ctrl_4 = 0;

      digi_out(sec2_1);

      dig_ctrl_4 = 1;

      dig_ctrl_2 = dig_ctrl_3 = dig_ctrl_1 = 0;

      digi_out(sec2_2);

    }

     

    TR0=0;

    TF0=0;

    }

     

    void main()

    {

    while(1)

    {

    start:  

      start_pin = 1;

      stop_pin = 1;

      reset_pin = 1;

      dig_ctrl_1 = 0;

      dig_ctrl_2 = 0;

      dig_ctrl_3 = 0;

      dig_ctrl_4 = 0;

      P2 = 0xFF;

      s = t = 0;

      while(start_pin == 1)

      {

      display(0,0);

      }

     

    stopwatch:  

      for (sec1=s;sec1<=99;sec1++)

      {

       if (stop_pin == 0 )  

       break;

        for (sec2=t;sec2<=99; sec2++)

        {

        if (stop_pin == 0 )  

        break;

        t=0;

        display(sec1,sec2);

        }

      }

      stop_pin = 1;

      s = sec1;

      t = sec2;

     

      while ( start_pin != 0 && reset_pin != 0 )  

      {

      display(sec1,sec2);

      }

     

      if (start_pin == 0) 

      {

      goto stopwatch;

      }

      else

      {

       if (reset_pin == 0 )  

       {

       s = t = 0;

       goto start;

       }

      }

    }

    }

     

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Fun with AI and swordfish basic June 23, 2025
  • Simple LED Analog Clock Idea June 23, 2025
  • Microinverters and storeage batteries? June 23, 2025
  • PIC KIT 3 not able to program dsPIC June 23, 2025
  • Is AI making embedded software developers more productive? June 23, 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