?? ad7703.c
字號:
/*
* ad7703.c
*
* AD7703
*
*
*
* 陳真勇(SA01010010)
* w3wind@sina.com or
* zychen@ustc.edu.cn
* 中國科學技術大學自動化系
* 2002/6/12
*/
#include "type.h"
#include "delay.h"
#include "link.h"
#include "watchdog.h"
void selfcal()
{
BYTE i;
ADCS=1;
ADCAL=1;
delay10us();
/* note: Self calibration last for at least 4 cycle clocks,
and AD7703's main clock is 2M Hz. Our AT89C52 is
12 MHz,so we put 4 NOP instructions here. If frequency
changed, you should change number of NOPs accordingly.*/
ADCAL=0;
}
UINT read_ad()
{
BYTE i=20; /* 20 bits to be read */
UINT mask=0x8000;
UINT result=0;
do{}while( ADDRDY );
EA = 0;
/*read first 16 bits of total 20 bits*/
ADCS=1;
ADCS=0;
do{
ADSCLK=1;/* data valid on rising edge */
if(i>4 && ADSDATA){ /* max delay 75 ns before data valid. first check i>4*/
result |= mask;
}
mask >>= 1;
ADSCLK=0;/* data changed on falling_edge */
}while(--i);
ADCS=1;
EA = 1;
return result;
}
void init_ad7703()
{
BYTE i;
selfcal();/*self calibration*/
/*we must wait for 3,500,000 clock cycles befor can access AD7703. It's
about 2s long*/
/* ????????????????????? */
for(i=0;i<20;i++){
/* TODO: you should clear watch dog while waiting.
you should provide delay function that delay
1 ms */
clear_watchdog();
delay(100);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -