1、关闭蜂鸣器
P2 = 0XA0;//打开蜂鸣器锁存
P0 = 0X00;//输送关闭蜂鸣器命令
P2 = 0X00;//关闭蜂鸣器锁存
2、流水灯
#include <reg52.h>
void delay(int t)
{
int a;
for(;t>0;t--)
{
for(a=20000;a>0;a--);
}
}
void main()
{
int status = 0x7f;
int a,b,count = 0;
P2=0xa0;P0=0x00;P2=0x80;P0=0xff;//关闭蜂鸣器,关闭所有小灯
while(1)
{
P0=status;//led0亮
delay(1);//时间间隔1秒
a = status>>1;//亮的小灯左移一位
b = status<<7;//确保status因左移而补进的0变为1
status = a|b;
count++;
if(7 == count)
{
status = 0x7f;
}
}
}