Bit/Byte array for Hserin/Hserout

THE BOOK of DT's INTERRUPTS is an organization of interrupt service routines and other works written by Darrel Taylor, RIP.

Interrupt routines are arranged per Darrel's original list. Darrel Taylor's Instant Interrupts are an extension of the work of Tim Box whom in October of 2002 wrote INT_CTRL.pbp

Many of the forum members felt this is a long overdue project.

will be a valuable resource and a tribute to Darrel Taylor the "Fanatical Contributor".

THE BOOK of DT's INTERRUPTS is located at

+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2005

    Default Bit/Byte array for Hserin/Hserout


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

    Frame var byte[7]

    Hserout [str frame\7]
    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?

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


  2. #2
    Join Date
    Sep 2004
    montreal, canada

    Did you find this post helpful? Yes | No


    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

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Sep 2005

    Did you find this post helpful? Yes | No


    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.


  4. #4
    Join Date
    Oct 2004
    Hangover, Germany

    Did you find this post helpful? Yes | No


    the DEFINES have default-values, they work for the most hardware.

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

    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 ;-)
    PBP 2.50C, MCS+, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

  5. #5
    Join Date
    May 2006
    Del Rio, TX, USA

    Did you find this post helpful? Yes | No


    Quote Originally Posted by mrx23
    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]


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

  6. #6
    Join Date
    Sep 2005

    Did you find this post helpful? Yes | No


    Thanks now I understand clearly

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

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Simple Array Demo
    By Archangel in forum Code Examples
    Replies: 5
    Last Post: - 15th February 2010, 04:46
  3. WRITECODE stores wrong 14-bit word values in FlashMEM
    By BobPigford in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 26th June 2009, 04:35
  4. RS232 receive an array (packet)
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th February 2008, 05:02
  5. If Then Array Oddity
    By atillotson in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st July 2005, 17:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts