Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 30th July 2007, 10:43 PM   (permalink)
Default Visual Basic 6 to PIC MCU (HOW TO)

Hey,

I'd like to write a Visual Basic 6 program that can send information to a PIC and receive information from the PIC.

We are talkin as simple as possible here... bare minimum.. once I am able to make connection .. the possibilities are endless.

I would use the MAX 232 chip.. Dont know exactly how to use the chip though..

Dont know what API Id use with VB6 either..

Any links or code would be very much appreciated.

Thanks
__________________
"Stick around" - Arnold Schwarzenegger in The Predator after impaling a soldier to a wood post

9vDC Guitar Pedal PSU

PIC16F84a Game Module
Peter_wadley is offline   Reply With Quote
Old 30th July 2007, 11:46 PM   (permalink)
Default

Goto Nigels site, or a similar one, for the PIC side of things:
http://www.winpicprog.co.uk/pic_tutorial7.htm
Then use HyperTerminal to check out your PIC project before writing your own 232 routines in VB6. As for VB6, it's not my area of expertise, but I'm sure there are built in routines for acessing the serial ports. Search the help files for COM PORT. A quick Google turned up this:
http://www.thaiio.com/prog-cgi/0002_serial.htm
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline   Reply With Quote
Old 31st July 2007, 01:00 AM   (permalink)
Default

You can use MSCOMM ActiveX control for RS232 communications.

Place one MSCOMM control named MSComm1 and two Textboxes named txtTx and txtRx on a form. Paste the following lines in the forms code.

txtRX will display all the characters received from serial port and whatever you type in txtTX will be sent to your PIC.

Code:
Private Sub Form_Load()
	With MSComm1
		.Settings = "9600,n,8,1"	' Baud=9600, Parity=None, Data-Bits=8, Stop-Bits=1
		.CommPort = 1			' COM1
		.PortOpen = True		' Open the port
	End With
End Sub

Private Sub Form_Unload()
	If MSComm1.PortOpen = True then MSComm1.PortOpen = False
End Sub

Private Sub MSComm1_OnComm()
	If MSComm1.CommEvent = comEvReceive Then
		txtRX.Text = txtRX.Text & MSComm1.Input
	End If
End Sub

Private Sub txtTX_KeyPress(KeyAscii As Integer)
	Mscomm1.Output = Chr(KeyAscii)
End Sub
Feel free to ask if you need any more help.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline   Reply With Quote
Old 31st July 2007, 04:04 AM   (permalink)
Default

Hey,

So is the MAXIM 232 the best chip to use? How would I hook it up?

Ive set up VB6 as you've stated.

So If I were to type 'ABC' into the textbox..

Would the PIC recieve:

100 0001 for A
100 0010 for B
and
100 0011 for C ?
__________________
"Stick around" - Arnold Schwarzenegger in The Predator after impaling a soldier to a wood post

9vDC Guitar Pedal PSU

PIC16F84a Game Module
Peter_wadley is offline   Reply With Quote
Old 31st July 2007, 04:22 AM   (permalink)
Default

Quote:
So is the MAXIM 232 the best chip to use? How would I hook it up?
Like this:
http://www.winpicprog.co.uk/pic_tuto...s232_board.htm
As the whether it is the best, that is a matter of opinion. The MAX232A uses smaller capacitors but if you have a MAX232 in the junk box, then you can't beat the price.
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline   Reply With Quote
Old 31st July 2007, 04:31 AM   (permalink)
Default

Here's a link to the cap free MAX233 and some additional info
http://www.compsys1.com/workbench/On...3_adapter.html

I've also found RealTerm recently, looks like a nice open source terminal and oddly has some I2C and 1wire (iButton) support
http://realterm.sourceforge.net/
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com

Last edited by blueroomelectronics; 31st July 2007 at 04:42 AM.
blueroomelectronics is online now   Reply With Quote
Old 31st July 2007, 06:58 AM   (permalink)
Default

Quote:
Originally Posted by Peter_wadley
Hey,

So is the MAXIM 232 the best chip to use? How would I hook it up?

Ive set up VB6 as you've stated.

So If I were to type 'ABC' into the textbox..

Would the PIC recieve:

100 0001 for A
100 0010 for B
and
100 0011 for C ?
hi Peter,
Assuming you set the VB RS232 comms for say, 9600,n,8,1 [baud rate 9600, no parity, 8 bit data, 1 stop bit]

The bit stream for the "A" character would be
1 Start bit
8 data bits ,,,, ASCII "A" is 0x41 == 01000001
1 Stop bit

ASCII "B" is 0x41,,, "C" is 0x42

You may, on some strings to a terminal also have to send the code for CRLF [carriage return line, line feed]
after the ie: "ABC" 0x0D, 0x0A

This depends upon the program in the receiving PC, some programs look for the CRLF in the string as a line terminator.

Use the ON COMM event in VB, there are examples in the online help files within the VB program.
Use the error trapping routines shown in the help files.

The MAX232 has 2 line drivers[transmitters] and 2 line receivers,
usually you just use one transmitter on the TXD output from the PIC to PC
and one line receiver to the RXD input of the PIC from the PC.

