• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

自己设计的用51单片机控制驱动的七彩LED渐变灯,与大家分享

自己设计的51单片机控制LED七彩渐变灯
MCU:89C51,89S51,89C2051等

晶振:12MHz

电路驱动(LED连接):
P1.0连接蓝色LED
P1.1连接红色LED
P1.2连接绿色LED (必须使用纯绿色高亮LED,不可使用普通草绿管)
全为低电平驱动(低电平点亮),可以加三极管驱动,红、蓝、绿LED也可以交换位置

控制方式:PWM

频率:约300-700Hz(我没有计算或测量过,只是试验显示效果足够好)

调节级数:共600级,相当平滑

编译后的HEX文件:
687241197859316.rar

HEX代码:
:0D009300E4FEEEC39F50060000000E80F555
:0100A000223D
:06005F00A9078D828C83CD
:10006500E4FDE96008C292FF120093D292E5824551
:10007500836009C291AF82120093D291EB4A600965
:0D008500C290AF03120093D2900DBD0AD5BA
:01009200224B
:100003007508C8E4F509F50AE5086008E50A70040F
:1000130015080509E5096008E50870041509050ACE
:10002300E50A6008E5097004150A0508E5082509CD
:10003300FFE433FE7C00EF250AFFEC3EFEEF64C8CD
:100043004E60087508C8E4F509F50AE509FD7C006A
:0C005300E50AFB7A00AF0812005F80ACE9
:030000000200A15A
:0C00A100787FE4F6D8FD75810A020003A8
:00000001FF

C语言源程序:
/*******************************
程序名称:七彩LED渐变程序
编写者:ZH YU
MCU:51/2051
晶振:12MHz
*********************************/
#include
#include

sbit gl=P1^2;   //绿色
sbit rl=P1^1;   //红
sbit bl=P1^0;   //兰

timer(unsigned char t)
{unsigned char b;
   for(b=0;b   {_nop_();
    _nop_();
_nop_();}
}


ledout(unsigned char g,r,b)
{unsigned char a;
  for(a=0;a<10;a++)
{if(g!=0)
    {gl=0;timer(g);gl=1;}
  if(r!=0)
    {rl=0;timer(r);rl=1;}
  if(b!=0)
    {bl=0;timer(b);bl=1;}
  }
}

main()
{ unsigned char g,r,b;
  g=200;r=0;b=0;
  while(1)
  {if(g!=0&&b==0)
    {g--;r++;}
   if(r!=0&&g==0)
    {r--;b++;}
   if(b!=0&&r==0)
    {b--;g++;}
   if(g+r+b!=200)
    {g=200;r=0;b=0;}
   ledout(g,r,b);
  }
}
入无法下载HEX,大家可以用KEIL自己编译,或者使用记事本保存HEX代码(重命名为.HEX文件)都可以
再把.hex文件写入单片机,接好电路即可工作

自己做的LED渐变灯(使用三极管8550驱动)及部分效果图:
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197858977.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197858994.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197859003.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197859010.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197859021.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197859031.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
500) {this.resized=true; this.width=500; this.alt='这是一张缩略图,点击可放大。\n按住CTRL,滚动鼠标滚轮可自由缩放';this.style.cursor='hand'}" onclick="if(!this.resized) {return true;} else {window.open('http://u.dianyuan.com/bbs/u/60/687241197859043.jpg?x-oss-process=image/watermark,g_center,image_YXJ0aWNsZS9wdWJsaWMvd2F0ZXJtYXJrLnBuZz94LW9zcy1wcm9jZXNzPWltYWdlL3Jlc2l6ZSxQXzQwCg,t_20');}" onmousewheel="return imgzoom(this);">
全部回复(1)
正序查看
倒序查看
v-mosfet
LV.7
2
2007-12-18 09:02
开始把帖子发到“照明电源”里了!这刚复制过来!
0
回复