Need help from PIC16F877A to VB2008 through rs232 serial port

Discussion in 'Embedded Systems and Microcontrollers' started by holybrings, Mar 4, 2010.

  1. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Hi, im a new VB learner and i need someone guidance to write a program. What i need to write is i get different signal from PIC16F877A and through serial port, i need to display diffrent text from different signal, Such as: Signal from portB.1 display 1, signal from portb.2 display 2.

    Thanks.
     
  2. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    Well, there are 2 programs involved here...

    First is the program on the microcontroller, did you make that program yet ?

    Then there is the program on the computer (in VB.NET).

    The microcontroller should simply send characters "1", or "2", when the bits on Port B enable, and the VB.NET program should just take the data that is comming from whatever comm port you are using for serial, and display the data.

    By the way, what about if bit 1 and bit 2 are enabled, then what do you want to display ?

    Give us more details on what you have done so far ? (at what stage are you ?)
     
  3. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Im just handling VB.net. Microcontroller programming my friend handling. What im doing is a lift project. I need to display which floor the lift at. I'd been searching for sample but still can't find any.
    Example:
    Lift at level 2, portd.2 high(1), VB display "level 2".
    Lift at level 3, portd.3 high(1), VB display "level 3".

    Thanks for the reply.
     
  4. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    BTW, im using MAX232 between microcontroller and serial port
     
  5. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Anyone can guide me???
     
  6. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    This is the first hit from searching for "VB serial port". Looks OK.
    http://www.dcs.napier.ac.uk/~bill/pdf/Io_ch26.PDF

    You need to look at the asynchronous part of the USART section of the PIC16F877 datasheet. That should help with the PIC end.
     
  7. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Is VB4 code similar to VB2008?
     
  8. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    there are some similarities to it but they are quite different VB2008 use the .net. VB4 is almost compatible to VB6.....

    Basically what you will need :

    on the uc side:

    1. UC with USART (which you already have)
    2. RS232 level converter IC (Such as the MAX232 TTL to Serial Level translator IC, which you already stated you have)
    On the PC Side:

    1. PC with serial port (or a USB to serial converter dongle)
    2. VB with the MSCOMM Control loaded on the form.... (I have VB6 so I can not help you with code for VB.net, but I can give you a sample code for VB6)
    This is all the hardware you will need to have uc "talk" to PC via RS232 (Serial)

    What is the format of the data coming from uc? Is there any terminator characters used in the data transmission (Such as CRLF, CR, LF (CR = Carriage return, LF = Line Feed)? I will need to know how the data is transmitted and in what format before I can go any further.....

    B. Morse
     
  9. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    what is uc?
     
  10. CVMichael

    Senior Member

    Aug 3, 2007
    416
    17
    I think he ment to write "IC" as in Integrated Circuit ? (in this case a microcontroller)
     
  11. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    uc is short for Microcontroller... the u is supposed to be the greek symbol for micro (µ). c = controller... also MCU or µC.

    B. Morse
     
  12. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Justb received a bad news, i need to write out my program for microcontroller to transmit any signal.
    Start from the very beginning,
    Write program for PIC,
    this is what i search,
    #include <htc.h> <=== This I don't understand
    #include "USART.H" <=== Is this the usart you mean?
    #include <stdio.h>
    __CONFIG(0x3f71); <=== This I don't understand

    Thanks for helping and sorry for knowing nothing.
     
  13. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    This are include files that are already written that you want the compiler to link to when the program is compiled before downloading it to the uc.


    Since you have to start from the beginning.... why don't we do it right,
    first lets see the schematic for the uc circuit you are using, this will help in the coding for setting configuration bits for the uc...... the __CONFIG statement tells the compiler what configuration you want to use for the uc, such as oscillator type, and MCLR I/O pin usage, etc.

    Once we have that on here then we will work on the code....

    Do you have the circuit already built for the uc?

    B. Morse
     
  14. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Im now trying simple circuit to understand how uc through max232 -> rs232 -> vb.
    when portd.2 high, portd.5 high
    portd.3 high, portd.6 high
    portd.4 high, portd.7 high
    This what i set for the uc.
    Currently i don't have any programmer, i just have the uc which got the above setting.
    Now is 3am in the morning, so have to wait till morning only can get the programmer to test what i can write later on.
     
  15. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    You can not write code for a circuit that doesn't exist yet (you can but it is futile, just simulating code does not guarantee it will actually work!), you have to have the working circuit in order to test it properly.....

    B. Morse
     
  16. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    the circuit is with my friend and it's working. For all the 3 ports as input, is connect with IR sensor.
     
  17. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234

    Ok, then get the circuit diagram from your friend and post it here....

    By the way, how do you know the circuit is working if you have to write the code for it from scratch??

    I can't help you write the code if I don't know what is connected to what pin on the PIC16F877A... and another thing, what language are you going to write the code in? Assembly or C?

    On the other hand I could write the code, but if I do, you will have to build my circuit to go with it, so unless you can help me help you, then we could always start from scratch, my way, and it is very possible you would end up with a useless program and circuit since you can't provide hardly any information to go by ;)

    B. Morse
     
    Last edited: Mar 5, 2010
  18. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    See how easy this is, I just created this circuit in about 5 minutes, and here is some sample code to go with it in both modes, but since I don't know anything else about your project this is a s far as I can go....

    Here is the basic circuit, with ICSP....
    PIC16F877A_RS232.png

    here is the initialization code for both uart modes, do not know which one you will be using...

    Asynchronous Transmitter/Receiver
    Code ( (Unknown Language)):
    1. BSF STATUS,RP0 ; Go to Bank1
    2. MOVLW <baudrate> ; Set Baud rate
    3. MOVWF SPBRG
    4. MOVLW 0x40 ; 8-bit transmit, transmitter enabled,
    5. MOVWF TXSTA ; asynchronous mode, low speed mode
    6. BSF PIE1,TXIE ; Enable transmit interrupts
    7. BSF PIE1,RCIE ; Enable receive interrupts
    8. BCF STATUS,RP0 ; Go to Bank 0
    9. MOVLW 0x90 ; 8-bit receive, receiver enabled,
    10. MOVWF RCSTA ; serial port enabled
    Synchronous Transmitter/Receiver
    Code ( (Unknown Language)):
    1. BSF STATUS,RP0 ; Go to Bank 1
    2. MOVLW <baudrate> ; Set Baud Rate
    3. MOVWF SPBRG
    4. MOVLW 0xB0 ; Synchronous Master,8-bit transmit,
    5. MOVWF TXSTA ; transmitter enabled, low speed mode
    6. BSF PIE1,TXIE ; Enable transmit interrupts
    7. BSF PIE1,RCIE ; Enable receive interrupts
    8. BCF STATUS,RP0 ; Go to Bank 0
    9. MOVLW 0x90 ; 8-bit receive, receiver enabled,
    10. MOVWF RCSTA ; continuous receive, serial port enabled
    In both examples the data is 8-bits, and the value to
    load into the SPBRG register is dependent on the desired baud rate and the device frequency.

    B. Morse
     
  19. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    If you have access to Eagle Lite Version 5.1.0 or higher you can edit the circuit I did to reflect the rest of your circuit... include value for crystal...


    Then post it back on here....

    B. Morse
     
  20. holybrings

    Thread Starter Active Member

    Apr 4, 2007
    64
    0
    Hi B Morse,
    My friend is using basic language.
    By the way, how i can know what type of transceiver im using?

    Thanks
     
Loading...