Mikroelektronika MIKROE-742 데이터 시트
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.
example demonstrates working with Microchip's MCP4921 12-bit D/A converter.
program Soft_SPI;
// DAC module connections
var Chip_Select : sbit at PORTB.B0;
var Chip_Select : sbit at PORTB.B0;
SoftSpi_CLK :
sbit at PORTB.B7;
SoftSpi_SDI :
sbit at PINB.B6; // Note: Input signal
SoftSpi_SDO :
sbit at PORTB.B5;
var Chip_Select_Direction : sbit at DDRB.B0;
SoftSpi_CLK_Direction :
sbit at DDRB.B7;
SoftSpi_SDI_Direction :
sbit at DDRB.B6;
SoftSpi_SDO_Direction :
sbit at DDRB.B5;
// End DAC module connections
var value : word;
procedure InitMain();
begin
DDA0 := 0; // Set PA0 pin as input
DDA1 := 0; // Set PA1 pin as input
DDA1 := 0; // Set PA1 pin as input
Chip_Select := 1; // Deselect DAC
Chip_Select_Direction := 1; // Set CS# pin as Output
Soft_SPI_Init(); // Initialize Soft_SPI
end;
// DAC increments (0..4095) --> output voltage (0..Vref)
procedure DAC_Output( valueDAC : word);
var temp : byte;
procedure DAC_Output( valueDAC : word);
var temp : byte;
begin
Chip_Select := 0; // Select DAC chip
// Send High Byte
temp := word(valueDAC
shr 8) and 0x0F; // Store valueDAC[11..8] to
temp[3..0]
temp := temp
or 0x30; // Define DAC setting, see
MCP4921 datasheet
Soft_SPI_Write(temp); // Send high byte via Soft SPI
// Send Low Byte
temp := valueDAC; // Store valueDAC[7..0] to temp[7..0]
Soft_SPI_Write(temp); // Send low byte via Soft SPI
Chip_Select := 1; // Deselect DAC chip
end;
362
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroPASCAL PRO for AVR
CHAPTER 6