ZBasic Language Reference
63
ZX Microcontroller Family
Example
val = Register.Port(C.2)
' reads Register.PortC
Register.Port(C.2) = val
' writes to Register.PortC
addr = Register.Pin(A.4).DataAddress
' address of Register.PortA
These three special register variables will often be used in conjunction with the ZBasic System Library
function PortMask() which returns the bit mask for an I/O port corresponding to a specified pin.
Example
Const pin as Byte = C.7
Call SetBits(Register.DDR(pin), PortMask(pin), &Hff)
' make a pin an output
3.8.1 CPU Registers
ZX-24, ZX-40, and ZX-44 Registers
The pre-defined CPU registers for the ZX-24, ZX40 and ZX-44 match those available on the ATmega32
CPU and all are Byte values. Discussion of the use of these registers is beyond the scope of this
document. See the Atmel documentation for a full description. Also, be advised that modifying some of
these registers may severely alter the behavior of the control program, possibly even rendering it
inoperable.
The register value may be accessed by using the register name, from the table below, prefixed by the
keyword Register, e.g. Register.PortC.
CPU Registers for mega32-based ZX Models
ACSR
EECR
OCR1AL
PORTD
TCCR2
UBRRH
ADCH
EEDR
OCR1BH
SFIOR
TCNT0
UBRRL
ADCL
GICR
OCR1BL
SPCR
TCNT1H
UCSRA
ADCSRA
GIFR
OCR2
SPDR
TCNT1L
UCSRB
ADMUX
GIMSK
OSCCAL
SPH
TCNT2
UCSRC
ASSR
ICR1H
PINA
SPL
TIFR
UDR
DDRA
ICR1L
PINB
SPMCR
TIMSK
WDTCR
DDRB
MCUCR
PINC
SPSR
TWAR
DDRC
MCUSR
PIND
SREG
TWBR
DDRD
MCUCSR
PORTA
TCCR0
TWCR
EEARH
OCR0
PORTB
TCCR1A
TWDR
EEARL
OCR1AH
PORTC
TCCR1B
TWSR
Some CPU registers are 16-bit values that have register names in the table above corresponding to the
high and low bytes. For convenience of access, the following UnsignedInteger register names are
available. When reading and writing to these registers, the control program ensures that the high and low
bytes are accessed in the correct order as required by the CPU. Note that UBRR cannot be supported
because the high and low bytes are not adjacent in the I/O address space.
ADC
EEAR
ICR1
OCR1A
OCR1B
SP
TCNT1
Because the ZX microcontrollers are implemented using a more powerful CPU, some registers available
in BasicX dont actually exist on the ZX CPU but there are equivalent registers. For compatibility, both
the original register name and the actual register name are supported on similar ZX models. For new
applications, the new register names should be used.