Mikroelektronika MIKROE-724 データシート

ページ / 726
474
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
  SPI1_Write(temp)                         ‘ Send high byte via SPI
  ‘ Send Low Byte
  temp = valueDAC                          ‘ Store valueDAC[7..0] to temp[7..0]
  SPI1_Write(temp)                         ‘ Send low byte via SPI
  Chip_Select = 1                          ‘ Deselect DAC chip
end sub
main:
  ADPCFG = 0xFFFF                          ‘ Configure AN pins as digital
  InitMain()                               ‘ Perform main initialization
  value = 2048                             ‘ When program starts, DAC gives
                                           ‘ the output in the mid-range
  InitMain()                               ‘ Perform main initialization
  value = 2048                             ‘ When program starts, DAC gives
                                           ‘   the output in the mid-range
  while ( TRUE )                           ‘ Endless loop
    if ((RB0_bit) and (value < 4095)) then ‘ If RB0 button is pressed
      Inc(value)                           ‘ increment value
    else
      if ((RB1_bit) and (value > 0)) then  ‘ If RB1 button is pressed
        Dec(value)                         ‘ decrement value
      end if
    end if
    DAC_Output(value)                      ‘ Send value to DAC chip
    Delay_ms(1)                            ‘ Slow down key repeat pace
  wend
HW Connection
SPI HW connection