0--------LED output
/*
**********************************************************************
* 头文件包含
**********************************************************************
*/
#include <reg52.h>
/*
**********************************************************************
* 本地宏定义
**********************************************************************
*/
#define LED_PORT P2
/*
**********************************************************************
* 本地全局变量
**********************************************************************
*/
/*
**********************************************************************
* 函数原型声明
**********************************************************************
*/
void Delay(void);
void FlashLed1(void);
void FlashLed2(void);
/*********************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 参数列表 : 无
* 函数输出 : 无
*********************************************************************/
void main(void)
{
while (1)
{
//FlashLed1(); // FlashLed1和FlashLed2效果一样
FlashLed2(); // FlashLed2使用了C语言位操作技术
}
}
/*********************************************************************
* 函 数 名 : Delay
* 函数功能 : 延时一段时间
* 参数列表 : 无
* 函数输出 : 无
*********************************************************************/
void Delay(void)
{
unsigned char i = 0, j = 0, k = 0;
for (i=0; i<50; i++)
for (j=0; j<50; j++)
for (k=0; k<50; k++);
}
/*********************************************************************
* 函 数 名 : FlashLed1
* 函数功能 : 实现P2端口8个LED成流水灯依次点亮
* 参数列表 : 无
* 函数输出 : 无
*********************************************************************/
void FlashLed1(void)
{
LED_PORT = 0x7f; // 0b01111111,左边数第1颗LED亮其他灭
Delay();
LED_PORT = 0xbf; // 0b10111111,左边数第2颗LED亮其他灭
Delay();
LED_PORT = 0xdf; // 0b11011111,左边数第3颗LED亮其他灭
Delay();
LED_PORT = 0xef; // 0b11101111,左边数第4颗LED亮其他灭
Delay();
LED_PORT = 0xf7; // 0b11110111,左边数第5颗LED亮其他灭
Delay();
LED_PORT = 0xfb; // 0b11111011,左边数第6颗LED亮其他灭
Delay();
LED_PORT = 0xfd; // 0b11111101,左边数第7颗LED亮其他灭
Delay();
LED_PORT = 0xfe; // 0b11111110,左边数第8颗LED亮其他灭
Delay();
}
/*********************************************************************
* 函 数 名 : FlashLed2