Microcontroller to Laptop through RS232-USB Converter

  • Thread starter Rickson
  • Start date
  • #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 wont 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 wont 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.
 

Answers and Replies

  • #2
berkeman
Mentor
59,624
9,757
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
3
0
Hi,
So do u have any sample programming code that almost the same as in my case so i can refer it?

Thanks...
 
  • #4
3
0
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
Averagesupernova
Science Advisor
Gold Member
3,845
772
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
1,564
7
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
Averagesupernova
Science Advisor
Gold Member
3,845
772
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.
 

Related Threads on Microcontroller to Laptop through RS232-USB Converter

Replies
1
Views
1K
  • Last Post
Replies
8
Views
2K
Replies
6
Views
2K
  • Last Post
Replies
2
Views
315
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
7
Views
5K
  • Last Post
Replies
8
Views
22K
Replies
1
Views
1K
Replies
2
Views
981
Replies
10
Views
29K
Top