这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 程序跑飞是什么意思呢

共2条 1/1 1 跳转至

程序跑飞是什么意思呢

院士
2006-09-17 18:14:16     打赏
程序跑飞是什么意思呢



关键词: 程序     跑飞     是什么     意思    

院士
2006-12-22 22:43:00     打赏
2楼
问 程序再执行到一条语句的时候发生跑飞
不知道如何查找跑飞的原因
还能赐教跑飞出现的几个比较多的原因 1: 是汇编还是C语言? 2: 是c语言啊
步知道怎么了 3: 可以贴出程序或发到zclierda.com 4: //**************************************************************************
#include "MSP430x14x.h" // Standard Definition Control Register

#define ADCMEM ((int*) 0x0140) // ADC12MEMx definition
//--------------------------------------------------------------------------
void Init(void); // Initialization of System/Control Registers
void Send( unsigned int MemX); // conversion result of ADCMemX is sent via RS232
int Hex2ASCII(int hex); // conversion of hexadecimal number into ASCII
int Digit0(int Register);
int Digit1(int Register);
int Digit2(int Register);
int Digit3(int Register);

static unsigned int Result[2]; // These need to be global in
// this example. Otherwise, the
// compiler removes them because
// they are not used

void main(void)
{
unsigned int m; //用以保存转换结果
unsigned int d1; // count number
unsigned int d2; // flag
unsigned int d3;
unsigned int k;
Init(); // Initialization
_EINT(); // enable global interrupts


while (1)
{

ADC12CTL0 |= 0x01; // 开始转换
ADC12CTL0 &=~0x01;
Result[0] = ADCMEM[0];
m=0xF000;
P1DIR &= ~(BIT0+BIT1);//定义p1.0,p1.1为输入引脚,接收d1与d2;


Result[0]|=m;//在A0通道的转化结果前面加了1111的头;

Result[1]=P4IN+P5IN;//将CPLD信号从430的P4和P5端口读入到MSP430中;

for (k=0;k<2;k++)
{
Send( Result[k]);
}
d1=P1IN & BIT0; //d1 from P1.0;
d2=P1IN & BIT1; //d2 from p1.1;
d3=(d1<<8)|d2;
Send (d3);//发送计数的标志以及判定方向的信号脉冲波形
}
}



void Init(void)//初始化ad以及选择ad的转化方式;初始化串口以及选择波特率等参数设置
{ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

/* USART Settings:
UART function, Idle line multiprocessor Protocol,
9600 baud, 8 data bits, even parity, 1 stop bit */
UCTL1 &=~ SWRST; // reset SWRST bit
UCTL1 = 0xD0; //8 data bits, even parity, 1 stop bit
UBR01 = 0x03;
UBR11 = 0x00;
UMCTL1 = 0x4A; //BDR=9600
UTCTL1 = 0x10; //CHOOSE ACLK32768H
URCTL1 = 0x00;

ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
IE1 |= URXIE0; // Enable USART0 RX interrupt
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10; // P3.4 output direction

ME2 |= UTXE1 + URXE1; // enable USART transmit
P3SEL = 0xC0; // Pin P3.6 P3.7 =USART1 TXD/RXD
P3DIR|= 0x40; // Pin P3.6 is output

/* ADC12 Settings: */
P6SEL = 0x01; // Pin P6.0 A0 P6.1 A1 USED AS INPUT

ADC12CTL0 &=~ 0x02; // Disable conversion before changing
// the ADC12 settings!!!
// selection of reference and input
ADC12MCTL0 = 0x50; // Ref = VREF+, VR-=VREF- ; Input = A0
//ADC12MCTL1 = 0xD1; // Ref = VREF+, VR-=VREF-; Input = A1
// ADC12MCTL1 is end of sequence
// (EOS bit is set!)

ADC12CTL1 = 0x0205; // first conv. result is stored in ADC12MEM0
// ADC12SC bit triggers Sample&Hold
// sample pulse is generated by Sampling Timer
// Clock Source: ADC12 ACLK
// Clock divider: 1
// conversion mode: SERIAL PORT CONVERT
ADC12CTL0 = 0x0010+SHT0_2; // Sample&Hold Time 0
// Sample&Hold Time 1
// Multiple Sample&Hold
// reference voltage is off
// ADC12 module is switched on
// Conversion Time Overflow interrupt enabled
// Overflow Interrupt enabled

ADC12IE = BIT0; // enable A0 interrupts
ADC12CTL0 |= 0x02; // enable conversion
_EINT();
}

void Send( unsigned int MemX)
{
TXBUF1=Digit3(ADCMEM[MemX]); // 传送标志位的ascii码
while ((UTCTL1&0X01)==0);
TXBUF1=Digit2(ADCMEM[MemX]); // 传送待传送的数据的高四位的ascii码
while ((UTCTL1&0x01)==0);
TXBUF1=Digit1(ADCMEM[MemX]); // 传送待传送数据的中间四位的ascii码
while ((UTCTL1&0x01)==0);
TXBUF1=Digit0(ADCMEM[MemX]); // 传送代传数据的最低四位的ascii码
while ((UTCTL1&0x01)==0);
TXBUF1=0x20;
while ((UTCTL1&0x01)==0); //transmit the end flag
}


int Digit0(int Register) // 讲最低位转化位ascii码
{ int result;

result = Hex2ASCII(0x0F & Register);
return result;
}

int Digit1(int Register) //讲ad转化的中间4位转换位ascii码
{ int result;

result = Register >> 4;
result = Hex2ASCII(0x0F & result);
return result;
}

int Digit2(int Register) // 将ad转换的嘴高4位转换位ascii码;
{ int result;

result = Register >> 8;
result = Hex2ASCII(0x0F & result);
return result;
}
int Digit3(int Register)//将标志位转化位ascii码
{ int result;
result=Register>>12;
result=Hex2ASCII(0x0F & result);
return result;
}

int Hex2ASCII(int hex) //4位16进制数转化位ascii码
{ int result;

if (hex<=9)
{ result=hex+'0'; } // convert number
else
{ result=hex+('A'-10); } // convert letter

return result;

} 5: //**************************************************************************
#include "MSP430x14x.h" // Standard Definition Control Register

#define ADCMEM ((int*) 0x0140) // ADC12MEMx definition
//--------------------------------------------------------------------------
void Init(void); // Initialization of System/Control Registers
void Send( unsigned int MemX); // conversion result of ADCMemX is sent via RS232
int Hex2ASCII(int hex); // conversion of hexadecimal number into ASCII
int Digit0(int Register);
int Digit1(int Register);
int Digit2(int Register);
int Digit3(int Register);

static unsigned int Result[2]; // These need to be global in
// this example. Otherwise, the
// compiler removes them because
// they are not used

void main(void)
{
unsigned int m; //用以保存转换结果
unsigned int d1; // count number
unsigned int d2; // flag
unsigned int d3;
unsigned int k;
Init(); // Initialization
_EINT(); // enable global interrupts


while (1)
{

ADC12CTL0 |= 0x01; // 开始转换
ADC12CTL0 &=~0x01;
Result[0] = ADCMEM[0];
m=0xF000;
P1DIR &= ~(BIT0+BIT1);//定义p1.0,p1.1为输入引脚,接收d1与d2;


Result[0]|=m;//在A0通道的转化结果前面加了1111的头;

Result[1]=P4IN+P5IN;//将CPLD信号从430的P4和P5端口读入到MSP430中;

for (k=0;k<2;k++)
{
Send( Result[k]);
}
d1=P1IN & BIT0; //d1 from P1.0;
d2=P1IN & BIT1; //d2 from p1.1;
d3=(d1<<8)|d2;
Send (d3);//发送计数的标志以及判定方向的信号脉冲波形
}
}



