找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1946|回复: 1
打印 上一主题 下一主题
收起左侧

买摇摇棒套件送的单片机程序

[复制链接]
跳转到指定楼层
楼主
ID:162582 发表于 2017-6-8 15:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
淘宝买套件送的程序
  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.       0x08,0x01,0x88,0x00,0x49,0x00,0xEE,0xFF,
  61.       0x58,0x00,0x88,0x00,0x00,0x00,0xF8,0x1F,
  62.       0x88,0x08,0x88,0x08,0xFF,0xFF,0x88,0x08,
  63.       0x88,0x08,0xFC,0x1F,0x08,0x00,0x00,0x00,
  64. //-- 奇 --
  65.       0x40,0x00,0x40,0x00,0x44,0x00,0x44,0x3E,
  66.       0x64,0x12,0x54,0x12,0x4C,0x12,0x47,0x12,
  67.       0x4C,0x3F,0x54,0x42,0x74,0x80,0xC6,0x7F,
  68.       0x44,0x00,0x60,0x00,0x40,0x00,0x00,0x00,
  69. //-- 魔 --
  70.       0x00,0x40,0x00,0x30,0xFE,0x8F,0x4A,0x80,
  71.       0xAA,0x5F,0x9A,0x4A,0xFE,0x2A,0xAA,0x1A,
  72.       0xCB,0x0F,0xAA,0x7A,0xFE,0x8A,0x9A,0xAA,
  73.       0xAA,0x8F,0x6B,0x80,0x22,0xE0,0x00,0x00,
  74. //-- 幻 --
  75.       0x80,0x20,0xC0,0x30,0xA0,0x28,0x98,0x24,
  76.       0x87,0x22,0x80,0x21,0xC4,0x30,0x04,0x60,
  77.       0x04,0x00,0x04,0x20,0x04,0x40,0x04,0x80,
  78.       0x04,0x40,0xFE,0x3F,0x04,0x00,0x00,0x00,
  79. //-- 摇 --
  80.       0x10,0x02,0x10,0x42,0x10,0x81,0xFF,0x7F,
  81.       0x90,0x04,0x54,0x05,0xCC,0xF4,0xB4,0x44,
  82.       0x84,0x44,0xBC,0x7F,0x82,0x44,0xA2,0x44,
  83.       0x9B,0xF4,0x82,0x06,0x00,0x04,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,0x04,0x10,0x03,0xD0,0x00,0xFF,0xFF,
  91.       0x90,0x00,0x54,0x05,0x44,0x12,0xD4,0x15,
  92.       0x74,0x14,0x5F,0xFF,0xD4,0x14,0x54,0x15,
  93.       0x56,0x12,0x44,0x06,0x40,0x02,0x00,0x00,
  94. //-- ! --
  95.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96.       0x00,0x00,0x00,0x00,0x7C,0x10,0xFE,0x3B,
  97.       0xFE,0x3B,0x7C,0x10,0x00,0x00,0x00,0x00,
  98.       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  99. };
  100. /*****函数声明*****/
  101. void display1_ltor(void);
  102. void display2_ltor(void);
  103. void display2_rtol(void);
  104. void display3(void);
  105. void display4(void);



  106. /*****n(us)延时子程序*****/
  107. void DelayUs(uint N)
  108. {
  109. uint x;
  110. for(x=0; x<=N;x++);
  111. }
  112. /*****中断服务程序*****/
  113. void intersvr0(void) interrupt 0
  114. {
  115. ;
  116. KY=~KY;      //每个摇动来回水银开关会在摆幅两端分别产生下降沿中断,只提取其中一次(从左向右摇才显示)
  117. if(KY==0)
  118. {
  119.    num++;     //计算中断次数
  120.    switch(pic)      //选择画面
  121.    {
  122.         case 0:{display1_ltor();}break;
  123.     case 1:{display2_ltor();}break;
  124.     case 2:{display3();}break;
  125.     case 3:{display4();}break;
  126.     default:{display1_ltor();}  
  127.    }
  128. }
  129. }
  130. /*****显示子程序1(汉字)*****/
  131. void display1_ltor(void)
  132. {
  133. uchar i;
  134. if(num>10){disp++;num=0;}     //12个汉字分为3次显示完(每次显示4个),每中断10次切换
  135. if(disp>2)disp=0;
  136.   DelayUs(5200);     //此处延时时间依各硬件差别而各不相同,试着调整使得显示内容居中即可
  137. for(i=0;i<64;i++)
  138. {
  139.      P0=~hanzi[disp*128+i*2];
  140.      P2=~hanzi[disp*128+i*2+1];
  141.      DelayUs(100);
  142. }
  143. }
  144. /*****显示子程序2(LOVE)*****/
  145. void display2_ltor(void)
  146. {
  147. uchar i;
  148. DelayUs(4000);
  149. for(i=0;i<64;i++)
  150. {
  151.      P0=~love[i*2];
  152.      P2=~love[i*2+1];
  153.      DelayUs(140);
  154. }
  155. }
  156. /*****显示子程序3(心形图案)*****/
  157. void display3(void)
  158. {
  159. uchar i;
  160.   DelayUs(4000);
  161. for(i=0;i<64;i++)
  162. {
  163.      P0=~loveyou[i*2];
  164.      P2=~loveyou[i*2+1];
  165.      DelayUs(120);
  166. }
  167. }
  168. /*****显示子程序4(呵呵o(∩_∩)o图案)*****/
  169. void display4(void)
  170. {
  171. uchar i;
  172. DelayUs(4000);
  173. for(i=0;i<64;i++)
  174. {
  175.      P0=~hehe[i*2];
  176.      P2=~hehe[i*2+1];
  177.      DelayUs(120);
  178. }
  179. }
  180. /*****主函数*****/
  181. void main(void)
  182. {
  183. IT0=1;
  184. EX0=1;
  185. EA=1;      //开中断,下降沿中断
  186. KY=0;
  187. KEY=1;
  188. while(1)     //主程序中只检测按键
  189. {
  190.   if(KEY==0)     //画面切换键按下
  191.   {
  192.      DelayUs(10000);     //按键去抖
  193.      if(KEY==0);
  194.      pic++;
  195.      while(KEY==0);
  196.   }
  197.   if(pic>3)pic=0;
  198. }
  199. }
  200. /*****END*****/

复制代码


摇摇棒.rar

19.7 KB, 下载次数: 6, 下载积分: 黑币 -5

摇摇棒

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:286719 发表于 2018-4-3 20:51 | 只看该作者
只有程序吗?
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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