欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
單片機(jī)流水燈三種不同方法源程序(位運(yùn)算+庫(kù)函數(shù)+字符型數(shù)組)
[打印本頁(yè)]
作者:
Lydia~
時(shí)間:
2018-10-28 08:08
標(biāo)題:
單片機(jī)流水燈三種不同方法源程序(位運(yùn)算+庫(kù)函數(shù)+字符型數(shù)組)
流水燈程序(位運(yùn)算):
#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
unsigned char i;
unsigned char temp;
void Delayms(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<120;j++);
}
void main(void)
{
while(1)
{
temp = 0x01; //0x01=0000 0001
for(i=1;i<8;i++)
{
P2=~temp; //P2=1111 1110 對(duì)temp取反,保證每次循環(huán)只亮一個(gè)燈
temp=temp<<1; //按位左移,高位丟棄,低位補(bǔ)0
Delayms(200);
}
for(i=1;i<8;i++)
{
P2=~temp;
temp=temp>>1; //按位右移,高位補(bǔ)0,低位丟棄
Delayms(200);
}
}
}
復(fù)制代碼
流水燈代碼(庫(kù)函數(shù)):
#include <REGX51.H>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
void Delayms(uint ms)
{
uchar t;
while(ms--)
{
for(t=0;t<120;t++);
}
}
void main()
{
uchar i,j;
P2 = 0xfe;
while(1)
{
for(i=0;i<7;i++)
{
P2 = _crol_(P2,1); //P1端口向左循環(huán)移動(dòng)一位
Delayms(300);
}
for(j=0;j<7;j++)
{
P2 = _cror_(P2,1); //P1端口向右循環(huán)移動(dòng)一位
Delayms(300);
}
}
}
復(fù)制代碼
流水燈(字符型數(shù)組):
#include <REGX51.H>
#define uchar unsigned char
#define uint unsigned int
uchar code Pattern_P2[] =
{
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
};
void Delayms(uint ms)
{
uchar t;
while(ms--)
{
for(t=0;t<120;t++);
}
}
int main()
{
uchar i;
while(1)
{
for(i=0;i<8;i++)
{
P2=Pattern_P2[i];
Delayms(200);
}
for(i=8;i--;i>0)
{
P2=Pattern_P2[i];
Delayms(200);
}
}
}
復(fù)制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1