Mikroelektronika MIKROE-724 データシート

ページ / 726
458
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
Soft_SPI_Write
Prototype
sub procedure Soft_SPI_Write(dim data_ as byte)
Description This routine sends one byte via the Software SPI bus.
Parameters 
sdata
: data to be sent. 
Returns
Nothing.
Requires
Soft SPI must be initialized before using this function. See Soft_SPI_Init.
Example
‘ Write a byte to the Soft SPI bus
Soft_SPI_Write($AA)
Notes
None
Library Example
This code demonstrates using library routines for Soft_SPI communication. Also, this example demonstrates working 
with Microchip’s MCP4921 12-bit D/A converter.
Copy Code To Clipboard 
program Soft_SPI
‘ DAC module connections
dim Chip_Select as sbit at LATF0_bit
    SoftSpi_CLK as sbit at LATF6_bit
    SoftSpi_SDI as sbit at RF2_bit
    SoftSpi_SDO as sbit at LATF3_bit
dim Chip_Select_Direction as sbit at TRISF0_bit
    SoftSpi_CLK_Direction as sbit at TRISF6_bit
    SoftSpi_SDI_Direction as sbit at TRISF2_bit
    SoftSpi_SDO_Direction as sbit at TRISF3_bit
‘ End DAC module connections
dim value as word
sub procedure InitMain()
  TRISB0_bit = 1                         ‘ Set RB0 pin as input
  TRISB1_bit = 1                         ‘ Set RB1 pin as input
  Chip_Select = 1                        ‘ Deselect DAC
  Chip_Select_Direction = 0              ‘ Set CS# pin as Output
  Soft_Spi_Init()                        ‘ Initialize Soft_SPI
end sub
‘ DAC increments (0..4095) --> output voltage (0..Vref)
sub procedure DAC_Output(dim valueDAC as word)
dim temp as byte volatile
  Chip_Select = 0                        ‘ Select DAC chip