让找料更便捷
电子元器件
采购信息平台
生意随身带
随时随地找货
一站式电子元器件
采购平台
半导体行业观察第一站
标签:
摘要: 用EBOX向我们的电力线调试模块发数据,但是要有一个控制接口,但是EBOX没有提供,所有只好用MCU来做伺服器。一般的单片机都只有一个串口,所以必须模拟一个出来。/*sbit TXD1= P1^4;//define p14 as the analog transmit portsbit RXD1= P1^2;//define p12 as the analog recieve port*/#inc
一般的单片机都只有一个串口,所以必须模拟一个出来。
/*
sbit TXD1= P1^4;//define p14 as the analog transmit port
sbit RXD1= P1^2;//define p12 as the analog recieve port
*/
#include "REG52.H"
#define uint unsigned int
#define uchar unsigned char
#include
void WaitTF0(void);
void TIMEINI(void)//counter initial
{
TMOD=0x02;
TH0=0xA0;、//9600 BPS
TL0=TH0;
TR0=1;
TF0=0;
}
void WByte(uchar input)//send function
{
uchar i=8;
TR0=1;
TXD1=0;//begin bit
WaitTF0();
//send the Byte
while(i--)
{
TXD1=input&0x01;//send Byte from low bit to high bit
WaitTF0();
input=input>>1;//right shift
}
TXD1=1;//stop bit
WaitTF0();
TR0=0;//stop the counter
}
uchar RByte()//the recieve function
{
uchar Output=0;
uchar i=8;
while(RXD1);
i=i;
i=i;
i=i;
i=i;
i=i;
i=i;
i=i;
TR0=1;//计数器开始工作
WaitTF0();
while(i--)//接收8位数据位
{
Output>>=1;
if(RXD1)Output=Output|0x80;//recieve from the high bit to low bit
WaitTF0();
}
TR0=0;
returnOutput;
}
void WaitTF0(void)//check the counter
{
while(!TF0);
TF0=0;
}
上一篇:已经是第一篇
型号 | 厂商 | 价格 |
---|---|---|
EPCOS | 爱普科斯 | / |
STM32F103RCT6 | ST | ¥461.23 |
STM32F103C8T6 | ST | ¥84 |
STM32F103VET6 | ST | ¥426.57 |
STM32F103RET6 | ST | ¥780.82 |
STM8S003F3P6 | ST | ¥10.62 |
STM32F103VCT6 | ST | ¥275.84 |
STM32F103CBT6 | ST | ¥130.66 |
STM32F030C8T6 | ST | ¥18.11 |
N76E003AT20 | NUVOTON | ¥9.67 |