//51单片机
//流水灯显示,循环移动
#include <reg51.h>
#include <intrins.h> //循环左移函数头
#define uint unsigned int
void delay(void); //声明delay函数
void main(void)
{
uint temp = 1;
while(1)
{
P1 = temp;
temp = _crol_(temp,1); //循环左移
//temp = _cror_(temp,1); //循环右移
delay(); //调用延迟函数
}
}
//隔灯闪烁
/*#include <reg51.h>
#define uint unsigned int
void delay(void);
void main(void)
{
P1 = 0;
while(1)
{
P1 = 170;
delay();
P1 = 85;
delay();
}
}*/
//只有p1.0灯亮
/*#include <reg51.h>
#define uint unsigned int
sbit P1_0 = P1^0 ;
void delay(void);
void main(void)
{
P1 = 0;
while(1)
{
P1_0 = 1;
delay();
P1_0 = 0;
delay();
}
}*/
//多彩灯效果
/*#include <reg51.h>
#include <intrins.h>
#define uint unsigned int
void delay(void);
void main(void)
{
uint a;
uint temp = 1;
P1 = temp;
while(1)
{
//循环左移
for(a=0;a<7;a++)
{
temp = _crol_(temp,1);
delay();
P1 = temp;
}
//循环右移
for(a=0;a<7;a++)
{
temp = _cror_(temp,1);
delay();
P1 = temp;
}
//隔灯闪烁
for(a=0;a<3;a++)
{
P1 = 170;
delay();
P1 = 85;
delay();
}
//全部同时闪烁
for(a=0;a<3;a++)
{
P1 = 0;
delay();
P1 = 255;
}
}
}*/
//延迟函数
void delay(void)
{
uint i,j;
for(i=50;i>0;i--)
{
for(j=200;j>0;j--)
{
;
}
}
}