三星S3F9454 ADC應用源代碼
//ADC通道號定義
#define ADC_Chanel0 (unsigned char)(0x00<<4)
#define ADC_Chanel1 (unsigned char)(0x01<<4)
#define ADC_Chanel2 (unsigned char)(0x02<<4)
#define ADC_Chanel3 (unsigned char)(0x03<<4)
#define ADC_Chanel4 (unsigned char)(0x04<<4)
#define ADC_Chanel5 (unsigned char)(0x05<<4)
#define ADC_Chanel6 (unsigned char)(0x06<<4)
#define ADC_Chanel7 (unsigned char)(0x07<<4)
#define ADC_Chanel8 (unsigned char)(0x08<<4)
//*************************************
// 函數名稱:AdcSwitch
// 函數功能: 在單通道模式下轉換某一通道的AD值
// 入口參數:要轉換的AD通道號
// 出口參數:無
//***************************************
void AdcSwitch(uint8 Chanel)
{
uint8 Tmp = 0 ;
Tmp = Chanel | 0x01 ;//選擇通道 啟動ADC轉換 速度16分頻
ADCON = Tmp ;
while((ADCON & 0x08)==0);
ADCON &= ~0x08 ; //轉換結束標志清0
}
//----實例應用-------
void main(void)
{
while(1)
{
while(!F_10MS);
F_10MS = 0 ;
//ADC啟動轉換
AdcSwitch(ADC_Chanel1) ;
g_ucTmp1 = ADDATAH ; // 提取AD轉換結果
// g_ucTmp2 = ADDATAL ;
}
}