//ARMADEUS+i2csw(avrlib)
void i2cInit(void)
{
sbi( SDADDR, SDA); // set SDA as output
sbi( SCLDDR, SCL); // set SCL as output
I2C_SDL_HI; // set I/O state and pull-ups
I2C_SCL_HI; // set I/O state and pull-ups
extended_command powerCommand = { 0, 0, 0, 0 };
powerCommand.powerMode = POWER_UP;
powerCommand.command = MAX5821_EXTENDED_COMMAND_MODE;
powerCommand.ctrlA = POWER_CTRL_SELECTED;
powerCommand.ctrlB = POWER_CTRL_SELECTED;
BUILD_EXTENDED_COMMAND(powerCommand, i2cdat);
i2cSend(MAX5821L_IC_SLAVE_ADDRESS_VDD * 2, i2cdat[0], 1, &i2cdat[1]);
}
void ouputDAC()
{
data_command setOutputCommand = { 0, 0, 0 };
unsigned short val;
float valf;
valf = sysStat.oilval * 1024 / 200;
if (valf >= 1023)
valf = 1023;
if (sysStat.statue == 0)
val = valf;
else val = 0;
setOutputCommand.Sbits = 0;
setOutputCommand.command = 0;
setOutputCommand.data = val;
BUILD_DATA_COMMAND(setOutputCommand, i2cdat);
i2cSend(MAX5821L_IC_SLAVE_ADDRESS_VDD * 2, i2cdat[0], 1, &i2cdat[1]);
}
atmega128任意io口接入MAX5821 ADC芯片实现
最新推荐文章于 2020-11-13 21:17:35 发布