2019-07-15 09:26发布
f310808020307 发表于 2017-10-27 15:43 贴程序看看吧 感觉是ADC配置没整对的吧
454783436 发表于 2017-10-27 18:27
最多设置5个标签!
- #define ADC_POWER 0x80
- #define ADC_SPEEDHH 0x60
- #define ADC_SPEEDH 0x40
- #define ADC_SPEEDL 0x20
- #define ADC_SPEEDLL 0x00
- #define ADC_FLAG 0x10
- #define ADC_START 0x08
- #define ADRJ 0x20
- #define CH0 0
- #define CH1 1
- #define CH2 2
- void Timer0init()
- {
- TMOD=0x01;
- TH0=0xF8;
- TL0=0x30;
- ET0=1;
- EA=1;
- TR0=1;
- }
- void ADC_Init()
- {
- P1ASF|=0x03;
-
- PADC=0;
-
- EA=1;
- EADC=1;
- ADC_RES=0;
- ADC_CONTR = ADC_POWER | ADC_SPEEDH;
- Delay(20);
- }
- uchar GetADC_data(uchar CH)
- {
- ADC_CONTR |=ADC_START+CH;
- TR0=1;
- _nop_();
- _nop_();
- _nop_();
- _nop_();
-
- while(!(ADC_CONTR & ADC_FLAG));
- ADC_CONTR &= ~ADC_FLAG; //Close ADC
-
- return ADC_RES; //Return ADC value
- }
- void main()
- {
- uchar i;
- cDATA=0x01;
- IO_Init();
- Timer0init();
- ADC_Init();
-
- while(1)
- {
- for(i=1;i<65;i++)
- ADC_data[i].real=GetADC_data(CH2);
- FFTProcess();
- led3=~led3;
- }
- }
- void timer0() interrupt 1 using 1
- {
- TH0=0xF8;
- TL0=0x30;
- P0=cDATA;
- led1=0;
- bright(ledBuf);//½øÐз¢¹â
- if(cDATA>=0x80)
- cDATA=0x01;
- else
- {
- cDATA<<=1;
- led2=0;
- }
- }
复制代码只选了一部分的,把41行这一句注释掉定时器中断就进得去,不注释掉就进不去了。ADC_CONTR |=ADC_START+CH;
一周热门 更多>