主要是主函数里一调用Cfg_AD(),串口不能显示字符串了,只显示第一个字母,后面的不显示,删除Cfg_AD()就可以显示字符串了,求解??????????
#include "msp430g2553.h"
#include "intrinsics.h"
#define uchar unsigned char
#define uint unsigned int
uint i;
char cc[4]={0,0,0,0};
long value=0;
void uart_write_char(uchar c);
void uart_write_string(char *str);
void Uart0Sends(char *s);
void uart_init(void);
void Cfg_AD(void);
int UARTGetChar(void);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
uart_init();
uart_write_char(0X39);
Cfg_AD();
while(1)
{
P1OUT&=~BIT0;
if(UARTGetChar()=='i')
{
uart_write_string("now temp is:");
uart_write_char(48);
uart_write_char(cc[0]);
uart_write_char(cc[1]);
uart_write_char(cc[2]);
uart_write_char(cc[3]);
}
}
void uart_init(void)
{
UCA0CTL1|=UCSWRST;
P1DIR|=BIT0+BIT6;
P1OUT|=BIT6;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x68; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = 0x40; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE+UCA0TXIE;
}
void uart_write_char(uchar c)
{
UCA0TXBUF=c;
while((IFG2&UCA0TXIFG)==0);
IFG2&=~UCA0TXIFG;
}
void uart_write_string(char *str)
{
while(*str)
{
uart_write_char(*str++);
//while ((IFG2 & UCA0TXIFG)==0);
//IFG2&=~UCA0TXIFG;
}
}
int UARTGetChar(void)
{
int GetChar=0;
while (!(IFG2&UCA0RXIFG));
IFG2&=~UCA0RXIFG;
UCA0TXBUF=UCA0RXBUF;
GetChar =UCA0RXBUF;
while (!(IFG2&UCA0TXIFG));
IFG2&=~UCA0TXIFG;
return GetChar;
}
void Cfg_AD(void)
{
long tt=0;
ADC10CTL1 = INCH_10 + ADC10DIV_3;
ADC10CTL0 = SREF_1 + ADC10SHT_3+REFON + ADC10ON+ADC10IE;
__delay_cycles(100);
ADC10CTL0 |= ENC + ADC10SC;
_BIS_SR(CPUOFF+GIE);
tt = ADC10MEM;
value = ((tt - 673) * 4230) / 1024;
cc[0]=value/100+'0';
cc[1]=value/10%10+'0';
cc[2]='.';
cc[3]=value%10+'0';
}
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
}
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
_BIC_SR_IRQ(CPUOFF);
P1OUT&=~BIT6;
}
此帖出自
小平头技术问答
一周热门 更多>