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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3955|回復: 8
收起左側

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

[復制鏈接]
ID:119239 發表于 2016-5-10 23:21 | 顯示全部樓層 |閱讀模式
       我的串口2程序調不通(用STC12C5A60S2),懷疑是我的Keil  C,版本為UV4設置可能有問題。測試STC-ISP串口范例程序,串口1范例可正常執行,輸出了字符串,串口2范例沒有字符串輸出,進入了死循環,不知何解?請朋友幫忙測試一下,究竟是何原因。

程序一:串口1例程(從STC-ISP燒寫軟件的范例中復制)
/*------------------------------------------------------------------*/
/* --- 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燒寫軟件的范例中復制)
/*------------------------------------------------------------------*/
/* --- 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
    }
}

回復

使用道具 舉報

ID:119239 發表于 2016-5-11 23:34 | 顯示全部樓層
怎么沒人回復?煩請各位幫忙花幾分鐘測試,回復測試結果,先謝了。
回復

使用道具 舉報

ID:119239 發表于 2016-5-12 17:31 | 顯示全部樓層
請幫忙測試程序2是否能正常運行,謝謝。
回復

使用道具 舉報

ID:444191 發表于 2018-12-11 16:16 | 顯示全部樓層
yyg123321a 發表于 2016-5-11 23:34
怎么沒人回復?煩請各位幫忙花幾分鐘測試,回復測試結果,先謝了。

其實STC-ISP有范例程序。。。。。
回復

使用道具 舉報

ID:280876 發表于 2018-12-11 19:55 | 顯示全部樓層
自己調試一下,看一下相關寄存器的值
回復

使用道具 舉報

ID:414093 發表于 2018-12-17 16:12 | 顯示全部樓層
你這個程序好復雜,不用這么復雜的吧
回復

使用道具 舉報

ID:875095 發表于 2021-9-14 22:18 | 顯示全部樓層
OK的,之前我跑過
回復

使用道具 舉報

ID:161164 發表于 2021-9-15 15:13 | 顯示全部樓層
在Protues上仿真有串口訊號輸出,但時序很慢
Tx/Rx腳是TxD2/RxD2(P1.1/P1.0)
回復

使用道具 舉報

ID:94031 發表于 2021-9-15 18:49 | 顯示全部樓層
軟件問題不大重點查硬件。 串口2.png

回復

使用道具 舉報

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

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久精品高清视频 | 国产精品视频一区二区三区四蜜臂 | 青青青伊人 | 免费啪啪| 国产综合久久久久久鬼色 | 成人一区二区电影 | 国产激情一区二区三区 | 精品久久久久一区二区国产 | 农夫在线精品视频免费观看 | 国产精品精品视频一区二区三区 | 波多野结衣先锋影音 | 资源首页二三区 | 久久久久成人精品 | 热99视频 | 欧美日韩精品影院 | 婷婷色婷婷 | 国产欧美日韩精品一区 | 一区二区在线不卡 | 国产日韩欧美一区 | 中文字幕 亚洲一区 | 亚洲美女网站 | 国产视频第一页 | 国产精品一区二区无线 | 欧美精品一区二区三区在线播放 | 日本不卡免费新一二三区 | 午夜欧美a级理论片915影院 | 国产日韩久久 | 亚洲视频在线免费观看 | 久草免费在线 | 国产一区二区精品在线 | 91看片网 | 午夜午夜精品一区二区三区文 | 国产精品天堂 | 国产一区视频在线 | 最新一级毛片 | 日本在线免费看最新的电影 | 九九成人 | 亚洲一区二区三区视频 | 免费日本视频 | www.47久久青青 | 一区二区久久 |