久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3858|回復(fù): 8
打印 上一主題 下一主題
收起左側(cè)

請各位朋友幫忙測試一下串口程序,謝謝。

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:119239 發(fā)表于 2016-5-10 23:21 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
       我的串口2程序調(diào)不通(用STC12C5A60S2),懷疑是我的Keil  C,版本為UV4設(shè)置可能有問題。測試STC-ISP串口范例程序,串口1范例可正常執(zhí)行,輸出了字符串,串口2范例沒有字符串輸出,進入了死循環(huán),不知何解?請朋友幫忙測試一下,究竟是何原因。

程序一:串口1例程(從STC-ISP燒寫軟件的范例中復(fù)制)
/*------------------------------------------------------------------*/
/* --- STC MCU Limited ---------------------------------------------*/
/* --- STC12C5Axx Series MCU UART (8-bit/9-bit)Demo ----------------*/
/* --- Mobile: (86)13922805190 -------------------------------------*/
/* --- Fax: 86-0513-55012956,55012947,55012969 ---------------------*/
/* --- Tel: 86-0513-55012928,55012929,55012966----------------------*/
/* 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 9600           //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
sbit bit9 = P2^2;           //P2.2 show UART data bit9
bit busy;
void SendData(BYTE dat);
void SendString(char *s);
void main()
{
#if (PARITYBIT == NONE_PARITY)
    SCON = 0x50;            //8-bit variable UART
#elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
    SCON = 0xda;            //9-bit variable UART, parity bit initial to 1
#elif (PARITYBIT == SPACE_PARITY)
    SCON = 0xd2;            //9-bit variable UART, parity bit initial to 0
#endif
    TMOD = 0x20;            //Set Timer1 as 8-bit auto reload mode
    TH1 = TL1 = -(FOSC/12/32/BAUD); //Set auto-reload vaule
    TR1 = 1;                //Timer1 start run
    ES = 1;                 //Enable UART interrupt
    EA = 1;                 //Open master interrupt switch
    SendString("STC12C5A60S2\r\nUart Test !\r\n");
    while(1);
}
/*----------------------------
UART interrupt service routine
----------------------------*/
void Uart_Isr() interrupt 4 using 1
{
    if (RI)
    {
        RI = 0;             //Clear receive interrupt flag
        P0 = SBUF;          //P0 show UART data
        bit9 = RB8;         //P2.2 show parity bit
    }
    if (TI)
    {
        TI = 0;             //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)
        TB8 = 0;            //Set parity bit to 0
#elif (PARITYBIT == EVEN_PARITY)
        TB8 = 1;            //Set parity bit to 1
#endif
    }
    else
    {
#if (PARITYBIT == ODD_PARITY)
        TB8 = 1;            //Set parity bit to 1
#elif (PARITYBIT == EVEN_PARITY)
        TB8 = 0;            //Set parity bit to 0
#endif
    }
    busy = 1;
    SBUF = ACC;             //Send data to UART 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
    }
}



程序二:串口2例程(從STC-ISP燒寫軟件的范例中復(fù)制)
/*------------------------------------------------------------------*/
/* --- 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("STC12C5A60S2\r\nUart2 Test !\r\n");
    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
    }
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:119239 發(fā)表于 2016-5-11 23:34 | 只看該作者
怎么沒人回復(fù)?煩請各位幫忙花幾分鐘測試,回復(fù)測試結(jié)果,先謝了。
回復(fù)

使用道具 舉報

板凳
ID:119239 發(fā)表于 2016-5-12 17:31 | 只看該作者
請幫忙測試程序2是否能正常運行,謝謝。
回復(fù)

使用道具 舉報

地板
ID:444191 發(fā)表于 2018-12-11 16:16 | 只看該作者
yyg123321a 發(fā)表于 2016-5-11 23:34
怎么沒人回復(fù)?煩請各位幫忙花幾分鐘測試,回復(fù)測試結(jié)果,先謝了。

其實STC-ISP有范例程序。。。。。
回復(fù)

使用道具 舉報

5#
ID:280876 發(fā)表于 2018-12-11 19:55 | 只看該作者
自己調(diào)試一下,看一下相關(guān)寄存器的值
回復(fù)

使用道具 舉報

6#
ID:414093 發(fā)表于 2018-12-17 16:12 | 只看該作者
你這個程序好復(fù)雜,不用這么復(fù)雜的吧
回復(fù)

使用道具 舉報

7#
ID:875095 發(fā)表于 2021-9-14 22:18 | 只看該作者
OK的,之前我跑過
回復(fù)

使用道具 舉報

8#
ID:161164 發(fā)表于 2021-9-15 15:13 | 只看該作者
在Protues上仿真有串口訊號輸出,但時序很慢
Tx/Rx腳是TxD2/RxD2(P1.1/P1.0)
回復(fù)

使用道具 舉報

9#
ID:94031 發(fā)表于 2021-9-15 18:49 | 只看該作者
軟件問題不大重點查硬件。

回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 精品一区二区三区视频在线观看 | 国产精品a久久久久 | 一级aaaa毛片 | 久久国产精品久久久久久久久久 | av黄色在线观看 | 亚洲精品二区 | 男女污污动态图 | 一级欧美视频 | 国产精品久久久久久久久久久久 | 欧洲视频一区二区 | 欧美福利三区 | 香蕉一区二区 | 色橹橹欧美在线观看视频高清 | 日日噜噜噜夜夜爽爽狠狠视频97 | 精品国产乱码久久久久久牛牛 | 国产美女自拍视频 | 羞羞的视频免费在线观看 | 丁香综合 | 中文字幕乱码视频32 | 久久精品国产亚洲夜色av网站 | 亚洲成人黄色 | 欧美一级在线 | av免费网站在线观看 | 无码一区二区三区视频 | 欧美网址在线观看 | 日韩精品一二三 | 亚洲成人精 | www.中文字幕.com | 91豆花视频 | 毛片网络 | 国产97在线看 | 色综合久久88色综合天天 | 91av视频在线观看 | 久久久久亚洲 | av在线一区二区三区 | 国产成人免费一区二区60岁 | 日本激情视频在线播放 | 亚洲网站在线 | 成人黄在线观看 | av中文字幕在线观看 | 亚洲视频在线一区 |