|
|
View previous topic :: View next topic |
Author |
Message |
breeyet
Joined: 17 Dec 2006 Posts: 4
|
dac6573 support? |
Posted: Fri Dec 07, 2007 11:16 am |
|
|
Hi,
I'm trying to interface a dac6573 to a PIC18F4585. Has anyone got example code for this? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Dec 07, 2007 2:51 pm |
|
|
I don't have this chip to test, but the following driver and test program
is based on the DAC6573 data sheet. It should be enough to get you
started.
Remember to put pull-up resistors on the SDA and SCL lines.
Code: |
#include <18F4585.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_C4, SCL=PIN_C4)
// The DAC6573 address pins A0,A1,A2,A3 must all
// be connected to ground.
#define DAC6573_I2C_WRT_ADDR 0x98
#define DAC6573_I2C_READ_ADDR 0x99
#define DAC6573_UPDATE_CMD 0x10
// Function parameters --
// Channel: 0 to 3.
// Data: 0 to 1023.
void DAC6573_write(int8 channel, int16 data)
{
int8 command;
// Format the channel select bits into the command byte.
command = ((channel & 3) << 1) | DAC6573_UPDATE_CMD;
i2c_start();
i2c_write(DAC6573_I2C_WRT_ADDR);
i2c_write(command);
i2c_write(data >> 8); // Write MSB
i2c_write(data); // Write LSB
i2c_stop();
}
//======================================
void main()
{
// Set channel 0 to the mid-range output voltage.
DAC6573_write(0, 512);
while(1);
}
|
|
|
|
breeyet
Joined: 17 Dec 2006 Posts: 4
|
|
Posted: Fri Dec 07, 2007 5:07 pm |
|
|
Wow, that was quick. Thanks for the help, I'll try it out as soon as I can and post the results. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|