📄 da_1.c
字号:
/**********************************************
* File: DA_1.C
* Description: DAC0832 Interface
* Created Date: 2007-10-01
* Last Modified: 2007-10-01
* Author: Jeffrey - Schicksal@126.com
* Notes: None
**********************************************/
#include "Atmel/AT89X51.h"
#include "INTRINS.H"
//*******定义DAC0832控制端口*****************//
#define CS1 P0_3
#define WR P0_4
#define XFER P0_7
#define DOUT P1
#define CS2 P2_6
//*******定义DAC0832控制端口*****************//
void InitDAC0832();
void SetDAC0832_1(unsigned char DAC);
void SetDAC0832_2(unsigned char DAC);
void SetDAC0832(unsigned char DACx,unsigned char DACy);
void Start_DAC();
/**********************************************
* Function: delay(unsigned int t)
* Input Variables: t
* Return Variables: None
* Usage: Common Delay Routine, t as the delay time ticks
**********************************************/
void delay(unsigned int t)
{
for(;t>0;t--); // 延时循环
}
/**********************************************
* Function: main()
* Input Variables: None
* Return Variables: None
* Usage: Program Entry
*********************************************/
void main()
{
unsigned char x = 0;
unsigned char y = 0;
InitDAC0832(); // 初始化AD7812
delay(50); // 启动时间约1.5us,延迟
while(1)
{
SetDAC0832_1(x); // DAC0832 1赋值x
SetDAC0832_2(y); // DAC0832 2赋值y
Start_DAC(); // 启动DAC转换
delay(1000); // 延时
x++; // x++
y++; // y++
SetDAC0832(x,y); // 同时写两个DAC
Start_DAC(); // 启动同步转换
//********************主程序部分*********************//
delay(1000); // 延时
//********************主程序部分*********************//
x++; // x++
y++; // y++
}
}
/**********************************************
* Function: InitDAC0832()
* Input Variables: None
* Return Variables: None
* Usage: Init DAC0832
*********************************************/
void InitAD7812()
{
CS1 = 1; // 置高Cs1
CS2 = 1; // 置高Cs2
WR = 0; // WR有效
}
/**********************************************
* Function: SetDAC0832_1( unsigned char DAC)
* Input Variables: unsigned char DAC
* Return Variables: None
* Usage: Set DAC Register of DAC0832
*********************************************/
void SetDAC0832_1( unsigned char DAC)
{
CS1 = 0; // CS1有效;
_nop_(); // nop
DOUT = DAC; // 写DAC寄存器
_nop_(); // nop
CS1 = 1; // CS1无效
}
/**********************************************
* Function: SetDAC0832_2( unsigned char DAC)
* Input Variables: unsigned char DAC
* Return Variables: None
* Usage: Set DAC Register of DAC0832
*********************************************/
void SetDAC0832_2( unsigned char DAC)
{
CS2 = 0; // CS2有效;
_nop_(); // nop
DOUT = DAC; // 写DAC寄存器
_nop_(); // nop
CS2 = 1; // CS2无效
}
/**********************************************
* Function: SetDAC0832( unsigned char DAC)
* Input Variables: unsigned char DAC
* Return Variables: None
* Usage: Set DAC Register of DAC0832
*********************************************/
void SetDAC0832(unsigned char DACx,unsigned char DACy)
{
SetDAC0832_1(DACx);
SetDAC0832_2(DACy);
}
/**********************************************
* Function: Start_DAC()
* Input Variables: void
* Return Variables: void
* Usage: Start a Conversion
*********************************************/
void Start_DAC()
{
XFER = 0; // XFER有效启动DA转换
_nop_(); // _nop_
XFER = 1; // XFER恢复高电平
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -