#include <msp430x14x.h>
#define CPU_F ((double)8000000) //外部高频晶振8MHZ
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define uchar unsigned char
#define uint unsigned int
uchar caltmp[4]={0,0,0,0};
uchar shuzi[] = {"0123456789.V"};
uchar AA[6]; //用来存放转换结果的数组
/*时钟*/
void Clock_Init()
{
uchar i;
BCSCTL1&=~XT2OFF; //打开XT2振荡器
BCSCTL2|=SELM1+SELS; //MCLK为8MHZ,SMCLK为8MHZ
do{
IFG1&=~OFIFG; //清楚振荡器错误标志
for(i=0;i<100;i++)
_NOP();
}
while((IFG1&OFIFG)!=0); //如果标志位1,则继续循环等待
IFG1&=~OFIFG;
}
/*ADC12初始化*/
void ADC_port()
{
P6SEL = 0x0F; //P6.0~P6.3为AD输入口
ADC12CTL0 = ADC12ON + REFON + REF2_5V + SHT0_2;
ADC12CTL1 = CONSEQ_1 + ADC12SSEL_0 + SHP;
ADC12MCTL0 = SREF_1 + INCH_0;
ADC12MCTL1 = SREF_1 + INCH_1;
ADC12MCTL2 = SREF_1 + INCH_2;
ADC12MCTL3 = SREF_1 + INCH_3 + EOS;
ADC12IE = 0x01;
ADC12CTL0 = ENC + ADC12SC;
}
/*USART 串口初始化*/
void USART_Inti()
{
U0CTL |= SWRST + CHAR; //8位长度
U0TCTL |= SSEL0; //选择MCLK时钟
U0BR0 = 0X41; //8M晶振,9600波特率
U0BR1 = 0X03;
U0MCTL = 0X00;
ME1 = UTXE0 + URXE0; //接收发送使能允许
U0CTL &= ~SWRST;
IE1 |= UTXIE0; //发送中断允许
P3SEL |= BIT4 + BIT5; //P3.5,P3.5串口引脚
P3DIR |= BIT4; //P3.4串口输出(发送)
}
/*串口发送函数*/
void USART_Send(uchar data)
{
while(!(IFG1&UTXIFG0));
U0TXBUF = data;
}
#pragma vector=ADC_VECTOR //AD12中断
__interrupt void ADC12ISR(void)
{
caltmp[0] = ADC12MEM0;
caltmp[1] = ADC12MEM1;
caltmp[2] = ADC12MEM2;
caltmp[3] = ADC12MEM3;
}
/*ADC12转换*/
void ADC12Tran()
{
uint i;
uchar temp,tempz;
tempz = caltmp[0];
temp = tempz*2500/4095;
AA[0] = temp/1000;
AA[1] = temp%1000/100;
AA[2] = 10;
AA[3] = temp%100/10;
AA[4] = temp%10;
AA[5] = 11;
for(i=0;i<6;i++)
{
USART_Send(AA[i]+0x30);
}
/*
tempz = caltmp[1];
temp = tempz*2500/4095;
AA[0] = temp/1000;
AA[1] = temp%1000/100;
AA[2] = 10;
AA[3] = temp%100/10;
AA[4] = temp%10;
AA[5] = 11;
tempz = caltmp[2];
temp = tempz*2500/4095;
AA[0] = temp/1000;
AA[1] = temp%1000/100;
AA[2] = 10;
AA[3] = temp%100/10;
AA[4] = temp%10;
AA[5] = 11;
tempz = caltmp[3];
temp = tempz*2500/4095;
AA[0] = temp/1000;
AA[1] = temp%1000/100;
AA[2] = 10;
AA[3] = temp%100/10;
AA[4] = temp%10;
AA[5] = 11;*/
}
void main()
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
USART_Inti(); //串口初始化
Clock_Init();
ADC_port(); //AD初始化
_EINT();
while(1)
{
}
}
这个程序为什么不能把采集到的数据发送到串口助手上呢???
此帖出自
小平头技术问答
之前我有种中断里面发数据但是也不行.........
一周热门 更多>