容易制作的16只LED发光管摇摇棒 电路图+源程序

-回复 -浏览
楼主 2021-01-12 16:07:22
举报 只看此人 收藏本贴 楼主

51黑电子论坛(网址:51hei.com)精选文章:

人的眼睛存在视觉暂留现象,正因为眼睛的反应迟钝,才丰富了人的视觉感受。LED摇摇棒很好地利用了人眼的视觉暂留特性。这样的电子小制作,人人者喜欢动手实践一下,下图是基于51单片机控制、容易制作的16只LED发光管摇摇棒,配合手的左右摇晃就可呈现一幅完整的画面,可以显示字符、图片等。


容易制作的16只LED发光管摇摇棒基本原理与硬件电路设计
容易制作的16只LED发光管摇摇棒,由16只LED发光管作为画面每一列的显示,左右摇晃起到了扫描的作用,人眼的视觉暂留现象使得看到的是一幅 完整的画面。容易制作的16只LED发光管摇摇棒与LED点阵的显示有几分相仿。下面介绍一下这个电子小制作——容易制作的16只LED发光管摇摇棒的原 理,供大家仿制。



容易制作的16只LED发光管摇摇棒硬件电路如下图(点击可放大)。系统电源VCC为5V,下载程序和调试时一定要保证5V电压,实际使用时用3节干电池串联4.5V即可。AT89S52单片机作为控制器,在它的P0、P2口接有16只以共阳的方式连接的高亮度LED,由单片机输出低电平点亮。P0口的上拉电阻RA1不能少。串在LED公共端的二极管D1会产生一定的压降,用来保护LED,经实测LED点亮时两端电压为3V左右,在LED的安全承受范围内。K1是画面切换开关,用于切换显示不同内容;S1为水银开关。水银开关的作用:棒在摇动时,只能在朝某一方向摇动时显示,否则会出现镜像字或镜像画面,所以通过接一只水银开关来控制,使摇摇棒从左向右摇动时将内容显示出来。



