?? cs5550.c
字號:
#include <config.h>
#include <head.h>
#include <CS5550.h>
#include <function.h>
#include <message.h>
code char gaint[]={0x20,0x40,0x50,0x60,0x80,0xa0,0xc0,0xe0,0xf0,0xff};
union
{
long rlong;
struct{
unsigned char hbyte; // High byte
unsigned char mbyte; // Middle byte
unsigned char lbyte; // Low byte
unsigned char zbyte; // Zero byte
}bytes;
} AD_NOW;
union
{
Uint rint;
struct{
unsigned char hbyte; // High byte
unsigned char lbyte; // Low byte
}bytes;
} AD_NOW_V;
BOOL hadad;
extern Uchar adchipdog;
extern bit resetadbit;
BOOL getad()
{
return hadad;
}
long readad()
{
hadad=0;
return AD_NOW.rlong;
}
Uint readvolt()
{
return AD_NOW_V.rint;
}
void inin5550(char gain,char Offset)
{
gain=gaint[gain];
reset=LOW;
delayms(1);
reset=HIGH;
sdo=HIGH;
sdi=LOW;
sclk=LOW;
cs_writebyte_4(Sync1,Sync1,Sync1,Sync0);
cs_writebyte_4(WReg_Config,0x01,0x00,0x01); //falling //使cpu時鐘反轉,打開高通濾波器
cs_writebyte_4(WReg_CycleCount,0x00,0x01,0x90); //0190 //400 04b0 //1200 //轉換速率
cs_writebyte_4(WReg_Mask,0x80,0x00,0x00); //允許DRDY中斷
cs_writebyte_4(WRegA1_DcOffset,Offset,0,0);
cs_writebyte_4(WRegA1_DcGain,gain,0,0);
cs_writebyte_4(WRegA2_DcOffset,0x00,0x00,0x00);
cs_writebyte(ContnuConvs);
//PX0=1;
IT0=1;
EX0=1;
EA=1;
adchipdog=0;
resetadbit=0;
while(!getad());
//adchipdog=0;
}
//***********************************************************************
BOOL cs_clock(void)
{
BOOL sample;
sclk=HIGH;
// _nop_();
sample=sdo;
sclk=LOW;
// _nop_();
return(sample);
}
//*********************************************
void cs_writebyte(Uchar cs_data)
{
Uchar i;
sclk=LOW;
/*發送8位數據*/
for(i=0;i<8;i++)
{
sdi=(bit)(cs_data&0x80);
cs_data=cs_data<<1;
cs_clock();
}
/*請求應答信號ACK*/
sdi=HIGH;
}
//*****************************************************************************
void cs_writebyte_4(Uchar a,Uchar b,Uchar c,Uchar d)
{
cs_writebyte(a);
cs_writebyte(b);
cs_writebyte(c);
cs_writebyte(d);
}
//*****************************************************************************
void int_0(void) interrupt 0
{
adchipdog=0;
cs_writebyte(RRegA2_FILT);
AD_NOW_V.bytes.hbyte=int_cs_readbyte();
AD_NOW_V.bytes.lbyte=int_cs_readbyte();
AD_NOW_V.rint+=2354;
AD_NOW_V.rint/=25.98;
cs_writebyte(WReg_Status);
cs_writebyte(0xff);
cs_writebyte(0xff);
cs_writebyte(0xff);
cs_writebyte(RRegA1_Output); //判斷符號
if(int_cs_readbyte()&0x80)AD_NOW.rlong=0;
else{
cs_writebyte(RRegA1_FILT); //讀AD值
AD_NOW.bytes.mbyte=int_cs_readbyte();
AD_NOW.bytes.lbyte=int_cs_readbyte();
AD_NOW.bytes.zbyte=int_cs_readbyte();
}
hadad=1;
PostMessageOne(M_ADHAD,0);
cs_writebyte(WReg_Status);
cs_writebyte(0xff);
cs_writebyte(0xff);
cs_writebyte(0xff);
}
//************************************************
Uchar int_cs_readbyte(void)
{
Uchar cs_data=0;
Uchar i;
sdi=HIGH;
for(i=0;i<8;i++)
{
if(i==7){sdi=LOW;}
cs_data<<=1;
if(cs_clock())
cs_data++;
}
return(cs_data);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -