CT107D蓝桥杯单片机按键代码

1、独立按键

/*
#include <reg52.h>

sbit led0 = P0^0;
sbit led1 = P0^1;
sbit led2 = P0^2;
sbit led3 = P0^3;
void delayms(int ms);

void main()
{
	char i,temp;
	P2=0XA0;P0=0X00;P2=0x80;P0=0XFF;
	
	while(1)
	{
		temp = 0x01;
		for(i=0;i<8;i++)
		{
			P0 = ~temp;
			delayms(1000);
			temp = 1<<temp;
			
			
		}
//		led0 = 0;
//		delayms(1000);
//		led1 = 0;
//		delayms(1000);
//		led2 = 0;
//		delayms(1000);
//		led3 = 0;
//		delayms(1000);
		
	}
}

void delayms(int ms)
{
	int i,j;
	for(i=ms;i>0;i--)
		for(j=845;j>0;j--);
}
*/
/*
#include <reg52.h> 
void delay(int t)
{    
	int a;
	for(;t>0;t--)
	{
		for(a=20000;a>0;a--);
	}
}
void main()
{
	int status = 0x7f;
	int a,b,count = 0;
	P2=0xa0;P0=0x00;
	P2=0x80;P0=0xff;//?????????????????С??
	while(1)
	{
		P0=status;//led0??
		delay(100);//?????1??
		a = status>>1;//????С???????λ
		b = status<<7;//???status?????????????0???1
		status = a|b;
		count++;
		if(7 == count)
		{
			status = 0x7f;
		}
	}
}*/
/*???????????????LED???????s7?????s6???s5???????s4??????*/
#include <reg52.h>
#include <intrins.h>

sbit s7 = P3^0;
sbit s6 = P3^1;
sbit s5 = P3^2;
sbit s4 = P3^3;

void Delay1ms();
void delayms(int ms);
void keyscan4();


void main()
{
	P2=0xa0;P0=0x00;P2=0x80;P0=0xff;
	while(1)
	{
		keyscan4();
	}
}

void keyscan4()
{
	//????s7???
	if(s7==0)
	{
		delayms(5);	 //??????
		if(s7==0)
		{
			P0 = 0x00;
		}
		while(!s7);  //??????????????????????????κ???
	}
	
	//????s6???
	if(s6==0)
	{
		delayms(5);
		if(s6==0)
		{
			P0 = 0xff;
		} 
		while(!s6);	
	}
	
	//????s5??????
	if(s5==0)
	{
		delayms(5);
		if(s5==0)
		{
			P0 = 0x55;
		}
		while(!s5);	
	}
	
	//????s4?????
	if(s4==0)
	{
		delayms(5);
		if(s4==0)
		{
			P0 = 0xaa;
		}	
		while(!s4);
	}
	
}

void Delay1ms()		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	_nop_();
	_nop_();
	i = 11;
	j = 190;
	do
	{
		while (--j);
	} while (--i);
}

void delayms(int ms)
{
	int i;
	for(i=0;i<ms;i++)
		Delay1ms();
}

 

上一篇:React 子组件类型检查 PropTypes介绍


下一篇:Oracle Tuning ( instance 级别 ) 01