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.

vb6.0 communicate with PIC16f877a

Status
Not open for further replies.

siawjf

Newbie level 4
Joined
Jul 4, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,315
Hi,Im new here. I want to know what the thing I need to do for vb6.0 communicate with PIC16f877a through usb to uart. I want to do a project when i click a command button, then the LED will light up through the PIC16f877a and I dunno what the thing Im going to start..help
 

Can you please tell us the experience level you have with PIC and VB...

The basic idea is this

1. Make a GUI with VB including th button and stuff to run on the PC
2. Write an ASM (or C) code for the PIC to make it as a serial data receiver using UART.
3. The PIC should wait till it receives some data fromt eh PC and then it should check the input data with some conditional statements and set a PIN on some PORT high or low.
 

I know how to use vb. I also already programmed my PIC which i push a pushbutton,the led will light up. but now all i wanna do is to replace the pushbutton with vb common button. and is there any programming need to connect the usb to uart? because i wanted connect my circuit to usb through usb to uart and controlled by VB6.0..thanks
 

Since you know how to use Vb things are a lot easy.
When you plug in a USB to UART module i will be registered as a virtual COM port. You can add a drop down style selection menu in your GUI to select the COM port. This is because the Virtual COM port can have any number COM1, COM2 etc on your system.

Once the VB program has selected the correct COM port, you need to set up the Push button, When the user press the Push Button onscreen, the VB code should send an ASCI value (eg A is alpha numeric 'A' represents the ASCI value 65 - the one byte long ASCII representation) https://www.asciitable.com/

You need to use a MAX232 or DS275 chip to connect the PC COM port to the PIC. You can also try making this simple Transistor circuit for RS level translation : https://www.sparkfun.com/datasheets/Prototyping/RS232-Shifter-v2.pdf

Next you need to program the PIC with its UART enabled and set an interrupt on UART data receive. If you are sending 65 on the press of the Pushbutton from PC to PIC, Here is a very well writte web page for connecting another PIC with PC. You can replace the PIC with 877. Since you have some experience with 877 I do not think you need more clarification. (If you need please contact me) - https://www.oz1bxm.dk/PIC/628uart.htm



Reading material :

- documentation for SERIAL port you can understand a lot about serial port there.

Added after 14 minutes:

Read the UART section under PIC Midrange Refrence Mannual 33023a : https://ww1.microchip.com/downloads/en/devicedoc/33023a.pdf

Int he page I linked, the guy have just copied the data to W register after receiving the data from PC. you can add a conditional skip here.
SUBLW 'A' --Subtract recieved value from 65 to check if they are equal
BTFSS STATUS, Z --check if the prevous was equal
GOTO RECEIVE -- if not return to receiving state
BANKSEL PORTD -- select register bank with PORTD register
BSF PORD, 0 -- Make output 0 of PORTD high.
GOTO RECIEVE

Use the above template to make another button press turn off your LED.

If you have any doubt feel free to ask.
 

Do I still need to use rs232 and max232 if I already bought a USB to UART module from Cytron?

Added after 3 hours 45 minutes:

I also dont know what to do to program the vb so that the pic know which pustbutton i clicked to light a led.Example,when i click pushbutton A,LED A will light up.Click the pushbutton B,LED B light up
 

If you are referring to this :http://www.cytron.com.my/viewProduct.php?pid=HyoPJCcdFAEFLx8PEC4MGkBLnV05bmROMITS0xgB7tM=

you have got the right product. as the description say "You do NOT need another MAX232 or other level translator"

You can directly connect the output of that module to your 877a.

What you can do with VB is Draw 8 (just an example) Push Buttons with labels "PB0, PB1...PB7" When a user pushes PB0, the software should send 0 (just an example , you can use any number you like or other Alphanumerics) through he Virtual COM port that represents your USB to UART module.

Here are two links you can use to learn how to send data to Serial port using VB

1. http://www.thaiio.com/prog-cgi/0002_serial.htm
2. http://www.bigresource.com/VB-How-to-send-data-to-RS232-serial-port-using-vb6-axNr8RiP.html

3.

Hope you have got the PIC part clear. :)
 

ok..thanks man...hopefully I dont get any trouble in it anymore
 

Ermmm....Do u have any sample code??? I cant find it on9 and confuse some of the mscomm command on the VB6.0
 

i have also have problem regarding interfacing with serial port.
im doing traffic light project which vb can interface the hardware means everything can control by vb.
my problem is when my vb change... my hardware didnt change.
for example, when in vb light change from green to yellow... but in hardware it not change.
can some1 help me on this?

my target is... every changes in vb will affect the hardware.

below vb code that im done it.
please correct me if im wrong. TQ

