Hello World程序出问题了,高手解决下

2019-03-24 15:06发布

学习LM3S系列,用LM3S8962写了一个串口发送数据程序,但是结果总是不对,请高手分析分析。以下是代码和串口调试助手的数据结果。


#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "interrupt.h"
#include "sysctl.h"
#include "uart.h"
char buf[] = "hello world! ";
void delay(unsigned long ms)
{
  while(ms--);
}
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
    while(ulCount--)
    {
        UARTCharPut(UART0_BASE, *pucBuffer++);
    }
}
void UART0_Init(void)
{
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  GPIOPinTypeUART(GPIO_PORTA_BASE,GPIO_PIN_0|GPIO_PIN_1);                       //将PA0、PA1配置成UART模式
  UARTConfigSet(UART0_BASE,9600,(UART_CONFIG_WLEN_8|UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE));  
  UARTEnable(UART0_BASE);
}
void main(void)
{
  
  SysCtlClockSet(SYSCTL_SYSDIV_1|SYSCTL_USE_OSC|SYSCTL_OSC_MAIN|SYSCTL_XTAL_8MHZ);//允许外部时钟作为系统主时钟
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);  
  GPIODirModeSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_DIR_MODE_OUT);
  GPIOPadConfigSet(GPIO_PORTF_BASE,GPIO_PIN_2,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD);
  UART0_Init();
  IntMasterEnable();
  UARTIntEnable(UART0_BASE,UART_INT_TX);
  //IntEnable(INT_UART0);
  while(1)
  {
   
    UARTSend(buf,sizeof(buf));
    UARTCharPut(UART0_BASE,'a');
    long i = GPIOPinRead(GPIO_PORTF_BASE,0xff);
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_2,GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_2)^GPIO_PIN_2);
    delay(120000);
    i++;
    /*i = UARTCharGet(UART0_BASE);
    while(1)
    {
      while(!UARTCharsAvail(UART0_BASE))
      {
        UARTCharPut(UART0_BASE,UARTCharGet(UART0_BASE));
      }      
    }
    */
  }
}



串口调试助结果如下:
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
ahello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
hello world!
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
Triton.zhang
2019-03-25 15:58
串口调试助手显示错误,

一周热门 更多>

相关问题

    相关文章