main.c
来自「博创2410的实验代码」· C语言 代码 · 共 49 行
C
49 行
#include "../inc/drivers.h"
#include "../inc/lib.h"
#include <string.h>
#include <stdio.h>
#pragma import(__use_no_semihosting_swi) // ensure no functions that use semihosting
#define ADCCON_FLAG (0x1<<15)
#define ADCCON_ENABLE_START_BYREAD (0x1<<1)
#define rADCCON (*(volatile unsigned *)0x58000000)
#define rADCDAT0 (*(volatile unsigned *)0x5800000C)
#define PRSCVL (49<<6)
#define ADCCON_ENABLE_START (0x1)
#define STDBM (0x0<<2)
#define PRSCEN (0x1<<14)
void ARMTargetInit(void);
void init_ADdevice()
{//初始化
rADCCON=(PRSCVL|ADCCON_ENABLE_START|STDBM|PRSCEN);//AD控制寄存器设置,参看手册P420
}
int GetADresult()
{
rADCCON=ADCCON_ENABLE_START_BYREAD|(1<<3)|PRSCEN|PRSCVL; //转换开始
hudelay(10);
while(!(rADCCON&ADCCON_FLAG));//转换结束
return (0x3ff&rADCDAT0);//返回采样值
}
int main(void)
{
int i;
float d;
ARMTargetInit(); // do target (uHAL based ARM system) initialisation //
init_ADdevice(); //AD初始化设置
Uart_Printf(0,"\n");
while(1)
{
d=GetADresult()*3.3/1023; // 数据 采集,处理,10位AD,满幅为3.3v
Uart_Printf(0,"a%d=%f\t",i,d);
hudelay(1000);
Uart_Printf(0,"\r");
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?