Code:
Private Sub tmrLampu_Timer()
   Static Index As Integer
   Static intLampu As Integer
   Dim intNum As Integer
   
   Select Case intLampu
   Case 0 'Hijau
       LampuMati
       tmrLampu.Interval = Val(txtHijau(Index).Text) * 1000
       LampuHijauNyala Index
       For intNum = 0 To 3
           If intNum <> Index Then LampuMerahNyala intNum
       Next
       intLampu = 1
   Case 1 'Kuning
       LampuMati
       tmrLampu.Interval = 1000
       LampuKuningNyala Index
       For intNum = 0 To 3
           If intNum <> Index Then LampuMerahNyala intNum
       Next
       intLampu = 0
       Index = Index + 1
       If Index = 4 Then Index = 0
   End Select
End Sub


Private Sub LampuMati()
   Dim ctl As Control
       
   For Each ctl In Me.Controls
       If TypeOf ctl Is Shape Then
           If ctl.Name = "shpLampuMerah" Then ctl.BackColor = RGB(70, 0, 0)
           If ctl.Name = "shpLampuKuning" Then ctl.BackColor = RGB(70, 70, 0)
           If ctl.Name = "shpLampuHijau" Then ctl.BackColor = RGB(0, 70, 0)
       End If
   Next
End Sub

Private Sub LampuMerahNyala(Index As Integer)
   Select Case Index
   Case 0
       MSComm1.Output = "c"
   Case 1
       MSComm1.Output = "f"
   Case 2
       MSComm1.Output = "i"
   Case 3
       MSComm1.Output = "l"
   End Select
  shpLampuMerah(Index).BackColor = vbRed

End Sub

Private Sub LampuMerahMati(Index As Integer)
   Select Case Index
   Case 0
   MSComm1.Output = "m"
   Case 1
   MSComm1.Output = "m"
   Case 2
   MSComm1.Output = "m"
   Case 3
   MSComm1.Output = "m"
   End Select
   shpLampuMerah(Index).BackColor = RGB(50, 0, 0)
End Sub

Private Sub LampuKuningNyala(Index As Integer)
   Select Case Index
   Case 0
       MSComm1.Output = "b"
    Case 1
       MSComm1.Output = "e"
    Case 2
       MSComm1.Output = "h"
   Case 3
       MSComm1.Output = "k"
   End Select
   shpLampuKuning(Index).BackColor = vbYellow
End Sub

Private Sub LampuKuningMati(Index As Integer)
   
   Select Case Index
   Case 0
   MSComm1.Output = "m"
   Case 1
   MSComm1.Output = "m"
   Case 2
   MSComm1.Output = "m"
   Case 3
   MSComm1.Output = "m"
   End Select
   shpLampuKuning(Index).BackColor = RGB(50, 50, 0)
End Sub

Private Sub LampuHijauNyala(Index As Integer)
   ResetArahAnim
   Select Case Index
   Case 0
       MSComm1.Output = "a"
       idxLampuHijau = 0
   Case 1
       MSComm1.Output = "d"
       idxLampuHijau = 1
   Case 2
       MSComm1.Output = "g"
        idxLampuHijau = 2
   Case 3
       MSComm1.Output = "j"
        idxLampuHijau = 3
   End Select
   shpLampuHijau(Index).BackColor = vbGreen
   tmrArah.Enabled = True
End Sub

Private Sub LampuHijauMati(Index As Integer)
 
Select Case Index
   Case 0
   MSComm1.Output = "m"
    Case 1
   MSComm1.Output = "m"
   Case 2
   MSComm1.Output = "m"
   Case 3
   MSComm1.Output = "m"
   End Select
   shpLampuHijau(Index).BackColor = RGB(0, 50, 0)
End Sub
 

siawjf said:
Ermmm....Do u have any sample code??? I cant find it on9 and confuse some of the mscomm command on the VB6.0

u can try to use this code 1st:

Code:
Private Sub Form_Load()
    ' Fire Rx Event Every single Bytes
    MSComm1.RThreshold = 1
    
    ' When Inputting Data, Input 1 Byte at a time
    MSComm1.InputLen = 1
    
    ' 9600 Baud, No Parity, 8 Data Bits, 1 Stop Bit
    MSComm1.Settings = "9600,N,8,1"
    ' Disable DTR
    MSComm1.DTREnable = False
          
    ' Open COM3
    MSComm1.CommPort = 3 'im choosing to open port 3 on my pc, u can chage it
MSComm1.PortOpen = True
End Sub


Private Sub Command6_Click() 'push button
    
    MSComm1.Output = "a" 'based on what number/alphabetic u program inside ur PIC.

End Sub
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top