当前位置:首页 > 单片机 > 单片机
[导读]//The program for CS5532-ASZ//This is a 24bit ADC and PGIA//Made by OurWay and 2006/03/21//#include //#include //根据实际情况定义//sbit SDI5532 = P2^1;//sbit SDO5532 = P2^2;//sbit CLK5532 = P2^3;//sbi

//The program for CS5532-ASZ
//This is a 24bit ADC and PGIA
//Made by OurWay and 2006/03/21

//#include
//#include

//根据实际情况定义
//sbit SDI5532 = P2^1;
//sbit SDO5532 = P2^2;
//sbit CLK5532 = P2^3;
//sbit CS5532 = P2^0;

//sbit ACC7 = ACC^7;
//sbit ACC0 = ACC^0;

//#define BYTE unsigned char
//#define WORD unsigned int
#define Adjust5532Run 0
#define ReadSADC5532Run 1
#define ReadMADC5532Run 1

//The ADC results varibles define
struct{
unsigned char top;
unsigned char high;
unsigned char mid;
unsigned char low;
}
RegDat;

//The CS5532-ASZ comm define
#define RegRead 0x08
#define RegWrite 0x00

//=== Offset Register ===
#define OffsetRS 0x09

//=== Gain Register ===
#define GainRS 0x0a

//=== Configuration Register ===
#define ConfigWrite 0x03//write config
#define ConfigRead 0x0b//read config

#define PSS 0x80//Power Save Select
#define PDW 0x40//Power Down Mode
#define RS 0x20//Reset System
#define RV 0x10 //Reset Valid
#define IS 0x08//Input Short
#define GB 0x04//Guard Signal Bit
#define VRS 0x02//Voltage Reference Select(Ref>2.5V,VRS=0)
#define A1 0x01
#define A0 0x80
#define OLS 0x40
#define OGS 0x10
#define FRS 0x08


//=== Channel Setup Register ===
#define SetupCH1 0x05
#define SetupCH2 0x15

//Channel Select Bits
#define CH1 0x00//CS1=0,CS0=0
#define CH2 0x40//CS1=0,CS0=1
//Gain Bits
#define Gain1 0x00
#define Gain2 0x08
#define Gain4 0x10
#define Gain8 0x18
#define Gain16 0x20
#define Gain32 0x28
#define Gain64 0x30

//=== Converter mode ===
#define SingleC 0x80
#define ContinC 0xC0
#define Setup1 0x00
#define Setup2 0x08
#define Setup3 0x10
#define Setup4 0x18
#define Setup5 0x20
#define Setup6 0x28
#define Setup7 0x30
#define Setup8 0x38

//The data(8bit) form MCU to CS5532
void SendByte5532(unsigned char Dat)
{
unsigned char i;
CLK5532 = 0;
for(i=8;i>0;i--)
{
SDI5532=(bit)(Dat & 0x80);
CLK5532=1;
_nop_();_nop_();
_nop_();_nop_();
CLK5532=0;
_nop_();_nop_();
_nop_();_nop_();
Dat = Dat<<1;
}
SDI5532 = 1;
}

//The Setup CS5532's register
void WriteReg5532(BYTE command,BYTE low,BYTE mid,BYTE high,BYTE top)
{
CS5532 = 0;
SendByte5532(command);
SendByte5532(low);
SendByte5532(mid);
SendByte5532(high);
SendByte5532(top);
CS5532 = 1;
}

//The data(8bit) form CS5532 to MCU
unsigned char ReceiveByte5532(void)
{
unsigned char i;
ACC=0;
for(i=8;i>0;i--)
{
ACC=ACC<<1;
ACC0=SDO5532;
CLK5532=1;
_nop_();_nop_();
_nop_();_nop_();
CLK5532=0;
_nop_();_nop_();
_nop_();_nop_();
}
return(ACC);
}

