led流水灯
c
#include <REGX52.H>
#include "INTRINS.H"
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--){
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void main(){
while(1){
P2=0xFE;
Delay(500);
P2=0xFD;
Delay(500);
P2=0xFB;
Delay(500);
P2=0xF7;
Delay(500);
P2=0xEF;
Delay(500);
P2=0xDF;
Delay(500);
P2=0xBF;
Delay(500);
P2=0x7F;
Delay(500);
}
}
延时代码
c
#include "INTRINS.H"
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--){
_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
独立按键控制led(松发式)
c
#include <REGX52.H>
void main(){
while(1){
if(P3_1==0)
P2_0=0;
else
P2=0xFF;
if(P3_0==0)
P2=0xFD;
else
P2=0xFF;
if(P3_2==0)
P2=0xFB;
else
P2=0xFF;
if(P3_3==0)
P2=0xF7;
else
P2=0xFF;
}
}
独立按键控制led 按键去除抖动
c
#include <REGX52.H>
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--){
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void main(){
while(1){
if(P3_1==0){
Delay(20);
while(P3_1==0);
Delay(20);
P2_0=~P2_0;
}
}
}
独立按键 led二进制
c
#include <REGX52.H>
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--){
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void main(){
unsigned char x=0;
while(1){
if(P3_1==0){
Delay(20);
while(P3_1==0);
Delay(20);
x++;
P2=~x;
}
}
}
独立按键控制led移位
c
#include <REGX52.H>
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--){
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
void main(){
unsigned char x=0;
P2_0=0;
while(1){
if(P3_0==0){
Delay(20);
while(P3_0==0);
Delay(20);
x++;
x=x%8;
P2=~(0x01<<x);
}
if(P3_1==0){
Delay(20);
while(P3_1==0);
Delay(20);
if(x==0)
x=7;
else
x--;
P2=~(0x01<<x);
}
}
}