Writing VB code for reading data from uC

Discussion in 'Programmer's Corner' started by kevy, Nov 27, 2006.

  1. kevy

    Thread Starter New Member

    Nov 22, 2006
    I am doing the project to make a microcontroller communicate with PC.
    I am facing the problem writing the VB code for command button to ask uC to display the data in my label.
    How to writing the code for visual basic to get the data from the microcontroller?
  2. BladeSabre

    Senior Member

    Aug 11, 2005
    What microcontroller are you using, what method of communicating with the PC, and what version of Visual Basic?

    I was using VB6 to try to communicate through the serial port. There is a thing called the MSComm control that is supposed to let Visual Basic send and get characters. I never got it to work, but I think I need to use a crystal rather than the inaccurate internal oscillator. Soon I intend to try an emulated serial port with a USB PIC.
  3. kevy

    Thread Starter New Member

    Nov 22, 2006
    I got AT89C52 and PIC16F84A. Both also can be use as I test my program can run in hyperterminal. I will learn to using PIC16F877A soon.
    I am using serial com port comunicate between PC and microcontoller.
    I am using VB6.

    I know a bit of the MSComm control.
    MSComm1.CommPort = 1
    MSComm1.Settings = "9600,N,8,1"
    MSComm1.PortOpen = True
    let say user need to click the button1 to send character "Q" to uC
    and the uC will send the data and display in the label1
    AdcValue = ASC(MSComm1.Input)

    But I don't know how to implement it.
    Can you tell me the very basic code to make my VB work.
    Like: source code for sending the command signal to uC and get the data from it which is just using click.button and label box.
  4. praveen_cpp

    New Member

    Dec 2, 2006
    add this in ur code form

    Private Sub MSComm1_OnComm()
    Select Case MSComm1.CommEvent
    Case comEvReceive
    adcvalue = MSComm1.Input
    Label1.caption = adcvalue
    End Select
    End Sub

    don't forget to set the RTthreshold for input buffer in mscomm properties
    RTthreshold = no of input characters from uC after which an event will occur
    on mscomm n MSComm1_OnComm() subroutine will be executed.