LED lights on and off to simulate the first sentence of Twinkle Twinkle Little Star

Publisher:BlissfulMoonLatest update time:2024-08-16 Source: cnblogsKeywords:LED Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The first line of the famous song Twinkle Twinkle Little Star is 1 1 5 5 6 6 5, 4 4 3 3 2 2 1


Then we use the light-emitting diode D1 to replace 1, and so on.


#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) //delay function

{

while(i--)

{

//Do nothing

};

}

void main()

{

while(1)

{

//The first sentence of Twinkle Twinkle Little Star is 1 1 5 5 6 6 5 4 4 3 3 2 2 1

//Use the first light to represent 1, and so on

//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);



}


}


Keywords:LED Reference address:LED lights on and off to simulate the first sentence of Twinkle Twinkle Little Star

Previous article:What is the difference between LED flashing code with loop and without loop
Next article:Basic knowledge of LED and LED in STC89C52

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号