adc.c

来自「天煌公司的THUS-1型嵌入式实验/开发系统的串口通信实验」· C语言 代码 · 共 41 行

C
41
字号
#include <string.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\adc.h"
extern volatile  int flag;

void Test_Adc(void)
{
           int i;
	float d;

  	rADCPSR=20;
	rADCCON=ADCCON_SLEEP;
	
	Uart_Printf("\n Print any key to stop!!\n\n");
           Delay(10000);
	for(i=1;i<=3;i++)
	{	
//		 if (Uart_GetKey()!=0)
//		{
//		 	flag=0;
//			return;
//		}
//		 else
		
			d=GetADresult(i)*2.5/1024;
			Uart_Printf("a%d=%f\n",i,d);
			Delay(10000);
		 

	}
}
//读取某路模拟量函数:
int GetADresult(int channel)
{
	rADCCON=(channel<<2)|ADCCON_ENABLE_START;//which channel A/D conversion starts
	Delay(10);
	while(!(rADCCON&ADCCON_FLAG));//check Flag bit,if end return ,else wait
	return rADCDAT;
}

⌨️ 快捷键说明

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