hello there..i was trying to control the relay 12V by using the serial port comm.the PIC that i used is PIC 16 F84. can someone check my VB PIC basic code below,it does not work:
VB code :
Private Sub Form_Load()
Optstate(0).Value = True
MSComm1.CommPort = 1
MSComm1.Settings = "2400,n,8,1"
MSComm1.DTREnable = False
MSComm1.RThreshold = 1
MSComm1.InputLen = 1
MSComm1.PortOpen = True
End Sub
Private Sub Command1_Click()
Dim pinstate As Long
If Optstate(0).Value = True Then
pinstate = 0
Else
pinstate = 1
End If
MSComm1.Output = Chr$(255) & Chr$(pinstate)
End Sub
Private Sub form_unload(cancel As Integer)
MSComm1.PortOpen = False
End Sub
PIC code :
INCLUDE "modedefs.bas"
Si VAR PORTA.4
RELAY VAR PORTB.2
pinstate VAR BYTE
main
SerIn Si,4,["255"],pinstate
IF pinstate=1 Then
GoSub Relayon
Else
GoSub Relayoff
EndIF
Relayon:
High RELAY
Return
Relayoff:
Low RELAY
Return
Bookmarks