2019-03-03 23:21:38 moofoogoo 阅读数 1432
  • 单片机控制第一个外设-LED-第1季第6部分

    本课程是《朱有鹏老师单片机完全学习系列课程》第1季第6个课程,主要讲解LED的工作原理和开发板原理图、实践编程等,通过学习目的是让大家学会给单片机编程控制LED灯,并且为进一步学习其他外设打好基础。

    3995 人正在学习 去看看 朱有鹏

一、流水灯实验
1、设计要求
P1口接8个发光二极管,烧录程序后发光二极管依次点亮
2、硬件要求
利用proteus Isis仿真,选择器件,AT89C51、LED-BLUE、RES
3、软件设计
源程序:

/*********************必要变量定义******************/
#include<reg51.h>
#include<intrns.h>
typedef  unsigned  char  u8;
typedef  unsigned  int  u16;
#define  led  P1
/****************延时程序**************/
void  delay(u16  k)
{
  u16  i ,j;
  for(i = 7; i < k; i++)
      for(j = 0;j < 124; j++);
 }
/**********************主函数*******************/
void  main()
{
  u8 i;
  led = 0x01;
  delay(500);
 while (1)
{
   /* for(i = 0;i < 8; i++)
    { 
     led = (0x01<<i);
     delay(500);
    }*/
   for(i = 0;i < 7; i++)
  {
     led = _crol_(led , 1); 
     delay(500);
   }
   for(i = 0;i < 7; i++)
  {
    led = _cror_(led , 1);
    delay(500);
   }
    }
 }
 
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019030323184025.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L21vb2Zvb2dvbw==,size_16,color_FFFFFF,t_70)
如有任何错误或者不足之处,欢迎指正 ^ - ^.
2016-12-24 22:06:01 Allureyou 阅读数 1533
  • 单片机控制第一个外设-LED-第1季第6部分

    本课程是《朱有鹏老师单片机完全学习系列课程》第1季第6个课程,主要讲解LED的工作原理和开发板原理图、实践编程等,通过学习目的是让大家学会给单片机编程控制LED灯,并且为进一步学习其他外设打好基础。

    3995 人正在学习 去看看 朱有鹏
#include "reg52.h"
#include "74hc595.h"
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int

char code table[]={0xFF,0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xFF,0xFF,0xFF,0xFF,

};

void Delay(uint Delay)
{   uchar i;
    for(;Delay>0;Delay--)
    {   
        for(i=0;i<123;i++);
    }
}
void main()
{
  int k,i,m,l;
	SCLR=1;
	while(1)
	{
		for(m=0;m<=175;m++)
		{
				for(l=0;l<100;l++)
				{
					for(i=0;i<16;i++)
					{
						writebyte(table2[m+i]);
						writebyte(table[m+i]);
						out();
						P1=table1[i];		
					}
				}
		}
	}
}

2011-07-14 16:14:34 iteye_20036 阅读数 1050
  • 单片机控制第一个外设-LED-第1季第6部分

    本课程是《朱有鹏老师单片机完全学习系列课程》第1季第6个课程,主要讲解LED的工作原理和开发板原理图、实践编程等,通过学习目的是让大家学会给单片机编程控制LED灯,并且为进一步学习其他外设打好基础。

    3995 人正在学习 去看看 朱有鹏
转载自http://hi.baidu.com/qiankun_room/blog/item/b0e925c24c79f75db219a856.html

/***************************************************
程序功能:控制8个LED闪烁,
测试说明:观察LED闪烁
***************************************************/
#include <msp430x14x.h>
unsigned int i = 0;
unsigned int flag = 0 ,speed = 0;
/****************主函数****************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗

CCTL0 = CCIE; //使能CCR0中断
CCR0 = 2047; //设定周期0.5S
TACTL = TASSEL_1 + ID_3 + MC_1; //定时器A的时钟源选择ACLK,增计数模式
P2DIR = 0xff; //设置P2口方向为输出
P2OUT = 0xff;

_EINT(); //使能全局中断
LPM3; //CPU进入LPM3模式
}
/*******************************************
函数名称:Timer_A
功 能:定时器A的中断服务函数
参 数:无
返回值 :无
********************************************/
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if(flag==0)
{
P2OUT = ~((0X80)>>(i++));
}

else
{
P2OUT = ~((0X01)<<(i++));
}

if(i==8)
{
i=0;
flag = ~flag;
speed++;
}
switch(speed)
{
case 0:TACTL &=~ (ID0 + ID1);TACTL |= ID_3;break;
case 1:TACTL &=~ (ID0 + ID1);TACTL |= ID_3;break;
case 2:TACTL &=~ (ID0 + ID1);TACTL |= ID_2;break;
case 3:TACTL &=~ (ID0 + ID1);TACTL |= ID_2;break;
case 4:TACTL &=~ (ID0 + ID1);TACTL |= ID_1;break;
case 5:TACTL &=~ (ID0 + ID1);TACTL |= ID_1;break;
case 6:TACTL &=~ (ID0 + ID1);TACTL |= ID_0;break;
case 7:TACTL &=~ (ID0 + ID1);TACTL |= ID_0;break;
default: break;
}
if(speed==8) speed=0;

}
2015-08-16 10:23:09 remainer 阅读数 6829
  • 单片机控制第一个外设-LED-第1季第6部分

    本课程是《朱有鹏老师单片机完全学习系列课程》第1季第6个课程,主要讲解LED的工作原理和开发板原理图、实践编程等,通过学习目的是让大家学会给单片机编程控制LED灯,并且为进一步学习其他外设打好基础。

    3995 人正在学习 去看看 朱有鹏

最近自学51单片机编程,看大神http://home.eeworld.com.cn/home.php?mod=space&uid=139222&do=blog&classid=988&view=me 的文章,看了前几个,迫不及待的上手,写了一个流水灯的小程序,开始也看了一些算法,看不懂,所以自己研究,写了个算法,算法不好,但好在好理解。
我的第一个单片机程序,让八个灯循环闪烁。
电路图

    #include<reg51.h>
#define TIME 5
void delay(int time){               //延时代码
    int i,j;
    for(i=1000; i>0; i--)
    for(j=time; j>0; j--);
}

int diff(int count){                //算2的i次方
    int i,rs = 1;
    for (i = 0; i < count; i++) {
        rs *= 2;
    }
    return rs;
}

void flicker(int time){             //闪烁算法
    int i,j = -1;
    for(i = 254; i>0; i = (i - diff(j))){
        P1 = i;
        delay(time);
        P1 = 0xff;
        delay(time);
        j++;
    }
}

void main(void)                     //主程序,无限循环
{
    while(1){
        flicker(TIME);
    }
}

延时算法解释
灯亮的顺序二进制表示
254-2^i即为要亮的灯。

单片机 流水灯

阅读数 3781

51单片机上设置流水灯程序

博文 来自: qq_45400902

嵌入式51单片机流水灯原理详解

博文 来自: liangmaoxuan
没有更多推荐了,返回首页