PDA

View Full Version : 2 questions



Archangel
- 29th November 2006, 05:17
Hi Everyone,
I have 2 serial related data questions.
1.How, do I make PIC Basic Pro, interpret a string sent Serially from a P/C or another PIC as a command? Using Hserin and the variable called Char I tried something like this:

While char = value
PortA.1 = 1
wend

Question 2:
I hooked my serial backpack up to my P/C.
The backpack uses the hserin protocol in and the lcdout protocol to output data to the LCD. It is equipped with a max232 to interface with the P/C. When I send data to it from the P/C it prints strings of text on screen in this order, Line 1, line 3, line 2, line 4. it completely ignores the commands $FE, $C0 and so on, rather printing them onscreen as part or the text string, so in many ways this question is related to question 1. When I send the data to it from a PIC it properly formats the screen with the normal LCDOUT commands.
Thank You,
JS

HenrikOlsson
- 29th November 2006, 06:33
Hi Joe,
What software are you using send the data from the PC to the LCD? If it's a terminal program you need to figure out how to send the ASCII representation of $FE. You can't just type "$FE" because that will send the three characters $,F,E and not the LCD's "command identifier".

If you are using Hyperterminal it MAY work by doing this:
Hold down the left ALT key on you keyboard, then, on the numerical keyboard type 254 and let go of the ALT key. Then do the same but type 192 instead. This should be the same as sending $FE,$C0

If you're using the Serial communicator in MCS look for "Parse Control Characters" in the help file.

/Henrik Olsson.

Archangel
- 29th November 2006, 06:37
Hi Joe,
What software are you using send the data from the PC to the LCD? If it's a terminal program you need to figure out how to send the ASCII representation of $FE. You can't just type "$FE" because that will send the three characters $,F,E and not the LCD's "command identifier".

If you are using Hyperterminal it MAY work by doing this:
Hold down the left ALT key on you keyboard, then, on the numerical keyboard type 254 and let go of the ALT key. Then do the same but type 192 instead. This should be the same as sending $FE,$C0

If you're using the Serial communicator in MCS look for "Parse Control Characters" in the help file.

/Henrik Olsson.
Hi Henrik,
I am using something I found SOMEWHERE called serial sender, I was unable to get hyperterminal to work. Thanks, JS

HenrikOlsson
- 29th November 2006, 07:05
Hi,
I found SerialSender here:
http://www.seetron.com/vfdmnl/mnl.htm

If that is what you got it looks like this is the way to send ASCII:
Try typing <254><192>LCDTest and then hit Send.

/Henrik Olsson.

Archangel
- 29th November 2006, 07:25
Thanks Henrik,
that is the way!
JS

skimask
- 29th November 2006, 08:15
Joe,
Do you have VB5 or any sort of programming language for the PC? If not, I could probably whip you up a simple program this weekend to do those types of things for you with a click instead of all the extra characters, and just for the serial backpack type of thing.
Heck, I may just whip one up for myself anyways...might come in handy...
JDG

Archangel
- 29th November 2006, 08:57
Joe,
Do you have VB5 or any sort of programming language for the PC? If not, I could probably whip you up a simple program this weekend to do those types of things for you with a click instead of all the extra characters, and just for the serial backpack type of thing.
Heck, I may just whip one up for myself anyways...might come in handy...
JDG
Hi Skimask,
Actually I do have VB3, 4,5,6 - Aint eBay great ;) communicating with PIC through PC is something I just wanted to try, it works, good. I really need to find out how to communicate commands through the serial port, say toggle an LED on another PIC from serial port, either sent by PC or PIC., and it's late and I am going to bed, even later in SD huh?
Regards
JS

skimask
- 29th November 2006, 10:12
Hi Skimask,
Actually I do have VB3, 4,5,6 - Aint eBay great ;) communicating with PIC through PC is something I just wanted to try, it works, good. I really need to find out how to communicate commands through the serial port, say toggle an LED on another PIC from serial port, either sent by PC or PIC., and it's late and I am going to bed, even later in SD huh?
Regards
JS


It's about 4am right now. I gotta work at 6am, had to put the snowthrower on tractor tonight, big problems, kinks to work out, stuff got broken over the summer, blah blah blah. At least I got to break out the big tools, hammers, welders, etc.etc.

