Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Doubts regarding Visual basic with PIC16F877A

Status
Not open for further replies.

parjun

New Member
I am doing a project " Infant monitoring system using PIC16F877A". It uses 3 sensors LM35 temperature sensor, CO2 sensor and breath rate sensor. We are transmitting those signals through RS-232 to PC for displaying in VB application. I am new to the VB sessions.

I want to know these :

1. When transmitting the data to the PC through RS-232 cables, where will the data be stored?

2. In the following program, plz explain
Code:
Dim tempA As Variant
Dim tempB As Variant
Public AvaL, BvaL, CvaL As Integer
Public FlagA, FlagB, FlagC As Integer

Private Sub cmd_1_Click()
    graphA.Show
End Sub

Private Sub cmd_2_Click()
   graphB.Show
    
End Sub

Private Sub cmd_3_Click()
    graphC.Show
End Sub

Private Sub Form_Load()

    With MSComm1
        [B].CommPort = 1
        .InputLen = 1[/B]
        [B].InputMode = comInputModeText
        .SThreshold = 1
        .RThreshold = 1[/B]
        .Settings = "9600,n,8,1"
        [B].Handshaking = comNone
        .PortOpen = True[/B]
    End With
    FlagA = 0
    FlagB = 0
    FlagC = 0
End Sub

[B]Private Sub MSComm1_OnComm()
    Dim Buffer As String
    Select Case MSComm1.CommEvent
        Case comEvReceive
            Buffer = MSComm1.Input
            Call HandleInpuT(Buffer)
    End Select
End Sub[/B]

Function HandleInpuT(ByVal DataBuf As String)

    If tempB = [B]CInt(&HAB)[/B] Then
        Select Case tempA
            Case [B]CInt(&HB1)[/B]
                txtTemperature = ((Val(Asc(DataBuf) + 81 + Rnd)) / 10)
            Case [B]CInt(&HB2)[/B]
                txtBreath = Val(Asc(DataBuf) - 100)
            Case [B]CInt(&HB3)[/B]
                txtCO2 = (Val(Asc(DataBuf) + Rnd)) * 500
        End Select
    End If
    
    tempB = tempA
    tempA = Asc(DataBuf)
End Function

Private Sub Timer1_Timer()
    AvaL = Val(txtTemperature)
    BvaL = Val(txtCO2)
    CvaL = Val(txtBreath)
    
    If AvaL > 265 Then
        'MSComm1.Output = "1"
        FlagA = 1
    Else
        'MSComm1.Output = "2"
        FlagA = 0
    End If
    If BvaL > 2000 And BvaL < 9000 Then
        FlagB = 2
    ElseIf BvaL > 8000 Then
        'MSComm1.Output = "1"
        FlagB = 1
    Else
        'MSComm1.Output = "2"
        FlagB = 0
    End If
    If CvaL > 20 And CvaL < 40 Then
        FlagC = 2
    ElseIf CvaL > 39 Then
        FlagC = 1
        'MSComm1.Output = "1"
    Else
        'MSComm1.Output = "2"
        FlagC = 0
    End If
    
    If AvaL > 265 Or BvaL > 8000 Or CvaL > 39 Then
        MSComm1.Output = "1"
    Else
        MSComm1.Output = "2"
    End If
End Sub
/CODE]

In these code the highlighted black portion is my problem....

I want to know these:

1. What is MSComm1 and what are COmmport and InputLen....why are they used..what purpose? Also tell about R threshold,  S threshold, Handshaking and Port open(what port is open??)

2. WHat is the purpose of this function

Private Sub MSComm1_OnComm()
    Dim Buffer As String
    Select Case MSComm1.CommEvent
        Case comEvReceive
            Buffer = MSComm1.Input
            Call HandleInpuT(Buffer)
    End Select
End Sub

in the program??

3. WHat is this Case CInt(&HB2) ? what is done here?

Sorry for the inconvenience.... I dont know VB so after doing my programming in PIC16F877A i gave it to a project centre who designed the code....He didnt explain it properly...SO plz help....

Also if you have any ebooks or so where i can learn about these things plz post....
 
Last edited:
1) That is some properties of MSComm1. Before dealing with comport you need to configure it.

There can be many of comport in your computer you need to select what comport number you are using by writing to commport.

You need to open the comport then only you can send & receive data.

You also need to match the baud rate with the PIC.P = parity, D the number of data bits, and S the number of stop bits.

2) CommEvent is like an interrupt.So all the time you don't need to poll the buffer even if there no data.MSComm control will tell you when data is there by firing the OnComm() event.

This PDF will clear many of your doubts.
 

Attachments

  • VB Serial Com.pdf
    600.2 KB · Views: 388
Last edited:
thanks

friend u didnt answer my first question

when the data is sent from PIC to PC where the data will be stored in PC
 
hi parjun.
The answers to all your questions are in the VB program 'online help' files.

The different Comm parameters are explained and some examples are given.
 
Hi Friend,

Note my point you are using on comm event what ever the bits receiving through RS232 which is passing through on comm event it fires each bit receives only on comm event.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top