Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
ReadPin() return value

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
spamiam



Joined: 13 Nov 2005
Posts: 739

Posted: 24 September 2017, 11:52 AM    Post subject: ReadPin() return value Reply with quote

I am FINALLY, after a LONG hiatus getting back to a project. It is some software to interface to an IEEE-488 (GPIB) bus. As usual, It is MUCH MUCH easier to do development in ZBasic rather than C/Arduino.

In the documentation of PinRead() it says
Quote:
a non-zero return value indicates a logic high


Is this return value always a "1" or is it some other non-zero value from time to time? Under what circumstances might a high value be represented by something other than a "1"?

-Tony
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2991
Location: Portland, OR

Posted: 24 September 2017, 14:39 PM    Post subject: Re: ReadPin() return value Reply with quote

spamiam wrote:
Under what circumstances might a high value be represented by something other than a "1"?
The return value is produced by ANDing a mask value having but one bit asserted with the value obtained by reading the PIN register containing the specified pin. Consequently, the non-zero return value will equal the mask value.

This may be more clear by examining the code produced for this simple program:
Code:
Dim b as Byte

Sub Main()
    b = PinRead(C.4)
End Sub


Generated code:
Code:
static uint8_t mt2_zv_b;

void
zf_Main(void)
{
    mt2_zv_b = (PINC & 0x10);
}


If you need the value to be either zero or 1, use this:
Code:
b = IIF(PinRead(C.4)<>0,1,0)
Back to top
spamiam



Joined: 13 Nov 2005
Posts: 739

Posted: 24 September 2017, 19:20 PM    Post subject: Reply with quote

Thanks, Don.

It is not a problem. It is easy to use "<> 0" instead of "= 1". I do not know the assembly language options, but it may be faster to compare to zero than to a non-zero number where the non-zero argument number may need to be loaded into a register for comparison.

I will adjust my code accordingly.

In some cases the "<>0 comparison will work well. But other times, I will compare against a variable which will be High or Low, and the IIF() statement is does the job nicely.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2017 Elba Corp. All rights reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group