下面的代码是什么意思,怎么让它被执行?
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD16_VECTOR))) SD16ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (SD16IV)
{
case 2: // SD16MEM Overflow
break;
case 4: // SD16MEM0 IFG
ADC_CH0 = SD16MEM0; // Save CH0 results (clears IFG)
break;
}
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
需要使能相应模块及其中断才可以用到这段程序
大神,您能帮我看看,我下面的程序,为什么中断不能被执行么?
#include <msp430.h>
#include <stdlib.h>
#define uchar unsigned char
#define uint unsigned int
long uint ADC_CH0;
uint VOL[41]={0x0000,0xFF78,0xFE89,0xFD9D,0xFCB0,0xFBC9,0xFADD,0xF9F7,0xF96B,0xF87F,0xF79A,
0xF6AE,0xEFCA,0xEEDF,0xEDFB,0xED77,0xEC8D,0xEBA9,0xEAC0,0xE9DD,0xE8FA,
0xE878,0xE78F,0xE6AD,0xDFCC,0xDEEA,0xDE69,0xDD88,0xDCA7,0xDBC7,0xDAE7,
0xDA67,0xD987,0xD8A7,0xD7C8,0xD6E9,0xD66A,0xCF8C,0xCEAE,0xCDD0,0xCCF8};//0~41度温度对应的AD值
void delay(long uint y)
{
while(y!= 0x00)
{
y--;
}
}
void WriteCommandLcd(unsigned char wdata)//向1602液晶写入命令子程序;
{
P5OUT&=~0x10;//RS清零,代表命令;
P5OUT&=~0x08;//RW清零;
P5OUT&=~0x04;//使能E清零;
delay(1); //短暂延时,代替检测忙状态
P5OUT|= 0x04;//使能E置1;
P2OUT=wdata;//送出命令或数据
delay(1);//短暂延时,代替检测忙状态
P5OUT&=~0x04;//使能E清零,下降沿将命令或数据送入1602;
}
void WriteDataLcd(unsigned char wdata)//向1602液晶写入数据子程序;
{
P5OUT|= 0x10;//RS置1,代表数据;
P5OUT&=~0x08;//RW清零;
P5OUT&=~0x04;//使能E清零;
delay(1); //短暂延时,代替检测忙状态
P5OUT|= 0x04;//使能E置1;
P2OUT=wdata;//送出命令或数据
delay(1);//短暂延时,代替检测忙状态
P5OUT&=~0x04;//使能E清零,下降沿将命令或数据送入1602;
}
void lcd_init(void)
{
P2OUT = 0;
delay(1);
WriteCommandLcd(0x38);//显示模式设置,设置为16X2显示,5X7点阵,8位数据接口
delay(5);
//WriteCommandLcd(0x38); //显示模式设置,设置为16X2显示,5X7点阵,8位数据接口
delay(5);
//WriteCommandLcd(0x38); //显示模式设置,设置为16X2显示,5X7点阵,8位数据接口
delay(5);
WriteCommandLcd(0x01); //显示清屏
WriteCommandLcd(0x0f); //开显示,显示光标,光标闪烁;
WriteCommandLcd(0x06); //读写操作时地址自动加1
}
int main(void)
{
volatile unsigned int i,j,flag=0; // Use volatile to prevent removal
// by compiler optimization
uint result,temp1;
P2DIR = 0xff; //设置P2口为输出状态;
P5DIR = 0xff; //设置P2口为输出状态;
P6DIR = 0xff; //设置P2口为输出状态;
P6SEL|= 0x03; //使能A/D通道A0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP14PF; // Configure load caps
for (i =9999; i < 10000; i++); // Delay for 32 kHz crystal to
// stabilize
P2OUT= 0x55; //向P2输出数据;
lcd_init(); //初始化子程序;
SD16CTL = SD16REFON+SD16SSEL0; // 1.2V ref, SMCLK,
SD16CCTL0 |= SD16SNGL+SD16IE ; // Single conv, enable interrupt,256次采样率
SD16INCTL0 |= SD16INTDLY_0; // Interrupt on 4th sample
for (i = 0X35FF; i < 0x3600; i++); // Delay for 1.2V ref startup
__enable_interrupt(); // Enable general interrupts
while (1)
{
SD16CCTL0 |= SD16SC; // SET BREAKPOINT HERE
// Set bit to start conversion
__bis_SR_register(LPM0_bits+GIE); // Enter LPM0
result=ADC_CH0;
for(j=0;j<41;j++)
{
temp1=abs(result-VOL[j]);
if(temp1==0)
{
flag=j;
}
}
delay(1);
WriteCommandLcd(0x80);//从第一行第一个位置开始显示数据,第一行第一个位置的地址是80H;
WriteDataLcd(0x30+flag%10000/1000);//显示千位;
WriteDataLcd(0x30+flag%1000/100);//显示百位;
WriteDataLcd(0x30+flag%100/10);//显示十位;
WriteDataLcd(0x30+flag%10);//显示个位;
delay(1); delay(1);
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD16_VECTOR))) SD16ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (SD16IV)
{
case 2: // SD16MEM Overflow
break;
case 4: // SD16MEM0 IFG
ADC_CH0 = SD16MEM0; // Save CH0 results (clears IFG)
break;
}
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}
一周热门 更多>