• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






ccs c 自带的文件有错误,下面是我找的正确的文件
#3
新會員
新會員


查看用戶資訊
///////////////////////////////////////////////////////////////////////////////////////////////////////
//// AD7705.C ////
//// Driver for analog device AD7705 ////
//// adc_init() Call after power up ////
//// read_adc_value(channel)Read adc value from the specified channel ////
//// adc_disable() Disables the adc conversion ////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//// Driver routines for the AD7705 chip
//Assuming a 2.4576 crystal ocsillator is used between MCLK IN and MCLK OUT

// ************************************************
// *************** AD7705 采样 ******************* **
// ************************************************
// connection pins to the PIC
#define ADC_DRDY PIN_B0 // 数据准备好
#define ADC_DO PIN_B2 // SPI数据输出
#define ADC_DI PIN_B1 // SPI数据输入
#define ADC_CLK PIN_B3 // SPI数据时钟

//Operation modes
#define ADC_NORMAL 0x00
#define ADC_SELF 0x40
#define ADC_ZERO_SCALE 0x80
#define ADC_FULL_SCALE 0xc0

//Gain settings
#define ADC_GAIN_1 0x00
#define ADC_GAIN_2 0x08
#define ADC_GAIN_4 0x10
#define ADC_GAIN_8 0x18
#define ADC_GAIN_16 0x20
#define ADC_GAIN_32 0x28
#define ADC_GAIN_64 0x30
#define ADC_GAIN_128 0x38

//Polar operations
#define ADC_BIPOLAR 0x00
#define ADC_UNIPOLAR 0x04

//update rates
#define ADC_50 0x04
#define ADC_60 0x05
#define ADC_250 0x06
#define ADC_500 0x07

void adc_init(void);
void write_adc_byte(BYTE data);
unsigned long read_adc_word();
void setup_adc_device(int calmode, int gainsetting, int operation, int rate);

unsigned long read_adc_value(int1 ch);
void adc_disable();
float convert_to_volts(long data);

//initailaization routine

void adc_init(void)
{
restart_wdt();
write_adc_byte( 0x04 );
setup_adc_device(ADC_SELF,ADC_GAIN_1,ADC_UNIPOLAR,ADC_50);
}

void write_adc_byte(BYTE data)
{
BYTE i;
for(i=1;i<=8;i++) {
output_bit(ADC_DI, shift_left(&data,1,0));
output_low(ADC_CLK);
output_high(ADC_CLK);
}
}

unsigned long read_adc_word()
{
BYTE i;
unsigned long data;

for(i=1;i<=16;++i) {
output_low(ADC_CLK);
output_high(ADC_CLK);
shift_left(&data,2,input(ADC_DO));
}
return data;
}

//setup the device paramaters(mode, gainsetting, polar operation and output rate)
void setup_adc_device(int calmode, int gainsetting, int operation, int rate)
{
restart_wdt();
write_adc_byte( 0x20 ); //Communications Register set to write of clock register
write_adc_byte( rate ); //Clock Register info here
write_adc_byte( 0x10 ); //Communications Register set to write of setup register
write_adc_byte( calmode|gainsetting|operation ); //calmode|gainsetting|operation);
//Setup Register info here
write_adc_byte( 0x21 ); //Communications Register set to write of clock register
write_adc_byte( rate ); //Clock Register info here
write_adc_byte( 0x11 );
write_adc_byte( calmode|gainsetting|operation );
}

//read an adc value from the specified channel
unsigned long read_adc_value(int1 ch)
{
unsigned long value;
while ( input(ADC_DRDY) );
if(!ch)
write_adc_byte(0x38); //communications register set to read of data register of channel 1
else
write_adc_byte(0x39); //communications register set to read of data register of channel 0
value=read_adc_word();
while ( !input(ADC_DRDY) );//
return value;
}

//disable the a/d conversion
void adc_disable()
{
write_adc_byte( 0x20 );//Communications Register set to write of clock register
write_adc_byte( 0x10 );//Clock Register info here
}

//Convert the value read to volts
float convert_to_volts(long data)
{
return ((float)data*2.498/0xffff);
}


發表於: 2006/9/2 13:31
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 我使用CCS C编写读取AD7705的数据,读不出数据
#2
資深會員
資深會員


查看用戶資訊

請看

C:\Program Files\PICC\Drivers\AD7705.C

發表於: 2006/8/21 2:00
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


我使用CCS C编写读取AD7705的数据,读不出数据
#1
新會員
新會員


查看用戶資訊
AD7705我只使用了SCLK、DIN、DOUT、DRDY与PIC16F877A相接,读不出数据?

發表於: 2006/8/18 12:01
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------