• 回复
  • 收藏
  • 点赞
  • 分享
  • 发新帖

祝女神生日快乐! 小小的摇摇棒

LED摇摇棒很好地利用了人眼的视觉暂留特性。下图是基于51单片机控制、32只高亮度LED发光LED构成的摇摇棒,配合手的左右摇晃就可呈现一幅完整的画面,可以显示字符、图片等。演示效果见自制LED摇摇棒效果展示图

    黑暗条件下拍摄的效果图片:

基本原理与硬件电路设计:

       32只LED发光管作为画面每一列的显示,左右摇晃起到了扫描的作用,人眼的视觉暂留现象使得看到的是一幅完整的画面。与LED点阵的显示有几分相仿。

        硬件电路如下图(点击可放大)   由于上传不上去我画的图,所以就截图分享一下!

        水银开关的作用:棒在摇动时,只能在朝某一方向摇动时显示,否则会出现镜像字或者镜像画面,所以采用接一支水银开关来进行控制,使摇摇棒在摇动过程时将内容显示出来。

硬件制作:包含单片机、PCB板、32个高亮蓝光LED、电池盒、震动开关、轻触按键、3pin插针(预留的程序下载接口)

水银开关里的水银珠很活跃,导致在接通时容易产生抖动,所以将水银开关斜向上放置(尖尖朝斜上方45°角),靠水银珠自身重力的作用减少抖动。

IC座里面隐藏元件,既美观又能保护元件:

软件设计:

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

/*    : 摇摇棒程序,通过滚珠开关检测周期,摇动时间自适应,图像始终保持在中间。开机后每摇晃10次切换下一组字模

/* 按了一下按键后变成了手动切换,直到回到第一组字的时候再自动切换

最后祝各位制作成功!学习进步!       

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

#include

/*********外部接口定义**********/

#define uchar unsigned char

#define uint unsigned int    //宏定义

#define out P1       //数据输出端口

sbit led1=P3^0;      //1LED

sbit led2=P3^1;      //2LED

sbit led3=P3^3;      //3LED

sbit led4=P3^4;      //4LED

sbit key1=P3^5;     //按键输入

sbit p3_2=P3^2;

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

uchar BUFF;                            //缓存

/*********全局变量定义**********/

unsigned long int TimeCount=0;

unsigned int   DelayN=80,           //延时临时计数

                            DelayTime=80;      //每次延时的周期个数

unsigned char key,keyy;       

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

void delay(unsigned char n);

void DelayMs(void);

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

 

unsigned char code text0[]={

 

 

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/

 

0x20,0x00,0x20,0x80,0x20,0x80,0x20,0x46,0xA0,0x45,0x70,0x28,0x2F,0x28,0x20,0x10,0x20,0x18,0x20,0x26,0xE0,0x21,0x20,0x40,0x20,0x80,0x20,0x00,0x20,0x00,0x00,0x00,/*"",1*/

 

0x08,0x02,0x08,0x01,0x89,0x00,0xEE,0xFF,0x98,0x00,0x00,0x03,0x00,0x00,0xF8,0x1F,0x88,0x08,0x88,0x08,0xFF,0xFF,0x88,0x08,0x88,0x08,0xF8,0x1F,0x00,0x00,0x00,0x00,/*"",2*/

0x80,0x40,0x40,0x40,0x30,0x42,0x1E,0x42,0x10,0x42,0x10,0x42,0x10,0x42,0xFF,0x7F,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x42,0x10,0x40,0x00,0x40,0x00,0x00,/*"",0*/

 

0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0x82,0x40,0x82,0x40,0x82,0x40,0x82,0x40,0x82,0x40,0x82,0x40,0x82,0x40,0xFE,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"",1*/

 

0x00,0x01,0xE0,0x00,0x00,0x00,0xFF,0xFF,0x10,0x00,0x20,0x81,0x08,0x41,0x08,0x31,0x08,0x0D,0xFF,0x03,0x08,0x0D,0x08,0x31,0xF8,0x41,0x00,0x81,0x00,0x81,0x00,0x00,/*"",2*/

 

0x00,0x00,0x00,0x20,0xE0,0x10,0x9C,0x08,0x84,0x06,0x84,0x40,0x84,0x80,0xF4,0x7F,0x82,0x00,0x82,0x00,0x83,0x02,0x82,0x04,0x80,0x08,0x80,0x30,0x00,0x00,0x00,0x00,/*"",3*/

 

 

 

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0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,0xF0,0x03,0x00,0x00,0xF8,0x03,0x00,0x00,0xFC,0x03,0x00,0x00,0xFE,0x03,0x00,0x00,0xFF,0x07,0x00,0x80,0xFF,0x0F,0x00,0xC0,0xFF,

0x1F,0x00,0xE0,0xFF,0x3F,0x00,0xE0,0xFF,0xFF,0x00,0xF8,0xFF,0xFF,0x01,0xFC,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,

0x07,0x00,0x00,0xE0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xC0,0xFF,0xFF,0xFF,0xC7,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,

0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xCF,0xFF,0xFF,0xFF,0xC7,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xC0,0x07,0x00,0x00,0xE0,0xFF,0xFF,0xFF,0xFF,/*"未命名文件",0*/

 

 

};