void Init(void)//初始化ad以及选择ad的转化方式;初始化串口以及选择波特率等参数设置
{ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

/* USART Settings:
UART function, Idle line multiprocessor Protocol,
9600 baud, 8 data bits, even parity, 1 stop bit */
UCTL1 &=~ SWRST; // reset SWRST bit
UCTL1 = 0xD0; //8 data bits, even parity, 1 stop bit
UBR01 = 0x03;
UBR11 = 0x00;
UMCTL1 = 0x4A; //BDR=9600
UTCTL1 = 0x10; //CHOOSE ACLK32768H
URCTL1 = 0x00;

ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
IE1 |= URXIE0; // Enable USART0 RX interrupt
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
P3DIR |= 0x10; // P3.4 output direction

ME2 |= UTXE1 + URXE1; // enable USART transmit
P3SEL = 0xC0; // Pin P3.6 P3.7 =USART1 TXD/RXD
P3DIR|= 0x40; // Pin P3.6 is output

/* ADC12 Settings: */
P6SEL = 0x01; // Pin P6.0 A0 P6.1 A1 USED AS INPUT

ADC12CTL0 &=~ 0x02; // Disable conversion before changing
// the ADC12 settings!!!
// selection of reference and input
ADC12MCTL0 = 0x50; // Ref = VREF+, VR-=VREF- ; Input = A0
//ADC12MCTL1 = 0xD1; // Ref = VREF+, VR-=VREF-; Input = A1
// ADC12MCTL1 is end of sequence
// (EOS bit is set!)

ADC12CTL1 = 0x0205; // first conv. result is stored in ADC12MEM0
// ADC12SC bit triggers Sample&Hold
// sample pulse is generated by Sampling Timer
// Clock Source: ADC12 ACLK
// Clock divider: 1
// conversion mode: SERIAL PORT CONVERT
ADC12CTL0 = 0x0010+SHT0_2; // Sample&Hold Time 0
// Sample&Hold Time 1
// Multiple Sample&Hold
// reference voltage is off
// ADC12 module is switched on
// Conversion Time Overflow interrupt enabled
// Overflow Interrupt enabled

ADC12IE = BIT0; // enable A0 interrupts
ADC12CTL0 |= 0x02; // enable conversion
_EINT();
}

void Send( unsigned int MemX)
{
TXBUF1=Digit3(ADCMEM[MemX]); // 传送标志位的ascii码
while ((UTCTL1&0X01)==0);
TXBUF1=Digit2(ADCMEM[MemX]); // 传送待传送的数据的高四位的ascii码
while ((UTCTL1&0x01)==0);
TXBUF1=Digit1(ADCMEM[MemX]); // 传送待传送数据的中间四位的ascii码
while ((UTCTL1&0x01)==0);
TXBUF1=Digit0(ADCMEM[MemX]); // 传送代传数据的最低四位的ascii码
while ((UTCTL1&0x01)==0);
TXBUF1=0x20;
while ((UTCTL1&0x01)==0); //transmit the end flag
}


int Digit0(int Register) // 讲最低位转化位ascii码
{ int result;

result = Hex2ASCII(0x0F & Register);
return result;
}

int Digit1(int Register) //讲ad转化的中间4位转换位ascii码
{ int result;

result = Register >> 4;
result = Hex2ASCII(0x0F & result);
return result;
}

int Digit2(int Register) // 将ad转换的嘴高4位转换位ascii码;
{ int result;

result = Register >> 8;
result = Hex2ASCII(0x0F & result);
return result;
}
int Digit3(int Register)//将标志位转化位ascii码
{ int result;
result=Register>>12;
result=Hex2ASCII(0x0F & result);
return result;
}

int Hex2ASCII(int hex) //4位16进制数转化位ascii码
{ int result;

if (hex<=9)
{ result=hex+'0'; } // convert number
else
{ result=hex+('A'-10); } // convert letter

return result;

} 6: 怎么发了两次
郁闷 7: 您发给我的只是工程文件,没有加载源文件。 8: 不好意思
已经重新发送了 9: 赵老师还能给我看看啊 10: ADC12CTL0 |= 0x01; // 开始转换
ADC12CTL0 &=~0x01;
删掉这句ADC12CTL0 &=~0x01。AD转换开启在AD转换完成之后会自动复位,
不需要进行关闭。 11: 告诉结果,期待中.... 12: 我试了一下,程序没有跑飞啊。 13: 没有跑飞正在验证是否可以实现自己需要的功能
感谢大家了 14: 赵老师还能告诉你是怎么试验的吗

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]