51单片机及AVR单片机的串口通信及Proteus仿真-2
 
- UID
- 852722
|
51单片机及AVR单片机的串口通信及Proteus仿真-2
最后把程序附上,里面有些变量声明了没有用到,当初只是实验。。
51的:
#Include "Reg52.H"
#Define AA 0x61
#Define Commun_symbol 0x31
Sbit LED=P2^0;
Unsigned Char Tx[]={"My Name Is Seven!"};
Void Uart_init(Void)
{
SCON = 0x50;
RCAP2H = 0xFF;
RCAP2L = 0xD9;
TH2 = 0xFF;
TL2 = 0xD9;
T2CON = 0x34;
}
Void Uart_send(Unsigned Char ByData)
{
TI=0;
SBUF=ByData;
While(TI==0);
TI=1;
}
Unsigned Char Uart_receive(Void)
{
RI=0;
While(RI==0);
RI=1;
Return(SBUF);
}
Void Main()
{
Unsigned Char ByBuff,I;
Uart_init();
Uart_send(Commun_symbol);
While(1)
{
ByBuff=Uart_receive();
LED=1;
If(ByBuff==0x31)
{
For(I=0;I<20;I++)
{
P1=ByBuff;
Uart_send(Tx[I]);
}
}
}
} |
|
|
|
|
|