求一段STC89C52单片机c语言程序,要求能通过串口通信由电脑向单片机发送数据,当发送的数据和前一个不一 50
样时,单片机的某个引脚可以发出高电平。第二个功能当p0.0引脚是低电平时p0.1、p0.2引脚输出高电平,要求两个功能都能实现,能帮我实现的我把所有分都给他...
样时,单片机的某个引脚可以发出高电平。第二个功能当p0.0引脚是低电平时p0.1、p0.2引脚输出高电平,要求两个功能都能实现,能帮我实现的我把所有分都给他
展开
1个回答
展开全部
#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
//---------------------------------------------------
sbit led = P1^0;
sbit key = P0^0;
sbit out1= P0^1;
sbit out2= P0^2;
uint run_cnt;
uchar temp;
//---------------------------------------------------
void send_one_byte(unsigned char tad )
{
TI=0;
SBUF=tad; //发送数据 os_wait2(K_TMO,1);
while(TI==0);
TI=0;
}
//---------------------------------------------------
void init_uart(void)
{
TMOD|=0x20;
TH1=0Xfd;
TL1=0Xfd;
SCON=0X50;
TR1=1;
ES=1;
}
//---------------------------------------------------
void main(void )
{
run_cnt=0;
init_uart();
EA=1;
//------------------------------
while(1)
{
run_cnt++;
if(run_cnt>1000)
{
send_one_byte(temp++);
led = ~led; //每次发送数据都不一样
run_cnt=0;
}
key=1;
if(key==0)
{
out1=1;
out2=1;
}
else
{
out1=0;
out2=0;
}
}
}
#define uchar unsigned char
#define uint unsigned int
//---------------------------------------------------
sbit led = P1^0;
sbit key = P0^0;
sbit out1= P0^1;
sbit out2= P0^2;
uint run_cnt;
uchar temp;
//---------------------------------------------------
void send_one_byte(unsigned char tad )
{
TI=0;
SBUF=tad; //发送数据 os_wait2(K_TMO,1);
while(TI==0);
TI=0;
}
//---------------------------------------------------
void init_uart(void)
{
TMOD|=0x20;
TH1=0Xfd;
TL1=0Xfd;
SCON=0X50;
TR1=1;
ES=1;
}
//---------------------------------------------------
void main(void )
{
run_cnt=0;
init_uart();
EA=1;
//------------------------------
while(1)
{
run_cnt++;
if(run_cnt>1000)
{
send_one_byte(temp++);
led = ~led; //每次发送数据都不一样
run_cnt=0;
}
key=1;
if(key==0)
{
out1=1;
out2=1;
}
else
{
out1=0;
out2=0;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询