SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);
这个一个配置串口能正确显示字符 0012345.12345
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //80M
这一个配置却出现了而这个却显示了错误的字符 ?Zg
以上使用的是同一个程序。
一下是程序
unsigned char i[15], j = 0, g;
int main(void)
{
double val = 12345.12345;
//SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
// SYSCTL_XTAL_16MHZ);
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //80M
UART_Init();
Num_String(i, val);
Num_String_Send(i);
while(1);
return 0;
}
//´®¿Ú³õʼ»¯
void UART_Init(void)
{ SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);//ʹÄÜUARTÍâÉè
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);//ʹÄÜRXD TXD IOÍâÉè
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));//ʹÓÃUART0 ÉèÖÃʱÖÓ£¬²¨ÌØÂÊ115200 8λÊý¾Ýλ 1ֹͣλ ÎÞУÑé
GPIOPinConfigure(GPIO_PA0_U0RX); //¸´ÓÃA0½ÅΪUART
GPIOPinConfigure(GPIO_PA1_U0TX); //¸´ÓÃA1½ÅΪUART
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);//ÉèÖÃioAµÄ0¡¢1½ÅΪ´®¿Ú
IntEnable(INT_UART0); //ʹÄÜURAT0×ÜÖжÏ
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);//ʹÄÜUART0ÊäÈëÊä³öÖжÏ
IntMasterEnable();//ʹÄÜ´¦ÀíÆ÷ÖжÏ
}
//double转unsigned char的程序
void Num_String(unsigned char *Pnum, double Num)
{
unsigned char Temp = 1;
Temp = (unsigned int)(Num); *Pnum = (unsigned int)(Num / 1000000) % 10 + '0';
Pnum++;
*Pnum = (unsigned int)(Num / 100000) % 10 + '0';
Pnum++;
*Pnum = (unsigned int)(Num / 10000) % 10 + '0';
Pnum++;
*Pnum = (unsigned int)(Num / 1000) % 10 + '0';
Pnum++;
*Pnum = (unsigned int)(Num / 100) % 10 + '0';
Pnum++;
*Pnum = (unsigned int)(Num / 10) % 10 + '0';
Pnum++;
*Pnum = (unsigned int)(Num) % 10 + '0';
Pnum++;
*Pnum = '.';
Pnum++;
*Pnum = (unsigned int)((Num – Temp) * 10) % 10+ '0';
Pnum++;
*Pnum = (unsigned int)((Num – Temp) * 100) % 10+ '0';
Pnum++;
*Pnum = (unsigned int)((Num – Temp) * 1000) % 10+ '0';
Pnum++;
*Pnum = (unsigned int)((Num – Temp) * 10000) % 10+ '0';
Pnum++;
*Pnum = (unsigned int)((Num – Temp) * 100000) % 10+ '0';
Pnum++;
*Pnum = '\0';}
void Num_String_Send(unsigned char *String_Group)
{
while(*String_Group != '\0')
{
// UARTCharPutNonBlocking(UART0_BASE, *String_Group);//这里的两个发送都是一个效果。
UARTCharPut(UART0_BASE, *String_Group);
String_Group++;
}
}
chongyao Chen:
回复 Michael Sun:
我是使用TivaWare_C_Series-2.1.0.12573
然后芯片死tm4c123gh6pm
使用后已解决。
没说清楚对不住。
谢谢!