標(biāo)題:
單片機(jī)LED循環(huán)跳閃程序
[打印本頁(yè)]
作者:
七彩祥云
時(shí)間:
2021-9-26 19:45
標(biāo)題:
單片機(jī)LED循環(huán)跳閃程序
led只能循環(huán)跳著一格閃爍一次!
#include "reg52.h" //此文件中定義了單片機(jī)的一些特殊功能寄存器
typedef unsigned int u16; //對(duì)數(shù)據(jù)類(lèi)型進(jìn)行聲明定義
typedef unsigned char u8;
sbit led1=P2^0; //將單片機(jī)的P2.0端口定義為led
sbit led3=P2^2;
sbit led5=P2^4;
sbit led7=P2^6;
void delay(u16 i)
{
while(i--);
}
void main()
{
while(1)
{
led1=0;
delay(50000); //大約延時(shí)450ms
led1=1;
delay(50000); //大約延時(shí)450ms
led3=0;
delay(50000); //大約延時(shí)450ms
led3=1;
delay(50000); //大約延時(shí)450ms
led5=0;
delay(50000); //大約延時(shí)450ms
led5=1;
delay(50000); //大約延時(shí)450ms
led7=0;
delay(50000); //大約延時(shí)450ms
led7=1;
delay(50000); //大約延時(shí)450ms
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1