Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC and PC in Visual Studio 2008

Status
Not open for further replies.

sangeo

Member level 2
Joined
Jun 2, 2013
Messages
44
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,647
Hai
I am Doing a project with Visual studio to communicate with PIC 16F 877A As I a beginner in Visual studio , my doubt is rs232 flow control is possible in Pic 16f877A. My Visual Studio project is aimed to read EEPROM values (250nos) and display it on computer screen , If anybody have similar VB programs please help me. I don’t have much more knowledge in Visual studio and VB also.
Thanks’
Saneesh George
 

Hi,

my doubt is rs232 flow control is possible in Pic 16f877A.
I don´t think there is hardware support for flow control. So you have to add it as software and use GPIO.

***
You have to decide a protocl on how you want to communicate.
* do you like to transmit binary data and commands (hard to read for debugging) or in ASCII style?
* do you want bytewise data transfer or blockwise?

An example:
PC --> uC: "R" ; R for Read complete EEPROM data
uC --> PC: 250 bytes of binary
(This method is simple to program, but you have about no chance to detect corrupt data or missing data, END of communicaton....)
or:
PC --> uC: "Read 12, 07 [CRC] [Cr] " ; Read, starting address 12 (decimal), 7 bytes, Checksum for validation, [Cr] to indicate End of command
uC --> PC: "EERead 12, 07 [CRC]" ; as header for the Pc, to describe the folowing data
uC --> PC: "EEData 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89 [CRC] [Cr]" 7 bytes of EEPROM data followed by CRC and end of comand

... or anything inbetween.

using binarydata is good if you want to transmit low byte count. But it is ahard to read.
using decimal (-> ASCII), hex (-> ASCII), or similar is easy to read, but needs more bytes to transmit.
Also you need to consider how to parse the incoming datastream on both sides.
Also, how to detect corrupt or missing data, and how to handle it (discard command or retry) how to detect a START or END of a command.
Baud rate...
Timeouts, and how to handle it.

Klaus
 
  • Like
Reactions: sangeo

    sangeo

    Points: 2
    Helpful Answer Positive Rating
This is a example for send and receive data from communication port.
Code:
 Private Sub btnSendData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSendData.Click
        If (SerialPort1.IsOpen) Then
        SendToSerial("0")             'Send as a string value
        Else
            MsgBox("Communication USB Port is not open. Anything will not transmit untill USB port is not in active mode. Chack to Communication port settings", MsgBoxStyle.Exclamation)
        End If
    End Sub

   Private Sub SendToSerial(ByVal data As String)
        SerialPort1.Write(data & Chr(13)) 'The value will be sent to the serial port as ASCII
        Thread.Sleep(100)
    End Sub

- - - Updated - - -

Code:
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
        If (lblSerialPort.Text = "") Then
            MsgBox("Please select communication serial port number first.", MsgBoxStyle.Exclamation)
            SerialPort1.Close()
            Form6.Show()
        ElseIf (lblBaud.Text = "") Then
            MsgBox("Please select communication serial port baudrate first.", MsgBoxStyle.Exclamation)
            SerialPort1.Close()
            Form6.Show()
        Else
            SerialPort1.PortName = lblSerialPort.Text         'Set SerialPort1 to the selected COM port at startup
            SerialPort1.BaudRate = lblBaud.Text               'Set Baud rate to the selected value on
            'Other Serial Port Property
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8

            'Open our serial port
            'than trying to open the port and catching errors.
            If PortIsAvailable(lblSerialPort.Text) Then
                SerialPort1.Open()
                SerialPort1.Write("@")
                Thread.Sleep(100)
                Dim asd As String
                asd = SerialPort1.ReadExisting            [COLOR="#FF0000"]' Read Data From Serial port[/COLOR]
                If (asd = "#") Then
                    MsgBox("Connected successfully and ready to write EEPROM memory.")
                    btnConnect.Visible = False          'Disable Connect button
                    btnDisconnect.Visible = True        'and Enable Disconnect button
                    btnSendData.Enabled = True
                    lblConnectColor.BackColor = Color.Lime
                    Label18.Text = "Yes"
                    lblReady.Visible = True
                Else
                    MsgBox("Communication Serial Port is not connected. Anything will not transmit untill serial port is not active mode. Make sure that your MOI-101 module is connect via USB port & Power on or Chack to Communication port settings", MsgBoxStyle.Exclamation)
                    SerialPort1.Close()
                End If
            Else
                MsgBox("Error ----- Port is already open : " & lblSerialPort.Text)
            End If
        End If
    End Sub
 
  • Like
Reactions: sangeo

    sangeo

    Points: 2
    Helpful Answer Positive Rating
Hello, Sangeo
I think ur problem might be interfacing microcontroller with PC. Reading eeprom and transfering to PC will be a small logic, which u can do.

There are function in VB of opeing com port.


Code Visual Basic - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Imports System
Imports System.IO.Ports
Imports System.Threading
Imports System.Threading.Thread
 
Public Class Form1
 
    Dim WithEvents COMport As New SerialPort
    Dim RXbyte As Byte
 
 
    Public Sub New()
 
        ' This call is required by the designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
 
        COMport.PortName = "COM8"
        COMport.BaudRate = 9600
        COMport.Open()
 
 
    End Sub
 
    Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles COMport.DataReceived
        RXbyte = COMport.ReadByte
        Me.Invoke(New MethodInvoker(AddressOf Display))
 
    End Sub
 
    Private Sub Display()
        txtReceived.Clear()
        txtReceived.Text = (ChrW(RXbyte))
    End Sub
 
End Class



Hope the above program will give u idea of what to do.

I would suggest google QT and try making GUI in QT rather than on VB.
Developing in QT is very easy. Just some knowledge in C++.
Qt is Rapid development tool. DO GOOGLE QT. or watch some U tube vids on QT
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top