PDA

View Full Version : Cleaner code



f_lez
- 22nd August 2006, 11:44
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.

Dave
- 22nd August 2006, 13:16
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

f_lez
- 23rd August 2006, 08:48
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!)