1 |
#include <avr/io.h> |
1 |
#include <avr/io.h> |
2 |
#include "mcp4922.h" |
2 |
#include "mcp4922.h" |
3 |
#include "spi.h" |
3 |
#include "spi.h" |
4 |
|
4 |
|
5 |
|
5 |
|
6 |
void DAC_write(unsigned char data) { |
6 |
void DAC_write(unsigned char data) { |
7 |
unsigned char first, second; |
7 |
unsigned char first, second; |
8 |
first=(0b10110000 | data>>4); // DACB, unbuffered, 1x, ON, 12 data bites |
8 |
first=(0b10110000 | data>>4); // DACB, unbuffered, 1x, ON, 12 data bites |
9 |
second=(data<<4); |
9 |
second=(data<<4); |
10 |
|
10 |
|
11 |
DAC_CS_PORT &= ~(1 << DAC_CS_PIN); |
11 |
DAC_CS_PORT &= ~(1 << DAC_CS_PIN); |
12 |
SPI_MasterTransmit(first); |
12 |
SPI_MasterTransmit(first); |
13 |
SPI_MasterTransmit(second); |
13 |
SPI_MasterTransmit(second); |
14 |
DAC_CS_PORT |= 1 << DAC_CS_PIN; |
14 |
DAC_CS_PORT |= 1 << DAC_CS_PIN; |
15 |
} |
15 |
} |