上午发布的ADC解读部分访问好高,呵呵,我又受鼓舞了,再接再励,把温度传感器这部分弄完就去吃晚饭。 直接贴代码了 void main(void) {// long sum=0;// float vol=0;int16 sensorSample,DegreesC;// int i=0;// Step 1. Initialize System Control:// PLL, WatchDog, enable Peripheral Clocks// This example function is found in the DSP2802x_SysCtrl.c file. InitSysCtrl();// Step 2. Initalize GPIO:// This example function is found in the DSP2802x_Gpio.c file and// illustrates how to set the GPIO to it's default state. InitGpio();// Step 3. Clear all interrupts and initialize PIE vector table:// Disable CPU interrupts DINT;// Initialize PIE control registers to their default state.// The default state is all PIE interrupts disabled and flags// are cleared.// This function is found in the DSP2802x_PieCtrl.c file. InitPieCtrl();// Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;// Initialize the PIE vector table with pointers to the shell Interrupt// Service Routines (ISR).// This will populate the entire table, even if the interrupt// is not used in this example. This is useful for debug purposes.// The shell ISR routines are found in DSP2802x_DefaultIsr.c.// This function is found in DSP2802x_PieVect.c. InitPieVectTable();// Step 4. Initialize all the Device Peripherals:// This function is found in DSP2802x_InitPeripherals.c// InitPeripherals(); // Not required for this example// Step 5. User specific code: InitAdc(); AdcOffsetSelfCal(); InitLCD12864(); EALLOW; AdcRegs.ADCCTL1.bit.TEMPCONV = 1; AdcRegs.ADCSOC0CTL.bit.TRIGSEL = 1; AdcRegs.ADCSOC0CTL.bit.CHSEL = 5; AdcRegs.ADCSOC0CTL.bit.ACQPS = 6;// AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 0; AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1; AdcRegs.INTSEL1N2.bit.INT1SEL = 1; AdcRegs.INTSEL1N2.bit.INT1CONT = 0; AdcRegs.INTSEL1N2.bit.INT1E = 1; PieCtrlRegs.PIEIER1.bit.INTx1 = 1; FlashRegs.FOTPWAIT.bit.OTPWAIT = 1; EDIS; CpuTimer0Regs.TCR.bit.TIE = 1; StartCpuTimer0(); EALLOW; PieCtrlRegs.PIEIER1.bit.INTx7 = 1; PieCtrlRegs.PIECTRL.bit.ENPIE = 1; IER |= 0x0001; EINT; EDIS; while(1) { if(AdcRegs.ADCSOCFLG1.bit.SOC0==1) { while(AdcRegs.ADCSOCFLG1.bit.SOC0==1); AdcRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; DELAY_US(10); sensorSample=AdcResult.ADCRESULT0; DegreesC=GetTemperatureC(sensorSample); DISLPLAY_LONGSTRING(2,0,DegreesC);// sum+=AdcResult.ADCRESULT0;// i++; } /* if(i==10) {// sum/=10;// vol=sum*3.3/4095; WRITECMD_LCD12864(0x01); DISLPLAY_LONGSTRING(2,0,sum);// DISLPLAY_FLOATSTRING(3,0,vol);// WRITEDATA_LCD12864('v'); sum=0; i=0; }*/ //sum=AdcResult.ADCRESULT0; //DISLPLAY_LONGSTRING(2,0,sum); } } 不知道为什么,程序一直卡在非法操作中断那里,坑爹呀,都检查好多遍了,先去吃发个饭再回来继续检查。 吃晚饭回来又调试了下,发现是温度转换成摄氏温度的时候算法有问题,但这是TI提供的标准算法,暂时没发现错在哪里。但前面的步骤都是没问题的,能够读取温度的数字量。 刚才到处找资料,想找这两个地址的默认值,找到一个,0x28A9,不知道对不对,然后自己把这两个地址的值替换计算了下,结果又差不多,不知道了,等待大神解答 |
|