ARM的S3C44B0X芯片串口程序输出到超级终端的是乱码,怎么回事?

时间:2022-06-07 23:36:34
板子一上电,输出到超级终端上的默认芯片信息是正常的,我在通过KEIL4和JLINK调试的时候,就出现一堆汉字,而不是我想要的英文字母。超级终端设置的是115200,数据位:8,停止位:1,校验位:无。数据流控制:无。现将串口初始化及输出的代码拷贝如下,希望高手帮忙解答一下。

main.c的程序

#include <S3C44B0X.H>
#include <string.h>
#include "Option.h"
#include "Main.h"
#include "Common.h"
#include "Led.h"
#include "Interrupt.h"
#include "UART.h"
#include "RTC.h"

int main()
{
    TIME tm;
memset((char*)&(tm.nYear), 0, sizeof(tm));
    SysInit();
GetLocalTime(&tm);
/*
    for(;;)
{
        LedDisplay(0xff); 
    Delay(3000);  
LedDisplay(0);
Delay(3000);
}
*/
}

void PortInit(void)
{
// CAUTION:Follow the configuration order for setting the ports. 
// 1) setting value 
// 2) setting control register 
// 3) configure pull-up resistor.  

//16bit data bus configuration  

// PORT A GROUP
//  9 8 7 6 5 4 3 2 1 0
//  A24 A23 A22 A21 A20 A19 A18 A17 A16 A0
// 0 1 1 1 1 1 1 1 1 1
pPIO->PCONA = 0x1ff;

// PORT B GROUP
//  10 9 8 7 6 5 4 3 2 1 0
// /CS5 /CS4 /CS3 /CS2 /CS1 GPB5 GPB4 /SRAS /SCAS SCLK SCKE
// EXT NIC USB IDE SMC NC NC Sdram Sdram Sdram Sdram
// ? ? ? ? ? Out Out ? ? ? ?
//  1  1    1    1     1     0       0      1     1     1    1
pPIO->PCONB = 0x1cf;
pPIO->PDATB = 0x7ff & ~(1 << 10);
    
// PORT C GROUP, BUSWIDTH=16
//  15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
// NC NC Uart1 Uart1 NC NC NC NC NC NC NC NC out out out out
// ? ? ? ? ? ? ? ? ? ? ? ? * * * * *
// 00 00 11 11 00 00 01 01 00 00 00 00 01 01 01 01
pPIO->PDATC = 0xfc00;
pPIO->PCONC = 0x0FF5FF55;
// pPIO->PCONC = 0x0ff0ff55; // EduKit-II
// pPIO->PCONC = 0x0ff0ffff; // S3CEV40
pPIO->PUPC  = 0x30ff; // PULL UP RESISTOR should be enabled to I/O

// PORT D GROUP
//  BIT7 6 5 4 3 2 1 0
// VF OUT VLINE VCLK VD3 VD2 VD1 VD0
// 10 01 10 10 10 10 10 10
pPIO->PDATD = 0xbf;
pPIO->PCOND = 0x9aaa;
pPIO->PUPD  = 0x0;
// These pins must be set only after CPU's internal LCD controller is enable

// PORT E GROUP 
//  8 7 6 5 4 3 2 1 0
//  CODECLK Out Out Out TOUT1 Out(Beep) RXD0 TXD0 ?
//  * * * * * * *
//  10 01 01 01 10 01 10 10 00
pPIO->PDATE = 0x1ff;
pPIO->PCONE = 0x25668;
pPIO->PUPE  = 0x6;

// PORT F GROUP
//  8 7 6 5  4 3 2 1 0
//  IISCLK IISDI IISDO IISLRCK Out Out Input IICSDA IICSCL
// * * * * * * * * *
//  100 100 100 100 01 01 00 10 10
pPIO->PDATF = 0xe7;
pPIO->PCONF = 0x24914A; // PF3:LED4 PF4:LED3 PF2:nWait
// pPIO->PCONF = 0x252A; //S3CEV40
pPIO->PUPF  = 0x0;

// PORT G GROUP
//  7 6 5 4 3 2 1 0
//  INT7 INT6 INT5 INT4 INT3 INT2 INT1 INT0
// S3 S4 S5 S6 NIC IDE USB
// *
// 11      11      11      11      11      11      11      11
pPIO->PDATG = 0xff;
pPIO->PCONG = 0xffff;
pPIO->PUPG  = 0x0; // should be enabled  
pPIO->SPUCR = 0x7;   // D15-D0 pull-up disable

// Non Cache area
//rNCACHBE0 = ((NON_CACHE_END>>12)<<16) | (NON_CACHE_START>>12); 
pCPUW->NCACNBE0 = 0xc0002000;
// Low level default
pPIO->EXTINT = 0x0;
}

void SysInit(void)
{
// Using 8KB Cache
pCPUW->SYSCFG = CACHECFG;   

// Initial 44B0X's I/O port
PortInit();

// Initilaize interrupt
InitInterrupts();

    // Initilaize external interrupt
pPIO->EXTINT = 0x22222222;                   // Level mode
pPIO->EXTINPND = 0xf; // Clear EXTINTPND reg

// Initial delay time
    //delay(0);
// beep(1);
//delay(1000);
// beep(0);

// Initial Serial port 
UARTInit(0, 115200);

    UARTPrintf("abcd\n");                     
  UARTPrintf("*******************************************************************\n");
}

void InitInterrupts(void)
{
    pIC->INTCON = 0x1;    // Vectored mode, IRQ disable, FIQ disable    
    pIC->INTMOD = 0x0;    // All=IRQ mode
    pIC->INTMSK = 0x07ffffff;    // All interrupt is masked.
    pIC->I_ISPC = 0xffffffff; // Clear all interrupt pend

// Set interrupt vector routine
// pISR_RESET //reserved
pISR_UNDEF = (unsigned) DealInterrupt;
pISR_SWI = (unsigned) DealInterrupt;
pISR_PABORT = (unsigned) DealInterrupt;
pISR_DABORT = (unsigned) DealInterrupt;
pISR_RESERVED = (unsigned) DealInterrupt; // not used
// pISR_IRQ = (unsigned) 0; // reserved
pISR_FIQ = (unsigned) DealInterrupt;

pISR_ADC = (unsigned) DealInterrupt;
pISR_RTC = (unsigned) DealInterrupt;
pISR_UTXD1 = (unsigned) DealInterrupt;
pISR_UTXD0 = (unsigned) DealInterrupt;
pISR_SIO = (unsigned) DealInterrupt;
pISR_IIC = (unsigned) DealInterrupt;
pISR_URXD1 = (unsigned) DealInterrupt;
pISR_URXD0 = (unsigned) DealInterrupt;
pISR_TIMER5 = (unsigned) DealInterrupt;
pISR_TIMER4 = (unsigned) DealInterrupt;
pISR_TIMER3 = (unsigned) DealInterrupt;
pISR_TIMER2 = (unsigned) DealInterrupt;
pISR_TIMER1 = (unsigned) DealInterrupt;
pISR_TIMER0 = (unsigned) DealInterrupt;
pISR_UERR01 = (unsigned) DealInterrupt;
pISR_WDT = (unsigned) DealInterrupt;
pISR_BDMA1 = (unsigned) DealInterrupt;
pISR_BDMA0 = (unsigned) DealInterrupt;
pISR_ZDMA1 = (unsigned) DealInterrupt;
pISR_ZDMA0 = (unsigned) DealInterrupt;
pISR_TICK = (unsigned) DealInterrupt;
pISR_EINT4567 = (unsigned) DealInterrupt;
pISR_EINT3 = (unsigned) DealInterrupt;
pISR_EINT2 = (unsigned) DealInterrupt;
pISR_EINT1 = (unsigned) DealInterrupt;
pISR_EINT0 = (unsigned) DealInterrupt;
pISR_TIMER0 = (unsigned) DealInterrupt;
}

uart.c文件的程序
static int f_nWhichUart = 0;

void UARTInit(int nMainClk, int nBaud)
{
    int i;

    if(0 == nMainClk)
{
nMainClk = MCLK;
}

//UART0   

 rUFCON0 =0x0;
    rUMCON0 = 0x0;
    rULCON0 = 0x3;      // Normal, No parity, 1 stop, 8 bit
rUCON0= 0x245;      // rx=edge, tx=level, disable timeout int., enable rx error int., normal,interrupt or polling
    rUBRDIV0 = ((int)(nMainClk /  16. / nBaud + 0.5) - 1);

    for(i = 0; i < 100; i++);
}

void UARTSendbyte(unsigned char nData)
{
if(0 == f_nWhichUart)
    {
if('\n' == nData)
{
    while(!(rUTRSTAT0 & 0x2));
    Delay(10); // because the slow response of hyper_terminal 
    rUTXH0 = '\r';
}
while(!(rUTRSTAT0 & 0x2));  // Wait until THR is empty.
Delay(10);
rUTXH0 = nData;
    }
else
    {
if('\n' == nData)
{
    while(!(rUTRSTAT1 & 0x2));
    Delay(10); // because the slow response of hyper_terminal 
    rUTXH1 = '\r';
}
while(!(rUTRSTAT1 & 0x2));  // Wait until THR is empty.
Delay(10);
rUTXH1 = nData;
    }
}

void UARTSendstring(unsigned char *pString)
{
    while(*pString)
    {
UARTSendbyte(*pString++);
}
}

void UARTPrintf(char *fmt,...)
{
    va_list ap;
   unsigned char szString[256]={0};

    va_start(ap, fmt);
// memset(szString,0,sizeof(char)*256);
    vsprintf(szString, fmt, ap);
    UARTSendstring(szString);                  
    va_end(ap);
}

4 个解决方案

#1


顶起  希望有大侠解答

#2


16进制显示呢?不行就上示波器

#3


我遇到过程序正常,但在串口终端下显示乱码的问题,最后我的解决办法是把板子的电压调过了,本来我的开发板电源是5.2V,我调到5.36V左右,乱码消失。这个5V和RS232有关系。。。

#4


该回复于2011-12-12 14:38:50被版主删除

#1


顶起  希望有大侠解答

#2


16进制显示呢?不行就上示波器

#3


我遇到过程序正常,但在串口终端下显示乱码的问题,最后我的解决办法是把板子的电压调过了,本来我的开发板电源是5.2V,我调到5.36V左右,乱码消失。这个5V和RS232有关系。。。

#4


该回复于2011-12-12 14:38:50被版主删除