上次的原理图有点问题,把TLC7528的引脚给画错了,这次改正了,阿莫注意了.
点击此处下载原理图
我把程序也重新遍了一下;在示波器里可以看到两路波形
#include<iom16v.h>
#include<macros.h>
#define BYTE unsigned char
#define WR PORTC&=~BIT(PC6) //向TLC7528锁存数据
#define NWR PORTC|=BIT(PC6)
#define CHBS PORTC|=BIT(PC7); //B通道DAC的选择
#define CHAS PORTC&=~BIT(PC7); //A通道DAC的选择
const BYTE Sin[]={0x00,0x02,0x04,0x06,0x08,0x0a,0x0c,0x0e,0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e,0x20,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3a,0x3c,0x3d,0x3f,0x41,0x43,0x45,0x47,0x49,0x4b,0x4d,0x4f,0x51,0x53,0x54,0x56,0x58,0x5a,0x5c,0x5e,0x60,0x62,0x63,0x65,0x67,0x69,0x6b,0x6d,0x6e,0x70,0x72,0x74,0x76,0x77,0x79,0x7b,0x7d,0x7e,0x80,0x82,0x84,0x85,0x87,0x89,0x8a,0x8c,0x8e,0x8f,0x91,0x93,0x94,0x96,0x98,0x99,0x9b,0x9c,0x9e,0x9f,0xa1,0xa3,0xa4,0xa6,0xa7,0xa9,0xaa,0xac,0xad,0xaf,0xb0,0xb1,0xb3,0xb4,0xb6,0xb7,0xb9,0xba,0xbb,0xbd,0xbe,0xbf,0xc1,0xc2,0xc3,0xc4,0xc6,0xc7,0xc8,0xc9,0xcb,0xcc,0xcd,0xce,0xcf,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdd,0xde,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe8,0xe9,0xea,0xeb,0xec,0xec,0xed,0xee,0xef,0xef,0xf0,0xf1,0xf1,0xf2,0xf3,0xf3,0xf4,0xf4,0xf5,0xf5,0xf6,0xf6,0xf7,0xf7,0xf8,0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,0x18,0x1a,0x1c,0x1e,0x20,0x22,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3a,0x3c,0x3d,0x3f,0x41,0x43,0x45,0x47,0x49,0x4b,0x4d,0x4f,0x51,0x53,0x54,0x56,0x58,0x5a,0x5c,0x5e,0x60,0x62,0x63,0x65,0x67,0x69,0x6b,0x6d,0x6e,0x70,0x72,0x74,0x76,0x77,0x79,0x7b,0x7d,0x7e,0x80,0x82,0x84,0x85,0x87,0x89,0x8a,0x8c,0x8e,0x8f,0x91,0x93,0x94,0x96,0x98,0x99,0x9b,0x9c,0x9e,0x9f,0xa1,0xa3,0xa4,0xa6,0xa7,0xa9,0xaa,0xac,0xad,0xaf,0xb0,0xb1,0xb3,0xb4,0xb6,0xb7,0xb9,0xba,0xbb,0xbd,0xbe,0xbf,0xc1,0xc2,0xc3,0xc4,0xc6,0xc7,0xc8,0xc9,0xcb,0xcc,0xcd,0xce,0xcf,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdd,0xde,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe8,0xe9,0xea,0xeb,0xec,0xec,0xed,0xee,0xef,0xef,0xf0,0xf1,0xf1,0xf2,0xf3,0xf3,0xf4,0xf4,0xf5,0xf5,0xf6,0xf6,0xf7,0xf7,0xf8,0xf8,0xf9,0xf9,0xfa,0xfa,0xfa,0xfb,0xfb,0xfc,0xfc,0xfc,0xfc,0xfd,0xfd,0xfd,0xfd,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,};
/******************************************************************************
Function Name: void delay()
Input: None
Output: None
Description: 延时函数
******************************************************************************/
void delay()
{
BYTE i;
for(i=0;i<10;i++)
{
;
}
}
/******************************************************************************
Function Name: void shortdelay()
Input: None
Output: None
Description: 较短的延时函数
******************************************************************************/
void shortdelay()
{
BYTE i;
for(i=0;i<2;i++)
{
;
}
}
/******************************************************************************
Function Name: void delay()
Input: None
Output: None
Description: 主函数
******************************************************************************/
void main(void)
{
unsigned int i;
i=0x00;
DDRA=0xff;
DDRC=0xff;
PORTA=0x00;
NWR; //禁止向TLC7528写数据
CHAS; //选择TLC7528的通道A
while(1)
{
PORTA=Sin; //正弦数据表
WR; //向TLC7528写数据使能
shortdelay();
NWR; //禁止向TLC7528写数据
CHBS; //选择TLC7528的通道B
shortdelay();
PORTA=Cos; //余弦数据表
WR; //向TLC7528写数据使能
shortdelay();
NWR; //禁止向TLC7528写数据
CHAS; //选择TLC7528的通道A
//shortdelay()
i++;
if(i==400)
{
i=0x00;
}
delay();
}
}
TLC7528是一片比较理想的8bit双通到 DAC,价格在15-20元一片左右,PDF里的一些参数如下:
这是DAC0832里的一段,"Voltage Mode Switching",
TLC0832也有类似的描述,"voltage-mode operation",但是写的不是很全面,
KA336和LM336一样的,2.5V的参考电压源. |