Mikroelektronika MIKROE-724 データシート

ページ / 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
419
Expander_Init_Advanced
Prototype
sub  procedure  Expander_Init_Advanced(dim  byref  rstPort,  rstPin,  haen  as 
byte)p> 
Description Initializes Port Expander using SPI communication.
Parameters 
rstPort
: Port Expander’s reset port 
rstPin
: Port Expander’s reset pin 
haen
: Port Expander’s hardware address 
Returns
Nothing.
Requires
SPExpanderCS
: Chip Select line 
SPExpanderRST
: Reset line 
SPExpanderCS_Direction
: Direction of the Chip Select pin 
SPExpanderRST_Direction
: Direction of the Reset pin 
must be defined before using this function. 
SPI module needs to be initialized. See SPIx_Init and SPIx_Init_Advanced routines. 
Example
‘ Port Expander module connections
dim SPExpanderRST as sbit at LATF0_bit
    SPExpanderCS  as sbit at LATF1_bit
    SPExpanderRST_Direction as sbit at TRISF0_bit
    SPExpanderCS_Direction  as sbit at TRISF1_bit
‘ End Port Expander module connections
...
‘ If Port Expander Library uses SPI1 module
SPI1_Init()               ‘ initialize SPI module
Expander_Init_Advanced(PORTB, 0, 0) ‘ initialize Port Expander
Notes
None.
Expander_Read_Byte
Prototype
sub function Expander_Read_Byte(dim ModuleAddress, RegAddress as byte) as 
byte
Description The function reads byte from Port Expander.
Parameters 
ModuleAddress
: Port Expander hardware address, see schematic at the bottom of this page 
RegAddress
: Port Expander’s internal register address 
Returns
Byte read.
Requires
Port Expander must be initialized. See Expander_Init.
Example
‘ Read a byte from Port Expander’s register
dim read_data as byte
...
read_data = Expander_Read_Byte(0,1)
Notes
None.