User manual
498
mikoC PRO for dsPIC
MikroElektronika
// 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
}
void main() {
 ADPCFG = 0xFFFF; // Conî‚¿gure AN pins as digital
 InitMain(); // Perform main initialization
 value = 2048; // When program starts, DAC gives
 // the output in the mid-range
 while (1) { // Endless loop
 if ((RB0_bit) && (value < 4095)) { // If RB0 button is pressed
 value++; // increment value
 }
 else {
 if ((RB1_bit) && (value > 0)) { // If RB1 button is pressed
 value--; // decrement value
 }
 }
 DAC_Output(value); // Send value to DAC chip
 Delay_ms(1); // Slow down key repeat pace
 }
}
HW Connection
SPI HW connection










