VB sending serial data to PIC


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default VB sending serial data to PIC

    I have the PIC side of things working OK. Very simple to start with, when i send a 1 to the PIC serially, it flashes an LED. Nice simple visual representation that the data is received.

    However, this is done using the serial communicator as part of Microcide Studio.

    I have made a small VB app which i planned on sending this code, but nothing is happening.

    Can anyone assist or point me in a direction of where to look for VB - PIC comms. Ultimately i would like to send a series of variables to the PIC for storage in EEPROM to use later in its program.

    Here is the VB Code i came up with:

    Code:
    Private Sub Form_Load()
    
    ' 2400 Baud, No Parity, 8 Data Bits, 1 Stop Bit
    MSComm1.Settings = "2400,N,8,1"
    
    ' Open COM1
    MSComm1.CommPort = 1
    MSComm1.PortOpen = True
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        MSComm1.PortOpen = False
    End Sub
    
    Private Sub Command1_Click()
        MSComm1.Output = Text1.Text
    End Sub
    
    Private Sub Command2_Click()
        MSComm1.PortOpen = False
        End
    End Sub
    Obvioulsy there is a text box where i am typing 1 into and then pressing the command button to send the 1 serially to the PIC.

    Thanks for any assistance.

    Steve

  2. #2
    Join Date
    Feb 2003
    Posts
    432

    Default

    Hi Steve,

    Havent got VB on the machine I am using at the moment but check the following properties for the MSComm control

    DTREnable
    InputLen
    RThreshold

    I think that is all.

    Regards
    Keith

    www.diyha.co.uk
    www.kat5.tv

  3. #3
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default

    Thanks for yur reply Keith.

    What should the settings be?

    Currently:

    DTREnable = False
    InputLen = 0
    RThreshold = 0

    Cheers,

    Steve

  4. #4
    Join Date
    Feb 2003
    Posts
    432

    Default

    Quote Originally Posted by Tissy
    Thanks for yur reply Keith.

    What should the settings be?

    Currently:

    DTREnable = False
    InputLen = 0
    RThreshold = 0

    Cheers,

    Steve
    Looking at one of my old projects

    DTREnable = False
    InputLen = 1
    RThreshold = 1

    And that works fine.

    Regards
    Keith

    www.diyha.co.uk
    www.kat5.tv

  5. #5
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default

    Don't quite know what i have done, but i am getting some kind of comms.

    If using the text1 box i put a 1 in there and send it, the PIC doesn't do anything. If i use ANY character first, such as Z1, then the LED flashes fine.

    I have also put a text box to read a line coming back of the PIC. If a 1 is successfully received then the PIC should output "That Worked". However i'm getting "??????2rked" in VB.

    It also takes two button presses in VB, one to send the 1 which will flash the LED, another press gets the garbled "IT WORKED", and then another press will flash the LED again. Who can this be done with one button push. ie, each time the button is pressed it sends the 1 and displays the input message. Do you have any exmaples of what you have done which you wouldn't mind sharing ?

    Obvioulsy haven't quite mastered this yet !!

    Cheers,

    Steve

  6. #6
    Join Date
    Dec 2005
    Location
    Corum,Turkiye
    Posts
    15

    Default

    You look at this program.
    Attached Files Attached Files

  7. #7
    Join Date
    Feb 2005
    Location
    Essex, UK
    Posts
    154

    Default

    Thanks elektroline, your VB allowed me to compare with what i had and the reason the serial data coming back was goofed was because of one of the setting in Comm1.

    I'm still not convinced i have the PIC code right though, does this look right?

    As i say, if i send a 1 from VB nothing if i send t1 or a1 or any letter followed by 1, then the LED flashes and the command is sent back to VB.

    Code:
    include "modedefs.bas"
    
    Clear
    DEFINE OSC 20          
    DEFINE LOADER_USED 1
    ADCON1 = %00001111
    
    In      VAR PORTA.5
    Out     VAR PORTA.4
    Loop    Var Byte
    LED     VAR PORTB.1
    test    var word
    
    test = 1
    
    TRISB = %10000001       ' Set PORTB (0)INPUT (1-5)OUTPUTS
    
    Start:
       SERIN IN, N2400, [#TEST]
        IF TEST = 1 THEN 
            GOSUB FLASH
        ENDIF
    
        write 3, test
    '    IF test = 1 THEN GOSUB FLASH
        pause 500
    '    low PortB.1
        read 3, test
        SEROUT out, N2400, ["That Worked ", #test + 5] ' Senda the wording "That Worked" and a number
    GOTO Start
    
    Flash:
        For loop = 1 to 5
            LED = 1
            Pause 100
            LED = 0
            Pause 100
    Cheers,

  8. #8

    Default try this...

    Try changing your "test" variable to a byte. Then don't bother with the serial qualifier, just jump right to the data input, and do a compare.

    -----------------PICSTER--------------

Similar Threads

  1. Parsing Serial data stream
    By boroko in forum Serial
    Replies: 5
    Last Post: - 26th October 2008, 11:12
  2. Forward Serial Data from pic to pc
    By Muller in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 2nd September 2008, 21:46
  3. PIC serial going to sleep!
    By stma in forum Off Topic
    Replies: 0
    Last Post: - 31st October 2007, 08:17
  4. wireless serial data?
    By Scott in forum Serial
    Replies: 0
    Last Post: - 13th January 2006, 01:44
  5. USB, PIC18F2550 and VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th November 2005, 18:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts