標(biāo)題:
C51——流水燈
[打印本頁]
作者:
來了就歐了
時間:
2020-4-16 11:37
標(biāo)題:
C51——流水燈
程序如下所示:
#include<reg52.h> //庫文件
#define uchar unsigned char//宏定義無符號字符型
#define uint unsigned int //宏定義無符號整型
/********************************************************************
初始定義
*********************************************************************/
uchar temp; //定義字符型變量
uchar a,b,i;
/********************************************************************
延時函數(shù)
*********************************************************************/
void delay()//延時程序
{
uchar m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
/********************************************************************
主函數(shù)
*********************************************************************/
void main()
{
temp=0xfe; //11111110定義每次一個燈亮
while(1)
{
P3=P2=P0=P1=temp;//直接對1/0口賦值,使批輸出低電平。
delay();//延時
for(i=1;i<8;i++)//實現(xiàn)廣告燈的從右到左移動
{
a=temp<<i; //左移i位
P3=P2=P0=P1=a;//相與求值
delay();
}
}
}
流水燈.jpg
(109.95 KB, 下載次數(shù): 61)
下載附件
2020-4-16 11:36 上傳
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1