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

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jon Chandler
Registered User
Registered User
Posts: 185
Joined: Mon Mar 10, 2008 8:20 am
Location: Seattle, WA USA
Contact:

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

Post by Jon Chandler » Fri Nov 18, 2016 4:50 am

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.
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

User avatar
octal
Registered User
Registered User
Posts: 586
Joined: Thu Jan 11, 2007 12:49 pm
Location: Paris IDF
Contact:

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

Post by octal » Fri Nov 18, 2016 9:50 am

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

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

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

Post by Jerry Messina » Fri Nov 18, 2016 10:44 am

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

Jon Chandler
Registered User
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?

Post by Jon Chandler » Sun Nov 20, 2016 1:10 am

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!
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

Post Reply