找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3222|回复: 5
收起左侧

16灯摇摇棒单片机程序与制作资料

[复制链接]
ID:488191 发表于 2019-5-28 22:59 | 显示全部楼层 |阅读模式
QQ图片20190528225302.png QQ图片20190528225354.png 摇摇棒电路图.JPG QQ图片20190528225331.png
  1. #include <AT89X52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int    //宏定义
  4. #define KEY P3_7      //定义画面切换按键
  5. uchar KY;    //KY作用在后面说明     
  6. uchar disp;     //显示汉字指针
  7. uchar pic=0,num=0;     //pic为按键次数;num为中断次数


  8. uchar code love[] = {
  9. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  10. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x20,0x00,0x20,0x00,0x20,
  11. 0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x0F,
  12. 0x04,0x10,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x04,0x10,0xF8,0x0F,0x00,0x00,
  13. 0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x20,0x00,0x10,
  14. 0x00,0x08,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x82,0x20,0x82,0x20,
  15. 0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
  16. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*LOVE*/
  17. };


  18. uchar code loveyou[] = {
  19. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  20. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  21. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  22. 0x78,0x00,0xFC,0x00,0xFE,0x01,0xFE,0x03,0xFE,0x07,0xFE,0x0F,0xFE,0x1F,0xFC,0x3F,
  23. 0xF8,0x7F,0xFC,0x3F,0xFE,0x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x00,
  24. 0x78,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. };

  28. uchar code hehe[] = {
  29. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30. 0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,
  31. 0xF0,0x0F,0x08,0x10,0x04,0x20,0x00,0x00,0x00,0x00,0xF0,0x3F,0x08,0x00,0x04,0x00,
  32. 0x04,0x00,0x04,0x00,0x08,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x20,
  33. 0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0xF0,0x3F,0x08,0x00,0x04,0x00,
  34. 0x04,0x00,0x04,0x00,0x08,0x00,0xF0,0x3F,0x00,0x00,0x00,0x00,0x04,0x20,0x08,0x10,
  35. 0xF0,0x0F,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,
  36. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*呵呵o(∩_∩)o图案*/
  37. };

  38. unsigned char code hanzi[] = {
  39. //-- 欢 --
  40.       0x04,0x10,0x34,0x08,0xC4,0x06,0x04,0x01,
  41.       0xC4,0x82,0x3C,0x8C,0x20,0x40,0x10,0x30,
  42.       0x0F,0x0C,0xE8,0x03,0x08,0x0C,0x08,0x10,
  43.       0x28,0x60,0x18,0xC0,0x00,0x40,0x00,0x00,
  44. //-- 迎 --
  45.       0x40,0x00,0x42,0x40,0x44,0x20,0xC8,0x1F,
  46.       0x00,0x20,0xFC,0x47,0x04,0x42,0x02,0x41,
  47.       0x82,0x40,0xFC,0x7F,0x04,0x40,0x04,0x42,
  48.       0x04,0x44,0xFE,0x63,0x04,0x20,0x00,0x00,
  49. //-- 使 --
  50.       0x40,0x00,0x20,0x00,0xF8,0xFF,0x07,0x00,
  51.       0x04,0x80,0xF4,0x43,0x14,0x45,0x14,0x29,
  52.       0x14,0x19,0xFF,0x17,0x14,0x21,0x14,0x21,
  53.       0x14,0x41,0xF6,0xC3,0x04,0x40,0x00,0x00,
  54. //-- 用 --
  55.       0x00,0x80,0x00,0x60,0xFE,0x1F,0x22,0x02,
  56.       0x22,0x02,0x22,0x02,0x22,0x02,0xFE,0x7F,
  57.       0x22,0x02,0x22,0x02,0x22,0x42,0x22,0x82,
  58.       0xFF,0x7F,0x02,0x00,0x00,0x00,0x00,0x00,


  59. };

  60. /*****函数声明*****/
  61. void display1_ltor(void);
  62. void display2_ltor(void);
  63. void display2_rtol(void);
  64. void display3(void);
  65. void display4(void);






  66. /*****n(us)延时子程序*****/
  67. void DelayUs(uint N)
  68. {
  69. uint x;
  70. for(x=0; x<=N;x++);
  71. }

  72. /*****中断服务程序*****/
  73. void intersvr0(void) interrupt 0
  74. {
  75. ;
  76. KY=~KY;      //每个摇动来回水银开关会在摆幅两端分别产生下降沿中断,只提取其中一次(从左向右摇才显示)
  77. if(KY==0)
  78. {
  79.    num++;     //计算中断次数
  80.    switch(pic)      //选择画面
  81.    {
  82.         case 0:{display1_ltor();}break;
  83.     case 1:{display2_ltor();}break;
  84.     case 2:{display3();}break;
  85.     case 3:{display4();}break;
  86.     default:{display1_ltor();}  
  87.    }
  88. }

  89. }
  90. /*****显示子程序1(汉字)*****/
  91. void display1_ltor(void)
  92. {
  93. uchar i;
  94. if(num>10){disp++;num=0;}     //12个汉字分为3次显示完(每次显示4个),每中断10次切换
  95. if(disp>2)disp=0;
  96.   DelayUs(5200);     //此处延时时间依各硬件差别而各不相同,试着调整使得显示内容居中即可
  97. for(i=0;i<64;i++)
  98. {
  99.      P0=~hanzi[disp*128+i*2];
  100.      P2=~hanzi[disp*128+i*2+1];
  101.      DelayUs(100);
  102. }
  103. }

  104. /*****显示子程序2(LOVE)*****/
  105. void display2_ltor(void)
  106. {
  107. uchar i;
  108. DelayUs(4000);
  109. for(i=0;i<64;i++)
  110. {
  111.      P0=~love[i*2];
  112.      P2=~love[i*2+1];
  113.      DelayUs(140);
  114. }
  115. }
  116. /*****显示子程序3(心形图案)*****/
  117. void display3(void)
  118. {
  119. uchar i;
  120.   DelayUs(4000);
  121. for(i=0;i<64;i++)
  122. {
  123.      P0=~loveyou[i*2];
  124.      P2=~loveyou[i*2+1];
  125.      DelayUs(120);
  126. }
  127. }

  128. /*****显示子程序4(呵呵o(∩_∩)o图案)*****/
  129. void display4(void)
  130. {
  131. uchar i;
  132. DelayUs(4000);
  133. for(i=0;i<64;i++)
  134. {
  135.      P0=~hehe[i*2];
  136.      P2=~hehe[i*2+1];
  137.      DelayUs(120);
  138. }
  139. }

  140. /*****主函数*****/
  141. void main(void)
  142. {
  143. IT0=1;
  144. EX0=1;
  145. EA=1;      //开中断,下降沿中断
  146. KY=0;
  147. KEY=1;
  148. while(1)     //主程序中只检测按键
  149. {
  150.   if(KEY==0)     //画面切换键按下
  151.   {
  152.      DelayUs(10000);     //按键去抖
  153.      if(KEY==0);
  154.      pic++;
  155.      while(KEY==0);
  156.   }
  157.   if(pic>3)pic=0;
  158. }
  159. }
  160. /*****END*****/
复制代码
全部资料51hei下载地址:
摇摇棒配套资料.zip (2.04 MB, 下载次数: 85)
回复

使用道具 举报

ID:587940 发表于 2019-7-26 11:28 | 显示全部楼层
元件清单在哪啊?
回复

使用道具 举报

ID:110278 发表于 2019-8-8 09:39 | 显示全部楼层
很好。。。。
回复

使用道具 举报

ID:42468 发表于 2021-2-2 21:26 | 显示全部楼层
我怎么摇不出这个效果,只亮边上一排
回复

使用道具 举报

ID:928591 发表于 2021-9-13 15:31 | 显示全部楼层
看着不错,有用吗?
回复

使用道具 举报

ID:1002257 发表于 2022-1-28 19:47 | 显示全部楼层
做个试试,这个是有遥的速度要求吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表