用C语言写一个51单片机流水灯程序给出详细代码
以下是51单片机流水灯程序的详细代码,其中采用了循环移位的方法实现流水灯效果:
#include <reg51.h>
#define LED P1 // 定义LED灯接口
void delay(unsigned int xms) // 延时函数 { unsigned int i, j; for (i = xms; i > 0; i--) for (j = 112; j > 0; j--); }
void main() { unsigned char i; while (1) { for (i = 0x01; i <= 0x80; i <<= 1) // 循环移位 { LED = i; // 点亮LED delay(500); // 延时500ms,控制流水灯速度 } for (i = 0x80; i >= 0x01; i >>= 1) // 循环移位 { LED = i; // 点亮LED delay(500); // 延时500ms,控制流水灯速度 } }
原文地址: https://www.cveoy.top/t/topic/cEna 著作权归作者所有。请勿转载和采集!