?? adc0832.c
字號:
/********************************************************************************/
/* filename : ADC0832.c */
/* created : xillinx */
/* descript : 處理ADC0832相關(guān)的函數(shù) */
/********************************************************************************/
#include "../CPU/CPU.h"
#include "../ADC0832/ADC0832.h"
/********************************************************************************/
/* function : ADC_set_clk() */
/* recension: xillinx */
/* descript : 設(shè)置或者清除ADC的CLK引腳 */
/********************************************************************************/
void ADC_set_clk(unsigned char clk)
{ if(clk)
{ c51_U19_latch|=0x08;
}
else
{ c51_U19_latch&=0xF7;
}
c51_hc138_cs_io2[0x0]=c51_U19_latch;
}
/********************************************************************************/
/* function : ADC_set_sel() */
/* recension: xillinx */
/* descript : 設(shè)置或者清除ADC的CS引腳 */
/********************************************************************************/
void ADC_set_sel(unsigned char sel)
{ if(sel)
{ c51_U19_latch|=0x04;
}
else
{ c51_U19_latch&=0xFB;
}
c51_hc138_cs_io2[0x0]=c51_U19_latch;
}
/********************************************************************************/
/* function : ADC_set_dat() */
/* recension: xillinx */
/* descript : 設(shè)置或者清除ADC的DATA引腳 */
/********************************************************************************/
void ADC_set_dat(unsigned char dat)
{ ADC_DA=dat;
}
/********************************************************************************/
/* function : ADC_set_dat() */
/* recension: xillinx */
/* descript : 設(shè)置或者清除ADC的DATA引腳 */
/********************************************************************************/
unsigned char ADC_get_dat(void)
{ return ADC_DA;
}
/********************************************************************************/
/* function : ADC_delay() */
/* recension: xillinx */
/* descript : 簡單延時處理 */
/********************************************************************************/
void ADC_delay(unsigned char time)
{ unsigned char i;
for(i=0;i<time;i++)
{ ;
}
}
/********************************************************************************/
/* function : ADC_read_1_channel() */
/* recension: xillinx */
/* descript : 讀取第一通道的數(shù)據(jù) */
/********************************************************************************/
unsigned char ADC_read_channel(unsigned char channel)
{ unsigned char mdata=0x0;
unsigned char i;
ADC_set_sel(0x1); //* CS=1,CK=0,禁止芯片工作,設(shè)置初始工作態(tài);
ADC_delay(0x2);
ADC_set_clk(0x0);
ADC_delay(0x2);
ADC_set_sel(0x0); //* 啟動工作
ADC_set_dat(0x1); //* 第1個時鐘,上升沿采樣 START位, 此時DATA=1
ADC_delay(0x2);
ADC_set_clk(0x1);
ADC_delay(0x2);
ADC_set_clk(0x0);
ADC_set_dat(0x1); //* 第2個時鐘,上升沿采樣 通道/差分 選擇(本設(shè)計選擇通道,所以為1)
ADC_delay(0x2);
ADC_set_clk(0x1);
ADC_delay(0x2);
ADC_set_clk(0x0);
if( channel==0x0)
{ ADC_set_dat(0x0); //* 第3個時鐘,上升沿采樣 通道編號 0 通道
}
else
{ ADC_set_dat(0x1); //* 通道編號 1 通道
}
ADC_delay(0x2);
ADC_set_clk(0x1);
ADC_delay(0x2);
ADC_set_clk(0x0);
ADC_set_dat(0x1); //* 第4個時鐘之前,需要把ADC_DA設(shè)置成為1,作為輸入引腳用了,這個時鐘周期是空閑的
ADC_delay(0x2);
/****************************************************************************/
/* 讀取ADC數(shù)據(jù) */
/****************************************************************************/
for(i=0x0;i<0x8;i++)
{ mdata<<=0x1;
ADC_set_clk(0x1); //* 上升沿ADC不處理
ADC_delay(0x2);
ADC_set_clk(0x0); //* 下降沿ADC輸出數(shù)據(jù)
ADC_delay(0x2);
if(ADC_get_dat())
{ mdata|=0x01;
}
}
/****************************************************************************/
/* 恢復(fù)初始化狀態(tài) */
/****************************************************************************/
ADC_delay(0x2);
ADC_set_sel(0x1); //* CS=1,CK=0,禁止芯片工作,設(shè)置初始工作態(tài);
ADC_delay(0x2);
ADC_set_clk(0x0);
ADC_delay(0x2);
return mdata;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -