实例源码2---基于51单片机的摇摇棒制作

最近整理资料,看见这个之前做的摇摇棒,是基于51单片机的,下面把源程序贴出来,有任何问题欢迎留言!

#include
#define uchar unsigned char
#define uint unsigned int

sbit key = P3^0;//定义切换画面开关
uchar Key_num;//定义按键次数
uchar Int0_num=0;//定义中断次数
uchar Direction;//定义摇动方向(从左到右)
uchar code Embed[]={
0x40,0x00,0x20,0x00,0xd0,0x3f,0x4c,0x40,0x43,0x40,0x44,0x42,0x48,0x44,0xd8,0x43,
0x30,0x78,0x10,0x00,0x00,0x00,0xfc,0x07,0x00,0x20,0x00,0x40,0xff,0x3f,0x00,0x00,

0x20,0x21,0x24,0x11,0x2c,0x4d,0x35,0x81,0xe6,0x7f,0x34,0x05,0x2c,0x59,0x24,0x21,
0x00,0x18,0xfc,0x07,0x24,0x00,0x24,0x00,0xe2,0xff,0x22,0x00,0x22,0x00,0x00,0x00,

0x00,0x00,0x10,0x82,0x0c,0x82,0x04,0x42,0x4c,0x42,0xb4,0x23,0x94,0x12,0x05,0x0a,
0xf6,0x07,0x04,0x0a,0x04,0x12,0x04,0xe2,0x14,0x42,0x0c,0x02,0x04,0x02,0x00,0x00,

0x02,0x08,0xfa,0x08,0x82,0x04,0x82,0x24,0xfe,0x40,0x80,0x3f,0x40,0x22,0x60,0x2c,
0x58,0x21,0x46,0x2e,0x48,0x20,0x50,0x30,0x20,0x2c,0x20,0x23,0x20,0x20,0x00,0x00,

0x00,0x40,0x10,0x40,0x2c,0x48,0x24,0x49,0xa4,0x49,0x64,0x49,0x25,0x49,0x26,0x7f,
0x24,0x49,0x24,0x49,0xa4,0x49,0x24,0x4b,0x34,0x48,0x2c,0x40,0x04,0x40,0x00,0x00,
};
uchar code love[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x00,0x20,0x00,0x20,0x00,0x20,
0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x0F,
0x04,0x10,0x02,0x20,0x02,0x20,0x02,0x20,0x02,0x20,0x04,0x10,0xF8,0x0F,0x00,0x00,
0x00,0x00,0x00,0x00,0xFE,0x07,0x00,0x08,0x00,0x10,0x00,0x20,0x00,0x20,0x00,0x10,
0x00,0x08,0xFE,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x82,0x20,0x82,0x20,
0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x82,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

uchar code love_picture[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x78,0x00,0xFC,0x00,0xFE,0x01,0xFE,0x03,0xFE,0x07,0xFE,0x0F,0xFE,0x1F,0xFC,0x3F,
0xF8,0x7F,0xFC,0x3F,0xFE,0x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x00,
0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

uchar code Hello[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x08,0x20,0xF8,0x3F,0x08,0x21,0x00,0x01,0x00,0x01,0x08,0x21,0xF8,0x3F,0x08,0x20,

0x00,0x00,0x00,0x1F,0x80,0x22,0x80,0x22,0x80,0x22,0x80,0x22,0x00,0x13,0x00,0x00,

0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,

0x00,0x00,0x08,0x20,0x08,0x20,0xF8,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x1F,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x00,0x1F,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x33,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

uchar code Smile[] =
{
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0xF0,0x1F,0x3C,0x3C,0x0E,0xF7,0x06,0xEF,0xF3,0xDC,0xF3,0xB0,0x63,0xB0,0x03,0xB0,
  0xF3,0xB0,0xF3,0xB8,0x03,0xDD,0x06,0xEF,0x0E,0x76,0x3C,0x3C,0xF8,0x1F,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};   

uchar code Hxembed_Make[]={
0x02,0x01,0xf2,0x03,0x12,0x41,0x12,0x81,0x1e,0x7f,0x00,0x00,0x80,0x00,0x80,0x40,
0xff,0xff,0xa0,0x40,0x90,0x23,0x88,0x0c,0x86,0x10,0x84,0x60,0x80,0x20,0x00,0x00,
0x80,0x00,0x80,0x40,0x80,0x30,0x80,0x0c,0xfe,0x03,0x82,0x00,0x8a,0x00,0x92,0x00,
0xf2,0x00,0xa2,0x20,0x82,0x40,0xfe,0x3f,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xC0,0x00,0xB8,0x1E,0xA0,0x02,0xFE,0x3F,0xA4,0x02,0x60,0x02,
0x50,0x1E,0x00,0x00,0xE0,0x03,0x00,0x00,0x14,0x60,0xEC,0x3F,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x80,0x00,0x40,0x00,0xF0,0x3F,0x0C,0x00,0x80,0x00,0x40,0x00,
0x30,0x00,0xEE,0x7E,0x20,0x09,0x20,0x09,0x20,0x05,0x10,0x00,0x00,0x00,0x00,0x00,
};

uchar code Thanks[] =
{
//-- 谢 --
     0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x52,0xFC,0x2B,0x56,0x12,0x55,0x4A,0x54,0x86,
     0xFE,0x7F,0x24,0x01,0x20,0x46,0x20,0x80,0xFF,0x7F,0x20,0x00,0x20,0x00,0x00,0x00,
//-- 谢 --
     0x40,0x00,0x42,0x00,0xCC,0x3F,0x00,0x52,0xFC,0x2B,0x56,0x12,0x55,0x4A,0x54,0x86,
     0xFE,0x7F,0x24,0x01,0x20,0x46,0x20,0x80,0xFF,0x7F,0x20,0x00,0x20,0x00,0x00,0x00,
//-- ! --
     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x10,0xFE,0x3B,
     0xFE,0x3B,0x7C,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
uchar code danpan_picture[] = {
0x7f,0xff,0x7f,0xbf,0x7f,0xcf,0x7f,0xf3,0x01,0xfc,0x7d,0xff,0x75,0xff,0x6d,0xff,
0x0d,0xff,0x5d,0xdf,0x7d,0xbf,0x01,0xc0,0x7f,0xff,0x7f,0xff,0x7f,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x78,0x00,0xFC,0x00,0xFE,0x01,0xFE,0x03,0xFE,0x07,0xFE,0x0F,0xFE,0x1F,0xFC,0x3F,
0xF8,0x7F,0xFC,0x3F,0xFE,0x1F,0xFE,0x0F,0xFE,0x07,0xFE,0x03,0xFE,0x01,0xFC,0x00,
0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x9f,0xfb,0xab,0xfb,0xb3,0xfd,0x80,0xdd,0xb3,0xd6,0x28,0xd5,0x92,0x55,0xad,0x01,
0x92,0xd5,0xab,0xd5,0x33,0xd5,0x80,0xd6,0xb3,0xdd,0xab,0xf9,0xab,0xfd,0xff,0xff,
};

void delay(uint X)
{
  uint i;
  for(i=0;i<=X;i++)
   ;
}
void delay1(uint n)
{
       uintx,y;
       for(x=0;x<120;x++)
       for(y=0;y
}
void display1()
{
 uchar i,disp;
 if(Int0_num>4 ){disp++;Int0_num=0;}
 if(disp>1)disp=0;
 delay(12000);
 for(i=0;i<48;i++)
 {
    P0=~Embed[disp*64+i*2];
    P2=~Embed[disp*64+i*2+1];
  delay(120);//延时时间自己可以调,最好让画面显示在中间
 }
}
void display2()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~love[i*2];
 P2=~love[i*2+1];
 delay(150);
  }

}
void display3()
{
  uchar i;
   delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~love_picture[i*2];
 P2=~love_picture[i*2+1];
 delay(200);
  }
}

void display4()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~Hello[i*2];
 P2=~Hello[i*2+1];
 delay(120);
  }
}
void display5()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~Smile[i*2];
 P2=~Smile[i*2+1];
 delay(150);
  }
}

void display6()
{
 uchar i;
 delay(12000);
 for(i=0;i<64;i++)
  {
  P0=~Hxembed_Make[i*2];
 P2=~Hxembed_Make[i*2+1];
 delay(90);
  }
}
void display7()
{
  uchar i;
  delay(12000);
 for(i=0;i<48;i++)
  {
  P0=~Thanks[i*2];
 P2=~Thanks[i*2+1];
 delay(80);
  }
}

void int0(void) interrupt 0
{
Direction=~Direction;
 if(Direction==0)
 {
 Int0_num++;//中断次数加1
 switch(Key_num)
  {
 case 0:display1();break;
 case 1:display2();break;
 case 2:display3();break;
 case 3:display4();break;
 case 4:display5();break;
 case 5:display6();break;
 case 6:display7();break;
 default :display1();
  }
 }
}
void main(void)
{
EA=1;//开总中断
IT0=1;//下降沿中断
EX0=1;//启动外部中断0你——怒目

Key_num=0;//初始化按键次数为零

while(1)
{
 if(!key)
 {
 delay1(5); // 去抖,可以跟自己的电路适当选择时间
 if(key==0)
  {
  Key_num++;
  if(Key_num>6)//如果超过切换页面的次数就清零
   Key_num=0;
  }
 delay1(5);
 while(!key);
 }
}
}


实例源码2---基于51单片机的摇摇棒制作

原文地址:https://blog.51cto.com/12483417/2419117

时间: 2024-10-17 00:04:22

实例源码2---基于51单片机的摇摇棒制作的相关文章

【源码】基于Android和蓝牙的单片机温度采集系统

如需转载请标明出处:http://blog.csdn.net/itas109 STC89C52单片机通过HC-06蓝牙模块与Android手机通信实例- 基于Android和蓝牙的单片机温度采集系统 整个工程下载:http://download.csdn.net/detail/itas109/7539057 其中包括, 1.下位机电路原理图 2.下位机采集温度.控制发送.自动纠错代码 3.Android端接收温度并显示代码 文件截图 这个是我当年毕业设计做的东西,虽然比较简单,但是还是有一定的参

基于Docker的TensorFlow机器学习框架搭建和实例源码解读

概述:基于Docker的TensorFlow机器学习框架搭建和实例源码解读,TensorFlow作为最火热的机器学习框架之一,Docker是的容器,可以很好的结合起来,为机器学习或者科研人员提供便捷的机器学习开发环境,探索人工智能的奥秘,容器随开随用方便快捷.源码解析TensorFlow容器创建和示例程序运行,为热爱机器学者降低学习难度. 默认机器已经装好了Docker(Docker安装和使用可以看我另一篇博文:Ubuntu16.04安装Docker1.12+开发实例+hello world+w

Android 上千实例源码分析以及开源分析

Android 上千实例源码分析以及开源分析(百度云分享) 要下载的直接翻到最后吧,项目实例有点多. 首先 介绍几本书籍(下载包中)吧. 01_Android系统概述 02_Android系统的开发综述 03_Android的Linux内核与驱动程序 04_Android的底层库和程序 05_Android的JAVA虚拟机和JAVA环境 06_Android的GUI系统 07_Android的Audio系统 08_Android的Video 输入输出系统 09_Android的多媒体系统 10_

Spark资源调度机制源码分析--基于spreadOutApps及非spreadOutApps两种资源调度算法

Spark资源调度机制源码分析--基于spreadOutApps及非spreadOutApps两种资源调度算法 1.spreadOutApp尽量平均分配到每个executor上: 2.非spreadOutApp尽量在使用单个executor的资源. 源码分析 org.apache.spark.deploy.master.Master 1.首先判断,master状态不是ALIVE的话,直接返回2.调度driver3. Application的调度机制(核心之核心,重中之重) 源码如下: 1 /*

分享45个android实例源码,很好很强大

分享45个android实例源码,很好很强大http://www.apkbus.com/android-20978-1-1.html andriod闹钟源代码http://www.apkbus.com/android-20974-1-1.html android源码分享之指南针程序http://www.apkbus.com/android-20973-1-1.html 重力感应的测试程序andriod源代码http://www.apkbus.com/android-20972-1-1.html

分享45个android实例源码,很好很强大.收藏吧!!!

andriod闹钟源代码http://www.apkbus.com/android-20974-1-1.htmlandroid源码分享之指南针程序http://www.apkbus.com/android-20973-1-1.html重力感应的测试程序andriod源代码http://www.apkbus.com/android-20972-1-1.htmlandroid源码分享之时光日志个人日程管理http://www.apkbus.com/android-20969-1-1.htmlOpen

微信小程序实例源码大全

怎么本地测试微信小程序实例源码 1.下载源码 2.打开微信开发者工具 3.添加项目->选择本项目目录->编译执行 微信小程序实例源码大全 微信小程序游戏类demo:识色:从相似颜色中挑选不同的一个 源码链接:http://www.wxapp-union.com/forum.php?mod=viewthread&tid=1105 微信小程序精品demo:仿网易云音乐:歌单,FM,播放,评论 源码链接:http://www.wxapp-union.com/forum.php?mod=vie

JAVA上百实例源码以及开源项目

简介 笔者当初为了学习JAVA,收集了很多经典源码,源码难易程度分为初级.中级.高级等,详情看源码列表,需要的可以直接下载! 这些源码反映了那时那景笔者对未来的盲目,对代码的热情.执着,对IT的憧憬.向往!此时此景,笔者只专注Android.Iphone等移动平台开发,看着这些源码心中有万分感慨,写此文章纪念那时那景! Java 源码包 Applet钢琴模拟程序java源码 2个目标文件,提供基本的音乐编辑功能.编辑音乐软件的朋友,这款实例会对你有所帮助.Calendar万年历 1个目标文件EJ

45个android实例源码

分享45个android实例源码,很好很强大http://www.apkbus.com/android-20978-1-1.html andriod闹钟源代码http://www.apkbus.com/android-20974-1-1.html android源码分享之指南针程序http://www.apkbus.com/android-20973-1-1.html 重力感应的测试程序andriod源代码http://www.apkbus.com/android-20972-1-1.html