我要摇摇棒的代码和硬件图,谁给个参考一下?

 我来答
chuanshanfeng
推荐于2016-06-29 · 超过10用户采纳过TA的回答
知道答主
回答量:16
采纳率:0%
帮助的人:20万
展开全部

摇摇棒这个玩意我上个学期做过几个,都很成功。你想做的话,按下面的硬件图做吧,这个代码烧上去定可以运行。想当年我在网上找个东西干,调试了半天。。。。不懂的就问。

说明一下哦,有一些人说没有取模软件做不了。其实不然,我都是人工取模的,只不过是麻烦一点而已。你试着将下面的十六进制数展开成二进制数,并排成一个方阵,你就知道是怎么回事了。

/**********************函数参数解释***********************

disp:显示的汉字=每次显示汉字(参数i=32为两个字,依次增加,

     同时满足disp*x中x=i*2)*disp

 pic:显示的字符图样的种数,该参数+1,则在原来的基础上加多

     一种显示的字符,要给相应的字符加上取模数组,同时要编

写display显示子函数,并在中断选择中加上相应的函数。

**********************************************************/

#include <AT89X52.h>

#define uchar unsigned char

#define uint unsigned int    //宏定义

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

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

uchar disp=0;     //显示汉字指针,该参数+1的话,显示的字符多4个,同时要给要显示的汉字取模加到汉字数组中。

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

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,/*LOVE*/

};

uchar code loveyou[] = {

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 jiayou[]={

/*---------------加----------------*/

0x08,0x20,0x08,0x18,0x08,0x06,0xFF,0x09,0x08,0x10,0x08,0x10,0xF8,0x0F,0x00,0x00,

0xF8,0x1F,0x08,0x08,0x08,0x08,0x08,0x08,0xFC,0x1F,0x08,0x00,0x00,0x00,0x10,0x04,

/*---------------油----------------*/

0x62,0x04,0x04,0x3E,0x8C,0x01,0x40,0x00,0xF8,0x3F,0x08,0x11,0x08,0x11,0x08,0x11,

0xFF,0x1F,0x08,0x11,0x08,0x11,0xFC,0x3F,0x08,0x00,0x00,0x00,0x00,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 hehe[] = {

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

0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0x40,0x01,0xC0,0x01,0x00,0x00,0x00,0x00,

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

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

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

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

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

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

};

unsigned char code hanzi[] = {

//-- 欢 --

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

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

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

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

//-- 迎 --

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

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

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

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

//-- 使 --

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

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

      0x14,0x19,0xFF,0x17,0x14,0x21,0x14,0x21,

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

//-- 用 --

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

      0x22,0x02,0x22,0x02,0x22,0x02,0xFE,0x7F,

      0x22,0x02,0x22,0x02,0x22,0x42,0x22,0x82,

      0xFF,0x7F,0x02,0x00,0x00,0x00,0x00,0x00,

//-- 神 --

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

      0x58,0x00,0x88,0x00,0x00,0x00,0xF8,0x1F,

      0x88,0x08,0x88,0x08,0xFF,0xFF,0x88,0x08,

      0x88,0x08,0xFC,0x1F,0x08,0x00,0x00,0x00,

//-- 奇 --

      0x40,0x00,0x40,0x00,0x44,0x00,0x44,0x3E,

      0x64,0x12,0x54,0x12,0x4C,0x12,0x47,0x12,

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

      0x44,0x00,0x60,0x00,0x40,0x00,0x00,0x00,

//-- 魔 --

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

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

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

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

//-- 幻 --

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

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

      0x04,0x00,0x04,0x20,0x04,0x40,0x04,0x80,

      0x04,0x40,0xFE,0x3F,0x04,0x00,0x00,0x00,

//-- 摇 --

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

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

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

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

//-- 摇 --

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

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

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

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

//-- 棒 --

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

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

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

      0x56,0x12,0x44,0x06,0x40,0x02,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

};

unsigned char code wode[]={

/*---------------祝----------------*/

0x08,0x01,0x88,0x00,0xC9,0x3F,0x6E,0x00,0x98,0x20,0x00,0x21,0x7E,0x10,0x42,0x0C,

0xC2,0x03,0x42,0x00,0xC2,0x1F,0x42,0x20,0x7F,0x20,0x02,0x38,0x00,0x00,0x00,0x00,

/*---------------你----------------*/

0x40,0x00,0x20,0x00,0x10,0x00,0xFC,0x3F,0x43,0x08,0x20,0x04,0x98,0x03,0x0F,0x10,

0x08,0x20,0xE8,0x1F,0x08,0x00,0xA8,0x00,0x1C,0x03,0x08,0x0C,0x00,0x00,0x00,0x00,

/*---------------们----------------*/

0x40,0x00,0x20,0x00,0xF8,0x3F,0x07,0x00,0x00,0x00,0xF8,0x3F,0x02,0x00,0x04,0x00,

0x00,0x00,0x04,0x00,0x04,0x10,0x04,0x20,0xFE,0x1F,0x04,0x00,0x00,0x00,0x00,0x00,

/*---------------中----------------*/

0x00,0x00,0xF8,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0x08,0x01,0xFF,0x3F,0x08,0x01,

0x08,0x01,0x08,0x01,0x08,0x01,0xFC,0x01,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

/*---------------秋----------------*/

0x14,0x04,0x14,0x03,0x94,0x00,0xFE,0x3F,0x93,0x00,0x12,0x21,0x40,0x10,0x30,0x0C,

0x00,0x03,0xFF,0x00,0x40,0x03,0x20,0x0C,0x18,0x30,0x00,0x10,0x00,0x00,0x00,0x00,

/*---------------节----------------*/

0x04,0x00,0x24,0x00,0x24,0x00,0x24,0x00,0x24,0x00,0x3F,0x00,0xE4,0x3F,0x24,0x00,

0x24,0x00,0x3F,0x04,0x24,0x08,0xE4,0x07,0x06,0x00,0x04,0x00,0x00,0x00,0x00,0x00,

/*---------------快----------------*/

0x70,0x00,0x00,0x00,0xFF,0x3F,0x08,0x00,0xB0,0x20,0x88,0x10,0x88,0x08,0x88,0x06,

0xFF,0x01,0x88,0x06,0x88,0x08,0xFC,0x10,0x88,0x30,0x80,0x10,0x00,0x00,0x00,0x00,

/*---------------乐----------------*/

0x00,0x00,0x00,0x10,0x70,0x08,0x4E,0x04,0x42,0x03,0x42,0x10,0x42,0x20,0xFA,0x1F,

0x42,0x00,0x41,0x01,0x41,0x02,0x41,0x04,0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,

/*---------------!----------------*/

0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x5F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

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

};

/*****函数声明*****/

void display1(void);

void display2(void);

void display3(void);

void display4(void);

void display5(void);

void display6(void);

/*****n(单位us微秒)延时子程序*****/

void DelayUs(uint N)

{

 uint x;

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

}

/*****主函数*****/

void main(void)

{

 IT0=1;

 EX0=1; 

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

 KY=0;

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

 {

  if(KEY==0)     //图案切换键按下

  {

   DelayUs(20000);     //去除按键抖动

   if(KEY==0);

   {

   pic++;

   disp=0;

   num=0;

   } //endif

  } //endif

  

 } //endwhile

} //endmain

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

void intersvr0(void) interrupt 0 using 1

{

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

 if(KY==0)

 {

 if(pic>5)pic=0;//总共有6个图案

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

  switch(pic)      //选择显示图案

  {

   case 0:{display1();}break;

   case 1:{display2();}break;

   case 2:{display3();}break;

   case 3:{display4();}break;

   case 4:{display5();}break;

   case 5:{display6();}break;

   default:{display1();}  

  }

    }

}

/*****显示子程序1(LOVE)*****/

void display1(void)

{

 uchar i;

 DelayUs(7000);

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

 {

     P0=~love[i*2];

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

     DelayUs(150);

 }

}

/*****显示子程序2(心形图案)*****/

void display2(void)

{

 uchar i;

  DelayUs(7000);

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

 {

     P0=~loveyou[i*2];

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

     DelayUs(150);

 }

}

/*****显示子程序3(汉字)*****/

void display3(void)

{uchar i=0;

 if(num>5){disp++;num=0;}     //12个汉字若分为6次显示完(每次显示2个),每中断5次切换(画面显示5次切换)

 if(disp>5)disp=0;           //有六个画面,0至5这六个,到第五个后,返回这组图案中的第0个画面

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

  //显示的汉字=每次显示汉字(参数i=32为两个字,依次增加,同时满足disp*x中x=i*2)*disp。

 for(i=0;i<32;i++)

 {

     P0=~hanzi[disp*64+i*2];// 取反(与所取的模有关)

     P2=~hanzi[disp*64+i*2+1];

     DelayUs(150);//LED灯闪烁的时间间隔(与摇动的速度有关,摇动的速度一定,时间越少,字越狭窄)。

 }

}

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

void display4(void)

{

 uchar i;

 DelayUs(6500);

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

 {

     P0=~hehe[i*2];

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

     DelayUs(145);

 }

}

/*****显示子程序5(汉字)*****/

void display5(void)

{uchar i=0;

 if(num>3){disp++;num=0;}     //11个汉字若分为11次显示完(每次显示1个),每中断3次切换画面

 if(disp>2)disp=0;          //共有三个画面,第二个画面后,返回到第0个画面

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

  //显示的汉字=每次显示汉字(参数i=32为两个字,依次增加,同时满足disp*x中x=i*2)*disp。

 for(i=0;i<48;i++)

 {

     P0=~wode[disp*96+i*2];

     P2=~wode[disp*96+i*2+1];

     DelayUs(150);

 }

}

/*****显示子程序6(汉字)*****/

void display6(void)

{uchar i=0;

 if(num>3){disp++;num=0;}     //3个汉字若分为1次显示完(每次显示1个),每中断3次切换画面

 if(disp>0)disp=0;          //共有1个画面,第0个画面后,返回到第0个画面

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

  //显示的汉字=每次显示汉字(参数i=32为两个字,依次增加,同时满足disp*x中x=i*2)*disp。

 for(i=0;i<48;i++)

 {

     P0=~jiayou[disp*96+i*2];

     P2=~jiayou[disp*96+i*2+1];

     DelayUs(150);

 }

}

/*****END*****/

德晟智能
2024-09-04 广告
舵机在机器人上的应用非常广泛,它通常作为机器人的关键驱动执行部件,用于实现精确的角度控制和位置定位。以下是舵机在机器人上的一些具体应用:1、关节驱动:在仿人型机器人、机械臂或多足机器人中,舵机被用于驱动各个关节的运动。通过控制舵机的旋转角度... 点击进入详情页
本回答由德晟智能提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式