现在的问题是我的8251单独调试时,用中断完全正确,但是当加上了adc0816时, 用中断就不行了,采集不到数值,ad[0]仍为原来赋的初值.但是不用中断,把原来 中断中的内容写入main()函数中却可以正确采集,为什么?百思不得其解,请大虾们指导! #define _TEST_C_ #include "reg52.h" #include "stdlib.h" #include "absacc.h" #include "intrins.h" #include "test.h" #include "math.h" #define uchar unsigned char #define uint unsigned int #define COM8251 XBYTE[0x8701] #define DAT8251 XBYTE[0x8700] #define IN0 XBYTE[0x8000]
uchar data data_temp[6]={0x52,0x53,0x54,0x55,0x00,0x58}; uchar temp[6]={52,0x53,0x54,0x55,0x00,0x58}; uchar k; uchar data a; static uchar idata ad[16]={0x52,0x53,0x54,0x55,0x00,0x58,0x52,0x53,0x54,0x55,0x00,0x58,0x52,0x53,0x54,0x55};
void initmcu(void); void wait(uchar p,uchar q); void init8251();
void ad0816(uchar idata *x);
void Trans8251(void) interrupt 1 using 1 { TH0 = 0XFF; TL0 = 0XFF; do { ad0816(ad);//采集信号 DAT8251=ad[0];//得到第0通道的转换值 }while((COM8251&0x01)==0); for(k=0;k<6;k++) { while((COM8251&0x02)==0) { temp[k]=DAT8251;//串口调试助手不能写成0x54样式,否则收不到 } } }
void main(void) { EA = 0; initmcu(); EA = 1; init8251(); }
void init8251() { //wait(11,82);//8251工作速度慢,每送一个控制字,等待一会儿延时2ms COM8251 = 0x00; DAT8251 = 0x00; DAT8251 = 0x00; COM8251 = 0x40;//以上为8251复位部分 wait(11,82); COM8251 = 0x4e;//9600baud,1停止位,无校验,8位数据,X16 wait(11,82); COM8251 = 0x35; wait(11,82); }
void initmcu(void) { TMOD = 0x06; //9600波特11.0592MHz,方式2 TL0 = 0XFF; TH0 = 0XFF; IP = 0x02; ET0 = 1;TR0 = 1; }
//adc0816 function...........................................................// void ad0816(uchar idata *x) { uchar i; uchar xdata *ad_adr; ad_adr=&IN0; for(i=0;i<16;i++) { *ad_adr=0; //启动转换从0通道开始 wait(2,28); x=*ad_adr; ad_adr++; } }
void wait(uchar p,uchar q) { uchar i,j; //(2*j+3)*i+4 for (i=p;i>0;i--) for (j=q;j>0;j--); }
|