欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
stc12c5a60s2單片機串口不夠用,TXD,RXD該怎么拓展啊?求大佬解答
[打印本頁]
作者:
雨晨
時間:
2018-8-1 11:22
標題:
stc12c5a60s2單片機串口不夠用,TXD,RXD該怎么拓展啊?求大佬解答
好像是有專門拓展芯片,求介紹那個比較好用
作者:
guangshi_wq
時間:
2018-8-1 12:29
1,普通IO口摸擬,2,串口協義中指定地址要操作哪個從機,主機TXD,從機1,RXD,從機2,RXD,主機RXD,從機1,TXD,從機2,TXD
作者:
huliujie
時間:
2018-8-1 16:06
用LS165或LS164芯片
作者:
yousunny
時間:
2018-8-2 08:45
那個燒錄軟件下有范例程序,串口二的
/*------------------------------------------------------------------*/
/* --- STC MCU Limited ---------------------------------------------*/
/* --- STC12C5Axx Series MCU UART2 (8-bit/9-bit)Demo ---------------*/
/* 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 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
}
}
復制代碼
作者:
什么什么
時間:
2018-9-5 16:06
你現在找到合適的了嗎,求分享,也遇到同樣的問題了
作者:
sxhwdz
時間:
2018-9-5 18:32
可以使用STC15W4K32S4替代,這個有4個串口可用
作者:
zhongmeijun007
時間:
2018-9-5 20:12
普通IO口就可以模擬
作者:
小貓貓愛吃魚
時間:
2018-9-5 20:21
什么什么 發表于 2018-9-5 16:06
你現在找到合適的了嗎,求分享,也遇到同樣的問題了
那你需要幾個串口才夠用?
作者:
guangshi_wq
時間:
2020-2-3 23:20
還可這樣IOto232
#include <reg52.h>
sbit BT_SND =P3^1;
sbit BT_REC =P3^0;
/**********************************************
IO 口模擬232通訊程序
使用兩種方式的C程序 占用定時器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;
}
//發送一個字符
void PSendChar(unsigned char inch)
{
unsigned char ii;
ii=0;
F_TM=0;
BT_SND=0; //start bit
TIMER0_ENABLE; //啟動
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
}
//接收一個字符
unsigned char PGetChar()
{
unsigned char rch,ii;
TIMER0_ENABLE;
F_TM=0;
ii=0;
rch=0;
while(!F_TM); //等過起始位
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; //定時器1為工作模式2(8位自動重裝),0為模式2(8位自動重裝)
PCON=00;
TR0=0; //在發送或接收才開始使用
TF0=0;
TH0=(256-104); //9600bps 就是 1000000/9600=104.167微秒 執行的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);
}
}
}
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1