点亮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);
}
}