单片机程序-利用C52库函数实现左右流水灯
时间:12-02
来源:互联网
点击:
本程序所用的原理图下载:点这里,单片机芯片使用的stc89c52;找到流水灯部分的原理图即可.这是一整个单片机开发板的电路图其他的忽略
下面是程序源代码:
/***********左右流水灯**************/
/**
*功能:利用C52库函数实现左右流水灯
* 方法一:goto 语句实现之
* 方法二: 顺序实现之
* 方法三: 顺序和goto语句实现之
*日期:2013-06-16-09:00-09:40
*备注:程序已通过调试
**/
/*********AT89C52-RC MCU*************/
/***********HL-1 开发板***********/
#include
#include
typedef unsigned int uint;
typedef unsigned char uchar;
void delay(uint xms)
{
uint x, y;
for(x = xms; x > 0; x--)
for(y = 110; y > 0; y--);
}
/**********方法1************/
/*
void main(void)
{
uchar temp, temp1, i;
/******流水灯向左流动********/
/*
loop1: while(1)
{
P1 = 0xfe;
for(i = 0; i < 7; i++)
{
temp = P1;
temp = _crol_(temp, 1);
P1 = temp;
delay(200);
}
goto loop;
}
/******流水灯向右流动********/
/*
loop: while(1)
{
P1 = 0x7f;
for(i = 0; i < 7; i++)
{
temp1 = P1;
temp1 = cror_(temp1, 1);
P1 = temp1;
delay(200);
}
goto loop1;
}
}
*/
/**********方法2************/
/*
void main(void)
{
uchar temp, i;
P1 = 0xfe;
while(1)
{
P1 = 0xfe;
temp = P1;
/******流水灯向左流动********/
/*
for(i = 0; i < 7; i++)
{
temp = _crol_(temp, 1);
P1 = temp;
delay(200);
}
/******流水灯向右流动********/
/*
P1 = 0x7f;
temp = P1;
for(i = 0; i < 7; i++)
{
temp = _cror_(temp, 1);
P1 = temp;
delay(200);
}
}
}
*/
/**********方法3***********/
void main(void)
{
uchar temp, i;
while(1)
{
P1 = 0xfe;
temp = P1;
/******流水灯向左流动********/
for(i = 0; i < 7; i++)
{
temp = _crol_(temp, 1);
P1 = temp;
delay(200);
if(i >= 7)
goto loop;
}
/******流水灯向右流动********/
loop: P1 = 0x7f;
temp = P1;
for(i = 0; i < 7; i++)
{
temp = _cror_(temp, 1);
P1 = temp;
delay(200);
}
}
}
下面是程序源代码:
/***********左右流水灯**************/
/**
*功能:利用C52库函数实现左右流水灯
* 方法一:goto 语句实现之
* 方法二: 顺序实现之
* 方法三: 顺序和goto语句实现之
*日期:2013-06-16-09:00-09:40
*备注:程序已通过调试
**/
/*********AT89C52-RC MCU*************/
/***********HL-1 开发板***********/
#include
#include
typedef unsigned int uint;
typedef unsigned char uchar;
void delay(uint xms)
{
uint x, y;
for(x = xms; x > 0; x--)
for(y = 110; y > 0; y--);
}
/**********方法1************/
/*
void main(void)
{
uchar temp, temp1, i;
/******流水灯向左流动********/
/*
loop1: while(1)
{
P1 = 0xfe;
for(i = 0; i < 7; i++)
{
temp = P1;
temp = _crol_(temp, 1);
P1 = temp;
delay(200);
}
goto loop;
}
/******流水灯向右流动********/
/*
loop: while(1)
{
P1 = 0x7f;
for(i = 0; i < 7; i++)
{
temp1 = P1;
temp1 = cror_(temp1, 1);
P1 = temp1;
delay(200);
}
goto loop1;
}
}
*/
/**********方法2************/
/*
void main(void)
{
uchar temp, i;
P1 = 0xfe;
while(1)
{
P1 = 0xfe;
temp = P1;
/******流水灯向左流动********/
/*
for(i = 0; i < 7; i++)
{
temp = _crol_(temp, 1);
P1 = temp;
delay(200);
}
/******流水灯向右流动********/
/*
P1 = 0x7f;
temp = P1;
for(i = 0; i < 7; i++)
{
temp = _cror_(temp, 1);
P1 = temp;
delay(200);
}
}
}
*/
/**********方法3***********/
void main(void)
{
uchar temp, i;
while(1)
{
P1 = 0xfe;
temp = P1;
/******流水灯向左流动********/
for(i = 0; i < 7; i++)
{
temp = _crol_(temp, 1);
P1 = temp;
delay(200);
if(i >= 7)
goto loop;
}
/******流水灯向右流动********/
loop: P1 = 0x7f;
temp = P1;
for(i = 0; i < 7; i++)
{
temp = _cror_(temp, 1);
P1 = temp;
delay(200);
}
}
}
单片机程C52库函数流水 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)