Anyways, communicating commands from the PC to the PIC....
You use JCP....that is Joe's Communications Protocol (or in my case Jeremy's Communications Protocol.
In my case, I usually use a 4 byte packet:
1st byte : $FF - leader byte, must be an $FF
2nd byte : data byte for function to be used
3rd byte : inverse of the data byte
4th byte : $FF - trailer byte, must be a $FF

For a bit of checking at the receiving end, the 2nd and 3rd byte must add up to $FF, and the 1st and 4th bytes must be $FF. When I'm using wireless, this will differentiate the end of the preamble for the modules (which are $55's) and the start of the packet.

So, I send a packet like:
$FF , $10, $E0, $FF
The receiver saves the last 4 bytes received (which I save by using a sort of shifting buffer, receive a byte, shift the rest over, receive another byte, shift the rest over, and so on).
If the 1st and 4th byte are $FF, the I check if the 2nd and 3rd add up to $FF. If all that is good, I do whatever is in the 2nd byte, and at the same time clear the last 4 bytes received in whatever variables I save them in. For example, in this case, $10 might turn on the LED on portb.0, $11 might turn it off. And so on, and so on.

That's the nice thing about JCP (or whatever you want to call it). Whatever you want, you make. In my case, if my leader and trailer are $FF, it's a one byte control (4 bytes per packet), if the leader/trailer are $FE, it's a 2 byte control packet (6 bytes per packet), and so on. It's always worked for me. The problem with this simple method is when I'm intermixing 4 byte and 6 byte packets in the same system. The fix for that is, just don't do it! Easy enough.
Just come up with a method that's easy for you to remember, that's the big thing. Maybe make the bits or characters in the packet match the pins of the PIC as you go around the PIC itself, something, anything....
JDG

Archangel
- 29th November 2006, 18:03
I will give that a try, <h3>yesiree, I sure will,YEP, I believe you are talkin' a couple of light years ahead of my experience level,</h3> what I think you are saying is send a string $FF, $10, $E0, $FF and receive it, then subtract $FF from it repeatedly to extract data which does not equal 0 after the subtraction process. I'm sure I can do this . . . a year from now :) Nevertheless . . the hardest part is figuring out what to do, then you can work out how!
JS

skimask
- 30th November 2006, 02:49
I will give that a try
JS


Well, that was just an example, limited info on what you really got going and a zillion different ways a guy could go about it all.
Let me know what you come up with. It's always interesting to see different methods of doing the same thing...
JDG

mister_e
- 30th November 2006, 03:45
Good ol' VB is still really easy to work with. Bruce have a short tutorial on that.
http://rentron.com/VisualBasic.htm

a piece of something to play around... posted here awhile back... when i had a good day :D
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=303&d=1117969258

skimask
- 30th November 2006, 14:39
I will give that a try, <h3>yesiree, I sure will,YEP, I believe you are talkin' a couple of light years ahead of my experience level,</h3> what I think you are saying is send a string $FF, $10, $E0, $FF and receive it, then subtract $FF from it repeatedly to extract data which does not equal 0 after the subtraction process. I'm sure I can do this . . . a year from now :) Nevertheless . . the hardest part is figuring out what to do, then you can work out how!
JS


Ya know, I think I got this posted confused with another that was talking about using RF modules.
If you're hardwired, then, heck, I wouldn't worry about all that packet stuff.

And from the sounds of it, it sounds like you've got a good handle on what to do and when to do it.
What are you trying to do anyways? What's the end result going to be?
JDG

Archangel
- 30th November 2006, 20:26
Hi Skimask,
I have no particular project at hand, I am trying to learn how to control a PIC via a serial connection, you know turn on some LEDs . . .
JS

skimask
- 1st December 2006, 02:47
Hi Skimask,
I have no particular project at hand, I am trying to learn how to control a PIC via a serial connection, you know turn on some LEDs . . .
JS


Well, heck, that should be simple enough for ya.
Set up the receiver PIC to read the serial port.
Receive an 'a', Portb.0 goes high, led goes on, echo back 'PB0=1' if you want,
receive a 'b', Portb.0 goes low, led goes off, echo back 'PB0=0',
get a 'c', portb.1 goes high, led goes on,
get a 'd', portb.1 goes low, led goes off....

And so on and so on.
It all goes back to JCP (remember Joe's Communications Protocol?). It's all about what you want to do. In the end, it doesn't matter what I or anybody else thinks....it's all about what you want.

So design the thing, write the firmware, and make it work!!!
The problem is, once you get that working, ideas start flooding forth, and then you start spending big money on pieces/parts... :)

JDG