您的位置:首页 > 其它

流水灯实验

2016-03-31 19:06 323 查看
单片机基本实验,流水灯。

首先需添加
#include<intrins.h>
,后面需要用到移位crol或者cror函数;

延迟函数delay(); 定义一个中转变量temp,对其赋值为0xfe,0xfe代表第一个灯亮(二进制是11111110),每次移位后赋值给P1; (P1控制LED灯亮)

#include<reg51.h>
#include<intrins.h>

#define uchar unsigned char
#define uint unsigned int
void delay(uint n);
uchar temp;

void main()
{
temp=0xfe;
P1=temp;
while(1)
{
delay(1000);
temp=_crol_(temp,1);
P1=temp;

}
}
void delay(uint n)
{
uint j,i;
for(i=0; i<n; i++)
for(j=0; j<110; j++)
;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  单片机