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

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

QQ登錄

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

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

stc12c5a60s2單片機(jī)串口不夠用,TXD,RXD該怎么拓展啊?求大佬解答

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:381195 發(fā)表于 2018-8-1 11:22 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
好像是有專門拓展芯片,求介紹那個(gè)比較好用

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

使用道具 舉報(bào)

沙發(fā)
ID:375003 發(fā)表于 2018-8-1 12:29 | 只看該作者
1,普通IO口摸擬,2,串口協(xié)義中指定地址要操作哪個(gè)從機(jī),主機(jī)TXD,從機(jī)1,RXD,從機(jī)2,RXD,主機(jī)RXD,從機(jī)1,TXD,從機(jī)2,TXD

評(píng)分

參與人數(shù) 1黑幣 +2 收起 理由
多德 + 2 回帖助人的獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

板凳
ID:366710 發(fā)表于 2018-8-1 16:06 | 只看該作者
用LS165或LS164芯片
回復(fù)

使用道具 舉報(bào)

地板
ID:308437 發(fā)表于 2018-8-2 08:45 | 只看該作者
那個(gè)燒錄軟件下有范例程序,串口二的
  1. /*------------------------------------------------------------------*/
  2. /* --- STC MCU Limited ---------------------------------------------*/
  3. /* --- STC12C5Axx Series MCU UART2 (8-bit/9-bit)Demo ---------------*/
  4. /* If you want to use the program or the program referenced in the  */
  5. /* article, please specify in which data and procedures from STC    */
  6. /*------------------------------------------------------------------*/

  7. #include "reg51.h"
  8. #include "intrins.h"

  9. typedef unsigned char BYTE;
  10. typedef unsigned int WORD;

  11. #define FOSC 18432000L      //System frequency
  12. #define BAUD 115200         //UART baudrate

  13. /*Define UART parity mode*/
  14. #define NONE_PARITY     0   //None parity
  15. #define ODD_PARITY      1   //Odd parity
  16. #define EVEN_PARITY     2   //Even parity
  17. #define MARK_PARITY     3   //Mark parity
  18. #define SPACE_PARITY    4   //Space parity

  19. #define PARITYBIT EVEN_PARITY   //Testing even parity

  20. /*Declare SFR associated with the UART2 */
  21. sfr AUXR  = 0x8e;           //Auxiliary register
  22. sfr S2CON = 0x9a;           //UART2 control register
  23. sfr S2BUF = 0x9b;           //UART2 data buffer
  24. sfr BRT   = 0x9c;           //Baudrate generator
  25. sfr IE2   = 0xaf;           //Interrupt control 2

  26. #define S2RI  0x01          //S2CON.0
  27. #define S2TI  0x02          //S2CON.1
  28. #define S2RB8 0x04          //S2CON.2
  29. #define S2TB8 0x08          //S2CON.3

  30. bit busy;

  31. void SendData(BYTE dat);
  32. void SendString(char *s);

  33. void main()
  34. {
  35. #if (PARITYBIT == NONE_PARITY)
  36.     S2CON = 0x50;           //8-bit variable UART
  37. #elif (PARITYBIT == ODD_PARITY) || (PARITYBIT == EVEN_PARITY) || (PARITYBIT == MARK_PARITY)
  38.     S2CON = 0xda;           //9-bit variable UART, parity bit initial to 1
  39. #elif (PARITYBIT == SPACE_PARITY)
  40.     S2CON = 0xd2;           //9-bit variable UART, parity bit initial to 0
  41. #endif

  42.     BRT = -(FOSC/32/BAUD);  //Set auto-reload vaule of baudrate generator
  43.     AUXR = 0x14;            //Baudrate generator work in 1T mode
  44.     IE2 = 0x01;             //Enable UART2 interrupt
  45.     EA = 1;                 //Open master interrupt switch

  46.     SendString("STC12C5A60S2\r\nUart2 Test !\r\n");
  47.     while(1);
  48. }

  49. /*----------------------------
  50. UART2 interrupt service routine
  51. ----------------------------*/
  52. void Uart2() interrupt 8 using 1
  53. {
  54.     if (S2CON & S2RI)
  55.     {
  56.         S2CON &= ~S2RI;     //Clear receive interrupt flag
  57.         P0 = S2BUF;         //P0 show UART data
  58.         P2 = (S2CON & S2RB8);//P2.2 show parity bit
  59.     }
  60.     if (S2CON & S2TI)
  61.     {
  62.         S2CON &= ~S2TI;     //Clear transmit interrupt flag
  63.         busy = 0;           //Clear transmit busy flag
  64.     }
  65. }

  66. /*----------------------------
  67. Send a byte data to UART
  68. Input: dat (data to be sent)
  69. Output:None
  70. ----------------------------*/
  71. void SendData(BYTE dat)
  72. {
  73.     while (busy);           //Wait for the completion of the previous data is sent
  74.     ACC = dat;              //Calculate the even parity bit P (PSW.0)
  75.     if (P)                  //Set the parity bit according to P
  76.     {
  77. #if (PARITYBIT == ODD_PARITY)
  78.         S2CON &= ~S2TB8;    //Set parity bit to 0
  79. #elif (PARITYBIT == EVEN_PARITY)
  80.         S2CON |= S2TB8;     //Set parity bit to 1
  81. #endif
  82.     }
  83.     else
  84.     {
  85. #if (PARITYBIT == ODD_PARITY)
  86.         S2CON |= S2TB8;     //Set parity bit to 1
  87. #elif (PARITYBIT == EVEN_PARITY)
  88.         S2CON &= ~S2TB8;    //Set parity bit to 0
  89. #endif
  90.     }
  91.     busy = 1;
  92.     S2BUF = ACC;            //Send data to UART2 buffer
  93. }

  94. /*----------------------------
  95. Send a string to UART
  96. Input: s (address of string)
  97. Output:None
  98. ----------------------------*/
  99. void SendString(char *s)
  100. {
  101.     while (*s)              //Check the end of the string
  102.     {
  103.         SendData(*s++);     //Send current char and increment string ptr
  104.     }
  105. }
復(fù)制代碼


回復(fù)

使用道具 舉報(bào)

5#
ID:394112 發(fā)表于 2018-9-5 16:06 | 只看該作者
你現(xiàn)在找到合適的了嗎,求分享,也遇到同樣的問(wèn)題了
回復(fù)

使用道具 舉報(bào)

6#
ID:387733 發(fā)表于 2018-9-5 18:32 | 只看該作者
可以使用STC15W4K32S4替代,這個(gè)有4個(gè)串口可用
回復(fù)

使用道具 舉報(bào)

7#
ID:262530 發(fā)表于 2018-9-5 20:12 | 只看該作者
普通IO口就可以模擬
回復(fù)

使用道具 舉報(bào)

8#
ID:303383 發(fā)表于 2018-9-5 20:21 | 只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽
回復(fù)

使用道具 舉報(bào)

9#
ID:375003 發(fā)表于 2020-2-3 23:20 | 只看該作者
還可這樣IOto232
#include <reg52.h>
sbit BT_SND =P3^1;
sbit BT_REC =P3^0;
/**********************************************

IO 口模擬232通訊程序

使用兩種方式的C程序 占用定時(shí)器0

**********************************************/
#define F_TM F0
#define TIMER0_ENABLE TL0=TH0; TR0=1;
#define TIMER0_DISABLE TR0=0;
#define uchar unsigned char
#define uint unsigned int



sbit ACC0= ACC^0;
sbit ACC1= ACC^1;
sbit ACC2= ACC^2;
sbit ACC3= ACC^3;
sbit ACC4= ACC^4;
sbit ACC5= ACC^5;
sbit ACC6= ACC^6;
sbit ACC7= ACC^7;

uchar bufSND[8],bufRCV[8],putRCV,getRCV,curSND,lenSND,staRCV;
uchar putKEY,getKEY,nFUN,nSTN,Cxy,Cxy0,nTIM;

void IntTimer0() interrupt 1
{
F_TM=1;
}

//發(fā)送一個(gè)字符
void PSendChar(unsigned char inch)
{
unsigned char ii;
ii=0;
F_TM=0;
BT_SND=0; //start bit
TIMER0_ENABLE; //啟動(dòng)
while(!F_TM);
while(ii<8){
    if(inch&1)BT_SND=1;
    else BT_SND=0;
    F_TM=0;
    while(!F_TM);
    ii++;
        inch>>=1;
        }
BT_SND=1;
F_TM=0;
while(!F_TM);
TIMER0_DISABLE; //停止timer
}

//接收一個(gè)字符
unsigned char PGetChar()
{
unsigned char rch,ii;
TIMER0_ENABLE;
F_TM=0;
ii=0;
rch=0;
while(!F_TM); //等過(guò)起始位

while(ii<8)
{
rch>>=1;
if(BT_REC)
{
rch|=0x80;
}
ii++;
F_TM=0;
while(!F_TM);
}
F_TM=0;
while(!F_TM)
{
if(BT_REC)
{
break;
}
}
TIMER0_DISABLE; //停止timer
return rch;
}

//檢查是不是有起始位
bit StartBitOn()
{
return (BT_REC==0);

}

void main()
{
unsigned char gch;
TMOD=0x22; //定時(shí)器1為工作模式2(8位自動(dòng)重裝),0為模式2(8位自動(dòng)重裝)
PCON=00;
TR0=0; //在發(fā)送或接收才開(kāi)始使用
TF0=0;
TH0=(256-104); //9600bps 就是 1000000/9600=104.167微秒 執(zhí)行的timer是104.167*11.0592/12= 96
TL0=TH0;
ET0=1;
EA=1;

//PSendChar(0x55);
//PSendChar(0xaa);
//PSendChar(0x00);
//PSendChar(0xff);

while(1)
{
if(StartBitOn())
{
gch=PGetChar();
bufRCV[putRCV++]=PGetChar();
putRCV &= 0X07;
   if(bSD){if(curSND<lenSND) SBUF=bufSND[curSND++];else {bSD=OFF;}}
PSendChar(gch);
}
}
}
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 亚洲国产精品一区二区三区 | 亚洲视频在线免费观看 | 久久成人免费 | 精品少妇一区二区三区在线播放 | 亚洲一区二区三区视频 | 亚洲成人免费视频在线观看 | 伊人精品一区二区三区 | 日韩视频在线免费观看 | 久久99蜜桃综合影院免费观看 | 国产成人一区在线 | 亚洲精品电影 | 国产精品久久久久一区二区 | a毛片视频网站 | 老司机67194精品线观看 | 亚洲欧美日韩一区二区 | 欧美一区二区三区视频 | 国产色爽 | 久久99精品视频 | 亚洲电影一区二区三区 | 一区二区三区在线免费观看 | 在线视频h | 超碰97人人人人人蜜桃 | 亚洲视频一区 | 久久久久国产 | www.五月天婷婷.com | 99久久婷婷国产亚洲终合精品 | av一区在线观看 | 亚洲一区二区三区在线免费 | 国产精品18久久久久久白浆动漫 | caoporn视频在线 | 日韩成人免费视频 | 男人的天堂中文字幕 | 精品一区精品二区 | 国产精品久久久 | 伦理二区 | 欧美日韩国产免费 | 男人天堂视频在线观看 | 日韩一级黄色毛片 | 91在线精品播放 | 午夜视频网 | 日韩精品一区二区三区免费视频 |