欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
單片機花樣流水燈程序
[打印本頁]
作者:
陸陸
時間:
2019-9-16 10:57
標題:
單片機花樣流水燈程序
圖片1.png
(795.81 KB, 下載次數: 66)
下載附件
流水燈
2019-9-16 10:55 上傳
單片機源程序如下:
#include "reg51.h"
#define uchar unsigned char //定義unsigned char 為 uchar
#define uint unsigned int
sbit F1 = P3^0;
sbit F2 = P3^1;
uint time =90; //通過改變TIME的參數可以改變流水燈的變換速度
/***************一微秒延時子程序******************/
void delayus(uint delay){
while(delay--);
}
/***************一毫秒延時子程序******************/
void delayms(uint delay){
while(delay--)
delayus(300);
}
/*******************************變換方式一 子函數 ***********************************/
void run_LED_fun1()
{
uchar a,temp,temp1;
temp=0x10;
for(a=9;a>0;a--) //P1口LED燈依次點亮
{
P1=~temp;
delayms(time);
temp<<=1;
}
temp=0x01;
for(a=9;a>0;a--) //P3口LED燈依次點亮
{
P3=~temp;
delayms(time);
temp<<=1;
}
temp=0x01; //P2口LED燈依次反向點亮
for(a=9;a>0;a--)
{
P2=~temp;
delayms(time);
temp<<=1;
}
temp=0x80; //P0口LED燈依次反向點亮
for(a=9;a>0;a--)
{
P0=~temp;
delayms(time);
temp>>=1;
}
temp=0x01;
for(a=9;a>0;a--) //P0口LED燈依次點亮
{
P0=~temp;
delayms(time);
temp<<=1;
}
temp=0x80;
for(a=9;a>0;a--) //P2口LED燈依次點亮
{
P2=~temp;
delayms(time);
temp>>=1;
}
temp=0x80; //P3口LED燈依次反向點亮
for(a=9;a>0;a--)
{
P3=~temp;
delayms(time);
temp>>=1;
}
temp=0x80; //P1口LED燈依次反向點亮
for(a=9;a>0;a--)
{
P1=~temp;
delayms(time);
temp>>=1;
}
temp=0xfe;
for(a=8;a>0;a--)
{
P1=temp;
delayms(time);
temp<<=1;
}
temp=0xfe;
for(a=8;a>0;a--)
{
P3=temp;
delayms(time);
temp<<=1;
}
temp=0xfe;
for(a=8;a>0;a--)
{
P0=temp;
delayms(time);
temp<<=1;
}
temp=0x7f;
for(a=8;a>0;a--)
{
P2=temp;
delayms(time);
temp>>=1;
}
temp=0x01;
for(a=8;a>0;a--)
{
P2=temp;
delayms(time);
temp1=~temp;
temp1<<=1;
temp=~temp1;
}
temp=0x80;
for(a=8;a>0;a--)
{
P0=temp;
delayms(time);
temp1=~temp;
temp1>>=1;
temp=~temp1;
}
temp=0x80;
for(a=8;a>0;a--)
{
P3=temp;
delayms(time);
temp1=~temp;
temp1>>=1;
temp=~temp1;
}
temp=0x80;
for(a=8;a>0;a--)
{
P1=temp;
delayms(time);
temp1=~temp;
temp1>>=1;
temp=~temp1;
}
}
/*******************************變換方式二 子函數 ***********************************/
void run_LED_fun2()
{
uchar a,temp,temp1,temp2;
temp=0x01;
temp1=0x80;
for(a=8;a>0;a--) //P1口LED燈依次點亮
{
P1=~temp;
P0=~temp;
P3=~temp1;
P2=~temp;
delayms(time);
temp<<=1;
temp1>>=1;
}
temp=0x80;
temp1=0x01;
for(a=8;a>0;a--) //P1口LED燈依次點亮
{
P1=~temp;
P0=~temp;
P3=~temp1;
P2=~temp;
delayms(time);
temp>>=1;
temp1<<=1;
}
temp=0xfe;
temp1=0x7f;
for(a=8;a>0;a--)
{
P1=temp;
P0=temp;
P3=temp1;
P2=temp;
delayms(time);
temp<<=1;
temp1>>=1;
}
temp=0x7f;
temp1=0xfe;
for(a=8;a>0;a--)
{
P1=~temp;
P0=~temp;
P3=~temp1;
P2=~temp;
delayms(time);
temp2=~temp;
temp>>=1;
temp2=~temp;
temp1<<=1;
}
}
/*******************************變換方式三 子函數 ***********************************/
void run_LED_fun3()
{
P0=0x00;
P1=0xff;
P2=0xff;
P3=0xff;
delayms(5*time);
P0=0xff;
P1=0x00;
P2=0xff;
P3=0xff;
delayms(5*time);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0x00;
delayms(5*time);
P0=0xff;
P1=0xff;
P2=0x00;
P3=0xff;
delayms(5*time);
P0=0xff;
P1=0x00;
P2=0xff;
P3=0x00;
delayms(5*time);
P0=0x00;
P1=0xff;
P2=0x00;
P3=0xff;
delayms(5*time);
P0=0xff;
P1=0xff;
P2=0xff;
P3=0xff;
}
/*******************************變換方式四 子函數 ***********************************/
void run_LED_fun4()
{
uchar a,temp,temp1,temp2;
P0=0xff;
P1=0x00;
P2=0xff;
P3=0xff;
delayms(time);
temp=0xfe;
temp1=0xfe;
for(a=8;a>0;a--)
{
P1=~temp;
P3=temp1;
delayms(time);
temp2=~temp;
temp<<=1;
temp2=~temp;
temp1<<=1;
}
temp=0xfe;
temp1=0x7f;
for(a=8;a>0;a--)
{
P3=~temp;
P2=temp;
delayms(time);
temp2=~temp;
temp<<=1;
temp2=~temp;
temp1>>=1;
}
temp=0xfe;
temp1=0x7f;
for(a=8;a>0;a--)
{
P2=~temp;
P0=temp1;
delayms(time);
//temp2=~temp1;
temp<<=1;
//temp2=~temp;
temp1>>=1;
}
temp=0x7f;
temp1=0xfe;
for(a=8;a>0;a--)
{
P0=~temp;
P1=temp1;
delayms(time);
temp2=~temp;
temp>>=1;
temp2=~temp;
temp1<<=1;
}
}
/*
void change_speed()
{
if(F1 == 0)
{
delayms(10);
if(F1 == 0)
{
while(!F1);
time = time +20;
}
}
if(F2 == 0)
{
delayms(10);
if(F2 == 0)
{
while(!F2);
time = time -20;
}
}
}
*/
/*******************************主函數 ***********************************/
void main()
{
while(1)
{
run_LED_fun1();
run_LED_fun2();
run_LED_fun3();
run_LED_fun4();
}
}
復制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1