Eric
ericgibbs is offline   Reply With Quote
Old 31st July 2007, 01:31 PM   (permalink)
Default

Quote:
Originally Posted by Peter_wadley
Hey,

So is the MAXIM 232 the best chip to use? How would I hook it up?

Ive set up VB6 as you've stated.

So If I were to type 'ABC' into the textbox..

Would the PIC recieve:

100 0001 for A
100 0010 for B
and
100 0011 for C ?
Yes, the PIC will receive whatever you type in txtTx. You'll get 0x41 for A, 0x42 for B and 0x43 for C. The start and stop bits are filtered off by the PICs UART module and you need not worry about that.
I forgot to mention, set the Multiline property of txtRx to True.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline   Reply With Quote
Old 31st July 2007, 02:05 PM   (permalink)
Default

if you will also be sending numerical data, remember mscomm sends ascii codes a byte at a time, so you could use chr$(n) where n is a byte of data to send.
this may be obvious, but shift work can make you a bit dense at times!
monkeybiter is offline   Reply With Quote
Old 31st July 2007, 02:08 PM   (permalink)
Default

Quote:
Originally Posted by monkeybiter
if you will also be sending numerical data, remember mscomm sends ascii codes a byte at a time, so you could use chr$(n) where n is a byte of data to send.
this may be obvious, but shift work can make you a bit dense at times!
My code already does that
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline   Reply With Quote
Old 31st July 2007, 02:45 PM   (permalink)
Default

if i want to send 8 then i have to output chr$(8). your code won't do that.
what i meant was sending numeric data from the pc, rather than echoing keypresses. perhaps i should have been more specific.
monkeybiter is offline   Reply With Quote
Old 31st July 2007, 02:48 PM   (permalink)
Default

Quote:
Originally Posted by monkeybiter
if i want to send 8 then i have to output chr$(8). your code won't do that.
what i meant was sending numeric data from the pc, rather than echoing keypresses. perhaps i should have been more specific.
Oh.. I got it. You are right. My mistake.
__________________
"There is no way to peace, peace is the way!"
kinjalgp is offline   Reply With Quote
Old 31st July 2007, 07:44 PM   (permalink)
Default

Ok,

So ive got the max 232 set up as Nigels has..

The program like kinjalgp, THANK YOU!

So..

Is PIN 9 on the MAX the TX

and

PIN 10 is the RX?

When I type in the TX box pin 10 drops about . 05 V.. so Im assuming that its the TX..

Im going to now try to program a 16f84a.. all i have right now.. so that it will talk to VB..

Can someone explain the purpose of the CAPS on the 232?

If this works out I think Im going going to have to automate my entire home

Basically, from what i understand.. is when I type a character..

The first bit, which lasts 104us is a 0.

This will get the pic into the INT or subroutine..

Then I will capture and place each bit into a variable..

then the stop bit will be a 1..

I would I send.. say an A to VB?

Sorry if this post is jumbled Im in a hurry..

Hope someone can answers these questions!

Thank you!
__________________
"Stick around" - Arnold Schwarzenegger in The Predator after impaling a soldier to a wood post

9vDC Guitar Pedal PSU

PIC16F84a Game Module
Peter_wadley is offline   Reply With Quote
Old 31st July 2007, 08:48 PM   (permalink)
Default

Quote:
Originally Posted by Peter_wadley
Can someone explain the purpose of the CAPS on the 232?
The MAX232 have internal charge pumps that convert TTL levels to true RS232 levels. The capacitors are required by the charge pumps to generate those voltages.

For the pin layout, check the datasheet. The figures can help you better understand the configuration of the receivers and transmitters.
eng1 is offline   Reply With Quote
Old 1st August 2007, 01:39 AM   (permalink)
Default

hmm..

well ive gotten key presses in the TX box to trigger the MICRO..

I cant seem to get the MICRO to send characters to the RX txt box.

I think it might be the caps im using for the 232.. I dont have 10uf caps so I exchanged with 4.7uf.. could this be the problem?

When I send the byte out the voltage on the TX (RS232) line is changing.. so it is doing something.. VB isnt displaying the characters though..

will keep trouble shooting.
__________________
"Stick around" - Arnold Schwarzenegger in The Predator after impaling a soldier to a wood post

9vDC Guitar Pedal PSU

PIC16F84a Game Module
Peter_wadley is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Visual Basic for Electronics Engineering Applications ThermalRunaway Electronic Books 22 27th August 2008 07:40 PM
Serial Communication Interrupt in PIC Basic Pro TheMaccabee Robotics Chat 5 12th April 2007 07:52 AM
K8055 USB Interface Visual Basic Help Sudonon General Electronics Chat 6 11th September 2006 12:24 AM
visual basic program for parallel port interface group_x3m Micro Controllers 5 26th May 2006 01:48 AM
Newcomers, please read! (PIC regarded) Upd. 0xD Jay.slovak Micro Controllers 0 17th April 2005 01:04 PM



All times are GMT. The time now is 12:27 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.