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
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.
 

Suggested for: Microcontroller to Laptop through RS232-USB Converter

Replies
14
Views
587
Replies
55
Views
2K
Replies
5
Views
677
Replies
4
Views
691
Replies
32
Views
2K
Replies
39
Views
2K
Replies
13
Views
1K
Replies
2
Views
752
Replies
5
Views
799
Back
Top