Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Microcontroller to Laptop through RS232-USB Converter

  1. Feb 26, 2009 #1
    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.
     
  2. jcsd
  3. Feb 26, 2009 #2

    berkeman

    User Avatar

    Staff: Mentor

    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.
     
  4. Feb 26, 2009 #3
    Hi,
    So do u have any sample programming code that almost the same as in my case so i can refer it?

    Thanks...
     
  5. Feb 26, 2009 #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...
     
  6. Feb 27, 2009 #5

    Averagesupernova

    User Avatar
    Science Advisor
    Gold Member

    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?
     
  7. Feb 27, 2009 #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: May 4, 2017
  8. Feb 27, 2009 #7

    Averagesupernova

    User Avatar
    Science Advisor
    Gold Member

    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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Microcontroller to Laptop through RS232-USB Converter
  1. RS232 to USB (Replies: 8)

Loading...