⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s1.c

📁 此文件包含用visual c++编译的程序代码
💻 C
字号:
#define uchar unsigned char
#include "string.h"
#include "reg51.h"
#include "stdio.h"
void SendData(uchar Dat)
{	uchar i=0;
	SBUF=Dat;
	while(1)
	{ 	if(TI)
		{	TI=0;
			break;
		}
	}
}
void mDelay(unsigned int DelayTime)
{	unsigned char j=0;
	for(;DelayTime>0;DelayTime--)
	{	for(j=0;j<125;j++)	
		{;}	
	}
}
uchar Key()
{	uchar KValue;
	P3|=0x3e;	//中间4位置高电平
	if((KValue=P3|0xe3)!=0xff)
	{	mDelay(10);
		if((KValue=P3|0xe3)!=0xff)
		{	for(;;)
			if((P3|0xe3)==0xff)
				return(KValue);
		}
	}
	return(0);
}	

void main()
{	uchar KeyValue;
	uchar c;
	P1=0xff;	//关闭P1口接的所有灯
	TMOD=0x20;	//确定定时器工作模式
	TH1=0xFD;
	TL0=0xFD;	//定时初值
	PCON&=0x80;	//SMOD=1
	TR1=1;		//开启定时器1
	SCON=0x40;	//串口工作方式1
	REN=1;		//允许接收
	for(;;)
	{	if(KeyValue=Key())
		{	if((KeyValue|0xfb)!=0xff)	//K1按下
				SendData(0x55);
			if((KeyValue|0xf7)!=0xff)
				SendData(0xaa);
		}

		if(RI)
		{	c=SBUF;
			P1=c;
			RI=0;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -