著名歌曲小星星第一句是 1 1 5 5 6 6 5 ,4 4 3 3 2 2 1
然后我们用D1这个发光二级管代替1 依次类推。
#include 'reg52.h'
typedef unsigned char u8;
typedef unsigned int u16;
sbit ledD1=P2^0; //P20
sbit ledD2=P2^1;
sbit ledD3=P2^2;
sbit ledD4=P2^3;
sbit ledD5=P2^4;
sbit ledD6=P2^5;
sbit ledD7=P2^6;
sbit ledD8=P2^7;//P27
void delay(u16 i) //延时函数
{
while(i--)
{
//什么也不做
};
}
void main()
{
while(1)
{
//小星星第一句是 1 1 5 5 6 6 5 4 4 3 3 2 2 1
//用第一个灯代表1,依次类推
//1
ledD1=0;
delay(60000);
ledD1=1;
delay(60000);
//1
ledD1=0;
delay(60000);
ledD1=1;
delay(60000);
//5
ledD5=0;
delay(60000);
ledD5=1;
delay(60000);
//5
ledD5=0;
delay(60000);
ledD5=1;
delay(60000);
//6
ledD6=0;
delay(60000);
ledD6=1;
delay(60000);
//6
ledD6=0;
delay(60000);
ledD6=1;
delay(60000);
//5
ledD5=0;
delay(60000);
ledD5=1;
delay(60000);
delay(60000);
delay(60000);
//4
ledD4=0;
delay(60000);
ledD4=1;
delay(60000);
//4
ledD4=0;
delay(60000);
ledD4=1;
delay(60000);
//3
ledD3=0;
delay(60000);
ledD3=1;
delay(60000);
//3
ledD3=0;
delay(60000);
ledD3=1;
delay(60000);
//2
ledD2=0;
delay(60000);
ledD2=1;
delay(60000);
//2
ledD2=0;
delay(60000);
ledD2=1;
delay(60000);
//1
ledD1=0;
delay(60000);
ledD1=1;
delay(60000);
delay(60000);
delay(60000);
}
}
相关文章









