27,509
社区成员




#include <reg51.h>
#include <stdio.h>
#include <string.h>
typedef unsigned char uchar;
int i;
uchar code info[] = {0x56,0x56,0x56,0x56,0x56,0x56,0x56};
sbit newTXD = P2^1;//
void UartInit()
{
SCON = 0x50; // SCON: serail mode 1, 8-bit UART
TMOD |= 0x21; //
PCON |= 0x80; // SMOD=1;
TH0 = 0xFE; // 2400bps fosc=11.0592MHz
TL0 = 0x7F; //400bps fosc=11.0592MHz
}
void WaitTF0(void)
{
while(!TF0);
TF0=0;
TH0=0xFE; // fosc=11.0592MHz
TL0=0x7F; // fosc=11.0592MHz
}
void WByte(uchar input)
{
//·¢ËÍÆôʼλ
uchar j=8;
TR0=1;
newTXD=(bit)0;
WaitTF0();
//·¢ËÍ8λÖÃÊý¾Ýλ
while(j--)
{
newTXD=(bit)(input&0x01); //ÏÈ´«µÍλ
WaitTF0();
input=input>>1;
}
//·¢ËÍУÑéλ(ÎÞ)
//·¢ËͽáÊøÎ»
newTXD=(bit)1;
WaitTF0();
TR0=0;
}
void Sendata()
{
for(i=0;i<sizeof(info);i++)//Íâ²ãÑ»·£¬±éÀúÊý×é
{
WByte(info[i]);
}
}
void main()
{
UartInit();
while(1)
{
Sendata();
}
}
char str[16];
int temperature = 25;
sprintf(str, "%d", temperature);
uart_send(str);