|
|
| Author |
Message |
lewtwo
Joined: 21 Oct 2007
Posts: 12
|
|
Posted: 30 November 2007, 21:26 PM Post subject: Const for Port |
|
|
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
 |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 30 November 2007, 22:35 PM Post subject: |
|
|
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: |
|
|
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: |
|
|
| 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: |
|
|
Thank you. Works perfect.
I will post the 8 bit LCD driver code later today. |
|
| Back to top |
|
 |
|