51单片机最简LED驱动
2016-11-20 22:58
253 查看
得到8盏LED交替亮灭的实验效果
#include <reg51.h>
void Delay10ms(unsigned int c); // 延时10ms
void main()
{
while(1)
{
P0 = 0x00; // 设置 P0 为低电平
Delay10ms(50); // 延时
P0 = 0xff; // 设置 P0 为高电平
Delay10ms(50); // 延时
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
LED灯做二进制加1显示
#include <reg51.h>
void Delay10ms(unsigned int c); // 延时10ms
void main()
{
unsigned char count = 0x00;
while(1)
{
P0 = count;
Delay10ms(50); // 延时
count++;
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
延时实现LED流水灯效果P2口八个灯作跑马灯
#include <reg51.h>
// #include <intrins.h>
/** intrins.h 方法
_crol_ 字符循环左移
_cror_ 字符循环右移
_irol_ 整数循环左移
_iror_ 整数循环右移
_lrol_ 长整数循环左移
_lror_ 长整数循环右移
_nop_ 空操作8051 NOP 指令
_testbit_ 测试并清零位8051 JBC 指令函数名: _crol_,_irol_,_lrol_
*/
void Delay10ms(unsigned int c); // 延时10ms
void main()
{
unsigned char LED;
LED = ~0xfe; // 0xfe = 1111 1110
while(1)
{
P0 = LED;
Delay10ms(50); // 延时
LED <<= 1;
if (P0 == 0x00)
{
LED = ~0xfe;
}
// LED = _crol_(LED, 1);
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
LED灯做跑马灯左右移动
#include <reg51.h>
void Delay10ms(unsigned int c); // 延时10ms
unsigned char LED;
void main()
{
unsigned char i;
LED = 0xfe; // 0xfe = 1111 1110
while(1)
{
for (i = 0; i < 7; i++)
{
P0 = LED;
Delay10ms(50);
LED <<= 1;
LED |= 0x01;
}
for (i = 0; i < 7; i++)
{
P0 = LED;
Delay10ms(50);
LED >>= 1;
LED |= 0x80;
}
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
#include <reg51.h>
void Delay10ms(unsigned int c); // 延时10ms
void main()
{
while(1)
{
P0 = 0x00; // 设置 P0 为低电平
Delay10ms(50); // 延时
P0 = 0xff; // 设置 P0 为高电平
Delay10ms(50); // 延时
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
LED灯做二进制加1显示
#include <reg51.h>
void Delay10ms(unsigned int c); // 延时10ms
void main()
{
unsigned char count = 0x00;
while(1)
{
P0 = count;
Delay10ms(50); // 延时
count++;
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
延时实现LED流水灯效果P2口八个灯作跑马灯
#include <reg51.h>
// #include <intrins.h>
/** intrins.h 方法
_crol_ 字符循环左移
_cror_ 字符循环右移
_irol_ 整数循环左移
_iror_ 整数循环右移
_lrol_ 长整数循环左移
_lror_ 长整数循环右移
_nop_ 空操作8051 NOP 指令
_testbit_ 测试并清零位8051 JBC 指令函数名: _crol_,_irol_,_lrol_
*/
void Delay10ms(unsigned int c); // 延时10ms
void main()
{
unsigned char LED;
LED = ~0xfe; // 0xfe = 1111 1110
while(1)
{
P0 = LED;
Delay10ms(50); // 延时
LED <<= 1;
if (P0 == 0x00)
{
LED = ~0xfe;
}
// LED = _crol_(LED, 1);
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
LED灯做跑马灯左右移动
#include <reg51.h>
void Delay10ms(unsigned int c); // 延时10ms
unsigned char LED;
void main()
{
unsigned char i;
LED = 0xfe; // 0xfe = 1111 1110
while(1)
{
for (i = 0; i < 7; i++)
{
P0 = LED;
Delay10ms(50);
LED <<= 1;
LED |= 0x01;
}
for (i = 0; i < 7; i++)
{
P0 = LED;
Delay10ms(50);
LED >>= 1;
LED |= 0x80;
}
}
}
void Delay10ms(unsigned int c)
{
unsigned char a, b;
for (; c > 0; c--)
{
for (b = 38; b > 0; b--)
{
for (a = 130; a > 0; a--);
}
}
}
相关文章推荐
- 51单片机驱动数码管(LED)时的注意事项
- 51单片机的LED与数码管的驱动
- 51单片机 28BYJ-48步进电机的细分驱动方式 Test
- mini2440 led驱动程序经典分析
- 基于sys文件系统的LED驱动的移植【原创】
- LED驱动实例3(自旋锁)
- linux设备驱动归纳总结(五):4.写个简单的LED驱动
- 【总结】高通Android LED驱动移植-GPIO,内核定时器
- LED背光学习_标准和白光LED的基础知识与驱动
- 驱动学习之led-class.c源码分析
- 在Raspberry PI上,NJU6061的LED控制模块的驱动
- 树莓派进阶之路 (016) - 通过595驱动4位LED显示系统时间
- Linux驱动:LED驱动测试
- s3c2440 LED驱动分析
- Linux字符驱动学习之LED
- 51单片机的IO口驱动能力、灌电流、拉电流、上拉电阻的选择
- Linux设备驱动工程师之路——硬件访问及混杂设备LED驱动
- LED驱动程序相关头文件简单介绍
- Linux 驱动之 platform 驱动模型总结 (基于tiny210 平台 LED 驱动)
- android平台led开发之内核硬件驱动层(一)