main.c

来自「数模转换模块」· C语言 代码 · 共 52 行

C
52
字号
#include "44b.h"
#include"uhal.h"
#include "option.h"
#include"def.h"

#define ADCCON_FLAG		0x40
#define ADCCON_SLEEP		0x20

#define ADCCON_ADIN0		(0x0<<2)
#define ADCCON_ADIN1		(0x1<<2)
#define ADCCON_ADIN2		(0x2<<2)
#define ADCCON_ADIN3		(0x3<<2)
#define ADCCON_ADIN4		(0x4<<2)
#define ADCCON_ADIN5		(0x5<<2)
#define ADCCON_ADIN6		(0x6<<2)
#define ADCCON_ADIN7		(0x7<<2)

#define ADCCON_READ_START	0x2
#define ADCCON_ENABLE_START	0x1

void init_ADdevice()
{//初始化
	rADCPSR=20;
	rADCCON=ADCCON_SLEEP;
}

int GetADresult(int channel)
{
	rADCCON=(channel<<2)|ADCCON_ENABLE_START;
	Delay(10);
	while(!(rADCCON&ADCCON_FLAG));//转换结束
	return rADCDAT;//返回采样值
}
int Main(int argc, char **argv)
{
	int i;
	float d;
	ARMTargetInit();	//开发版初始化
	init_ADdevice();
	Uart_Printf("\n");
	while(1)
	{
		for(i=0; i<=3; i++)
		{//采样0~3路A/D值
			d=GetADresult(i)*2.5/1024; // 数据 采集,处理
			Uart_Printf("a%d=%f\t",i,d);
			Delay(1000);
		}	
		Uart_Printf("\r");
	}
	return 0;
}

⌨️ 快捷键说明

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