PDA

View Full Version : Leading 0's or BCD



RYTECH
- 27th December 2005, 02:01
let's say i have this command:

SEROUT serpout, N9600, "A",#RRECADD,"B",#RBITVALUE,"C","227","D"]

in which RRECADD and RBITVALUE are decimal byte variables which vary in length depending on if its like a 3 or a 255 in between the A - B etc.. ie. there are no leading 0's on the smaller values to "space out" the number of charecters in the string.


The thing is i think my pc side and it's parsing routines would benefit (our parsing wouldnt fail as much due to incomplete "packets" or packets in which two A's appear in the same received string) if we could limit the input to a fixed number of bytes to receive (which we can do using visual basics mscomm control using the OnComm / comEvReceive events and setting the MSComm1.InputLen to whatever our complete data packet is going to be) then our data to parse would be what we sent and (hopefully) no more or less. The project is trying to implement a 2 way communication via PIC's, PC, and it uses TWS-434 and RWS-434 modules to do so at (eek only) N1200 (ok no so bad it's pretty reliable)

The major problem is i cant count the length of my outgoing data string before i send it, i wanted to "fill" "packets" that were short charecters based on a subtracted total. But no length or LEN feature, so how to do this?

I'm even considering converting to BCD (binary coded decimal) to transmit (does seem like much of a solution considering i would be - i think - increasing the amount of transmission for the same amount of actual data). But BCD values would give the desired fixed length

I understand that this non byte array / buffer method of communication is "lossy" but i'm mostly interested in speed of data exchange (as close to real time as possible), data integrity is secondary, (its mostly reliable using this sort of "push" and "poll" method)

Darrel Taylor
- 27th December 2005, 11:54
Hi RYTECH,

Use a Fixed width DECimal modifier with SEROUT2.

SEROUT2 serpout, 16468, ["A",DEC3 RRECADD,"B",DEC3 RBITVALUE,"C","227","D"]
<br>

RYTECH
- 27th December 2005, 23:13
Yes, i've made the switch to serout2 and serin2,

why even have a "serout" and a "serin" they pretty useless, just add's to a newbies confusion.

Thanks for your reply, i might of still been pulling out my hair trying to figure this one out...lol

RYTECH
- 28th December 2005, 01:06
I'd like to be using the hardware serial ports on my pic's for my current project.

The current project is a PC to TRANSMITTER PIC out wireless to remote side which receives wireless and tranmits back to RECEIVER PIC and then to pc. I'm going to use 2 chips on both sides. Currently I dont believe that i'm utilizing the features of the 2 pic's im using (we'll actually soon to be 4) on the "PC side" im using 2 PIC16F767 chips, currently the remote side is just a single 16F84A @ 4mhz. i'm going to be using 2 P16F872's when i put 2 chips on that side...i know pin overkill, I probobly only require 1, but im trying to keep things as "real time" as possible, and 2 chips yeilded speed inprovements for "the system" so i accepted the method. I'm sure there's ways to do with 1 chip a side, if anybody would like to tell me this, while keeping the system close to "real time" i'd appreciate it. Any good howto's i havent read yet. I'm thinking of attaching my holtek encoders to the other pins on the tx and rx chips, adding tx and rx endoder / decoder and have a switching mode to use the pic to send signals and receive, or the encoders /decoders. I may build some "thing" that i want to have feeding into a holtek chip. I wonder how the pic and holtek chips will handle sharing the antenna's. Oh can i use my same antenna thats another big question to work out. currently the RWS-434's and the TWS-434's have their own antenna's. The TWS-434 apparently can operate without the antenna, but i keep em on anyways. It would be ideal, from a design perspective, if all the rx and tx systems on either side could have 1 antenna for tx rx.

And crystals... 20mhz seems to be what im using (except on the soon to be phased out 16F84A@4mhz). Can we do as Melanie had suggested and hook up the osc pins? ( http://www.picbasic.co.uk/forum/showthread.php?t=575 ) is there a schematic floating around with the exact configuration for the sake of clarity.

Hardware serial ports, how to use those... they'd likely be better that just using 2 pins assigned as the rx /tx and serin2 seriout2. I've got some reading to do.... :)