Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Serial communication program

Status
Not open for further replies.

Fan174

Member level 2
Member level 2
Joined
Mar 27, 2018
Messages
51
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
413
I need help in a program that will read the sensor and send to the port of the computer

Please look at the attached circuit

I wrote this program

Code:
#include<reg51.h>

sbit Sensor    =   P2^0;        // Sensor connected to p2.0
#define High       1
#define Low        0

//Initialize Timer 1 for serial communication

void initialize()     
    {
         TMOD=0x20;     //Timer1, mode 2, baud rate 9600 bps
         TH1=0XFD;      //Baud rate 9600 bps
         SCON=0x50;   
         TR1=1;         //Start timer 1
    }

// Funtion to transmit serial Data
void transmit()       
   {
		 
		  sensor = High;
     
      while(TI==0);
      
		  TI=0;
   }

	 void main()
  {
     while(1)
      {
        initalize();

        transmit();
  }
How to write program that will read the sensor and send to the port of the computer
 

Attachments

  • serial communication.jpg
    serial communication.jpg
    37.8 KB · Views: 144

Hi,

... we need to guess what the "sensor" is and what "interface" it uses...

-->
* decide which sensor to use
* read it´s datasheet
* connect the sensor according datasheet
* set up the interface according datasheet
* communicate with the sensor according datasheet
* decide how to process the sensor data
* decide the data format to be transmitted via UART
* then send the data through UART

Klaus
 

Your diagram has DB9 connectors which is associated with an older type of serial interface. It's okay if your computer uses that older style of serial interface. (Possibly a parallel port 25 pins.)
However if your computer only has USB then you'll need to use that communication protocol.

Your cable appears to be a null modem. It uses a ground wire, and data goes through the other wire. The DB9 connectors have jumper wires between certain pins so you don't need to do all the handshaking protocols. It's the easier hookup and you can transmit ordinary ascii characters to your computer. The computer runs a utility program (typical name might be Hyperterminal, etc.), and displays characters as it receives them.

Your program needs to open a communication channel. Make settings match the computer's (baud rate, parity, 7 vs 8 data bits, full vs half duplex).
Voltage levels need to match.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top