应该是第三个while(1)循环的部分不对,请问一下应该怎么写呢?
#include
#include
#include
#include "msp430g2553.h"
/*
* ======== Grace related declaration ========
*/
extern void CSL_init(void);
char mystring[50] = "300 my test program!\r\n";
void ADC10_init(void);
void myputs(char * string);
/*
* ======== delay ========
*/
void delay(unsigned int time_delay)
{
unsigned int i,j,k,a;
for(i = 0; i < time_delay; i++)
{
for(j = 0; j < 20; j++)
{
for(k = 0; k < 20; k++)
{
for(a = 0; a < 20; a++)
__delay_cycles(8);
}
}
}
}
/*
* ======== main ========
*/
int main(void)
{
int result;
int temp;
int IntDeg;
CSL_init();
ADC10_init();
while(1)
{
myputs(mystring);
myputs("msp430 startup!erererer\r\n");
delay(10);
}
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
while(1)
{
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
// _bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
__delay_cycles(1000);
//-----ADC转换完成中断唤醒CPU后才执行以下代码-----
temp = ADC10MEM; //读取AD采样值
IntDeg= temp*4225/1024 - 2777; //转换为摄氏度,并10倍处理
}
while(1)
{
ADC10CTL0 |= ENC+ADC10SC;
while((ADC10CTL0&ADC10IFG)==0);
//result = ADC10MEM;
IntDeg=(unsigned int)((result-746)/(0.24069)+286);//P64 in the book
mystring[0] = (IntDeg/1000) + '0';
mystring[1] = ((IntDeg%1000)/100) + '0';
mystring[2] = ((IntDeg%100)/10) +'0';
mystring[3] = (IntDeg%10) + '0';
myputs(mystring);
delay(50);
}
}
/*
* ======== string output ========
*/
void myputs(char * string)
{
unsigned char num;
for( num = 0; num < strlen(string); num++ )
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = string[num]; // TX -> RXed character
}
}
void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
void ADC10_init(void)
{
ADC10CTL0 &= ~ENC;
ADC10CTL0 = ADC10IE + ADC10ON + REFON + ADC10SHT_3 + SREF_1;
ADC10CTL1 = CONSEQ_0 + ADC10SSEL_0 + ADC10DIV_3 + SHS_0 + INCH_10;
__delay_cycles(30000);
ADC10CTL0 |= ENC;
}
/******************************************************************************************************
* 名 称:ADC10_ISR_HOOK
* 功 能:ADC转换完成后唤醒CPU
* 入口参数:无
* 出口参数:无
* 说 明:直接从CCS的Example中移植过来
* 范 例:无
******************************************************************************************************/
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR_HOOK(void)
{
_bic_SR_register_on_exit(LPM4_bits);
}
怎么可能有三个while(1)呢?当你执行了第一个的时候,就不往下运行了
直接在第一个while(1)里死循环了,下面的初始化都用不到了,你的本意是用for循环吧,你的程序怪怪的