LED灯亮灭模拟小星星第一句
Posted yfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LED灯亮灭模拟小星星第一句相关的知识,希望对你有一定的参考价值。
著名歌曲小星星第一句是 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灯亮灭模拟小星星第一句的主要内容,如果未能解决你的问题,请参考以下文章