源程序如下:

  1. /**********************************************************

  2. 程序名称:容易制作的16只LED发光管摇摇棒

  3. 简要说明:外部中断方式INT0显示;取模方式:纵向取模、字节倒序

  4. 电子小制作优选制作题材

  5. **********************************************************/

  6. #include <AT89X52.h>

  7. #define uchar unsigned char

  8. #define uint unsigned int //宏定义

  9. #define KEY P3_0 //定义画面切换按键

  10. uchar KY; //KY作用在后面说明

  11. uchar disp; //显示汉字指针

  12. uchar pic=0,num=0; //pic为按键次数;num为中断次数


  13. uchar code love[] = {

  14. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  15. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x20,0x00,0x20,0x00,0x20,

  16. 0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x0F,

  17. 0x04,0x10,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x04,0x10,0xF8,0x0F,0x00,0x00,

  18. 0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x20,0x00,0x10,

  19. 0x00,0x08,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x82,0x20,0x82,0x20,

  20. 0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x00,0x00,0x00,0x00,0x00,0x00,

  21. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*LOVE*/

  22. };


  23. uchar code loveyou[] = {

  24. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  25. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  26. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  27. 0x78,0x00,0xFC,0x00,0xFE,0x01,0xFE,0x03,0xFE,0x07,0xFE,0x0F,0xFE,0x1F,0xFC,0x3F,

  28. 0xF8,0x7F,0xFC,0x3F,0xFE,0x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x00,

  29. 0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  30. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  31. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*心形图案*/

  32. };


  33. uchar code hehe[] = {

  34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  35. 0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,

  36. 0xF0,0x0F,0x08,0x10,0x04,0x20,0x00,0x00,0x00,0x00,0xF0,0x3F,0x08,0x00,0x04,0x00,

  37. 0x04,0x00,0x04,0x00,0x08,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x20,

  38. 0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0xF0,0x3F,0x08,0x00,0x04,0x00,

  39. 0x04,0x00,0x04,0x00,0x08,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x04,0x20,0x08,0x10,

  40. 0xF0,0x0F,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,

  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*呵呵o(∩_∩)o图案*/

  42. };


  43. unsigned char code hanzi[] = {

  44. //-- 欢 --

  45. 0x04,0x10,0x34,0x08,0xC4,0x06,0x04,0x01,

  46. 0xC4,0x82,0x3C,0x8C,0x20,0x40,0x10,0x30,

  47. 0x0F,0x0C,0xE8,0x03,0x08,0x0C,0x08,0x10,

  48. 0x28,0x60,0x18,0xC0,0x00,0x40,0x00,0x00,

  49. //-- 迎 --

  50. 0x40,0x00,0x42,0x40,0x44,0x20,0xC8,0x1F,

  51. 0x00,0x20,0xFC,0x47,0x04,0x42,0x02,0x41,

  52. 0x82,0x40,0xFC,0x7F,0x04,0x40,0x04,0x42,

  53. 0x04,0x44,0xFE,0x63,0x04,0x20,0x00,0x00,

  54. //-- 使 --

  55. 0x40,0x00,0x20,0x00,0xF8,0xFF,0x07,0x00,

  56. 0x04,0x80,0xF4,0x43,0x14,0x45,0x14,0x29,

  57. 0x14,0x19,0xFF,0x17,0x14,0x21,0x14,0x21,

  58. 0x14,0x41,0xF6,0xC3,0x04,0x40,0x00,0x00,

  59. //-- 用 --

  60. 0x00,0x80,0x00,0x60,0xFE,0x1F,0x22,0x02,

  61. 0x22,0x02,0x22,0x02,0x22,0x02,0xFE,0x7F,

  62. 0x22,0x02,0x22,0x02,0x22,0x42,0x22,0x82,

  63. 0xFF,0x7F,0x02,0x00,0x00,0x00,0x00,0x00,

  64. //-- 神 --

  65. 0x08,0x01,0x88,0x00,0x49,0x00,0xEE,0xFF,

  66. 0x58,0x00,0x88,0x00,0x00,0x00,0xF8,0x1F,

  67. 0x88,0x08,0x88,0x08,0xFF,0xFF,0x88,0x08,

  68. 0x88,0x08,0xFC,0x1F,0x08,0x00,0x00,0x00,

  69. //-- 奇 --

  70. 0x40,0x00,0x40,0x00,0x44,0x00,0x44,0x3E,

  71. 0x64,0x12,0x54,0x12,0x4C,0x12,0x47,0x12,

  72. 0x4C,0x3F,0x54,0x42,0x74,0x80,0xC6,0x7F,

  73. 0x44,0x00,0x60,0x00,0x40,0x00,0x00,0x00,

  74. //-- 魔 --

  75. 0x00,0x40,0x00,0x30,0xFE,0x8F,0x4A,0x80,

  76. 0xAA,0x5F,0x9A,0x4A,0xFE,0x2A,0xAA,0x1A,

  77. 0xCB,0x0F,0xAA,0x7A,0xFE,0x8A,0x9A,0xAA,

  78. 0xAA,0x8F,0x6B,0x80,0x22,0xE0,0x00,0x00,

  79. //-- 幻 --

  80. 0x80,0x20,0xC0,0x30,0xA0,0x28,0x98,0x24,

  81. 0x87,0x22,0x80,0x21,0xC4,0x30,0x04,0x60,

  82. 0x04,0x00,0x04,0x20,0x04,0x40,0x04,0x80,

  83. 0x04,0x40,0xFE,0x3F,0x04,0x00,0x00,0x00,

  84. //-- 摇 --

  85. 0x10,0x02,0x10,0x42,0x10,0x81,0xFF,0x7F,

  86. 0x90,0x04,0x54,0x05,0xCC,0xF4,0xB4,0x44,

  87. 0x84,0x44,0xBC,0x7F,0x82,0x44,0xA2,0x44,

  88. 0x9B,0xF4,0x82,0x06,0x00,0x04,0x00,0x00,

  89. //-- 摇 --

  90. 0x10,0x02,0x10,0x42,0x10,0x81,0xFF,0x7F,

  91. 0x90,0x04,0x54,0x05,0xCC,0xF4,0xB4,0x44,

  92. 0x84,0x44,0xBC,0x7F,0x82,0x44,0xA2,0x44,

  93. 0x9B,0xF4,0x82,0x06,0x00,0x04,0x00,0x00,

  94. //-- 棒 --

  95. 0x10,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,

  96. 0x90,0x00,0x54,0x05,0x44,0x12,0xD4,0x15,

  97. 0x74,0x14,0x5F,0xFF,0xD4,0x14,0x54,0x15,

  98. 0x56,0x12,0x44,0x06,0x40,0x02,0x00,0x00,

  99. //-- ! --

  100. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

  101. 0x00,0x00,0x00,0x00,0x7C,0x10,0xFE,0x3B,

  102. 0xFE,0x3B,0x7C,0x10,0x00,0x00,0x00,0x00,

  103. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

  104. };


  105. /*****函数声明*****/

  106. void display1(void);

  107. void display2(void);

  108. void display3(void);

  109. void display4(void);


  110. /*****n(us)延时子程序*****/

  111. void DelayUs(uint N)

  112. {

  113. uint x;

  114. for(x=0; x<=N;x++);

  115. }


  116. /*****中断服务程序*****/

  117. void intersvr0(void) interrupt 0 using 1

  118. {

  119. KY=~KY; //每个摇动来回水银开关会在摆幅两端分别产生下降沿中断,只提取其中一次(从左向右摇才显示)

  120. if(KY==0)

  121. {

  122. num++; //计算中断次数

  123. switch(pic) //选择画面

  124. {

  125. case 0:{display1();}break;

  126. case 1:{display2();}break;

  127. case 2:{display3();}break;

  128. case 3:{display4();}break;

  129. default:{display1();}

  130. }

  131. }

  132. }


  133. /*****显示子程序1(汉字)*****/

  134. void display1(void)

  135. {

  136. uchar i;

  137. if(num>10){disp++;num=0;} //12个汉字分为3次显示完(每次显示4个),每中断10次切换

  138. if(disp>2)disp=0;

  139. DelayUs(5200); //此处延时时间依各硬件差别而各不相同,试着调整使得显示内容居中即可

  140. for(i=0;i<64;i++)

  141. {

  142. P0=~hanzi[disp*128+i*2];

  143. P2=~hanzi[disp*128+i*2+1];

  144. DelayUs(100);

  145. }

  146. }


  147. /*****显示子程序2(LOVE)*****/

  148. void display2(void)

  149. {

  150. uchar i;

  151. DelayUs(4000);

  152. for(i=0;i<64;i++)

  153. {

  154. P0=~love[i*2];

  155. P2=~love[i*2+1];

  156. DelayUs(120);

  157. }

  158. }


  159. /*****显示子程序3(心形图案)*****/

  160. void display3(void)

  161. {

  162. uchar i;

  163. DelayUs(4000);

  164. for(i=0;i<64;i++)

  165. {

  166. P0=~loveyou[i*2];

  167. P2=~loveyou[i*2+1];

  168. DelayUs(120);

  169. }

  170. }


  171. /*****显示子程序4(呵呵o(∩_∩)o图案)*****/

  172. void display4(void)

  173. {

  174. uchar i;

  175. DelayUs(4000);

  176. for(i=0;i<64;i++)

  177. {

  178. P0=~hehe[i*2];

  179. P2=~hehe[i*2+1];

  180. DelayUs(120);

  181. }

  182. }


  183. /*****主函数*****/

  184. void main(void)

  185. {

  186. IT0=1;

  187. EX0=1;

  188. EA=1; //开中断,下降沿中断

  189. KY=0;

  190. while(1) //主程序中只检测按键

  191. {

  192. if(KEY==0) //画面切换键按下

  193. {

  194. DelayUs(10000); //按键去抖

  195. if(KEY==0);

  196. pic++;}

  197. if(pic>3)pic=0;

  198. }

  199. }

复制代码






96%的人点击了下方的“阅读原文”查看海量的设计资料,有不懂的问题还能在51黑论坛免费交流哦
↓↓↓




我要推荐
转发到

友情链接