//#include"../ucos-ii/includes.h"
//#include "../ucos-ii/add/osaddition.h"
#include "../inc/drivers.h"
/* uC/OS interface */
#include "../inc/lib.h"
//#include "../src/gui/gui.h"
#include
#include
#pragma import(__use_no_semihosting_swi)
(0x1<<15)
#define ADCCON_FLAG
// ensure no functions that use semihosting
#define ADCCON_ENABLE_START_BYREAD(0x1<<1)
(*(volatile unsigned *)0x58000000)
(*(volatile unsigned *)0x5800000C)
#define rADCCON
#define rADCDAT0
#define PRSCVL (49<<6)
#define ADCCON_ENABLE_START (0x1)
#define STDBM (0x0<<2)
#define PRSCEN (0x1<<14)
#define GPCCON
#define GPCDAT
#define GPCUP
(*(volatile unsigned *)0x56000020)
(*(volatile unsigned *)0x56000024)
(*(volatile unsigned *)0x56000028)
void ARMTargetInit(void);
void init_ADdevice()
{//初始化
rADCCON=(PRSCVL|ADCCON_ENABLE_START|STDBM|PRSCEN);
}
int GetADresult(int channel)
{
rADCCON=ADCCON_ENABLE_START_BYREAD|(channel<<3)|PRSCEN|PRSCVL;
hudelay(10);
while(!(rADCCON&ADCCON_FLAG));//转换结束
return (0x3ff&rADCDAT0);//返回采样值
}
int main(void)
{
int i,j;
float d;
ARMTargetInit();
// do target (uHAL based ARM system) initialisation //
init_ADdevice();
//printf("\n");
Uart_Printf(0,"\n");
while(1)
{
for(i=0; i>=0; i--)
{//采样 0~3 路 A/D 值
//for(j=0;j<=1;j++)
{d=GetADresult(i)*3.3/1023; // 数据 采集,处理
}
Uart_Printf(0,"a%d=%f\t",i,d);
//printf("a%d=%f\t",i,d);
GPCCON=0x55555555;
GPCUP=0xFFFF;
GPCDAT=0x0;
hudelay(1+d*2);
GPCCON=0x55555555;
GPCUP=0xFFFF;
GPCDAT=0x00E0;
hudelay(1+d/10000);
}
//printf("\r");
Uart_Printf(0,"\r");
}
return 0;
}
下
#include "../inc/drivers.h"
#include "../inc/lib.h"
#include
#include
#pragma import(__use_no_semihosting_swi)
#define ADCCON_FLAG
(0x1<<15)
#define ADCCON_ENABLE_START_BYREAD(0x1<<1)
(*(volatile unsigned *)0x58000000)
#define rADCCON
#define rADCDAT0
(*(volatile unsigned *)0x5800000C)
#define PRSCVL (49<<6)
#define ADCCON_ENABLE_START (0x1)
#define STDBM (0x0<<2)
#define PRSCEN (0x1<<14)
#define GPCCON
#define GPCDAT
#define GPCUP
void ARMTargetInit(void);
void init_ADdevice()
{//初始化
(*(volatile unsigned *)0x56000020)
(*(volatile unsigned *)0x56000024)
// ensure no functions that use semihosting
(*(volatile unsigned *)0x56000028)
rADCCON=(PRSCVL|ADCCON_ENABLE_START|STDBM|PRSCEN);
}
int GetADresult(int channel)
{
rADCCON=ADCCON_ENABLE_START_BYREAD|(channel<<3)|PRSCEN|PRSCVL;
hudelay(10);
while(!(rADCCON&ADCCON_FLAG));//转换结束
return (0x3ff&rADCDAT0);//返回采样值
}
int main(void)
{
int i,j;
int d;
ARMTargetInit();
init_ADdevice();
Uart_Printf(0,"\n");
GPCCON=0x55555555;
// do target (uHAL based ARM system) initialisation //
GPCUP=0xFFFF;
while(1)
{
for(i=0; i<=2; i++)
{//采样 0~3 路 A/D 值
{
d=GetADresult(0)/10;//数据 采集,处理
}
GPCDAT=0x0;
hudelay(1+d);
GPCDAT=0x00E0;
hudelay(103-d);
}
}
}