"On" instruction help please

bobladell

New Member
Happy Xmas all

I'm using the "on" instruction to parse the first 32 control characters of the ASCII code table = 0x00 to 0x31 :-

On DataIn goto TD,MS,MS,MS,MS,MS,MS,MS,OP,OP,OP,OP,OP,OP,Sft,DCG,WCG,WS,WClkM,LEDCl,HWC,L1,L2,L3,L4,Hm,CS,MS,MS,MS,MS,MS

Everything works fine, going to the right subroutine, down to L2 ( where L1 and L2 are code to set Line 1 and line 2 on a 20 x 4 OLED - using hex codes 0x15 and 0x16). However, if I then send the L3 and L4 codes, 0x17 and 18 the re-direction is only to L2.

I have tested the coding and 20 x 4 OLED addressing separately so there's no problem with the subroutine code of addressing the OLED - it overcomes the usual OED 1,3,2,4 line addressing to make life easier. The changes from the AXE133Y type command structure of 254, 192 etc are because I'm running over infra red which only runs on 7 bit data. Using the ASCII command codes makes obvious sense whilst maintaining AXE1xx compatibility for e.g. the display time code of 0x00 and the writable messages 1 to 7 - which are all parsed and display correctly.

Questions
1 Reading the forum there is reference to a coding line being "too long" but I can't find a definition of the maximum permitted length for a line of code. Anyone point me to that definition please ? I have just reduced all my labels to (mostly) 2 characters to reduce the line length to the above but still get the same result. PE 6.08.6 doesn't flag any errors.

2 Anyone know of any limitations in the "on" command ? Manual 2 says it can handle :-
Syntax:
ON offset GOTO address0,address1...addressN
- Offset is a variable/constant which specifies which Address# to use (0-N).

Where N is apparently infinite - but this is a simple 8 bit cpu so there must be a practical limit to N. Anyone know what Nmax is please ?

Any suggestions while avoiding the washing up most welcome :)

Bob
 

lbenson

Senior Member
How does this work?
Code:
if DataIn = 0 then
  goto TD
elseif DataIn < 8 or DataIn > 26 then
  goto MS
else
  DataIn = DataIn - 8
  On DataIn goto OP,OP,OP,OP,OP,OP,Sft,DCG, WCG,WS,WClkM,LEDCl,HWC,L1,L2,L3,L4,Hm,CS
endif
 

bobladell

New Member
&quot;On&quot; instruction OK

Hi

Many thanks - your code works a treat.

I've now debugged my code - I'd left a bit of debugging code in the sender yesterday which was overriding the 23 and 24 codes. Late syndrome !

Plus - the TD code invokes the writing of the time generated by a Soft RTC in the display, using the "time" instruction, which was taking ages and so missing the next code to go to the next line, code 23. Increasing that to 200mS (at 32MHz) sorted that out too - so 2 coding errors causing the confusion.

So this also works :-

On DataIn goto TD,MS,MS,MS,MS,MS,MS,MS,OP,OP,OP,OP,OP,OP,Sft,DCG,WCG,WS,WClkM,LEDCl,HWC,L1,L2,L3,L4,Hm,CS,MS,MS,MS,MS,MS

Prefer the above as it is a single instruction so should be faster execution.

Splitting the parsing like this also works :-

if DataIn <16 then
On DataIn goto TD,MS,MS,MS,MS,MS,MS,MS,OP,OP,OP,OP,OP,OP,Sft,DCG
else
DataIn = DataIn - 16
On DataIn goto WCG,WS,WClkM,LEDCl,HWC,L1,L2,L3,L4,Hm,CS,MS,MS,MS,MS,MS
endif

So answer to my question 1 is that the "on" instruction can handle at least 32 jumps to labels. Still none the wiser re Q2 and maximum coding line length.

Thanks again for your reply and working code.

Bob
 

lbenson

Senior Member
Glad it's working.

I thought splitting the line up might provide some clues as to whether the problem was with the line itself, or elsewhere.

Are you saying that the original line now works?

I tried this, using gosub instead of goto. It worked for up to 253 addresses in the "on b4 gosub ... " line, saying memory used was 1428 out of 4096 bytes. Any more than 253 and it said "Program far too long".
Code:
  for b4 = 0 to 253
     on b4 gosub z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z,z
  next b4
  sertxd(cr,lf)
  end
  
z:
  sertxd(#b4," ")
  return
The program ran successfully in the simulator, printing the numbers 0 through 253.
 
Top