本帖最后由 ztx123 于 2014-9-23 15:23 编辑
这是控制电机的AD转换子程序,程序可以进AD中断,但是ADC_RES一直为零,如果我在pwmoutput();子函数里面直接给pwmoutput(0X5A),,电机就可以运转,或者直接给ADC_RES赋值也可以让电机转。。。但就是采不到ADC_RES,求大神指教
#include<12c5204.h>
#include<intrins.h>
#include<func
tion.h>
#define FOSC 24000000L
#define BAUD 9600
#define ADC_FLAG 0x10
//unsigned char a ;
unsigned char i = 0;
sbit OPEN = P3^3;
void adc_isr() interrupt 5 using 1
{
ADC_CONTR&= !ADC_FLAG;
ADC_CONTR = 0x8A;
// GETADCResult();
//a = ADC_RES;
pwmoutput(ADC_RES);
}
void InitADC()
{
P1ASF = 0x04;
ADC_RES = 0;
ADC_CONTR = 0x8A;
Delay123(2);
}
void GETADCResult()
{
ADC_CONTR = 0x8A;
_nop_();
_nop_();
_nop_();
_nop_();
while((!ADC_CONTR&ADC_FLAG));
// a = ADC_RES;
}
void Delay123(unsigned int n)
{
unsigned int x;
while(n--)
{
x = 5000;
while(x--);
}
}
void pwmoutput(unsigned char a)
{
if(a == 0x00)
{CCAP0H = 0x00;}
else if((a>=0x55)&&(a<=0x57))
{pwm0();}
else if((a>=0x5A)&&(a<=0x5C))
{pwm1();}
else if((a>=0x60)&&(a<=0x61))
{pwm2();}
else if((a>=0x64)&&(a<=0x66))
{pwm3();}
else if((a>=0x69)&&(a<=0x6B))
{pwm4();}
else if((a>=0x6D)&&(a<=0x6F))
{pwm5();}
else if((a>=0x72)&&(a<=0x74))
{pwm6();}
else if((a>=0x77)&&(a<=0x79))
{pwm7();}
else if((a>=0x7B)&&(a<=0x7D))
{pwm8();}
else if((a>=0x80)&&(a<=0x82))
{pwm9();}
}
一周热门 更多>