您的位置:首页 > 其它

ok6410的 ADC中断触发转换 实验

2012-06-11 19:50 225 查看
View Code

#include "library.h"
#include "system.h"
#include "sysc.h"
#include "adcts.h"
#include "intc.h"

#define    ADCTS        ((volatile oADCTS_REGS*)ADCTS_BASE)

void    Adcts_Init(int channal, u32 freq);
void __irq    Adcts_Isr(void);
void    Delay(int time);

u32    sample_data=0;
int adc_flag = 0;
void    main(void)
{
int channal = 0;
u32 freq = 2500000;
SYSTEM_EnableVIC();
SYSTEM_EnableIRQ();
//得到g_PCLK;
SYSC_GetClkInform();

Uart_Printf("此测试现在开始,可以按下ECS按键推出\n");
Adcts_Init(channal, freq);
Uart_Printf("该ADC转换频率为: %d\n",freq);

while(Uart_Getch() != 0x1b)
{
while(! adc_flag);
adc_flag = 0;
Uart_Printf("转换通道为:%d , 所得到的转换值为:%04d\n",channal, sample_data);
Delay(3000);
}
}
void    Delay(int time)
{
int i;
for(; time>0; time--)
for(i=0; i<3000;i++);
}

//adc初始化;

void    Adcts_Init(int channal, u32 freq)
{
int prescale;
u32    uConValue;

prescale = (int)(g_PCLK/freq - 1);
ADCTS->rADCCON = (1 << 14) | (prescale << 6) |(channal << 3);//配置分频率,选择通道;

ADCTS->rADCCLRINT = 1; //清除ADC中断;

//设置ADC的中断向量地址
Outp32(rVIC1VECTADDR + 4*(NUM_ADC - 32), (u32)Adcts_Isr);
//使能中断向量;
uConValue = Inp32(rVIC1INTENABLE);
uConValue |= 1 << (NUM_ADC-32);
Outp32(rVIC1INTENABLE,uConValue);

//开始转换:
ADCTS->rADCCON |= 0x1;

}

void __irq    Adcts_Isr(void)
{
//清除中断标志位;
ADCTS->rADCCLRINT = 1;

sample_data = ADCTS->rADCDAT0 & 0X3FF;
adc_flag = 1;
//开始下一次转换;
ADCTS->rADCCON |= 0x1;
Outp32(rVIC1ADDR,0);
Outp32(rVIC0ADDR,0);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: