看书上说如果你进入AD中断后,那么这时总中断也应该被关了吧,如果你不在这个中断服务程序里开总中断的话,那么以后就永远不会进入中断了吧?
今天我调程序dsp2407时,写了下面代码: interrupt void ADCInt(void) { //Get ADC result Disable(); //关中断 count++; asm(" clrc SXM"); j = RESULT0; adcResult[i++] = (*j) >> 6; if (i == 22) i = 0; //*ADCTRL2 |= 0x4000; SocADC(); //*IFR = *IFR | 0x0001; if (count>65534) count = 0; //Enable(); } 结果一运行,发现count能不断地增加,意思是它不止一次地进入中断,不知有谁知道是怎么回事?
程序的全部代码如下:#include "DSP2407A.h"
/********* Declare Functions ******/
typedef unsigned int uint;
//Global functions inline void Disable(void); inline void Enable(void); void SysInit(void); void nothing(void);
//ADC functions void ADCInit(void); interrupt void ADCInt(void); inline void SocADC(void);
//Global variables volatile uint *j; static uint adcResult[22]; static uint i = 0; static uint count = 0; /************ End ********************/
/************* main ******************/ int main(void) { Disable(); SysInit(); ADCInit(); Enable(); SocADC(); while(1); return 0; } /************* End of main ************/
/************* Implement of functions *******************/ inline void Disable(void) { asm(" setc INTM"); }
inline void Enable(void) { asm(" clrc INTM"); }
void ADCInit(void) { *ADCTRL1 = 0x0000; *ADCTRL2 = 0x0600; *MAXCONV = 0x0000; //one channel to be converted *CHSELSEQ1 = 0x0000; //Channel 0 *CHSELSEQ2 = 0; *CHSELSEQ3 = 0; *CHSELSEQ4 = 0; }
interrupt void ADCInt(void) { //Get ADC result Disable(); count++; asm(" clrc SXM"); j = RESULT0; adcResult[i++] = (*j) >> 6; if (i == 22) i = 0; //*ADCTRL2 |= 0x4000; SocADC(); //*IFR = *IFR | 0x0001; if (count>65534) count = 0; //Enable(); }
void SysInit(void) { asm(" setc SXM"); //符号扩展位有效 asm(" clrc OVM"); //累加器结果正常溢出 asm(" clrc CNF"); //B0被配置成数据存储空间 *SCSR1 = 0x81fe; *WDCR = 0x0e8; *IMR = 0x0001; //enable INT1 *IFR = 0x0ffff; //clear all interrupt flag: write a 1 clears these bits }
inline void SocADC(void) { *ADCTRL2 |= 0x2000; //set SOC SEQ1 }
void nothing(void) { return; } /***************** End ********************************************/
|