コピー用サンプルプログラム

 コピーしても文字化けしないように、 コメントを英語にしたプログラムです。

DACwrite

対応する日本語版
void DACwrite(unsigned char d)
{
  /* Set internal reference voltage */
  CS_DAC(1); CK(1); /* Initial state */
  CS_DAC(0);
  DACwrite_byte(0xd0); DACwrite_byte(0x02);
  CS_DAC(1);

  /* Generate a voltage corresponding to parameter "d" */
  CS_DAC(0);
  DACwrite_byte(0xc0 | (d >> 4));
  DACwrite_byte(d << 4);
  CS_DAC(1);
}

CK, CS_DAC, DO_DAC

対応する日本語版
/* CK(d): Set SCLK for D/A, A/D as d (d=0 or 1) */
void CK(char d)    {if (d == 1) IOE |= 0x01; else IOE &= ~0x01;}

/* CS_DAC(d): Set /CS for  D/A as d (d=0 or 1) */
void CS_DAC(char d){if (d == 1) IOE |= 0x04; else IOE &= ~0x04;}

/* DO_DAC(d): Set DIN for D/A as d (d=0 or 1) */
void DO_DAC(char d){if (d == 1) IOE |= 0x08; else IOE &= ~0x08;}

CS_ADC, DI_ADC

対応する日本語版

 ここで新規に追加する関数2個。

/* CS_ADC(d): Set /CS for A/D as d (d=0 or 1) */
void CS_ADC(char d){if (d == 1) IOE |= 0x02; else IOE &= ~0x02;}

/* DI_ADC(): Read DATAOUT from A/D */
char DI_ADC(){if ((IOE & 0x10) == 0) return(0); else return(1);}

 D/Aと共通の関数3個。

/* CK(d): Set SCLK for D/A, A/D as d (d=0 or 1) */
void CK(char d)    {if (d == 1) IOE |= 0x01; else IOE &= ~0x01;}

/* CS_DAC(d): Set /CS for  D/A as d (d=0 or 1) */
void CS_DAC(char d){if (d == 1) IOE |= 0x04; else IOE &= ~0x04;}

/* DO_DAC(d): Set DIN for D/A as d (d=0 or 1) */
void DO_DAC(char d){if (d == 1) IOE |= 0x08; else IOE &= ~0x08;}