User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
418
Expander_Init_Advanced
Prototype
procedure Expander_Init_Advanced(var rstPort : byte; rstPin : byte; haen :
byte);
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 dened before using this function.
SPI module needs to be initialized. See SPIx_Init and SPIx_Init_Advanced routines.
Example
// Port Expander module connections
sbit SPExpanderRST at LATF0_bit;
sbit SPExpanderCS at LATF1_bit;
sbit SPExpanderRST_Direction at TRISF0_bit;
sbit SPExpanderCS_Direction at TRISF1_bit;
// End Port Expander module connections
...
// If Port Expander Library uses SPI1 module
SPI1_Init(); // Initialize SPI1 module used with PortExpander
Expander_Init_Advanced(PORTB, 0, 0); // Initialize Port Expander
Notes None.
Expander_Read_Byte
Prototype
function Expander_Read_Byte(ModuleAddress, RegAddress : byte) : 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
var read_data : byte;
...
read_data := Expander_Read_Byte(0,1);
Notes None.