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

Thread Starter

texas5

Joined Sep 3, 2008
3
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.
 

Thread Starter

texas5

Joined Sep 3, 2008
3
:):):)

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







 
Top