-
Notifications
You must be signed in to change notification settings - Fork 37
Description
- 串口2demo:FwLib_STC8\FwLib_STC8\demo\uart\uart2_timer2_tx.c
在使用串口2的情况下必须要对IO进行配置,否则无法输出。在STC8H手册上(321页)有这么一段话:
*** 关于 I/O 的注意事项:
1、 P3.0 和 P3.1 口上电后的状态为弱上拉/准双向口模式
2、 除 P3.0 和 P3.1 外,其余所有 IO 口上电后的状态均为高阻输入状态,用户在使用 IO 口
前必须先设置 IO 口模式
3、 芯片上电时如果不需要使用 USB 进行 ISP 下载, P3.0/P3.1/P3.2 这 3 个 I/O 口不能同时
为低电平,否则会进入 USB 下载模式而无法运行用户代码
4、 芯片上电时,若 P3.0 和 P3.1 同时为低电平, P3.2 口会短时间由高阻输入状态切换到双
向口模式,用以读取 P3.2 口外部状态来判断是否需要进入 USB 下载模式。
所以在使用串口2时,需要对串口2的引脚进行配置。
`
void main(void)
{
// SYS_SetClock();//SDCC编译器使用
// UART2, baud 115200, baud source Timer2, 1T mode, no interrupt
// P_SW2 |= 0x80;//使能访问 XFR
// P4M0=0x00;
// P4M1=0x00;
P1M0=0x00;//准双向
P1M1=0x00;
// P_SW2 |= 0x00; //RXD2/P1.0, TXD2/P1.1
// P_SW2 |= 0x01; //RXD2_2/P4.6, TXD2_2/P4.7
UART2_Set8bitUART();
UART2_Config(HAL_State_ON, 115200);
UART2_TxString("Uart Test !\r\n");
while(1)
{
UART2_TxChar('T');
UART2_TxHex(0x41);
UART2_TxString("U");
UART2_TxString(" string\r\n");
SYS_Delay(1000);
}
}
`