///////////////////////////////////////////////////////////////////////// //// AD5320.c ver 0.1b //// //// author:V.Andreev //// //// http://variate.narod.ru //// //// e-mail:ne-rad@mail.ru //// //// compiler:CCS PCWH 4.057 //// ///////////////////////////////////////////////////////////////////////// //// автор не несет ответственности за возможный /// //// и/или принесенный ущерб и т.п. /// #define SYNC PIN_B5 #define SCLK PIN_C6 #define DIN PIN_C7 // Power-Down Modes of Operation for the AD5320 #define NORMAL 0x00 #define PDM1 0x01 #define PDM2 0x02 #define PDM3 0x03 union { int16 dd; struct { byte dL ; // data 8 bit | byte dH : 4; // data 4 bit | = 12 bit byte sdac : 2; // config Power-Down modes of operation byte c : 2; // not use }; }HL; byte MODE; // user functions // void init_dac(void) - инициализация // void ext_dac_send2Bytes(int16 data) - передача данных ЦАП'у void init_dac(void) { MODE = NORMAL; // select Power-Down mode of operation, user setting output_high(SYNC); output_high(SCLK); output_high(DIN); } void ext_dac_send2Bytes(int16 data) { int j; HL.dd = data; HL.sdac = MODE; // Power-Down mode of operation output_low(SCLK); output_low(SYNC); for(j=0; j<16; j++) // { output_high(SCLK); output_bit(DIN,shift_left(&HL,2,0)); output_low(SCLK); } output_high(SYNC); output_high(SCLK); }