Cleaner code


Closed Thread
Results 1 to 3 of 3

Thread: Cleaner code

  1. #1

    Default Cleaner code

    Can I make this cleaner? (works but its orrible!)

    z=1:y=1

    loop:

    SERIN portb.7,t1200,1000,timeout,combuf(z)

    z=z+1

    if z<87 then no_time_out

    timeout:
    y=0 ' flag that a timeout has occured IE end of data stream

    no_time_out:

    if y>0 then loop





    What would be better is

    for z=1 to 90

    SERIN portb.7,t1200,1000,timeout,combuf(z)

    next

    BUT the problem is I dont want to timeout 89 times if only 10 bytes is in the stream.



    Is their no command to read the serial into the byte array without looping, I'm worried it may not be fast enough if running a 4mhz crystal, I have lowered incoming data to 1200 but its then a bit slow, I'm shocked my dirty code kept up.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    f_lez, Why don't you use the STR modifier and if you know the data stream will be terminated with a constant character like a CR or LF then use one of them as a string terminator. That way you can terminate the string load early if lass data is entered. It's in the book......

    Dave Purola,
    N8NTA

  3. #3


    Did you find this post helpful? Yes | No

    Default

    STR ? never heard of it !



    But I have changed the code some, I was worried that if I did something like this



    for n=1 to 10:serin wanted data(n):next
    for n=1 to 10:serin garbage data(n):next
    for n=1 to 10:serin wanted data(n):next

    I thought I may miss a byte between statements, but I'm not, I suppose I'm just lucky or the codes just fast enough to keep up at 1200 baud.

    I guess I should have used the skip command but once again I cant seem to win the battle of the syntax when also using the wait command, can they not be used in the same instance?(anyone!)

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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