• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

VB serial data

Not open for further replies.


New Member
i have made a VB program as described

but silly me read the page and then realised at the bottom that they are programming a basic stampII

how do i carry out the same function with the pic?

i know i need to
- Read Data somehow
- Put Pin Number & State into W register
- Move to according pin

i could probably manage the last 2 points ...its just reading the data :?

how would you do this with a pic? (16F84A)

Thanks ((once again :p ))


Active Member
The Pic16F84 doesn't have a hardware serial port (USART) so you'll have to do it all in software. You've got 3 options.

Eighter get a pic 16F628 wich is almost identical to F84 but with more features like a hardware usart. (or even a 16F877 ) and go the easy way. Because receiving serial data with these chips is as simple a reading a register.

Or go the more difficult way and try to receive the serial data in software.
one of the tutorials on www.winpicprog.co.uk handles serial reception in software.

There's also the option of using Picbasic pro to create a basic program that you can put in a normal pic.


New Member
well i have a couple of sample 16F628's but the programmer i have you need to

"Pull the PGM pin to ground"

but on the datasheet it says "RB4/PGM" so does that mean pin RB4 needs connecting to ground?



Active Member
It should work without pulling PGM low. But some ppl have experienced problems with High voltage programming these devices while their Low voltage bit was enabled. Try without connecting PGM to GND first. If you have problems you could try pulling it to gnd. Once you programmed a 16F628 and you disable the Low voltage bit in the config word it should work without pulling pgm low


New Member
right well i now have the 16F628 (no grounding needed)

but ive searched and searched and cant seem to find anything about how to deal with the data which is sent from my visual basic program.

the VB program sends the data as
2400 baud, no parity, 8 data bits, 1 stop bit

and it also sends the character 255 (as a synchronous bit i think)

this is what it said in the article

From VB we will send an ASCII 255, as a synch byte, the pin number (0 to 15), and the on/off state (0 or 1). The microcontroller will wait for three (3) bytes of data. After these three bytes of data are received, it will then either switch the pins to their High or Low state.
but this is for a basic stamp as said above.

so how can i set up the 16F628 so that it recieves this pin information and sets the correct pins/bits?

the only examples i have found are a few source codes

but i just dont understand them!
i really need a tutorial
does anybody know of one? or could anybody be kind enough to describe how it would be done?

This was my overall aim of using the pic.. to control a robot from my PC. so once i have this figured out i should be done
Thanks Alot


New Member
Basic Stamps and PICS are pretty much the same thing.... if I remember correctly stamps carry a PIC in them.... the biggest difference is that PICs run faster because they store the programs in the PIC instead of a external memory like the stamp does. The code for prograimg a Stamp and the PICBASIC PRO comands are very close together.

They are sending a 255 only for your software pupose. You could send whatever you want. Serial transmition is dependent on that both devices use the same baudrate.

PICBasic Pro Serout comand uses 8N1 8-Bits of data, No parityand 1 stop bit. You have to make sure that this in fact are your settings in the VB program When you are talking about baudrates you are talking about asynchronous. No clock line needed..... the 255 you send asynchronously, for you to know that there is some right data.... say you want to send ABC, so for your program to start receiving you can do it so it starts looking for a 255 and then you know that ABC is coming along. Or you could just have the PC send ABC and in your software you just receive the ABC from the serial port without having to look for this ASCII(255)

If you are connecting you PIC straigth to the serial port without a voltage inverter like the MAX232 then you must receive and send in an Inverted mode. If you are using the MAX232 then you will have to receive in TRUE mode.

Hope it helps you some.



New Member
Or you could just have the PC send ABC and in your software you just receive the ABC from the serial port without having to look for this ASCII(255)
well if i do it that way so the ouput is just
MSComm1.Output = Chr$(PinNumber) & Chr$(PinState)
rather than sending the 255 ...how will the pic know when to start?
if it needs a 'high' signal then how will the vb program send this? or is it automatic in the settings
MSComm1.Settings = "9600,N,8,1"
cos that shows 1 stop bit....but what about the start bit?



New Member
You are going to have to check this out to get more inside info: http://www.beyondlogic.org/serial/serial.htm

In a nutshell.... serial comunication or RS232 sends 8-bits of data.... this data is refered to ASCII. There are 256 possible "characters" that you can send. Asynchronous RS232 transmition lack a clock line therefore the use of a timing must be done.... this is where the baudrates come in hand.... you set the baudrate on both devices so they can talk at the same speed.

Apart from the 8-bits of data serial transmition can include other "headers" and other stuff to make the transmtion more reliable. Among them there is Parity, Odd, Even, 1 stop bit, 2 stop bit, etc. The transmition line in the serial transmition is alway held "high", at the start of a transmition the first bit is always the "START" bit. This bit pulls the transmition line low. Then the data starts, after 8 bits, the parity is sent and the stop bits.

Now the serin command in the pic is a command that stalls the program and waits for incoming data to enter the specified pin. This is done by software..... you can see how is to your advantage having a hardware serial port in your PIC. Once the data you specefied arrives (say you specefied you are receiving 2 characters) then those characters are saved into the variables that you point. Those variables will always have a number betweeb 0-255..... so you define those variables as bytes.

If you want to assign a character received to a port, so that it turns on certain pins then you can do so. Say you want to turn on, all the pins in the PortB. You tell VB to send:

Mscomm1.ouput = chr(255)

You must now create a handshake type of deal.... where you can send to the PC a "START" variable so that the PC send you the data you want. Why? Beacuse if your PIC is not waiting for the data when you send it then the data will be lost. Another reason to have a hardware Serial Port.

Now once the PC sends you the 255 you receive it into a variable and set PortB iqual to that variable.....

Make sure that the properties on you MSCOMM1 are set to the port you have and to the right baudrate and to 8N1 (8 bits no parity 1 stop bit)

Not open for further replies.

EE World Online Articles