- 打卡等级:初来乍到
- 打卡总天数:1
- 最近打卡:2025-04-17 15:44:33
已绑定手机
新手上路
- 积分
- 7
|
提示掉线内容如下:
源代码见附件,我自己写的源代码,也是一样的情况:
/******************* IOÅäÖú¯Êý *******************/
void GPIO_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure; //½á¹¹¶¨Òå
GPIO_InitStructure.Pin = GPIO_Pin_6 | GPIO_Pin_7; //Ö¸¶¨Òª³õʼ»¯µÄIO, GPIO_Pin_0 ~ GPIO_Pin_7
GPIO_InitStructure.Mode = GPIO_PullUp; //Ö¸¶¨IOµÄÊäÈë»òÊä³ö·½Ê½,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure); //³õʼ»¯
GPIO_InitStructure.Pin = GPIO_Pin_0| GPIO_Pin_1; //Ö¸¶¨Òª³õʼ»¯µÄIO, GPIO_Pin_0 ~ GPIO_Pin_7
GPIO_InitStructure.Mode = GPIO_PullUp; //Ö¸¶¨IOµÄÊäÈë»òÊä³ö·½Ê½,GPIO_PullUp,GPIO_HighZ,GPIO_OUT_OD,GPIO_OUT_PP
GPIO_Inilize(GPIO_P1,&GPIO_InitStructure); //³õʼ»¯
}
/*************** ´®¿Ú³õʼ»¯º¯Êý *****************/
void UART_config(void)
{
COMx_InitDefine COMx_InitStructure; //½á¹¹¶¨Òå
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
COMx_InitStructure.UART_BRT_Use = BRT_Timer1; //Ñ¡Ôñ²¨ÌØÂÊ·¢ÉúÆ÷, BRT_Timer1, BRT_Timer2 (×¢Òâ: ´®¿Ú2¹Ì¶¨Ê¹ÓÃBRT_Timer2)
COMx_InitStructure.UART_BaudRate = 115200ul; //²¨ÌØÂÊ, Ò»°ã 110 ~ 115200
COMx_InitStructure.UART_RxEnable = ENABLE; //½ÓÊÕÔÊÐí, ENABLE»òDISABLE
COMx_InitStructure.BaudRateDouble = DISABLE; //²¨ÌØÂʼӱ¶, ENABLE»òDISABLE
UART_Configuration(UART1, &COMx_InitStructure); //³õʼ»¯´®¿Ú1 UART1,UART2,UART3,UART4
NVIC_UART1_Init(ENABLE,Priority_1); //ÖжÏʹÄÜ, ENABLE/DISABLE; ÓÅÏȼ¶(µÍµ½¸ß) Priority_0,Priority_1,Priority_2,Priority_3
COMx_InitStructure.UART_Mode = UART_8bit_BRTx; //ģʽ, UART_ShiftRight,UART_8bit_BRTx,UART_9bit,UART_9bit_BRTx
// COMx_InitStructure.UART_BRT_Use = BRT_Timer2; //Ñ¡Ôñ²¨ÌØÂÊ·¢ÉúÆ÷, BRT_Timer2 (×¢Òâ: ´®¿Ú2¹Ì¶¨Ê¹ÓÃBRT_Timer2, ËùÒÔ²»ÓÃÑ¡Ôñ)
COMx_InitStructure.UART_BaudRate = 57600ul; //²¨ÌØÂÊ, 110 ~ 115200
COMx_InitStructure.UART_RxEnable = ENABLE; //½ÓÊÕÔÊÐí, ENABLE»òDISABLE
UART_Configuration(UART2, &COMx_InitStructure); //³õʼ»¯´®¿Ú2 UART1,UART2,UART3,UART4
NVIC_UART2_Init(ENABLE,Priority_1); //ÖжÏʹÄÜ, ENABLE/DISABLE; ÓÅÏȼ¶(µÍµ½¸ß) Priority_0,Priority_1,Priority_2,Priority_3
UART1_SW(UART1_SW_P36_P37); //UART1_SW_P30_P31,UART1_SW_P36_P37,UART1_SW_P16_P17,UART1_SW_P43_P44
UART2_SW(UART2_SW_P10_P11); //UART2_SW_P10_P11,UART2_SW_P46_P47
}
/***********************************************/
void main(void)
{
u8 i;
EAXSFR(); /* À©Õ¹¼Ä´æÆ÷·ÃÎÊʹÄÜ */
GPIO_config();
UART_config();
EA = 1;
PrintString1("STC8 UART1 Test Programme!\r\n"); //UART1·¢ËÍÒ»¸ö×Ö·û´®
PrintString2("STC8 UART2 Test Programme!\r\n"); //UART2·¢ËÍÒ»¸ö×Ö·û´®
while (1)
{
delay_ms(1);
if(COM1.RX_TimeOut > 0) //³¬Ê±¼ÆÊý
{
if(--COM1.RX_TimeOut == 0)
{
if(COM1.RX_Cnt > 0)
{
for(i=0; i<COM1.RX_Cnt; i++) TX1_write2buff(RX1_Buffer); //ÊÕµ½µÄÊý¾ÝÔÑù·µ»Ø
}
COM1.RX_Cnt = 0;
}
}
if(COM2.RX_TimeOut > 0) //³¬Ê±¼ÆÊý
{
if(--COM2.RX_TimeOut == 0)
{
if(COM2.RX_Cnt > 0)
{
for(i=0; i<COM2.RX_Cnt; i++) TX2_write2buff(RX2_Buffer); //ÊÕµ½µÄÊý¾ÝÔÑù·µ»Ø
}
COM2.RX_Cnt = 0;
}
}
}
}
|
|