/****************************************************
程序功能 : 使用TLC5615進行DA轉(zhuǎn)換
單位 : 桂林電子科技大學 電信 EDA工作室
程序說明 : 本程序適應(yīng)于絕大多數(shù)沒有四線制SPI口的8051
單片機,模擬一個接口,可根據(jù)實際情況修改四個
接口的地址即可實現(xiàn)移植,使用編譯器為keil c2
***************************************************/
#ifndef __DAC1615_H_
#define __DAC1615_H_ //定義開始
//***************************//
//*************************************//
#ifndef uchar
#define uchar unsigned char
#endif
//***************************//
#ifndef uint
#define uint unsigned int
#endif
#ifndef uint
#define uint unsigned int
#endif
//****************************//
sbit cs = P3^2; //片選
sbit clk = P3^3; //時鐘
sbit din = P3^4; //數(shù)據(jù)入口
sbit dout = P3^5; //數(shù)據(jù)出口
//****************************//
void delay(); //延時函數(shù)
void DA_Conver(unsigned int DA_Value);
//***********************************//
//*************************************//
void delay()
{
int i = 5;
while(i--);
}
/*------------------------------------------------------------- */
void DA_Conver(unsigned int DAValue)
{
unsigned char i;
DAValue <<= 6;
cs = 0; // 片選DA芯片
clk = 0; // 在以下12個時鐘周期內(nèi),每當在上升沿的
// 數(shù)據(jù)被鎖存,形成DA輸出。在前10個時鐘
for(i = 0; i < 12; i++) // 內(nèi)輸入的是10位DA數(shù)據(jù),后兩個時鐘周期
{ // 為填充字節(jié)。
din = (bit)(DAValue & 0x8000); //
clk = 1; //
DAValue <<= 1; //
clk = 0;
}
cs = 1; // CS的上升沿和下降沿只有在clk為低的時候
clk = 0; // 才有效
}
#endif //結(jié)束定義
|