I/O ports are mapped to registers. These registers are special purpose. In order to address them you have to use extended addressing (12 bit vs normal 8 bit).
Example: LD dest,src [becomes] LDX dest,src
Table 1. GPIO Port Registers and Subregisters | ||
Port register mnemonic | Port register description | |
PxADDR | Port A-H Address Register (r/w selects subregisters) | |
PxCTL | Port A-H Control Register (r/w to/from selected subregister) | |
PxIN | Port A-H Input Data Register (read-only) | |
PxOUT | Port A-H Output Data Register (r/w) | |
Subregister mnemonic | Port register description | |
00h | - | (No function) |
01h | PxDD | Data Direction |
02h | PxAF | Alternate Function |
03h | PxOC | Output Control (Open-Drain) |
04h | PxHDE | High-drive Enable |
05h | PxSMRE | Stop Mode Recovery Source Enable |
Selecting a subregister and writing to it:
ldx PBADDR, #01h ;Select subregister Data Direction ldx PBCTL, #03h ;Pin B0 and B1 are now inputs. The rest are outputs. 0=output, 1=input
Write to the output register:
ldx PBOUT, #04h ;Pin B2 is now HIGH. The other output pins are LOW
Read from input register
ldx R0,PBIN ;Load the content of the input register into working register R0.
Notice that you have to use extended addressing to be able to access these registers. They are not in range of standard 8 bit addressing.
In order to use the normal addressing mode you have to set up the Register Pointer using the SRP instruction. Make it point to the start of the block of 16 registers of the peripheral you want to control.
;This is optimized srp 0FDh ; Set register pointer to address 0FDh (2 execution cycles, 2 fetch, 2 bytes of memory) ld R8,#10h ; Set register 0FD8h to 10h (2 execution cycles, 2 fetch, 2 bytes of memory) ld R9,#EFh ; Set register 0FD9h to EFh (2 execution cycles, 2 fetch, 2 bytes of memory)
;This is NOT optimized ldx 0FD8h,#10h ; 2 execution cycles, 4 fetch and 4 bytes of memory ldx 0FD9h,#EFh ; 2 execution cycles, 4 fetch and 4 bytes of memory
Please submit corrections, suggestions, and new documentation here: Submit a ticket
← Return to Reference Index
This is not an official Zilog website. Zilog nor 8times8 are liable for any damage done to equipment. Tutorial and reference copyright ©8times8 Creative Commons CC-0 License (public domain.) This reference uses content from Zilog's technical datasheets. Fair use only. Datasheets copyright © 2013 Zilog®, Inc. Z8, Z8 Encore!, Z8 Encore! XP and Z8 Encore! MC are trademarks or registered trademarks of Zilog, Inc. Read Zilog's terms at zilog.com
Website design by Koen van Vliet. Hosted by sourceforge.net