//————————————————头文件———————————————————— #include "inc/hw_ints.h"//硬件中断 #include "inc/hw_memmap.h" #include "inc/hw_types.h"//硬件类型 #include "driverlib/gpio.h"//GPIO #include "driverlib/sysctl.h"//系统 #include "grlib/grlib.h"//画图 #include "drivers/kitronix320x240x16_ssd2119_8bit.h" #include "drivers/set_pinout.h" #include "driverlib/interrupt.h"//中断 #include "driverlib/comp.h"//comp #include "driverlib/systick.h"//systick #include "driverlib/adc.h"//adc #include <stdio.h> //——————————————————————————————————————— tContext sContext;//声明绘图 tBoolean ADC_EndFlag = false;//定义A/D转换结束的标志 unsigned long TheSysClock = 12000000UL;//定义系统时钟12MHZ //——————————————————————————————————————— // The error routine that is called if the driver library encounters an error. //——————————————————————————————————————— #ifdef DEBUG4 void __error__(char *pcFilename, unsigned long ulLine) { } #endif //——————————————————————————————————————— //****************************************************************************** // Initialize the System timer (SysTick)初始化 void SysTickInit(void) { // Set the period of the SysTick SysTickPeriodSet(TheSysClock);//SysTick(一个简单的定时器)的周期 // Enable SysTick interrupts SysTickIntEnable();//使能SysTick中断 // Enable System interrupts IntMasterEnable();//使能处理器中断 // Enable the SysTick SysTickEnable();//使能SysTick计数器 } //****************************************************************************** //——————————————————————————————————————— // Display the temperature of the chip void tmpDisplay(unsigned long ulValue) { unsigned long ulTemp; char pcBuffer1[4]; char pcBuffer2[3]; ulTemp = 151040UL - 225 * ulValue;//(ADC采样值转化为温度值)的1024倍 pcBuffer1[0] = ' ';//空格 pcBuffer1[1] = (ulTemp/1024)%100/10 + '0';//十位 pcBuffer1[2] = (ulTemp/1024)%10 + '0';//个位 pcBuffer1[3] = '\0';//结束符 GrContextFontSet(&sContext, &g_sFontCm36b);//字体设置 GrStringDrawCentered(&sContext, pcBuffer1, -1, 110, 180, 1);//写整数部分 pcBuffer2[0] = '.';//小数点 pcBuffer2[1] = (ulTemp%1024)/102+'0';//小数 pcBuffer2[2] = '\0';//结束符 GrContextFontSet(&sContext, &g_sFontCm36b);//字体设置 GrStringDrawCentered(&sContext, pcBuffer2, -1, 150, 180, 1);//写小数部分 } //——————————————————————————————————————— //****************************************************************************** // SysTick ISR SysTick的中断服务函数 void SysTick_ISR(void) { // Just used to wake up CPU,do nothing 唤醒CPU } //****************************************************************************** //——————————————————————————————————————— // ADC Sequence 3 ISR ADC序列3的中断服务函数 void ADC_Sequence_3_ISR(void) { unsigned long ulStatus; //Get interrupt status ulStatus = ADCIntStatus(ADC_BASE, 3, true);//获取当前的中断状态 // Clear interrupts ADCIntClear(ADC_BASE, 3);//清除中断状态,重要 // If interrupt status is ture, set ADC ending flag as ture //如果中断状态有效,置位ADC采样结束标志 if (ulStatus != 0) { ADC_EndFlag = true; } } //如果中断状态值为真,则将中断结束标志置为真,真表示需要屏蔽的中断状态 //假表示需要原始的中断状态 //——————————————————————————————————————— int main(void) { unsigned long ulValue; // Set the clocking to run directly from the crystal. SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // Get system clock TheSysClock = SysCtlClockGet();//获取处理器时钟速率 // Initialize the device pinout appropriately for this board. //—————————————初始化显示驱动————————————————— PinoutSet(); // Initialize the display driver and graphics context. Kitronix320x240x16_SSD2119Init(); //————————————————————————————————————— GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119);//初始化a drawning context //————————————————设置方框————————————————— tRectangle sRect; sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 23; //————————————————————————————————————— GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); GrContextFontSet(&sContext, &g_sFontCm20); GrStringDrawCentered(&sContext, "Lab7-2: ADC Controls", -1,GrContextDpyWidthGet(&sContext) / 2, 10, 0); // Operation Tips GrContextFontSet(&sContext, &g_sFontCm26b); GrStringDrawCentered(&sContext, "Temperature Sample", -1,GrContextDpyWidthGet(&sContext) / 2, 60, 1); GrContextFontSet(&sContext, &g_sFontCm16); GrStringDrawCentered(&sContext, "Sample from the internal temperature sensor,", -1,GrContextDpyWidthGet(&sContext) / 2, 100, 1); GrStringDrawCentered(&sContext, "the current temperature of MCU is :", -1,GrContextDpyWidthGet(&sContext) / 2, 140, 1); GrStringDrawCentered(&sContext, "o", -1,GrContextDpyWidthGet(&sContext) / 2+20, 165, 1); GrContextFontSet(&sContext, &g_sFontCm36); GrStringDrawCentered(&sContext, "C", -1,GrContextDpyWidthGet(&sContext) / 2+35, 180, 1); // Initialize the ADC0. // Enable ADC0 SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);//使能ADC0 // Set the sample rate of ADC0 SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);//设置ADC采样速率 // Disable before setting ADCSequenceDisable(ADC_BASE, 3);//禁止一个采样序列 // Configure sample sequence:ADC base address,sample sequence number,trigger event,and priority ADCSequenceConfigure(ADC_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);//采样序列配置,0表示最高优先级 // Sample step setup:ADC base address,sample sequence number,step value,channel setting ADCSequenceStepConfigure(ADC_BASE, 3, 0, ADC_CTL_TS|ADC_CTL_END|ADC_CTL_IE);//采样步进设置 // Enable ADC interrupt ADCIntEnable(ADC_BASE, 3);//使能ADC中断 // Enable interrupt for ADC sequence 3 IntEnable(INT_ADC3);//使能ADC采样序列中断 // Enable system clock IntMasterEnable();//使能处理器中断 // Start Sampling ADCSequenceEnable(ADC_BASE, 3);//使能采样序列 // Initialize SysTick SysTickInit();//SysTick初始化 while(1) { // fall into sleep mode SysCtlSleep();//使处理器进入睡眠模式 // Process ADCProcessorTrigger(ADC_BASE, 3);//处理器触发采样序列 // Waiting for sample complete while (!ADC_EndFlag); // Clear flag ADC_EndFlag = false; ADCSequenceDataGet(ADC_BASE, 3, &ulValue);//获取采样序列3捕获的数据 // Display the current temperature of the CPU tmpDisplay(ulValue); GrFlush(&sContext); } }
为什么执行到SysCtlSleep()就停止执行了,恳求高手帮忙。
|