Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   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
Const for Port

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



Joined: 21 Oct 2007
Posts: 12

Posted: 30 November 2007, 21:26 PM    Post subject: Const for Port Reply with quote

Is there a way to assign a constant to a port ?
Something along the lines of:

Private Const LCD_DATA as BYTE = PortA
or
Private Const LCD_DATA as PORT = PortA

Can pin number be assigned in a similar manner:
Private Const LCD_Enable as BYTE = B.1
or
Private Const LCD_Enable as PIN = B.1

Question
Back to top
dkinzer
Site Admin


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

Posted: 30 November 2007, 22:35 PM    Post subject: Reply with quote

Regarding ports, if you expect to access the entire port you can use the built-in register reference, e.g. Register.PortA. That reference is treated like a pre-defined variable that can be read or written. On the other hand, the built-in Port constants like Port.A, Port.B, etc. have the ordinal value of the referent port, A=0, B=1, etc. These values can be used at compile time or run time to compute a composite port/bit value (equivalent to a particular pin number) by using the built-in PortBit() function. Consider these examples:
Code:
b = GetPin(PortBit(Port.A, 7))
b = GetPin(12)
b = GetPin(A.7)

All of these do the same thing on a 24-pin ZX device.

Since the ZBasic compiler evaluates functions at compile time if it can, you can also define constants using System library functions, e.g.
Code:
Const myPort as Byte = Port.A
Const myBit as Byte = 7
Const myPin as Byte = PortBit(myPort, myBit)

b = GetPin(myPin)
Back to top
lewtwo



Joined: 21 Oct 2007
Posts: 12

Posted: 01 December 2007, 0:06 AM    Post subject: Reply with quote

Thank you.
I was using the register to move 8 bits at a time.

Register.PortA= ByteValue

Then when I did the board layout found out that Port C was more
more convenient. So I thought there must be some way to define
a constant at the top of the code for the Port rather than replacing
it everywhere.
Back to top
dkinzer
Site Admin


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

Posted: 01 December 2007, 2:19 AM    Post subject: Reply with quote

lewtwo wrote:
I thought there must be some way to define a constant[...]

You can, using either an Alias or a Based variable, like this:
Code:
Dim myRegister as Byte Based MemAddress(Register.PortA)
or
Code:
Dim myRegister as Byte Alias Register.PortA

With either definition, every read/write on the variable 'myRegister' actually operates on Register.PortA.


Last edited by dkinzer on 01 December 2007, 15:17 PM; edited 1 time in total
Back to top
lewtwo



Joined: 21 Oct 2007
Posts: 12

Posted: 01 December 2007, 15:02 PM    Post subject: Reply with quote

Thank you. Works perfect.
I will post the 8 bit LCD driver code later today.
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-2012 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