⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drv_ad.c

📁 该模板使用于周立功公司研发的EasyARM2100系列开发板
💻 C
字号:
/******************************************************************************
  Copyright (C), 2007-2008, wanyi Tech. Co., Ltd.
  FileName		:drv_ad.c
  Author		:kevin 
  modify		:       
  Version 		:1.0          
  Date			:2008-4-21
  Description	:auto design for driver ad function       
  Function List	:
******************************************************************************/
#include "\inc\system.h"






/******************************************************************************
  Function:       // void test_ch375_pin(void)
  Description:    // for test ch375 pin
  Calls:          // none
  Called By:      // init ()
  Table Accessed: // none
  Table Updated:  // none
  Input:          // void
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
void test_ad_pin(void)
{
}
//=============================================================================



/******************************************************************************
  Function:       // void init_ad(void)
  Description:    // for init ad
  Calls:          // none
  Called By:      // init ()
  Table Accessed: // none
  Table Updated:  // none
  Input:          // void
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
void init_ad(void)
{
	ADCR |= 0x00000002;				//0.1        select channel ad1.2
	ADCR |= 0x0000ff00;				//0.8--1.5   clkdiv
	ADCR &= 0xfffeffff;				//0.16       burst=0
	ADCR &= 0xfff1ffff;				//0.17--0.19 clks    11 clock,10 bit result
	ADCR |= 0x00200000;				//0.21       pdn=1
	ADCR &= 0xff3fffff;				//0.22-0.23  normal mode=00		
}
//=============================================================================



/******************************************************************************
  Function:       // unsigned short read_ad(void)
  Description:    // for test ad
  Calls:          // none
  Called By:      // init ()
  Table Accessed: // none
  Table Updated:  // none
  Input:          // void
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
unsigned short read_ad(void)
{
	volatile unsigned long int ad_data;
	volatile unsigned short ad_value=0; 
	
	ad_data = ADDR;																//读取ADC结果,并清除DONE标志位
	ad_value=ad_data;
	
	ADCR |= 0x01000000;															//启动转换
	while ((ADDR & 0x80000000) == 0);											//等待转换结束
	ad_data = ADDR;																//读取ADC结果
	ad_data = (ad_data >> 6) & 0x3ff;

	ad_value=ad_data;
		
	return(ad_value);
}
//=============================================================================



/******************************************************************************
  Function:       // unsigned short test_ad(void)
  Description:    // for test ad
  Calls:          // none
  Called By:      // init ()
  Table Accessed: // none
  Table Updated:  // none
  Input:          // void
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
unsigned short test_ad(void)
{
	volatile unsigned long int ad_data;
	volatile unsigned short ad_value=0; 
	
	ad_data = ADDR;																//读取ADC结果,并清除DONE标志位
	ad_value=ad_data;
	
	ADCR |= 0x01000000;															//启动转换
	while ((ADDR & 0x80000000) == 0);											//等待转换结束
	ad_data = ADDR;																//读取ADC结果
	ad_data = (ad_data >> 6) & 0x3ff;

	ad_value=ad_data;
		
	return(ad_value);
}
//=============================================================================




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -