Array -- something wrong?


Closed Thread
Results 1 to 24 of 24
  1. #1

    Default Array -- something wrong?

    For the life of me, I can't figure out what is wrong with this code. This is just the start of a program where I check all the bytes in the serial port (DATAIN) --
    if the total = 0 then it just loops and an LED is off.

    If any of the bytes contain data (a 1 or greater) then the LED is on. Then, eventually on to do other stuff.

    Maybe it's the way I set up the array as I've never used one in picbasic before.

    The pause is in there so I can see the LED. Thanks for any help.


    DATAIN VAR BYTE[13]
    ADDUP VAR BYTE
    TOTAL VAR BYTE

    QUAL1 VAR BYTE
    QUAL2 VAR BYTE

    DATAIN= 0
    TOTAL = 0
    ADDUP = 0

    QUAL1 = 170
    QUAL2 = 255

    START:


    SerIn PORTA.0,N1200,[QUAL1,QUAL2],DATAIN

    FOR TOTAL = 1 TO 13
    ADDUP = ADDUP + DATAIN[TOTAL]
    NEXT TOTAL

    IF ADDUP = 0 THEN
    LOW PORTA.1 'DATA RECEIVED LED OFF
    GOTO START
    ENDIF

    IF ADDUP >= 1 THEN
    HIGH PORTA.1 'DATA RECEIVED LED ON
    ENDIF

    PAUSE 3000

    ADDUP = 0
    TOTAL = 0
    DATAIN = 0

    GOTO START

  2. #2
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    For a 13 element array it should be 0 to 12
    Keith

    www.diyha.co.uk
    www.kat5.tv

  3. #3


    Did you find this post helpful? Yes | No

    Default

    right after I posted I went to lay down -- and realized I put a one in there for some odd reason.

    thanks.

  4. #4


    Did you find this post helpful? Yes | No

    Default

    oh well -- thought that was it myself but still no go -- yet I know my data is there on the serial port.

    on the PC end (using VBnet), I have my 2 qualifiers 170 and 255 then 13 bytes being sent. everything fine N1200, port etc.

    changed the PIC to --

    DATAIN[13]

    and (FOR 1 TO 12).

    still nothing?

  5. #5
    Join Date
    Feb 2003
    Posts
    432


    Did you find this post helpful? Yes | No

    Default

    What chip are you using ?

    does it have analogue ports ?
    Keith

    www.diyha.co.uk
    www.kat5.tv

  6. #6


    Did you find this post helpful? Yes | No

    Default

    16c72 (old timer)

    but I did ADCON1 = 7

    that changes porta to digital, right?

  7. #7


    Did you find this post helpful? Yes | No

    Default

    I see I did it again in my reply (for 1 to 12)

    trust me -- it's for 0 to 12

    jeeez

  8. #8


    Did you find this post helpful? Yes | No

    Default

    Michael, I'm no expert but some of your references to DATAIN include brackets and an array element identifier after them, others don't.
    In the serin command does picbasic know to put the received data byte into sequential bytes of the datain array, or should yo be putting that command in a loop and incrementing the array pointer with every pass through ?

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Chris --

    I've never used array either in picbasic anyway.

    You're probably right -- there has to be more to the serin code than what I have shown. ? But all I see with SERIN in the books is how I have it set up.

    I do get some action if I use separate byte variables rather than an array --

    like [QUAL1,QUAL2],b0,b1,b2,b3,b4 etc

    but I really want to use an array -- and to learn how as well.

    Everything is setup fine on the breadboard -- I see the data with my scope etc.

    Maybe someone can point to the problem, in the mean time I need to study some more on it.

  10. #10
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Look at SERIN2.
    Dave
    Always wear safety glasses while programming.

  11. #11


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Michael View Post
    Chris --

    You're probably right -- there has to be more to the serin code than what I have shown. ? But all I see with SERIN in the books is how I have it set up.

    .
    Working with the condition that you know you will receive 13 bytes of data in advance

    For Bytes = 0 to 12
    SerIn PORTA.0,N1200,[QUAL1,QUAL2],DATAIN[Bytes]
    Next

    Does the SerIn command also have a timeout which is similar to how I remember Hserin working, IE if no data is received for a predefined period the command makes a jump to another label in order to escape the loop.

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Ok -- I'll try that -- I would have thought it would automatically load all the bytes you declare in the array.

    Whatever -- I'll try it. thanks.

  13. #13


    Did you find this post helpful? Yes | No

    Default

    still no luck -- 2 days on this.

    I think "STR" needs to be in there somewhere but as always the PBP manual is extremely vague and can't google much on it.

  14. #14
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Did you see post #10 ?
    Dave
    Always wear safety glasses while programming.

  15. #15


    Did you find this post helpful? Yes | No

    Default

    yeah but?

    I looked at SERIN2 in the PBP manual, don't know what you're getting at.

    I may just forget the array idea -- went back to 13 bytes in a row and now that isn't even cooking.

    Trying to fiddle with the timeout to see if that's it -- but once again, reading the PBP manual on certain subjects is fruitless.

    For example, they say there is an optional timeout and say it's in milliseconds -- AND THAT'S IT.

    No examples -- no info about "default timeouts" -- I've said it before, it's the worst manual I've ever had.

    By the way, my other SERIN projects work great (even ones I've interfaced to the PC with VBnet).

  16. #16
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    From the manual... SERIN2 part
    STR followed by a byte array variable, count and optional ending character will receive a string of characters. The string length is determined by the count or when the optional character is encountered in the input.
    Dave
    Always wear safety glasses while programming.

  17. #17


    Did you find this post helpful? Yes | No

    Default

    I'll try it out.

    Went back to 13 bytes b1 thru b13

    serin porta.0,n1200 [qual1,qual2],b1,b2, -- b13

    which can be done, right?

    even added a long timeout.

    n1200,1000,start [qual1 etc

    but having problems with it too.

    I'm just testing each byte for the right number 1,2,4,8,16 etc

    even tried t1200 and pullups and pulldowns -- 22k and no resistor.

    I'll get it.

  18. #18
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Dave, we must agree with Michael, the PBP manual is not realy a masterpiece.

    So I think we should give him some help:


    START:
    SerIn2 PORTA.0,17197,500, START,[WAIT(QUAL1,QUAL2),STR DATAIN\13]


    The above is the line code you must use with serin2 command.

    17197 comes from 813 for 1200 bauds, plus 16384 (bit 14 set because inverted)

    500 are the milliseconds serin2 will wait for data before to timeout to START

    WAIT() will wait for the qualifier sequence before acquiring data

    Str array_name \ 13 is the command to collect 13 bytes in your 13 byte array

    Try it should work.

    Tray to read again,(more carefully) the manual (pag 132-136) very likely you will find it more clear now.

    Al.
    Last edited by aratti; - 26th March 2010 at 17:13.
    All progress began with an idea

  19. #19
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post
    Dave, we must agree with Michael, the PBP manual is not realy a masterpiece.

    So I think we should give him some help:
    You are correct.
    Sorry Michael.
    Dave
    Always wear safety glasses while programming.

  20. #20
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by aratti View Post

    START:
    SerIn2 PORTA.0,17197,500, START,[WAIT(QUAL1,QUAL2),STR DATAIN\13]


    The above is the line code you must use with serin2 command.

    17197 comes from 813 for 1200 bauds, plus 16384 (bit 14 set because inverted)

    500 are the milliseconds serin2 will wait for data before to timeout to START

    WAIT() will wait for the qualifier sequence before acquiring data

    Str array_name \ 13 is the command to collect 13 bytes in your 13 byte array

    Try it should work.

    Try to read again, (more carefully) the manual (pages 132-136) very likely you will find it more clear now.

    Al.
    Short and sweet, very elegant explanation Al, thanks !
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  21. #21


    Did you find this post helpful? Yes | No

    Default

    Great -- I always hate to end up getting code written for me (and I usually don't) but the manual does have problems with being vague.

    More code examples would be nice.

    Oh well, at least this is added to forum "array" search.

    Crystal clear now.

    At first, I just saw SERIN2 as "basic stamp" friendly and ignored it -- after all, I've never even touched a stamp so why should I care?

    Yet the manual sells it that way right up front.

    Thanks kindly.

  22. #22
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    At first, I just saw SERIN2 as "basic stamp" friendly and ignored it
    SERIN = Basic Stamp 1
    SERIN2 = Basic Stamp 2

    So you should have ignored both.
    Dave
    Always wear safety glasses while programming.

  23. #23


    Did you find this post helpful? Yes | No

    Default

    been ill all week and haven't tried this out yet before I burn a chip, do I also need to add DEFINE SER2_BITS 8 ?

    Or does it default to that?

    Good thing all those mode codes are on melabs site ot that would have been my next question.

  24. #24
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Default is
    8 N 1
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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