#include <msp430f149.h>
#include "usart.h"
#include "delay.h"
#define uint unsigned int#define uchar unsigned char
void AD_init (void);
unsigned int i;
uchar value=0;
uchar rec;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
AD_init();//AD初始化
usartInit();//串口初始化
do
{
IFG1 &= ~OFIFG; //Reset OFIFG
for(i = 0xff; i > 0; i–);
}
while((IFG1 & OFIFG));
BCSCTL1 &= ~XT2OFF;
BCSCTL2 |= SELM_2 + SELS;
while(1)
{
/*
if((IFG1 & URXIFG0))
{
rec = rdata();
}*/
P6OUT &= ~BIT5;//转换没完成,开发板LED灯亮
while(!(ADC12IFG & BIT0));
P6OUT |= BIT5;
value = ADC12MEM0;
delay_ms(10);
if((IFG1 & UTXIFG0))
{
// sdata(rec);
sdata(value);
delay_ms(5);
}
}
/*
while((ADC12IFG & ADC12IV_ADC12IFG0))
{
value = ADC12MEM0;
sdata(value);
}*/
}
void AD_init (void)
{
P6DIR = 0XFF;
P6OUT = 0Xff;
P6DIR &= ~BIT0;
P6SEL &= ~BIT0;
P6SEL |= 0X01;//通道A0
ADC12CTL0 = SHT0_2 + MSC + REFON +REF2_5V;//自动转换参考电压2.5V
ADC12CTL0 |= ADC12ON;
ADC12CTL0 |= ENC;
ADC12CTL0 |= ADC12SC;
ADC12CTL1 |= SHP; ADC12CTL1 |= CONSEQ_2;//单通道多次转换
ADC12MCTL0 |=SREF_1 + INCH_0;
}
灯一直亮,标志位没有置位,转换一直不成功。
rui zhu2:
回复 HG:
用例子可以啊
灰小子:
回复 rui zhu2:
建议现在例程的基础上修改。调试没问题再添加串口等其他的代码
rui zhu2:
回复 灰小子:
谢谢,我试试