Microcontroller to Laptop through RS232-USB Converter

In summary, the conversation discussed using a microcontroller 16f877A with Tx and Rx pins to output either 1 or 0, connected to a laptop using an RS232-USB converter. The microcontroller has been programmed and tested. The project involves using the Tx and Rx outputs to activate certain functions in a VB program. Sample code and direction were requested for reference. Suggestions were given to use hyperterminal and the MSComm control for VB.net, and to check for proper connections and components.
  • #1
Rickson
3
0
HI,
I'm currently using a microcontroller 16f877A. The Tx and Rx pins of my microcontroller will output either 1 or 0 respectively. The microcontroller is connected to my laptop using RS232-USB converter. The microcontroller has been programmed and the connection was tested. May i know what is the code to determine the output for Tx and Rx using VB? Because what i would like to do for my project is when the Tx output is 1, then some operation will be running and same for the Rx...


Below is roughly what my microcontroller will do:
#if pin no 19 & 20 at PIC is 0, then will make pin no 25 & 26 as 0 (output), so it won't activate your visual basic
#if pin no 19 at PIC is 1, then will make pin no 25 as 1 (output)so, activate visual basic due to first sensor
#if pin no 20 at PIC is 1, then will make pin no 26 as 1 (output) so activate visual basic due to second sensor

So, may i know whether my microcontroller code is correct as below?

void main()
{
trisd=1; // set port d as input
trisc=0; // set port c as output
portd=1; // initialize port d as 0
portc=1; // initialize port c as 0
while(1) {
if (portd== 0b00000000) // if pin no 19 & 20 at PIC is 0, then will
{ // make pin no 15 & 16 as 0 (output)
portc=0x00; // so it won't activate your visual basic
}

if (portd== 0b00000001) // if pin no 19 at PIC is 1, then will
{ // make pin no 25 as 1 (your output)
portc.f6=1; // activate visual basic due to first sensor
}

if (portd== 0b00000010) // if pin no 20 at PIC is 1, then will
{ // make pin no 26 as 1 (your output)
portc.f7=1; // activate visual basic due to second sensor
}

if (portd== 0b00000011) // if pin no 19 & 20 at PIC is 1, then will
{ // make pin no 15 & 16 as 1 (your output)
portc=0b00000011; // activate visual basic due to both sensors
}
}

}

Thanks.
 
Engineering news on Phys.org
  • #2
Welcome to the PF.

The Rx pin is an input, not an output. The Tx pin, in RS-232 mode, will output a string of 1's and 0's according to the baud rate setting and data that you put through the UART.
 
  • #3
Hi,
So do u have any sample programming code that almost the same as in my case so i can refer it?

Thanks...
 
  • #4
Hi,
Actually what I'm doing is like this:

When the sensors detect something, it will send info to my Visual Basic so that my visual basic will take further action. So the connection i done so far is roughly like below:

At 16F877:
Pin 19 ==> IR sensor 1
Pin 20 ==> IR sensor 2
Pin 25 ==> pin 9 of MAX232
Pin 26 ==> pin 10 of MAX232

At MAX232
pin 7 ==> pin 2 of DB9
pin 8 ==> pin 3 of DB9

So is there any sample code and direction for me to do my project.. I'm really new to microcontroller.. Thanks...
 
  • #5
It's been a while since I've worked with VB and the RS-232 port. Are there other handshaking lines on the serial port you can connect to and let your VB program read?
 
  • #6
Assuming your MAX232 chip is set up and working your first task should be communicate with hyperterminal simply be having your pic send a byte or two of data to the PC. Once you get communication established, you will want to use the http://support.microsoft.com/kb/823179" [Broken] command for visual basic.net (I'm assuming your using .net). The tutorial on MS's site is fairly strait forward.

Some helpful hints;
-Be sure all your pins and wires a secured and your grounds are common.
-Start at low baud rates, such as 9600 b/sec, where there is less probability of error.
-Start by not using hardware control, I've never had it work properly.
-Be certain that you are using the proper capacitors for the Max232 chip, I've learned the hard way that you need to use the values given in the data sheet.

Another Note: For future projects look into FTDI chips. They are basically a Max232 and Serial->USB converter in one and can be flashed to suite your needs (RTS and DTS control).
 
Last edited by a moderator:
  • #7
I may not be 100% clear on what the OP is trying to do. I don't think the OP is trying to send back serial data. I think he just wants to use 2 hardware lines as outputs from his PIC to interface with the PC that VB can read. I don't understand why he is setting port D up as an input when he seems to want it as an output. But, maybe I am misunderstanding what he is trying to do.
 

What is a microcontroller?

A microcontroller is a small computer on a single integrated circuit that is used to control electronic devices. It contains a processor, memory, and input/output peripherals.

What is an RS232-USB converter?

An RS232-USB converter is a device that converts the signals from a serial port (RS232) to a USB port, allowing communication between devices that use different protocols. This is commonly used to connect a microcontroller to a laptop for data transfer.

How does a microcontroller communicate with a laptop through an RS232-USB converter?

The microcontroller sends data through its serial port, which is converted into USB signals by the RS232-USB converter. The laptop receives the data through its USB port and can interpret and process it using software.

What are the benefits of using an RS232-USB converter for microcontroller communication?

Using an RS232-USB converter allows for a more reliable and standardized communication between the microcontroller and the laptop. It also eliminates the need for specialized hardware or drivers, making it easier to connect and transfer data.

Are there any limitations to using an RS232-USB converter for microcontroller communication?

One limitation is the maximum data transfer rate, as USB has a higher speed compared to RS232. Additionally, older microcontrollers may not have a serial port or may require additional hardware for communication through an RS232-USB converter.

Similar threads

  • Electrical Engineering
Replies
1
Views
2K
  • Electrical Engineering
Replies
1
Views
1K
Replies
7
Views
806
  • Electrical Engineering
Replies
1
Views
2K
  • Electrical Engineering
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Electrical Engineering
Replies
1
Views
2K
Replies
1
Views
2K
  • Electrical Engineering
Replies
8
Views
22K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top