Microcontroller to Laptop through RS232-USB Converter

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. What i would like to do for my project is when the Tx output is 1, then some operation will be running using visual basic 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.

Replies

  • silverscorpion
    silverscorpion
    There seems to be nothing wrong with the code. I think the problem might be lying in the RS232 to USB converter. You see, when you use RS232, there are specific pins which you can use to test for the output signal. But from USB port, how will you gie a signal to VB to instruct it to do some task?

    You better check the status of the pins before connecting to the rs232. I think the output will be correct. I'm not sure, though..
  • Ashraf HZ
    Ashraf HZ
    Some points to consider;
    - You are using both RX and TX as outputs? This is not possible, because there is only one receive pin for the Host rs232. (PIC TX ---- > HOST RX)
    - Serial communications has to use the UART function of the PIC. Since thats the case, you don't need to just send 1 and 0. You can send a lot more commands, even at a baud rate of 1200bps, over a single TX pin.
    - On your visual basic app, make sure it opens the correct COM port. Usually USB-RS232 emulators choose a high port number.
  • Rickson
    Rickson
    Hi,
    So do u have any sample programming code that almost the same as in my case so i can refer it?

    Thanks...
  • Rickson
    Rickson
    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...

You are reading an archived discussion.

Related Posts

Hey! our college's CS department is going to organize competitions any ideas for competitions rather than c/c++ programming competitions πŸ˜•
Hello everyone, i have a project to do in my freshmen year. it does not have to be professional. The subject I picked is about making cell phone robot. we...
here's a good find I stumbled on- This Chicago, IL firm is betting an old design will breathe vigor into the alternate energy market. They have designed and produced wind...
hi engineeres😎😎😎 can anyone tell me how i can commperss air in minimum money & sufficent quntity?πŸ˜•πŸ˜•πŸ˜•πŸ˜•
now i do my b.tech in mechanical engineering.. and i am looking here for new and relevant paper presentation topics on aerospace.. plese let me know what i want...and i...