當(dāng)前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀]//The program for CS5532-ASZ//This is a 24bit ADC and PGIA//Made by OurWay and 2006/03/21//#include //#include //根據(jù)實際情況定義//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

//根據(jù)實際情況定義
//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值的程序。


本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫毥谦F公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風(fēng)險,如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術(shù)學(xué)會聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(shù)(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