Page 1 of 1

PORT command in Basic

Posted: Sat May 30, 2020 12:48 pm
by speedracer
I want to ask a question about the Basic command, PORT. I would like to read a 12-bit input on my EzSBC1 and print the result as a number. If I understand this command, I can set 12 pins to inputs (P0.0 to P0.11, say), execute x = PORT(0), and then AND the result with some appropriate number to get my result, yes? Only my attempts to do this result in odd results. Not the least of which is the number is a huge floating-point number.

The text in the Basic manual is, well, hard to comprehend. Not least is the difference in nomenclature. For example, what pin on the board is represented by P1.0 or P1.31? These don’t seem to correspond to board pins.

Can you enlighten me? How would I read 12 input pins as a ‘port’?

Re: PORT command in Basic

Posted: Sat May 30, 2020 1:15 pm
by Janke
Well, the PORT command gives you a 32-bit value, which should NOT be considered as a number - rather, each BIT in the value represents the state of one port.

So you need some binary operations ( &, |, and ^ ) to get the state of the port. See page 23-24 in the manual.

If you use AND and OR commands, you'te handling the value as a number - hence the floating point result.

The actual port numbers for the pins can be found in the schematic. Only pins 10 to 23 have the same number as in port P0.

I assume you have downloaded all documents? If not, they are available from the EzSBC website.

Best regards,

Janke (a user in Finland!)

Re: PORT command in Basic

Posted: Mon Jun 01, 2020 3:39 pm
by speedracer
Thanks for the tip to look at the schematic! I revised my test board and can now read input bits. The difficulty is finding which 12 bits will work best as there are some gaps and some dedicated port pins that I will have to work around. But I think I can accomplish what I need to.