Page 62 of 346 Start Back Next End ZBasic System Library 50 ZBasic Microcontrollers BusRead Type Subroutine Invocation BusRead(addr, data, count) BusRead(addr, data, count, delta) Parameter Method Type Description addr ByVal integral The bus address at which to begin reading. data ByRef anyType A buffer to receive the data read. count ByVal integral The number of bytes to read. delta ByVal integral The amount by which the address should be changed after each byte is read. Discussion For ZBasic devices that support external RAM (e.g. ZX-1281), if the external RAM interface is enabled and a bus has not been defined using DefineBus(), then the external RAM interface is used for the read operation. In this case, the full 16 bits of the specified address are used and the delta parameter is interpreted as a signed 8-bit value that is sign-extended before adding it to the address with each iteration. For ZBasic devices that do not support external RAM or if the external RAM interface is not enabled, this routine performs a series of read operations on the bus previously defined with the DefineBus() call. This is called the “bit bang” mode. For each read cycle, the low 8-bits of the address is output on the previously specified port and then the ALE pin is strobed (high, then back low). Next, the port is made an input and the RD pin is set low, data is read via the PIN register corresponding to the port, and the RD pin is set back high again. The data value read is stored in the buffer, the specified delta is added to the 8-bit bus address and the cycle is repeated until the specified number of bytes has been read. It is important to remember that in the bit bang mode only 8 bits of the address are used. Depending on the values of the addr, count and delta parameters, the effective address may wrap around to zero. For example, with delta=1 specifying a count parameter larger than (256 – LoByte(addr)) will result in the effective address wrapping around to zero. In either mode, if the optional delta parameter is not specified, the value of 1 is assumed. Specifying the delta as zero will result in multiple reads from the same address. A delta of –¹ or &Hff will result in the address being decremented after each read. Example Dim data(1 to 20) as Byte Call DefineBus(Port.A, C.0, C.1, C.2) Call BusRead(0, data, SizeOf(data)) Compatibility This subroutine is not available on ZX models that are based on the ATmega32 processor (e.g. the ZX- 24) nor is is available on ATxmega-based ZBasic devices. Moreover, it is not available in BasicX compatibility mode. See Also BusWrite, DefineBus