unsigned char code text3[]={

 

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",0*/

 

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",1*/

 

0x00,0x08,0x00,0x04,0x00,0x03,0xE0,0x00,0x00,0x00,0x00,0x40,0x00,0x80,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x80,0x01,0x00,0x0E,0x00,0x00,/*"",0*/

 

0x10,0x04,0x60,0x04,0x02,0x7E,0x8C,0x01,0x00,0x00,0x44,0x00,0x54,0xFF,0x54,0x15,0x54,0x15,0x7F,0x15,0x54,0x55,0x54,0x95,0x54,0x7F,0x44,0x00,0x40,0x00,0x00,0x00,/*"",1*/

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",4*/

 

0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*" ",5*/

0x40,0x20,0x44,0x12,0x54,0x4A,0x65,0x82,0xC6,0x7F,0x64,0x02,0x54,0x0A,0x44,0x92,0x00,0x60,0xFC,0x1F,0x44,0x00,0x44,0x00,0xC4,0xFF,0x42,0x00,0x40,0x00,0x00,0x00,/*"",2*/

 

0x40,0x00,0x40,0x40,0x42,0x20,0xCC,0x1F,0x00,0x20,0x88,0x40,0x89,0x50,0x8E,0x48,0x88,0x46,0xF8,0x41,0x88,0x42,0x8C,0x44,0x8B,0x58,0x88,0x40,0x80,0x40,0x00,0x00,/*"",3*/

 

 

};

/***********nus)延时子程序***************/

void DelayUs(uint N)

{

 uint x;

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

}

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

void main()

{    

       AUXR=0x80;

       CLK_DIV=0; 

       EX0=1;   //开放外部中断0

       IT0=1;    //中断0为边沿触发方式

       IP=0x02; //设置中断优先级

       TMOD=0x02; //定时器0方式28位重装载

       TH0=0x80;     //设定定时器初值

       TL0=0x80;              

       KY=0;

       EA=1;     //开放中断

       ET0=1;   //开放定时器0中断

       TR0=1;   //启动定时器0,开始计时*/

       key=0;    //初始化显示第一组文字

       keyy=0;

       P1M0=0x55;   //0101 0101    /P1.0  P1 .2 P1.4 P1.6推挽输出

    P1M1=0xAA;

 

       while(1){//等待中断

         

       if(key1==0){  //有键按下

        DelayUs(50);

        if(key1==0){                    

              key++;                         //更换下一幅图片        

              if(key>2) key=0;    //图片循环显示 根据显示的组数来定义 这里有9 所以就要keyy>9

              while(key1==0);           //等待按键释放                  

              }

              }

       if(num>10) //每中断10次切换

              {

              keyy++;

              num=0;

              }    

        if(keyy>2)keyy=0; //图片循环显示 根据显示的组数来定义 这里有9 所以就要keyy>9

       }    

}

  

/*********文字显示子程序**********/

 

void display_word(unsigned char code *text)

