使用IAR调试无法进入中断
#include"msp430x54x.h"
typedef unsigned char uint8;
typedef unsigned int uint16;
uint8 gRdata,gADvalue_L, gADvalue_H,flag;
uint16 gADvalue,gADvalue0;
void uca1_init(void);
void ADC12Init(void);
void uca1_init(void)
{
P5SEL |= 0xc0; // P5.6,7 用作USCI_A1的TXD/RXD
UCA1CTL1 |= UCSWRST; // UCA1CTL1串口控制寄存器,复位状态保持
UCA1CTL1 |= UCSSEL_2; // 选择时钟为SMCLK,频率为1MHz.
UCA1BR0 = 0x09; // 1MHz/115200=8.6
UCA1BR1 = 0x00;
UCA1MCTL = UCBRS_1 + UCBRF_0; // 波特率调整(见数据手册)
UCA1CTL1 &= ~UCSWRST; // 串口释放
}
void ADC12Init(void)
{
ADC12CTL0 &= ~ADC12ENC; //ADC12初始状态,不能启动AD转换
P6SEL |= 0x01; // 选择A0通道;
ADC12CTL0 = ADC12ON + ADC12REFON + ADC12REF2_5V + ADC12SHT0_1 + ADC12MSC; //打开ADC转化内核,内部参考电压发生器打开,2.5V,选择采样保持定时器0
P11DIR |= 0x07; // ACLK, MCLK, SMCLK 设置为时钟
P11SEL |= 0x07; // P11.0,1,2 ACLK = REFO = 32.768kHz, MCLK = SMCLK = (Default DCO)/2 = (2MHz/2) = 1MHz
ADC12CTL1 = ADC12DIV_7 + ADC12SSEL_1 + ADC12CONSEQ_0 + ADC12SHP + ADC12SHS_1; //ACLK分频因子为8,单通道单次转换,采样信号来自采样定时器,定时器A触发采样
ADC12MCTL0 = ADC12INCH_0 + ADC12SREF_1; //ADC12MCTL0的输入通道为A0
ADC12CTL0 |= ADC12ENC; //允许转换
}
void Clear_WDT(void) //WDT计数器清零函数
{
WDTCTL = WDTPW + WDTCNTCL;
}
void main(void)
{
WDTCTL = WDTPW; //启动看门狗
uca1_init(); //UART初始化
ADC12Init(); //AD初始化
UCA1IE |= UCRXIE; //接收中断允许
ADC12IE |= BIT0; //AD中断允许
TA1CTL = TASSEL_2 + MC_1 + TACLR ; //时钟源选择 SMCLK=1MHZ, 增计数模式,清除 TAR,定时器溢出中断允许
TA1CCTL0 = CCIE; //TA1CCR0中断允许
TA1CCR0 = 250; //设定中断间隔,1MHZ,250us,
_EINT(); //中断使能
while(1)
{
Clear_WDT(); //看门狗计数器清零
if(flag == 1)
{
gADvalue0 = gADvalue;
while((UCA1IFG&0x02) == 0x00); //判断缓冲区
gADvalue_H = gADvalue0&0xFF00; //输出高8位
gADvalue_H = gADvalue_H>>8;
UCA1TXBUF = gADvalue_H;
while((UCA1IFG&0x02) == 0x00);
gADvalue_L = gADvalue0&0x00FF; //输出低8位
UCA1TXBUF = gADvalue_L;
flag = 0;
}
}
}
#pragma vector = TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR (void)
{
if((gRdata > 0x00)&&(gRdata != 0xff)) //向串口输入0x01与0xff之间的数值
{
ADC12CTL0 |= ADC12SC;
gRdata--;
flag = 1;
}
else if(gRdata == 0xff) //向串口输入0xff;
{
ADC12CTL0 |= ADC12SC;
flag = 1;
}
}
#pragma vector = ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
if(ADC12IV == 0x06)
{
gADvalue = ADC12MEM0; //将结果存入ADvalue
}
}
#pragma vector = USCI_A1_VECTOR //串口接收与发送中断
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // 无中断
case 2: //接收中断
gRdata = UCA1RXBUF; // 接收缓存的数据赋给变量gRdata
break;
case 4: //发送中断
break;
default: break;
}
} |