Page 1 of 1

Brain Fade? Reading 8 Bits of a Port to a Variable?

Posted: Fri Nov 18, 2016 4:50 am
by Jon Chandler
I'm trying to read the value of a port into a byte array. Seems like it should be simple, but my efforts last night didn't work.

What I tried was

A(1) = PortB()

This resulted in the compiler going off into never never land. No error was indicated but compiling didn't complete.

What I'm trying to do is sample the state of PortB as rapidly as possible and stuff the results into an array for later analysis. I couldn't find anything in the documentation to help.

Re: Brain Fade? Reading 8 Bits of a Port to a Variable?

Posted: Fri Nov 18, 2016 9:50 am
by octal
Hello Jon,
you don't need the parenthesis after PORTB, PORTB is a system variable defined in the header file of your device (PIC), you just read it as you read any BYTE variable

Code: Select all

dim a(20) as Byte

TRISB = $FF  ' make portb an input

a(1) = PORTB
a(2) = PORTB
....
Jon Chandler wrote: I couldn't find anything in the documentation to help.
The best source of code for Swordfish basic is:
1- the examples folder
2- the swordfish Library folder (All swordfish libraries are written in Swordfish BASIC and are opensource)
3- and the module codes provided on Swordfish website http://www.sfcompiler.co.uk/wiki/pmwiki ... er.Modules

Re: Brain Fade? Reading 8 Bits of a Port to a Variable?

Posted: Fri Nov 18, 2016 10:44 am
by Jerry Messina
Not to distract from what octal said, but
What I tried was
A(1) = PortB()
This resulted in the compiler going off into never never land. No error was indicated but compiling didn't complete.
That's odd. When I tried that I got:

Code: Select all

dim A(20) as Byte
A(1) = PortB()

[Error] main.bas(3): Illegal use of parenthesis: PortB

Re: Brain Fade? Reading 8 Bits of a Port to a Variable?

Posted: Sun Nov 20, 2016 1:10 am
by Jon Chandler
The more things I tried to make sense of this problem, the less sense everything made.

Rebooting solved everything. Thanks for the suggestions and sorry for the needless question!