?? da_3.c
字號(hào):
/**********************************************
* File: DA_3.C
* Description: DAC7614
* Created Date: 2007-10-01
* Last Modified: 2007-10-01
* Author: Jeffrey - Schicksal@126.com
* Notes: None
**********************************************/
#include "Atmel/AT89X51.h"
#include "INTRINS.H"
//*******定義DAC7614控制端口*****************//
#define MOSI P2_0
#define SCK P2_1
#define PCS0 P2_2
#define PDAC P2_3
#define PRESET P2_4
//*******定義DAC7614控制端口*****************//
volatile unsigned int DAC7614_Code = 0;
// 函數(shù)聲明
void InitDAC7614(); // 初始化DAC7614
void SetDAC7614(); // 將控制命令寫(xiě)入DAC7614
void Chn_Sel(unsigned char chn); // 選擇DAC輸出通道
void SetDACout(unsigned int dac); // 設(shè)置DAC轉(zhuǎn)換數(shù)值
/**********************************************
* 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--); // 延時(shí)循環(huán)
}
/**********************************************
* Function: main()
* Input Variables: None
* Return Variables: None
* Usage: Program Entry
*********************************************/
void main()
{
unsigned int x = 0; // 通道A轉(zhuǎn)換值
unsigned int y = 1024; // 通道B轉(zhuǎn)換值
unsigned int z = 2048; // 通道C轉(zhuǎn)換值
unsigned int h = 3072; // 通道D轉(zhuǎn)換值
InitDAC7614(); // 初始化ADC7614
while(1)
{
Chn_Sel(0x00); // 選擇通道A
SetDACout(x); // 設(shè)置轉(zhuǎn)換值為x
SetDAC7614(); // 將設(shè)置值寫(xiě)入DAC7614,啟動(dòng)DAC轉(zhuǎn)換
Chn_Sel(0x01); // 選擇通道B
SetDACout(y); // 設(shè)置轉(zhuǎn)換值為y
SetDAC7614(); // 將設(shè)置值寫(xiě)入DAC7614,啟動(dòng)DAC轉(zhuǎn)換
Chn_Sel(0x02); // 選擇通道C
SetDACout(z); // 設(shè)置轉(zhuǎn)換值為z
SetDAC7614(); // 將設(shè)置值寫(xiě)入DAC7614,啟動(dòng)DAC轉(zhuǎn)換
Chn_Sel(0x03); // 選擇通道D
SetDACout(h); // 設(shè)置轉(zhuǎn)換值為h
SetDAC7614(); // 將設(shè)置值寫(xiě)入DAC7614,啟動(dòng)DAC轉(zhuǎn)換
if(++x==4096)
x=0;
if(++y==4096)
y=0;
if(++z==4096)
z=0;
if(++h==4096)
h=0;
delay(100);
}
}
/**********************************************
* Function: InitDAC7614()
* Input Variables: None
* Return Variables: None
* Usage: Init DAC7614
*********************************************/
void InitDAC7614()
{
PCS0 = 1;
PDAC = 1;
SCK = 1;
PRESET = 0;
_nop_();
PRESET = 1;
}
/**********************************************
* Function: Chn_Sel( unsigned char chn)
* Input Variables: unsigned char chn
* Return Variables: None
* Usage: Select Channel of DAC7614
*********************************************/
void Chn_Sel(unsigned char chn)
{
if(chn > 0x03)
return; // chn值只能從0~3
DAC7614_Code &= ~0xf000;
DAC7614_Code |= ((unsigned int)(chn)<<14);
}
/**********************************************
* Function: SetDAC7614( unsigned int dac)
* Input Variables: unsigned int dac
* Return Variables: None
* Usage: Set DAC7614_Code
*********************************************/
void SetDACout( unsigned int dac)
{
DAC7614_Code &= ~0x0fff;
DAC7614_Code |= dac;
}
/**********************************************
* Function: SetDAC7614()
* Input Variables: void
* Return Variables: void
* Usage: Set DAC7614
*********************************************/
void SetDAC7614()
{
unsigned char i;
unsigned char ps = 0x8000;
PCS0 = 0;
PDAC = 1;
for(i = 0;i<16;i++)
{
SCK = 0;
_nop_();
MOSI = (ps&DAC7614_Code)?1:0;
_nop_();
SCK = 1;
ps>>=1;
_nop_();
}
PCS0 = 1;
_nop_();
PDAC = 0;
_nop_();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -