首页 > 其他 > 详细

LED闪烁及流水灯——清翔51单片机(V3.0)

时间:2020-01-31 17:03:54      阅读:111      评论:0      收藏:0      [点我收藏+]

LED闪烁

延时(至少20ms以上)

技术分享图片

 

 技术分享图片

 源代码

 #include <reg52.h>

 unsigned int i;//0~65535

 void main() //main函数自身会循环
 {
     while(1)
    {
        P1 = 0;    //点亮P1口8个LED灯
        i = 65535;
        while(i--);
        P1 = 0xff; //1111 1111 熄灭P1口8个LED灯
        i = 65535;
        while(i--);
    }    
 }

 二、流水灯

1.宏定义

技术分享图片

 

 技术分享图片

2.函数的定义

技术分享图片

3.延时函数

技术分享图片

4.标准库函数中的循环移位函数

技术分享图片

5.循环移位函数与左移和右移运算符的区别

技术分享图片

6.Keil中Debug的方法

图标:技术分享图片

7.源代码

#include <reg52.h>
#include <intrins.h>

#define uint unsigned int
#define uchar unsigned char

uchar temp;//LED灯相关变量

void delay(uint z) //毫秒级延时函数定义
{
    uint x,y;
    for(x = z;x > 0;x--)
        for(y = 114;y > 0;y--);;
}

void main()
{
    temp = 0xfe;
    P1 = temp;
    delay(100);
    while(1)
    {
        temp = _crol_(temp,1);
        P1 = temp;
         delay(100);
     }

}

 

LED闪烁及流水灯——清翔51单片机(V3.0)

原文:https://www.cnblogs.com/16WSH/p/12243737.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!