PDA

View Full Version : Bit/Byte array for Hserin/Hserout



mrx23
- 31st August 2006, 14:44
Hi!

I need to send 64 pieces of bits from a PIC to second PIC via Hardware serial.
I tested some ways by Oshon sim:

-----------------
DEFINE HSER_BAUD 9600
Frame var byte[7]
frame[0]=%10110010
frame[1]=%10011001
frame[2]=%00011011
frame[3]=%00101011
frame[4]=%10110010
frame[5]=%10011001
frame[6]=%00011011
frame[7]=%00101011

Hserout [str frame\7]
End
-----------------
but the oshon receive characters, not binarys.
I tried Bin modifier like: Hserout [Bin{str frame\7}]
I couldnt complie.

I want to receive all 1s and all 0s (when example the last bit is only 1), and store in the second PIC in the same way.
Hserin [str frame/7]
How can I do this?

Can I set the values like this?

counter=0
while counter<>64 '63+1
frame.0(counter) = %0
counter=counter+1
wend

Thx

mister_e
- 1st September 2006, 01:42
how about simply trash every sim software on the market as they are useless and untrustable anyway? ok maybe those over few 10 or 100 thousand dollars.

Send your data to your PC...
HSEROUT [STR YourArray\8]
wooohoo it's working

Now, send from your PC to your PIC...
HSERIN [STR YourArray\8]
wohoo it works

guess what, when you'll do your PIC-to-PIC it will work.

BUT you did a mistake Frame var byte[7] must be 8. You defined from 0 to 7.. so 8 elements.

Also, maybe because you didn't copy them here but i don't see any DEFINE HSER_TXSTA and/or DEFINE HSER_RCSTA

good luck

mrx23
- 1st September 2006, 17:32
Sorry for using oshon:)
which is the best (and most expensive:) simulator for PIC?

I want to send 64 pieces of bits-> so its 8 bytes
I think its ok Frame var byte[7] because 0-7 8 pieces of bytes->8*8=64 bits.

Its worked without DEFINE HSER_TXSTA , I think it has a default value.

Thx

BigWumpus
- 1st September 2006, 22:14
Yes,
the DEFINES have default-values, they work for the most hardware.

But,
"Hserout [str frame\7]"
here you transfer seven Byte (0..6) which are NOT 64 Bits !!!!


But,
how do you receive this 56 Bits ?
HSERIN... placed this bits into Byte-Variables.
If you print them to a LCD, you get 7 charaters.
If you want to see 56 Bits (0 and 1), you have to use LCDOUT BIN frame[x]!

Just sit down and write on a sheet of paper, what you really want.
Then we will deliver the ready code ;-)

SteveB
- 1st September 2006, 22:17
I want to send 64 pieces of bits-> so its 8 bytes
I think its ok Frame var byte[7] because 0-7 8 pieces of bytes->8*8=64 bits.


Your not understanding how PBP sets up arrays. When you declare the array, the first element gets assinged an address in the pics RAM. When you access that array, PBP starts at the beginning address, then adds to that address the element number you are accessing.


Frame var byte[7]
OtherByte var Byte

Frame[0] = 1 ; Address = Frame + 0
Frame[1] = 2 ; Address = Frame + 1
Frame[2] = 3 ; Address = Frame + 2
Frame[3] = 4 ; Address = Frame + 3
Frame[4] = 5 ; Address = Frame + 4
Frame[5] = 6 ; Address = Frame + 5
Frame[6] = 7 ; Address = Frame + 6
;--------------------------------------
; Outside the Array
Frame[7] = 8 ; Address = Frame + 7
; which will also be = OtherByte
Here is how PBP actually output:

; Frame var byte[7]
_Frame EQU RAM_START + 018h
; OtherByte var Byte
_OtherByte EQU RAM_START + 01Fh

; frame[0] = 1 ; Address = Frame + 0 (18h)
MOVE?CB 001h, _Frame
; frame[1] = 2 ; Address = Frame + 1 (19h)
MOVE?CB 002h, _Frame + 00001h
; frame[2] = 3 ; Address = Frame + 2 (1Ah)
MOVE?CB 003h, _Frame + 00002h
; frame[3] = 4 ; Address = Frame + 3 (1Bh)
MOVE?CB 004h, _Frame + 00003h
; frame[4] = 5 ; Address = Frame + 4 (1Ch)
MOVE?CB 005h, _Frame + 00004h
; frame[5] = 6 ; Address = Frame + 5 (1Dh)
MOVE?CB 006h, _Frame + 00005h
; frame[6] = 7 ; Address = Frame + 6 (1Eh)
MOVE?CB 007h, _Frame + 00006h
; frame[7] = 8 ; Address = Frame + 7 (1Fh) which also = OtherByte
MOVE?CB 008h, _Frame + 00007h

When you assing a value (or read a value) to Frame[7], you are actually going to access a RAM address beyond the array. Not a big deal IF no other values have been assigned to that address. Not likely in any real program.

So yes, it works, sort of. It doesn't cause an error at compilation, but you will almost certianly get runtime errors from such a setup. Take Steve's (Mister_e, the other Steve ;)) advice, change your array declaration to:

Frame VAR BYTE[8]

Steve

EDIT: With arrays of WORDs, PBP just adds 2 to the starting address for each element that you are accessing.

mrx23
- 1st September 2006, 23:07
Thanks now I understand clearly

Frame VAR BYTE[8]
and Hserout [str frame\8] is the good for me:)