ok6410的 ADC中断触发转换 实验

View Code
 1 #include "library.h"
 2 #include "system.h"
 3 #include "sysc.h"
 4 #include "adcts.h"
 5 #include "intc.h"
 6 
 7 #define    ADCTS        ((volatile oADCTS_REGS*)ADCTS_BASE)
 8 
 9 void    Adcts_Init(int channal, u32 freq);
10 void __irq    Adcts_Isr(void);
11 void    Delay(int time);
12 
13 u32    sample_data=0;
14 int adc_flag = 0;
15 void    main(void)
16 {
17     int channal = 0;
18     u32 freq = 2500000;
19     SYSTEM_EnableVIC();
20     SYSTEM_EnableIRQ();
21     //得到g_PCLK;
22     SYSC_GetClkInform();
23     
24     Uart_Printf("此测试现在开始,可以按下ECS按键推出\n");
25     Adcts_Init(channal, freq);
26     Uart_Printf("该ADC转换频率为: %d\n",freq);
27 
28     while(Uart_Getch() != 0x1b)
29     {
30         while(! adc_flag);
31         adc_flag = 0;
32         Uart_Printf("转换通道为:%d , 所得到的转换值为:%04d\n",channal, sample_data);
33         Delay(3000);
34     }
35 }
36 void    Delay(int time)
37 {
38     int i;
39     for(; time>0; time--)
40         for(i=0; i<3000;i++);
41 }
42 
43 //adc初始化;
44 
45 void    Adcts_Init(int channal, u32 freq)
46 {
47     int prescale;
48     u32    uConValue;
49     
50     prescale = (int)(g_PCLK/freq - 1);
51     ADCTS->rADCCON = (1 << 14) | (prescale << 6) |(channal << 3);//配置分频率,选择通道;
52     
53     ADCTS->rADCCLRINT = 1; //清除ADC中断;
54 
55     //设置ADC的中断向量地址
56     Outp32(rVIC1VECTADDR + 4*(NUM_ADC - 32), (u32)Adcts_Isr);
57     //使能中断向量;
58     uConValue = Inp32(rVIC1INTENABLE);
59     uConValue |= 1 << (NUM_ADC-32);
60     Outp32(rVIC1INTENABLE,uConValue);  
61     
62     //开始转换:
63     ADCTS->rADCCON |= 0x1;
64     
65 }
66 
67 void __irq    Adcts_Isr(void)
68 {
69     //清除中断标志位;        
70     ADCTS->rADCCLRINT = 1;
71     
72     sample_data = ADCTS->rADCDAT0 & 0X3FF;
73     adc_flag = 1;
74     //开始下一次转换;    
75     ADCTS->rADCCON |= 0x1;    
76     Outp32(rVIC1ADDR,0);
77     Outp32(rVIC0ADDR,0);    
78 }

 

posted on 2012-06-11 19:50  小虫儿  阅读(672)  评论(0编辑  收藏  举报