📄 cs5532.txt
字号:
CS5532 C51驱动程序2007-09-03 09:10//The program for CS5532-ASZ
//This is a 24bit ADC and PGIA
//Made by OurWay and 2006/03/21
//#include <reg51.h>
//#include <intrins.h>
//根据实际情况定义
//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);
:[原创]CS5532程序
作者:txyuseing 编辑 删除 楼主
CS5532_TEST
//////////////////////////////////////////////////////////
//////////////// CS5532 ////////////////////////
//////////////////////////////////////////////////////////
//#include "AT89X51.H"
#include "reg51.h" //changed by taoxy@20060110
#include "stdio.h"
#include "intrins.h"
#include "stdlib.h"
#include "absacc.h"
#define uchar unsigned char
// Original design board
sbit CS5532_CS=P1^2;
sbit CS5532_SDI=P1^3;
sbit CS5532_SCLK=P1^5;
sbit CS5532_SDO=P2^4;
// PCB Version
//sbit CS5532_CS=P1^3;
//sbit CS5532_SDI=P1^2;
//sbit CS5532_SDO=P1^1;
//sbit CS5532_SCLK=P1^0;
// all design board ?
sbit CS5532_A0=P1^6;
sbit CS5532_A1=P1^7;
#define RxdTxd4b_0 DBYTE[0x20]
#define RxdTxd4b_1 DBYTE[0x21]
#define RxdTxd4b_2 DBYTE[0x22]
#define RxdTxd4b_3 DBYTE[0x23]
uchar idata RxdTxd4b[4];
void CS5532_Txd(uchar);
void CS5532_Txd_init(uchar);
void read_reg(uchar address_pt);
void read_data(uchar address_pt);
void read_data1(uchar address_pt);
void CS5532_init(void);
void main(void)
{
uchar i,k,address_pt;
uchar flag=0;
address_pt = 32; // RAM 数据区起始地址
CS5532_init();
for(k=0;k<20;k++) _nop_();
//************************************************
// 系统软复位( CS5532_init() 包含该部分)
CS5532_Txd(0x03); // Soft Reset
CS5532_Txd(0x2A);
CS5532_Txd(0x00);
CS5532_Txd(0x04);
CS5532_Txd(0x00);
CS5532_Txd(0x0B); // Read Config Reg
DBYTE[address_pt++]=0x0B;
read_reg(address_pt);
address_pt = address_pt +4;
CS5532_Txd(0x0B); // Read Config Reg
DBYTE[address_pt++]=0x0B;
read_reg(address_pt);
address_pt = address_pt +4;
//////////////////////////////////////////////
CS5532_Txd(0x05); // Setup REG
CS5532_Txd(0x32);
CS5532_Txd(0x34);
CS5532_Txd(0x00);
CS5532_Txd(0x00);
CS5532_Txd(0x03); // Config ReG
CS5532_Txd(0x40);
CS5532_Txd(0x00);
CS5532_Txd(0x00);
CS5532_Txd(0x00);
CS5532_Txd(0x03); // Config ReG
CS5532_Txd(0xC0);
CS5532_Txd(0x00);
CS5532_Txd(0x00);
CS5532_Txd(0x00);
CS5532_Txd(0x03); // Config ReG
CS5532_Txd(0x01);
CS5532_Txd(0x80);
CS5532_Txd(0x00);
CS5532_Txd(0x00);
CS5532_Txd(0x0B); // Read Config Reg
DBYTE[address_pt++]=0x0B;
read_reg(address_pt);
address_pt = address_pt +4;
CS5532_Txd(0x0D); // Read Setup Reg
DBYTE[address_pt++]=0x0D;
read_reg(address_pt);
address_pt = address_pt +4;
_nop_(); _nop_(); _nop_(); _nop_();
address_pt = 52;
CS5532_CS=1; // 未校准前转换
CS5532_Txd(0x80);
while(CS5532_SDO)
_nop_(); _nop_(); _nop_(); _nop_();
DBYTE[address_pt++]=0x80;
read_data(address_pt);
address_pt = address_pt +4;
_nop_(); _nop_(); _nop_(); _nop_();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -