1. 本次使用esay5509开发板,具体做这个板子叫做大道科技。
2. 5509有2个ADC的输入引脚,就是2个采集通道
3. 看下ADC的寄存器
4. 看下代码中怎么引用ADC的寄存器的,这种写法很少用,但是在DSP中很常见的。
1 ioport unsigned int *ADCCTL1=(unsigned int *)0x6800; 2 ioport unsigned int *ADCDATA1=(unsigned int *)0x6801; 3 ioport unsigned int *ADCCLKDIV1=(unsigned int *)0x6802; 4 ioport unsigned int *ADCCLKCTL1=(unsigned int *)0x6803; 5 #define ADCCTL (*ADCCTL1) 6 #define ADCDATA (*ADCDATA1) 7 #define ADCCLKDIV (*ADCCLKDIV1) 8 #define ADCCLKCTL (*ADCCLKCTL1)
5. 主程序比较简单
1 main() 2 { 3 int i; 4 unsigned int uWork; 5 6 EnableAPLL(); 7 8 InitADC(); 9 PLL_Init(132); 10 while ( 1 ) 11 { 12 for ( i=0;i<256;i++ ) 13 { 14 ADCCTL=0x8000; // 启动AD转换,通道0 15 do 16 { 17 uWork=ADCDATA; 18 } while ( uWork&0x8000 ); 19 nADC0[i]=uWork&0x0fff; 20 } 21 for ( i=0;i<256;i++ ) 22 { 23 ADCCTL=0x9000; // 启动AD转换,通道1 24 do 25 { 26 uWork=ADCDATA; 27 } while ( uWork&0x8000 ); 28 nADC1[i]=uWork&0x0fff; 29 } 30 asm( " nop"); // break point 在这里设断点 31 } 32 } 33 34 void InitADC() 35 { 36 ADCCLKCTL=0x23; // 4MHz ADCLK 37 ADCCLKDIV=0x4f00; 38 }
6. 在程序中注意到一个细节,怎么直接给寄存器赋值的,看下面*( ioport volatile unsigned short* )0x1f00 = 4;这种写法很重要,一定要掌握。
1 void EnableAPLL( ) 2 { 3 /* Enusre DPLL is running */ 4 *( ioport volatile unsigned short* )0x1f00 = 4; 5 wait( 25 ); 6 *( ioport volatile unsigned short* )0x1f00 = 0; 7 // MULITPLY 8 *( ioport volatile unsigned short* )0x1f00 = 0x3000; 9 // COUNT 10 *( ioport volatile unsigned short* )0x1f00 |= 0x4F8; 11 wait( 25 ); 12 //*( ioport volatile unsigned short* )0x1f00 |= 0x800 13 // MODE 14 *( ioport volatile unsigned short* )0x1f00 |= 2; 15 wait( 30000 ); 16 // APLL Select 17 *( ioport volatile unsigned short* )0x1e80 = 1; 18 // DELAY 19 wait( 60000 ); 20 }