//Receive ADC signal data form CS5532 to MCU
#if ReadSADC5532Run
void ReadSADC5532(unsigned char command)
{
CS5532 = 0;
SendByte5532(command);
do{_nop_();CLK5532=0;SDI5532=0;}while(SDO5532!=0);
SendByte5532(0x00);//8bit SCLK and SDI=0;
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#endif

#if ReadMADC5532Run
void ReadMADC5532(unsigned char command)
{
CS5532 = 0;
do{_nop_();}while(SDO5532!=0);
//SDO5532 = 1;
SendByte5532(command);//8bit SCLK and SDI=command;
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#endif

//Receive CS5532's Register from CS5532 to MCU
void ReadReg5532(unsigned char command)
{
CS5532 = 0;
SendByte5532(command);
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}

#if Adjust5532Run
void Adjust5532(unsigned char command)
{
CS5532 = 0;
SendByte5532(command);
do{_nop_();}while(SDO5532!=0);
SendByte5532(0x0a);
RegDat.top = ReceiveByte5532();
RegDat.high = ReceiveByte5532();
RegDat.mid = ReceiveByte5532();
RegDat.low = ReceiveByte5532();
CS5532 = 1;
}
#endif

//The initialization CS5532
void Init5532(void)
{
WriteReg5532(0xff,0xff,0xff,0xff,0xff);
WriteReg5532(0xff,0xff,0xff,0xff,0xff);
WriteReg5532(0xff,0xff,0xff,0xff,0xff);
WriteReg5532(0xff,0xff,0xff,0xff,0xfe);
}
//The CS5532-ASZ subpram end

//用的时间注意我定义的宏,这是个查询方式采集AD值的程序。


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

USB摄像头是一种采用USB接口的视频采集设备,其优点在于即插即用、操作简便,无需额外驱动程序,支持笔记本电脑,并且成本较低,可以支持远程网络观看。

关键字: usb摄像头 驱动程序

与两相双极步进电机的驱动电路相比,两相单极步进电机的驱动电路在输入段配置、内部逻辑及控制电路和驱动电路使用双通道方面基本相同,但是输出段的配置不同。

关键字: 四相步进电机 驱动程序 程序电路

本文介绍了如何实现嵌入式MICREL网卡的驱动程序开发和设计。首先,我们介绍了MICREL网卡的概述和工作原理。然后,详细探讨了驱动程序的开发流程,包括硬件和软件的配置以及驱动程序的编写和测试。最后,总结了几点注意事项和...

关键字: 嵌入式 MICREL网卡 驱动程序

在这篇文章中,小编将对OLED的相关内容和情况加以介绍以帮助大家增进对它的了解程度,和小编一起来阅读以下内容吧。

关键字: OLED 驱动程序 无源驱动

单片机内部有很多的特殊功能寄存器,每个寄存器在单片机内部都分配有唯一的地址,一般我们会根据寄存器功能的不同给寄存器赋予各自的名称,当我们需要在程序中操作这些特殊功能寄存器时,必须要在程序的最前面将这些名称加以声明,声明的...

关键字: C51 数据类型 扩充定义

数据元(Data Element),也称为数据元素,是用一组属性描述其定义、标识、表示和允许值的数据单元,在一定语境下,通常用于构建一个语义正确、独立且无歧义的特定概念语义的信息单元。数据元可以理解为数据的基本单元,将若...

关键字: C51 数据类型

近日,英特尔发布了锐炫显卡的新版驱动更新。本次驱动更新涵盖了锐炫A770、A750、A380以及移动端的锐炫GPU,这使得英特尔锐炫整个家族的DX9性能都实现了显著提升。

关键字: 英特尔 显卡 驱动程序

摘 要:从硬件与软件方面介绍了基于PXI技术的1553B总线通讯模块的设计,并对PXI总线接口设计、驱动程序的开发、 SDRAM存储器的控制和1553B总线通信协议实现等关键技术进行了详细的阐述,为航空领域测控系统开发P...

关键字: PXI技术 驱动程序 SDRAM存储器 1553B总线

PnP全称Plug-and-Play,译文为即插即用。PnP的作用是自动配置低层计算机中的板卡和其他设备,然后告诉对应设备都做了什么。PnP的任务是把物理设备和软件设备驱动程序相配合,并操作设备,在每个设备和它的驱动程序...

关键字: PnP 驱动程序 操作设备

▼点击下方名片,关注公众号▼欢迎关注【玩转单片机与嵌入式】公众号,回复关键字获取更多免费资料。回复【加群】,限时免费进入知识共享群;回复【3D封装库】,常用元器件的3D封装库;回复【电容】,获取电容、元器件选型相关的内容...

关键字: C51 MDK RealView
关闭
关闭