完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
烧入的时候,选项有没有打勾呢?
|
|
|
|
|
|
大神你好,是哪个选项,我烧串口1的程序进去,能输出,串口2就没输出,还是官网的代码。 |
|
|
|
|
|
波特率对不对,IO设置了没有
|
|
|
|
|
|
将你烧录时的截图发送上传看看
|
|
|
|
|
|
发上程序和烧录截图上来,大家帮你分析一下啊
|
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------*/
/* --- STC MCU Limited ---------------------------------------------*/ /* --- STC12C5Axx Series MCU UART2 (8-bit/9-bit)Demo ---------------*/ /* --- Mobile: (86)13922805190 -------------------------------------*/ /* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/ /* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/ /* --- Web: www.STCMCU.com -----------------------------------------*/ /* --- Web: www.GXWMCU.com -----------------------------------------*/ /* If you want to use the program or the program referenced in the */ /* article, please specify in which data and procedures from STC */ /*------------------------------------------------------------------*/ #include "reg51.h" #include "intrins.h" typedef unsigned char BYTE; typedef unsigned int WORD; #define FOSC 11059200L //System frequency #define BAUD 115200 //UART baudrate /*Define UART parity mode*/ #define NONE_PARITY 0 //None parity #define ODD_PARITY 1 //Odd parity #define EVEN_PARITY 2 //Even parity #define MARK_PARITY 3 //Mark parity #define SPACE_PARITY 4 //Space parity #define PARITYBIT EVEN_PARITY //Testing even parity /*Declare SFR associated with the UART2 */ sfr AUXR = 0x8e; //Auxiliary register sfr S2CON = 0x9a; //UART2 control register sfr S2BUF = 0x9b; //UART2 data buffer sfr BRT = 0x9c; //Baudrate generator sfr IE2 = 0xaf; //Interrupt control 2 #define S2RI 0x01 //S2CON.0 #define S2TI 0x02 //S2CON.1 #define S2RB8 0x04 //S2CON.2 #define S2TB8 0x08 //S2CON.3 bit busy; void SendData(BYTE dat); void SendString(char *s); void main() { #if (PARITYBIT == NONE_PARITY) S2CON = 0x50; //8-bit variable UART #elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY) S2CON = 0xda; //9-bit variable UART, parity bit initial to 1 #elif (PARITYBIT == SPACE_PARITY) S2CON = 0xd2; //9-bit variable UART, parity bit initial to 0 #endif BRT = -(FOSC/32/BAUD); //Set auto-reload vaule of baudrate generator AUXR = 0x14; //Baudrate generator work in 1T mode IE2 = 0x01; //Enable UART2 interrupt EA = 1; //Open master interrupt switch SendString("STC12C5A60S2rnUart2 Test !rn"); while(1); } /*---------------------------- UART2 interrupt service routine ----------------------------*/ void Uart2() interrupt 8 using 1 { if (S2CON & S2RI) { S2CON &= ~S2RI; //Clear receive interrupt flag P0 = S2BUF; //P0 show UART data P2 = (S2CON & S2RB8);//P2.2 show parity bit } if (S2CON & S2TI) { S2CON &= ~S2TI; //Clear transmit interrupt flag busy = 0; //Clear transmit busy flag } } /*---------------------------- Send a byte data to UART Input: dat (data to be sent) Output:None ----------------------------*/ void SendData(BYTE dat) { while (busy); //Wait for the completion of the previous data is sent ACC = dat; //Calculate the even parity bit P (PSW.0) if (P) //Set the parity bit according to P { #if (PARITYBIT == ODD_PARITY) S2CON &= ~S2TB8; //Set parity bit to 0 #elif (PARITYBIT == EVEN_PARITY) S2CON |= S2TB8; //Set parity bit to 1 #endif } else { #if (PARITYBIT == ODD_PARITY) S2CON |= S2TB8; //Set parity bit to 1 #elif (PARITYBIT == EVEN_PARITY) S2CON &= ~S2TB8; //Set parity bit to 0 #endif } busy = 1; S2BUF = ACC; //Send data to UART2 buffer } /*---------------------------- Send a string to UART Input: s (address of string) Output:None ----------------------------*/ void SendString(char *s) { while (*s) //Check the end of the string { SendData(*s++); //Send current char and increment string ptr } } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
大神们,而且我将P1.2跟P1.3(这款单片机串口2的RXD2 TXD2)短接起来,用串口调试助手发数据,还是没法自发自收,而将串口1的P3.0跟P3.1短接,就能自发自收,小白不懂什么问题
|
|
|
|
|
|
P1.0 P1.1选项
|
|
|
|
|
|
勾选了,还是不行,下载程序是能下载进去,但是下载完后用串口调试助手看,串口2的代码没输出,串口1就正常 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
我的是stc12c5a60s2,那个官方代码是stc15F的。而且我用官方的stc12c5a60s2的串口2代码烧进去,没有任何输出,不知道是我哪一步有问题 ,用了两片单片机都不行。
|
|
|
|
|
是这个程序吗? |
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
265 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
789 浏览 0 评论
1306 浏览 2 评论
787 浏览 0 评论
【RA4M2-SENSOR开发板评测】Analogue+Timers综合测试
1587 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16899 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 19:48 , Processed in 1.239611 second(s), Total 109, Slave 90 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
5020