DIRS similar to PBASIC

Questions about the BASICtools and MakeItC
Post Reply
YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

DIRS similar to PBASIC

Post by YahooArchive »

Hello,

I am new to ARM7 (SuperPro-Pro+) and this version of Basic. I generally use
Microchip MCU's with PicBasic Pro. This Basic syntax is a bit different than
what I am familiar with. I would appreciate your help with an explanation on how
this code executes.....what does it do and how does it do it?
Best Regards,
Nick



SUB DIRS (x) ' similar to PBASIC keyword
DIM i AS INTEGER

FOR i = 0 to 15
DIR(i) = x and (1 << i)
NEXT i
END SUB

main:

DIRS (&H00FF) ' set pins 0 to 7 to output

FOR I=0 TO 7
WAIT (1000)
HIGH I ' set each pin HIGH one after the other every second
NEXT I



YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: DIRS similar to PBASIC

Post by YahooArchive »

ARMbasic uses a syntax more like VB (Visual BASIC), but also supports
the older GOSUB/GOTO style

So that could have been written ( a rough translation to PICBASIC, which
I don't use so forgive any errors)

' variables i and x are automatically defined on first use, which was
' part of the original BASIC which I learned back then, tough to break
' old habits, its the equivalent of
'VAR I WORD ' our words are 32 bits
'VAR X WORD

GOTO MAIN ' if there is a main this statement is implied
' otherwise code starts here

DIRS: ' we can do GOSUB
FOR i=0 to 15
DIR(i) = x and (1<

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: DIRS similar to PBASIC

Post by YahooArchive »

Thanks for the reply. I am still unclear what the sub routine in this example.
Why does main use 0 -7 and the sub routine uses 0-15.....?

Best regards, Nick

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: DIRS similar to PBASIC

Post by YahooArchive »

Actually main and DIRS: should use different variables. When you use GOSUB, all
variables are global in scope which means in the way I typed it DIRS: would
change the value of i which would be a bug for main:

This is one of the advantages of using SUB over GOSUB. The subroutines can have
local variables that can share names without affecting other variables with
similar names. Often times I will get used as a quick FOR I... in multiple
places in a program. You either have to be real careful with GOSUBs or you
start seeing

FOR I001 ...

and

FOR I002... or something like that

As for why 0-7 one place and 0-15 otherwise. This example was originally
written for the ARMexpress which only had 16 IOs. For the SuperPRO, that gets
expanded to multiple ports of 32 bits each, so it should be 0-31 in the SUB.

The comment in main states why its 0-7

' pass (&H00FF) in x ' set pins 0 to 7 to output

It was an arbitrary choice to have half the pins as outputs.

YahooArchive
Posts: 1462
Joined: Fri Oct 19, 2012 5:11 am

Re: DIRS similar to PBASIC

Post by YahooArchive »

OK, thanks!!! I was wondering if my logic was off or what. The points that
didn't make sense now do.

Best Regards,
Nick

Post Reply