用移位运算法将AT89C51单片机P1P2端口16个灯(P1.0P1.1P1.2P1.3全部点亮熄灭)(P1.4P1.5P1.6P1.7全部点亮熄灭)(P2.0P2.1P2.2P2.3全部点亮熄灭)(P2.4P2.5P2.6P2.7全部点亮熄灭)循环
时间: 2023-09-19 15:07:49 浏览: 106
基于AT89C51单片机的智能台灯项目
#include<reg52.h>
void delay(unsigned int i)
{
while(i--);
}
void main()
{
unsigned char a,b,c,d;
while(1)
{
for(a=0;a<16;a++)
{
P1=0xff;
P2=0xff;
b=a<<4;
c=b>>4;
d=b|c; //P1.0-P1.3控制的灯
P1=~d;
b=a>>4;
d=b|c; //P2.0-P2.3控制的灯
P2=~d;
delay(50000);
}
}
}
阅读全文