{

   unsigned   char i,j=2;                     //j为图片起始位置 3 为第3个开始是图片 如果要显示高时32的大字 也属于图片格式

    DelayUs(6300);     

      

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

       {

            

        P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;

              if((key>=j)||(keyy>=j))

              BUFF=(*(text+i*4+3));

              else                     

              BUFF=(*(text+128+i*2+1));

              led4=0;

              P1=~BUFF>>1;

              P3M0=0x10;                 //0001 0000    //P3.4推挽输出 P3 .0 P3.3 P3.1输入高阻

           P3M1=0x0B;          //0000 1011

               delay(1);

              P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;                      //0001 1011

              led4=1;

          P1=BUFF;             //01010101  1357

              P3M0=0x10;                 //0001 0000    //P3.4推挽输出 P3 .0 P3.3 P3.1输入高阻

           P3M1=0x0B;          //0000 1011

             delay(1);

              P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;                      //0001 1011

              if((key>=j)||(keyy>=j))

              BUFF=(*(text+i*4+2));

              else

              BUFF=(*(text+128+i*2));

              led3=0;

              P1=~BUFF>>1;

              P3M0=0x08;                 //0000 1000    //P3.3推挽输出 P3 .0 P3.1 P3.4输入高阻

           P3M1=0x13;          //0001 0011

              delay(1);

              P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;                      //0001 1011

              led3=1;

          P1=BUFF;             //01010101  1357

              P3M0=0x08;                 //0000 1000    //P3.3推挽输出 P3 .0 P3.1 P3.4输入高阻

           P3M1=0x13;          //0001 0011

             delay(1);

              P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;

              if((key>=j)||(keyy>=j))

              BUFF=(*(text+i*4+1));

              else

              BUFF=(*(text+i*2+1));

              led2=0;

           P1=~BUFF>>1;

              P3M0=0x02;                 //0000 0010    //P3.1推挽输出 P3 .0 P3.3 P3.4输入高阻

           P3M1=0x19;                 //0001 1001

              delay(1);

              P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;                      //0001 1011

              led2=1;      

          P1=BUFF;            //01010101  1357

              P3M0=0x02;                 //0000 0010    //P3.1推挽输出 P3 .0 P3.3 P3.4输入高阻

           P3M1=0x19;                 //0001 1001

             delay(1);

              P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;                      //0001

              if((key>=j)||(keyy>=j))

              BUFF=(*(text+i*4));

              else

              BUFF=(*(text+i*2));

              led1=0;

              P1=~BUFF>>1;

              P3M0=0x01;                 //0000 0001    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1A;                      //0001 1010

              delay(1);

           P3M0=0x00;                 //0000 0000    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1B;                      //0001 1011

              led1=1;                  

          P1=BUFF;            //01010101  1357

              P3M0=0x01;                 //0000 0001    //P3.0推挽输出 P3 .1 P3.3 P3.4输入高阻

           P3M1=0x1A;                      //0001 1010

             delay(1);

 

} }

/*********显示内容选择子程序**********/

void display(unsigned char t)

{     keyy=0;

       switch (t){             //通过按键选择显示内容

              case 0:     {display_word(text0);}break;

              case 1:     {display_word(text1);}break;

              case 2:     {display_word(text2);}break;

              case 3:     {display_word(text3);}break;

//            case 4:     {display_word(text4);}break;

//            case 5:     {display_word(text5);}break;

//            case 6:     {display_word(text6);}break;

//            case 7:     {display_word(text7);}break;

       //     case 8:     {display_word(text8);}break;             

       //     case 9:     {display_word(text9);}break;

       //     case 10:{display_word(text10);}break;

              //default:{display_word(text1);}

             

             

              }}

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

void display1(unsigned char y)

{

       switch (y){            //通过按键选择显示内容

              case 0:     {display_word(text0);}break;

              case 1:     {display_word(text1);}break;

              case 2:     {display_word(text2);}break;

              case 3:     {display_word(text3);}break;

//            case 4:     {display_word(text4);}break;

//            case 5:     {display_word(text5);}break;

//            case 6:     {display_word(text6);}break;

//            case 7:     {display_word(text7);}break;

       //     case 8:     {display_word(text8);}break;

       //     case 9:     {display_word(text9);}break;

       //     case 10:{display_word(text10);}break;

              }

              }

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

/*********延时子程序**********/

void delay(unsigned char n)

