Here's a somewhat simple library for the TLC7528 DAC.
I know, I know, the DAC is very simple to use, but I hope someone will make good (or evil) use of it...
/* Copyright David Gustafik, 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description: A simple library for the AVRs to control the Texas Instruments TLC7528 DAC contact: darth.daqq@gmail.com usage: if you wanna set the A part of the DAC, you use the write_dac_tlc7528_a(x) function and as x you enter an 8bit nubmer. if you wanna set the B part of the DAC, you use the write_dac_tlc7528_b(x) function and as x you enter an 8bit nubmer. enjoy... visit my page: www.daqq.eu */ #include#define TLC7528_ALWAYS_ENABLED 42 //make a comment out of this line if the DAC is not supposed to be always enabled //for instance if you have multiple devices on the data and write enable lines #define TLC7528_DATA_PORT PORTC //the port on which D0-D7 of the DAC is hooked to #define TLC7528_COMMAND_PORT PORTA //the port on #define TLC7528_CS 2 //the chip select pin #define TLC7528_DACA_DACB 1 //which DAC is supposed to be set #define TLC7528_WRITE_EN 0 //the write enable pin #ifdef TLC7528_ALWAYS_ENABLED #define write_dac_tlc7528_a(x) {cbi(TLC7528_COMMAND_PORT,TLC7528_DACA_DACB);\ TLC7528_DATA_PORT=x;\ cbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);\ sbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);} #define write_dac_tlc7528_b(x) {sbi(TLC7528_COMMAND_PORT,TLC7528_DACA_DACB);\ TLC7528_DATA_PORT=x;\ cbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);\ sbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);} #else #define write_dac_tlc7528_a(x) {cbi(TLC7528_COMMAND_PORT,TLC7528_DACA_DACB);\ cbi(TLC7528_COMMAND_PORT,TLC7528_CS);\ TLC7528_DATA_PORT=x;\ cbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);\ sbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);\ sbi(TLC7528_COMMAND_PORT,TLC7528_CS);} #define write_dac_tlc7528_b(x) {sbi(TLC7528_COMMAND_PORT,TLC7528_DACA_DACB);\ cbi(TLC7528_COMMAND_PORT,TLC7528_CS);\ TLC7528_DATA_PORT=x;\ cbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);\ sbi(TLC7528_COMMAND_PORT,TLC7528_WRITE_EN);\ sbi(TLC7528_COMMAND_PORT,TLC7528_CS);} #endif
There. BTW: I'm now shifting through old code, and will post stuff that someone might find useful.