This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
是读取ADC的采样信号,uart到pc,程序如下:
#include "msp430g2533.h"
#include"stdio.h"
void UART0_send_byte(unsigned char data) //发送一位
{
int j;
for( j=1000;j>0;j--);
UCA0TXBUF=data;
}
void UART0_send_str(char *s) //发送字符串
{
while(*s != '\0')
{
UART0_send_byte(*s++);
}
}
int main(void)
{
float num;
char buf[10];
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10ON; //开adc
ADC10CTL1 = INCH_0; //1通道
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; //开始转换
int j;
for( j=10000;j>0;j--);
num = (float)ADC10MEM*3.3/1024;
sprintf(buf,"V: %8.4f\n",num);
UART0_send_str(buf);
}
}
建议参考TI MSPWARE中例程,ADC 和UART都有现场的代码。
例外你现在碰到什么问题,请把问题描述清楚。
yao wang5 说:是读取ADC的采样信号,uart到pc,程序如下:
#include "msp430g2533.h"
#include"stdio.h"void UART0_send_byte(unsigned char data) //发送一位
{
int j;
for( j=1000;j>0;j--);
UCA0TXBUF=data;
}void UART0_send_str(char *s) //发送字符串
{
while(*s != '\0')
{
UART0_send_byte(*s++);
}
}
int main(void)
{
float num;
char buf[10];
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 = ADC10ON; //开adc
ADC10CTL1 = INCH_0; //1通道
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**while(1)
{
ADC10CTL0 |= ENC + ADC10SC; //开始转换
int j;
for( j=10000;j>0;j--); // 建议参考我们的例程,判定采样标志位是否完成或利用中断来获取ADC采样值
num = (float)ADC10MEM*3.3/1024;
sprintf(buf,"V: %8.4f\n",num);
UART0_send_str(buf);
}
}
这个TI MSP430没有这个例程,在TI M4 的tiva ware中有sensor lib 有TMP100例程,你可以参考。
yao wang5 说:问题已经解决了,在库文件改成full就可以,谢谢回答,另外有没有,采集tmp101的温度,uart到pc的例程?