led流水灯
#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);}}
延时代码
#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(松发式)
#include <REGX52.H>void main(){while(1){if(P3_1==0)P2_0=0;elseP2=0xFF;if(P3_0==0)P2=0xFD;elseP2=0xFF;if(P3_2==0)P2=0xFB;elseP2=0xFF;if(P3_3==0)P2=0xF7;elseP2=0xFF;}}
独立按键控制led 按键去除抖动
#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二进制
#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移位
#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;elsex--;P2=~(0x01<<x);}}}