STC89C52

 

 

点亮LED

#include <REGX52.H>
#include <INTRINS.H>
void Delay50ms()		//@11.0592MHz
{
    unsigned char i,j,k;
    _nop_();
    i=4;
    j=205;
    k=187;
do{
	do{

        while (--k);

	   }while (--j);

   }while(--i);
 
}

void main(){
    while(1){
    P2=0xAA;
    Delay50ms();
    P2=0XFF;
    Delay50ms();
}
}

LED流水灯

#include <REG52.H>
#include <INTRINS.H>
void Delay500ms()		//@11.0592MHz
{
    unsigned char i, j, k;
    _nop_();
    i = 4;
    j = 129;
    k = 119;
do
{
	do
	{
		while (--k);
	} while (--j);
} while (--i);
 
}


void main(){
    while (1){
        P2=0xFE;
        Delay500ms();
        P2=0xFD;
        Delay500ms();
        P2=0xFB;
        Delay500ms();
        P2=0xF7;    
        Delay500ms();
        P2=0xEF;
        Delay500ms();
        P2=0xDF;
        Delay500ms();
        P2=0xBF;
        Delay500ms();
        P2=0x7F;
        Delay500ms();
    }
}

按住一个K1,亮起LED灯

#include <REGX52.H>
void main(){
while(1){
	if(P3_1==0){
		P2_0=0;
	}
	else{
		    P2_0=1;
	}
    }
 
}
#include <REGX52.H>
void Delay(unsigned int xms)		
{
    unsigned char i, j;
    while (xms){
        i = 2;
        j = 239;
    do{
        while (--j);
      } while (--i);
    xms--;
    }
}

void main(){
    while(1){
        if(P3_1==0){
        Delay(20);
    while(P3_1==0);
        Delay(20);
		P2_0=~P2_0;
		}
 
    }
}

 

独立按键控制按键显示二进制灯光

#include <REGX52.H>
void Delay(unsigned int xms)		
{
	unsigned char i, j;
    while (xms--){
	    i = 2;
	    j = 239;
	    do
	    {
		    while (--j);
	    } while (--i);
	
}
}

void main(){
	while(1){
			P2_0=0;
			Delay(500);
			P2_0=1;
			Delay(500);
		        
			}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值