找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 16986|回復(fù): 12
打印 上一主題 下一主題
收起左側(cè)

STC12C單片機(jī)串口通信波特率怎么設(shè)置9600

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:102000 發(fā)表于 2016-4-1 17:52 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
60黑幣
選工作方式2,波特率怎么設(shè)置?晶振11.0592的

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:110895 發(fā)表于 2016-4-5 13:52 | 只看該作者
SCON = 0x50;                //8位數(shù)據(jù),可變波特率
        AUXR |= 0x40;                //定時(shí)器1時(shí)鐘為Fosc,即1T
        AUXR &= 0xFE;                //串口1選擇定時(shí)器1為波特率發(fā)生器
        TMOD &= 0x0F;                //設(shè)定定時(shí)器1為16位自動(dòng)重裝方式
        TL1 = 0xE0;                //設(shè)定定時(shí)初值
        TH1 = 0xFE;                //設(shè)定定時(shí)初值
        ET1 = 0;                //禁止定時(shí)器1中斷
        TR1 = 1;                //啟動(dòng)定時(shí)器1
回復(fù)

使用道具 舉報(bào)

SCON = 0x50;                //8位數(shù)據(jù),可變波特率
        AUXR |= 0x40;                //定時(shí)器1時(shí)鐘為Fosc,即1T
        AUXR &= 0xFE;                //串口1選擇定時(shí)器1為波特率發(fā)生器
        TMOD &= 0x0F;                //設(shè)定定時(shí)器1為16位自動(dòng)重裝方式
        TL1 = 0xE0;                //設(shè)定定時(shí)初值
        TH1 = 0xFE;                //設(shè)定定時(shí)初值
        ET1 = 0;                //禁止定時(shí)器1中斷
        TR1 = 1;                //啟動(dòng)定時(shí)器1
回復(fù)

使用道具 舉報(bào)

地板
ID:107339 發(fā)表于 2016-4-5 20:32 | 只看該作者
/*------------------------------------------------------------------*/ /* --- STC MCU Limited ---------------------------------------------*/ /* --- STC12C5Axx Series MCU UART (8-bit/9-bit)Demo ----------------*/ /* --- Mobile: (86)13922805190 -------------------------------------*/ /* --- Fax: 86-755-82905966 ----------------------------------------*/ /* --- Tel: 86-755-82948412 ----------------------------------------*/ /* --- Web: www.STCMCU.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 18432000L      //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     } }
回復(fù)

使用道具 舉報(bào)

5#
ID:321166 發(fā)表于 2018-5-6 21:11 | 只看該作者

    TMOD=0x20;    //定時(shí)器1工作在方式2  8位自動(dòng)重裝
    SCON=0x50;    //串口1工作在方式1  10位異步收發(fā) REN=1允許接收
    TH1=0xFD;           //定時(shí)器1初值  9600BIT
    TL1=0xFD;
    TR1=1;           //定時(shí)器1開(kāi)始計(jì)數(shù)
        RI=0;   
    EA=1;        //開(kāi)總中斷
    ES=1;        //開(kāi)串口1中斷
回復(fù)

使用道具 舉報(bào)

6#
ID:698784 發(fā)表于 2020-4-24 17:31 | 只看該作者
SCON = 0x50;                //8位數(shù)據(jù),可變波特率
        AUXR |= 0x40;                //定時(shí)器1時(shí)鐘為Fosc,即1T
        AUXR &= 0xFE;                //串口1選擇定時(shí)器1為波特率發(fā)生器
        TMOD &= 0x0F;                //設(shè)定定時(shí)器1為16位自動(dòng)重裝方式
        TL1 = 0xE0;                //設(shè)定定時(shí)初值
        TH1 = 0xFE;                //設(shè)定定時(shí)初值
        ET1 = 0;                //禁止定時(shí)器1中斷
        TR1 = 1;                //啟動(dòng)定時(shí)器1
回復(fù)

使用道具 舉報(bào)

7#
ID:456580 發(fā)表于 2020-5-16 23:09 | 只看該作者
void UART_INIT()
{
        SM0 = 0;
        SM1 = 1;
        REN = 1;                                                                                                         
        EA = 1;
        ES = 1;
        TMOD = 0x20;
        TH1 = 0xfd;
        TL1 = 0xfd;
        TR1 = 1;
}
回復(fù)

使用道具 舉報(bào)

8#
ID:420836 發(fā)表于 2020-5-17 01:35 | 只看該作者
試一下使用以下配置:

void init_com( void )
{
    SCON = 0x50 ; //串口工作方式1,8位UART,波特率可變
    TMOD |= 0x20 ; //定時(shí)器1,工作方式2,自動(dòng)再裝入8位定時(shí)器
    PCON |= 0x80 ; //SMOD=1; 波特率加倍
    TH1 = 0xfa ; //波特率:9600 晶振=11.0592MHz
    IE |= 0x90 ; //使能串口中斷
    TR1 = 1 ; // 定時(shí)器1開(kāi)始
}
回復(fù)

使用道具 舉報(bào)

9#
ID:420836 發(fā)表于 2020-5-17 01:35 | 只看該作者
試一下使用以下配置:

void init_com( void )
{
    SCON = 0x50 ; //串口工作方式1,8位UART,波特率可變
    TMOD |= 0x20 ; //定時(shí)器1,工作方式2,自動(dòng)再裝入8位定時(shí)器
    PCON |= 0x80 ; //SMOD=1; 波特率加倍
    TH1 = 0xfa ; //波特率:9600 晶振=11.0592MHz
    IE |= 0x90 ; //使能串口中斷
    TR1 = 1 ; // 定時(shí)器1開(kāi)始
}
回復(fù)

使用道具 舉報(bào)

10#
ID:811102 發(fā)表于 2020-9-3 09:56 | 只看該作者
        SCON=0X50;                        //設(shè)置為工作方式1 ,既然是方式一,自然要確定波特率,設(shè)置定時(shí)器1
        TMOD|=0X20;//8位重裝載
        PCON|=0x00;
        TH1=0xfa;//波特率9600
        TL1=0xfa;
        RI=1;
        TI=1;
        ES=1;                                                //打開(kāi)通信中斷
        EA=1;                                                //打開(kāi)總中斷
        TR1=1;       
回復(fù)

使用道具 舉報(bào)

11#
ID:245053 發(fā)表于 2020-9-3 12:24 | 只看該作者
學(xué)會(huì)看資料,一般資料里都有介紹使用,串口波特率一般都會(huì)指定一個(gè)定時(shí)器來(lái)產(chǎn)生,設(shè)置好定時(shí)器的計(jì)數(shù)周期,也就是波特率就可以了
回復(fù)

使用道具 舉報(bào)

12#
ID:235954 發(fā)表于 2020-9-3 17:25 | 只看該作者
SCON = 0x50;            //8-bit variable UART
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表