{

       for(;n>0;n--){

              DelayN=DelayTime;

              while (DelayN);

       }

}

/*********中断子程序**********/

void int0() interrupt 0    //使用外部中断0

{

 KY=~KY;

 if(KY==0)

 {                 

       DelayTime=TimeCount/1580;      

       TimeCount=0; //延时周期计数清零

       if(key==0)

       {

        num++;

        display1(keyy);    //根据按键选择循环显示文字

       }

       else

       {

       display(key);   //根据按键选择循环显示文字

       }

}

}

void timer0() interrupt 1              //定时器0中断子程序

{

       TimeCount++;

       if (DelayN!=0)

       DelayN--;

}

最后别的不多说了,自己刚刚学习,希望大家可以多多给予小清新同学在学习上面的帮助,十分感谢各位!

全部回复(20)
正序查看
倒序查看
2014-09-17 09:47
话说女神追到了嘛?
0
回复
小清新
LV.5
3
2014-09-17 10:12
@电源网-天边
话说女神追到了嘛?
只是祝她生日快乐,朋友而已!
0
回复
2014-09-17 10:28
@小清新
只是祝她生日快乐,朋友而已!
你以为你娜娜姐和天边姐会相信么,和娜娜姐说说,帮你追!~~
0
回复
小清新
LV.5
5
2014-09-17 12:33
@电源网-娜娜姐
你以为你娜娜姐和天边姐会相信么[图片],和娜娜姐说说,帮你追!~~
哈哈  娜娜姐别逗了  那你不信  它也是事实啊  所谓事实胜于雄辩!
0
回复
2014-09-17 13:16
@电源网-娜娜姐
你以为你娜娜姐和天边姐会相信么[图片],和娜娜姐说说,帮你追!~~
娜娜姐要帮忙了哇
0
回复
小清新
LV.5
7
2014-09-17 17:15
@西华杨林
娜娜姐要帮忙了哇
娜娜姐  和天边姐在这逗我玩呢
0
回复
2014-09-18 09:35
@小清新
娜娜姐 和天边姐在这逗我玩呢
清新啊~~你现在大几啦?
0
回复
2014-09-18 09:36
@西华杨林
娜娜姐要帮忙了哇
哈哈 娜娜姐一出手,木有不成的事儿啦
0
回复
小清新
LV.5
10
2014-09-18 11:11
@电源网-天边
哈哈娜娜姐一出手,木有不成的事儿啦
哈哈  娜娜姐无敌的存在!
0
回复
2014-09-18 14:31
@小清新
哈哈 娜娜姐别逗了 那你不信 它也是事实啊 所谓事实胜于雄辩!
事实是可以改变滴,只要你想 哈哈~
0
回复
2014-09-18 14:31
@小清新
哈哈 娜娜姐无敌的存在!
嗯哼,哈哈 清新你毕业了嘛~
0
回复
小清新
LV.5
13
2014-09-18 15:46
@电源网-娜娜姐
嗯哼,哈哈清新你毕业了嘛~
还没呢,刚刚大三!还在努力学习中!
0
回复
2014-09-18 15:52
@小清新
还没呢,刚刚大三!还在努力学习中!
明年是不是还有一次参加设计大赛的机会啊?
0
回复
小清新
LV.5
15
2014-09-18 17:18
@电源网-天边
明年是不是还有一次参加设计大赛的机会啊?
嗯   还有一次参加国赛的机会!
0
回复
2014-09-18 17:37
@小清新
嗯 还有一次参加国赛的机会!
加油!
0
回复
小清新
LV.5
17
2014-09-18 17:42
@西华杨林
加油!
一定的   会继续努力的!
0
回复
SKY丶辉煌
LV.10
18
2014-09-23 22:21
@小清新
一定的 会继续努力的!
不错~
0
回复
小清新
LV.5
19
2014-09-24 08:39
@SKY丶辉煌
不错~
还好   在你面前就是个小菜鸟啦    哈哈
0
回复
2015-11-04 20:54
我做了一个16灯的摇摇棒,但是取出来的字模老是不对,能不能把你的取字模软件发一下
0
回复
一人醉
LV.1
21
2017-04-06 21:52
版主啊 你的水印开关在哪儿连着啊
0
回复