1. 程式人生 > >LED燈亮滅模擬小星星第一句

LED燈亮滅模擬小星星第一句

bsp clu sbit 我們 P20 def type main 第一個

著名歌曲小星星第一句是 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); } }

LED燈亮滅模擬小星星第一句