/*****************************************************
This program was produced by the
CodeWizardAVR V2.04.4a Advanced
Automatic Program Generator
?Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : 激光颗粒计数器
Version : 1.0
Date : 2013/5/13
Author : 张行海
Company : 山东惠工
File Name:DAC.c
Comments:用来确定标定颗粒的基准电压
Chip type : stm32f103
Program type : Application
ARM Core Clock frequency: 8 MHz
Memory model : Small
External RAM size : 64K
说 明:使用DAC8718的输出来作为比较器AD79JR的基准
*****************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_GPIO.h"
#include "DAC.h"
// #define CLR_SET GPIO_WriteBit(GPIOD, GPIO_Pin_9, Bit_SET)
// #define CLR_RESET GPIO_WriteBit(GPIOD, GPIO_Pin_9, Bit_RESET)
#define CLR_SET GPIO_WriteBit(GPIOB, GPIO_Pin_8,Bit_SET) //
#define CLR_RESET GPIO_WriteBit(GPIOB, GPIO_Pin_8,Bit_RESET) //
#define WAKEUP_SET GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_SET) //
#define WAKEUP_RESET GPIO_WriteBit(GPIOC, GPIO_Pin_10, Bit_RESET) //
#define LDAC_SET GPIO_WriteBit(GPIOC, GPIO_Pin_11, Bit_SET) //
#define LDAC_RESET GPIO_WriteBit(GPIOC, GPIO_Pin_11, Bit_RESET) //
#define SDO_SET GPIO_WriteBit(GPIOC, GPIO_Pin_12, Bit_SET) //
#define SDO_RESET GPIO_WriteBit(GPIOC, GPIO_Pin_12, Bit_RESET) //
#define SDI_SET GPIO_WriteBit(GPIOD, GPIO_Pin_0, Bit_SET) //
#define SDI_RESET GPIO_WriteBit(GPIOD, GPIO_Pin_0, Bit_RESET) //
#define CS_SET GPIO_WriteBit(GPIOD, GPIO_Pin_1, Bit_SET) //
#define CS_RESET GPIO_WriteBit(GPIOD, GPIO_Pin_1, Bit_RESET) //
#define SCLK_SET GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_SET) //
#define SCLK_RESET GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_RESET) //
#define RST_SET GPIO_WriteBit(GPIOD, GPIO_Pin_7, Bit_SET) //
#define RST_RESET GPIO_WriteBit(GPIOD, GPIO_Pin_7, Bit_RESET) //
extern void Delay(vu32 nCount );
/*----------------------------------------------
*函数名称:Reset_DAc8718()
*函数功能:复位DAC8718
*入口参数:无
*出口参数:无
------------------------------------------- */
void Reset_DAc8718(void)
{
CS_SET;
RST_SET; //?????
Delay(500);
RST_RESET; //??
Delay(500);
RST_SET; //?????
CS_RESET;
}
/*----------------------------------------------
*函数名称:void DAC8718_Write(unsigned long OutData)
*函数功能:写DAC8718
*入口参数:OutData 外部写入dac8718的数据
*出口参数:无
------------------------------------------- */
void DAC8718_Write(unsigned long OutData) //???24bit???
{
unsigned char i;
unsigned long value;
value = OutData & 0x00ffffff; //??24bit
value = value<<8; //??8?,ok
LDAC_SET;
SCLK_SET;
CS_SET;
CS_RESET;
for ( i = 0; i < 24; i ++ )
{
SCLK_SET;
Delay(50);
if((value & 0x80000000) == 0x80000000)
{
SDI_SET;
}
else
{
SDI_RESET;
}
Delay(50);
SCLK_RESET;
Delay(100);
value = value << 1;
}
CS_SET;
CS_SET;
CS_SET;
Delay(200);
LDAC_RESET;
Delay(100);
LDAC_SET;
Delay(500);
}
// /*----------------------------------------------
// *函数名称:write_DAC8718_control_register()
// *函数功能:写DAC8718控制寄存器
// *入口参数: pp 字符串
// *出口参数:无
// ------------------------------------------- */
// void Write_DAC8718_control_register(void)
// {
// DAC8718_Write(0x00200012); //09-11 21:36 ????
// }
/*----------------------------------------------
*函数名称:DAC8718_init()
*函数功能:写DAC8718控制寄存器
*入口参数: pp 字符串
*出口参数:无
------------------------------------------- */
void DAC8718_init(void)
{
CLR_SET; //clr-1
Delay(500); //500---50
CLR_RESET;
Delay(500); //500---50
CLR_SET;
Reset_DAc8718(); //rst-1
DAC8718_Write(0x00000000);
DAC8718_Write(0x00030000); //Offset DAC - A=0
DAC8718_Write(0x00040000); //Offset DAC - B=0
DAC8718_Write(0x00060000); //SLEEP = 0,正常模式
DAC8718_Write(0x00100000); //zero -0
DAC8718_Write(0x00180006); //GAIN0 =6
}