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.
Brain Fade? Reading 8 Bits of a Port to a Variable?
Moderators: David Barker, Jerry Messina
-
- Registered User
- Posts: 185
- Joined: Mon Mar 10, 2008 8:20 am
- Location: Seattle, WA USA
- Contact:
Re: Brain Fade? Reading 8 Bits of a Port to a Variable?
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
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
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
....
The best source of code for Swordfish basic is:Jon Chandler wrote: I couldn't find anything in the documentation to help.
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
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
Re: Brain Fade? Reading 8 Bits of a Port to a Variable?
Not to distract from what octal said, but
That's odd. When I tried that I got: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.
Code: Select all
dim A(20) as Byte
A(1) = PortB()
[Error] main.bas(3): Illegal use of parenthesis: PortB
-
- Registered User
- Posts: 185
- Joined: Mon Mar 10, 2008 8:20 am
- Location: Seattle, WA USA
- Contact:
Re: Brain Fade? Reading 8 Bits of a Port to a Variable?
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!
Rebooting solved everything. Thanks for the suggestions and sorry for the needless question!