help:send data from pc(Visual Basic) to pic16f877a through serial port(DB9)

Discussion in 'Programmer's Corner' started by texas5, Sep 3, 2008.

  1. texas5

    Thread Starter New Member

    Sep 3, 2008
    3
    0
    hi.i want to send data from pc(Visual Basic) to pic16f877a through serial port(DB9).all the hardware have been setup(i'm using max232).can someone help me for the coding part(both code for VB and pic).just a simple code(LED blinking) for testing my pic circuit.
     
  2. texas5

    Thread Starter New Member

    Sep 3, 2008
    3
    0
    :(:(:(

    somebody help me please...
     
  3. binu_ji

    Member

    Jul 13, 2007
    22
    1
  4. texas5

    Thread Starter New Member

    Sep 3, 2008
    3
    0
    :):):)

    thanx...it really help....but the coding is for micro controller.can i use it for my PIC16f877a.

    VB code:

    Private Sub Form_Load()
    On Error Resume Next
    'use comm port 1
    MSComm1.CommPort = 1

    ' 9600 baud, no parity, 8 data bits, 1 stop bit
    MSComm1.Settings = "9600,N,8,1"


    ' Disable DTR
    MSComm1.DTREnable = False


    'open the port
    MSComm1.PortOpen = True
    End Sub

    Private Sub cmdsend_Click()
    Dim LED As Long

    ' Get LED State
    If opton.Value = True Then
    LED = 0
    Else
    LED = 1
    End If

    ' Send Out Data
    MSComm1.Output = Chr$(255) & Chr$(LED)

    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    MSComm1.PortOpen = False'Close the COMM port
    End Sub


    PIC code:



    PinNumber var byte
    PinState var byte

    Main:

    ' Use the programming port to receive
    ' data at 2400 baud
    ' Wait for the synch byte (255) and then
    ' get the PinNumber and PinState
    Serin2 portb.5,16780,[WAIT(255),PinNumber,PinState]

    ' If PinState=0 Then go to GoLow
    ' otherwise go to GoHigh
    Branch PinState,[GoLow,GoHigh]
    Goto Main


    ' Set The pin low
    GoLow:
    LOW PinNumber
    Goto Main


    ' Set the pin high
    GoHigh:
    HIGH PinNumber
    Goto Main







     
  5. hidayah

    New Member

    Jun 3, 2009
    1
    0
    Hi,

    Can i use the same code for USB ? Thanks.
     
  6. nanovate

    Distinguished Member

    May 7, 2007
    665
    1
    Try it out and see.
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
Loading...