热度 15
2009-5-19 12:53
6437 次阅读|
0 个评论
TLC5628是一个8通道8位的DAC转换芯片,其电气参数如下: (1)Eight 8-Bit Voltage Output DACs (2)5-V Single-Supply Operation (3)Serial Interface (4)High-Impedance Reference Inputs (5)Programmable 1 or 2 Times Output Range (6)Simultaneous Update Facility (7)Internal Power-On Reset (8)Low-Power Consumption (9)Half-Buffered Output 下面是AVR单片MEGA16对其的控制程序: /***************************************************** This program was produced by the CodeWizardAVR V2.03.4 Standard Date : 2009-4-5 Author : sharcky Chip type : ATmega16L Program type : Application Clock frequency : 8.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ #ifndef _define_h #define _define_h #include #include #include //DA设置 #define DACLK_1 PORTC.4 = 1 //CLK端口 #define DACLK_0 PORTC.4 = 0 #define DADAT_1 PORTC.5 = 1 //数据DA端口 #define DADAT_0 PORTC.5 = 0 #define DALDAC_1 PORTC.6 = 1 //LDAC端口 #define DALDAC_0 PORTC.6 = 0 #define DALOAD_1 PORTC.7 = 1 //LOAD端口 #define DALOAD_0 PORTC.7 = 0 /***************************************/ //void SerialDAC_init(void) 串行DAC初始化 /*2009-5-4 */ /***************************************/ void SerialDAC_init(void) //串行DAC初始化 { DALOAD_1;DALDAC_1;DACLK_1;DADAT_1; } /*******************************************************************/ /*void SerialDAC_Seting( unsigned char sensor, unsigned char ch , unsigned char mode) 串行DAC设置 */ /* unsigned char sensor (范围0~255) 输出值范围:0V~2.5V */ /* unsigned char ch 通道选择(0~7) */ /* unsigned char mode 模式选择 (两种模式:一倍(0)、二倍(1)) */ /* 时间:2009-5-4 email:sharck@163.com 调节成功 */ /*******************************************************************/ void SerialDAC_Seting(unsigned char sensor,unsigned char ch ,unsigned char mode) { unsigned char i; unsigned int data1,data2; if(mode) { switch(ch) { case 0: data1 = 0x0100;break; case 1: data1 = 0x0300;break; case 2: data1 = 0x0500;break; case 3: data1 = 0x0700;break; case 4: data1 = 0x0900;break; case 5: data1 = 0x0B00;break; case 6: data1 = 0x0D00;break; case 7: data1 = 0x0F00;break; } } else { switch(ch) { case 0: data1 = 0x0000;break; case 1: data1 = 0x0200;break; case 2: data1 = 0x0400;break; case 3: data1 = 0x0600;break; case 4: data1 = 0x0800;break; case 5: data1 = 0x0A00;break; case 6: data1 = 0x0C00;break; case 7: data1 = 0x0E00;break; } } data2 = (unsigned int)(sensor); data1 = data1+data2; //左对齐 DACLK_0; DALOAD_1; DALDAC_0; for (i=0;i<12;i++) { DACLK_1; if(data1 & 0x0800) DADAT_1; else DADAT_0; data1 <<= 1; DACLK_0; delay_us(5); } DALOAD_0; delay_us(10); DACLK_0; DALOAD_1; DALDAC_1; } #endif