<strike id="um4h1"></strike>
<legend id="um4h1"><pre id="um4h1"><dl id="um4h1"></dl></pre></legend>
<th id="um4h1"><track id="um4h1"></track></th>
  • <dd id="um4h1"></dd><nav id="um4h1"><sub id="um4h1"></sub></nav>
    <rp id="um4h1"></rp>

    <dd id="um4h1"></dd>
    1. <th id="um4h1"></th>
       找回密碼
       馬上注冊

      QQ登錄

      只需一步,快速開始

      搜索

      [ 單片機 ] 迷你搖搖棒制作

      2014-4-27 18:48| 發布者: 513696765 | 查看: 12329

          手頭上攢了一些手機電池不知道干嘛就尋思著做一些小玩意,于是就有了一個主意就是搖搖棒即簡單又好玩,本人喜歡小而巧的東西所以就把這個東西做的很小。

          上圖是搖搖棒的原理利用人的視覺暫留結合單片機控制LED的亮滅就可以在空中顯示字符或者圖標。

          上圖是電路圖為了把東西做小我選擇了STC15F104單片機它有8個引腳去除VCC和GND還有6個I/O口可以顯示一些簡單的字母和數字單片機內部自帶了EEPROM所以利用它可以存儲每一次顯示的狀態(每一次的開關電源就可以切換到下一個顯示的字符)

      程序在最后面。






      代碼在下面:

      #include
      #define uchar unsigned char
      #define EN_EPROM 0x83;        //使能EEPROM
      #define S_MODE     0x00;        //待機模式
      #define R_MODE     0x01;        //讀模式
      #define W_MODE     0x02;        //寫模式
      #define F_MODE     0x03;        //擦除模式
      sfr IAP_DATA  =  0xC2;
      sfr IAP_ADDRH =  0xC3;
      sfr IAP_ADDRL =  0xC4;
      sfr IAP_CMD   =  0xC5;
      sfr IAP_TRIG  =  0xC6;
      sfr IAP_CONTR =  0xC7;
      void init();
      uchar num=0,m=0;
      uchar read_dat(uchar addr_h,uchar addr_l);
      void erase_dat(uchar addr_h,uchar addr_l);
      void write_dat(uchar addr_h,uchar addr_l,uchar w_dat);
      unsigned char code tab[10][32]={
          {
              0xe7,0xc3,0xc1,0xe0,0xc1,0xc3,0xe7,0xff,
              0xff,0xff,0xff,0xe7,0xc3,0xc1,0xe0,0xc1,
              0xc3,0xe7,0xff,0xff,0xff,0xff,0xe7,0xc3,
              0xc1,0xe0,0xc1,0xc3,0xe7,0xff,0xff,0xff         
          },

          {
              0xff,0xff,0xde,0xc0,0xde,0xff,0xff,0xff,
              0xff,0xff,0xff,0xe7,0xc3,0xc1,0xe0,0xc1,
              0xc3,0xe7,0xff,0xff,0xff,0xff,0xff,0xc1,
              0xfe,0xfe,0xfe,0xfe,0xc1,0xff,0xff,0xff       
          },

          {
               0xde,0xed,0xf3,0xf3,0xed,0xde,0xff,0xff,
              0xff,0xff,0xff,0xde,0xed,0xf3,0xf3,0xed,
              0xde,0xff,0xff,0xff,0xff,0xff,0xff,0xde,
              0xed,0xf3,0xf3,0xed,0xde,0xff,0xff,0xff       
          },

          {
              0xfb,0xfd,0xd6,0xe8,0xd6,0xfd,0xfb,0xff,
              0xff,0xff,0xff,0xfb,0xfd,0xd6,0xe8,0xd6,
              0xfd,0xfb,0xff,0xff,0xff,0xff,0xfb,0xfd,
              0xd6,0xe8,0xd6,0xfd,0xfb,0xff,0xff,0xff        
          },

          {
               0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5,
              0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5,
              0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5,
              0xea,0xd5,0xea,0xd5,0xea,0xd5,0xea,0xd5       
          },
         
          {
               0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff,
              0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff,
              0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff,
              0xfa,0xfd,0xfa,0xff,0xef,0xd7,0xef,0xff       
          },
         
          {
              0xf0,0xed,0xdd,0xed,0xf0,0xff,0xff,0xdf,
              0xdf,0xc0,0xdf,0xdf,0xff,0xff,0xc1,0xfe,
              0xfe,0xfe,0xc1,0xff,0xff,0xc1,0xfe,0xf1,
              0xfe,0xc1,0xff,0xff,0xe1,0xde,0xde,0xe1     
          },
         
          {
              0xc0,0xfb,0xfb,0xfb,0xc0,0xff,0xff,0xff,
              0xff,0xff,0xde,0xed,0xf3,0xf3,0xed,0xde,
              0xff,0xff,0xff,0xff,0xff,0xff,0xcf,0xf7,
              0xf8,0xf7,0xcf,0xff,0xff,0xff,0xff,0xff     
          },
         
          {
              0xc0,0xde,0xd2,0xda,0xda,0xc2,0xfe,0xc0,
              0xdf,0xd0,0xd6,0xd6,0xd2,0xde,0xc0,0xff,
              0xc0,0xde,0xd2,0xda,0xda,0xc2,0xfe,0xc0,
              0xdf,0xd0,0xd6,0xd6,0xd2,0xde,0xc0,0xff
          },
         
          {
              0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,
              0xf7,0xef,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,
              0xfd,0xfb,0xf7,0xef,0xdf,0xef,0xf7,0xfb,
              0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xff
          },
      };                                     
      void delay(uchar xms)
      {
          char i,j;
          for(i=0;i    for(j=0;j<50;j++);
      }
      void main()
      {
          init();
          num=read_dat(0x00,0x01);
          ++num;
          if(num>=11)
          {
              num=1;
          };   

          erase_dat(0x00,0x01);
          write_dat(0x00,0x01,num);
          while(1)
          {
              uchar i=0;
             
              for(i=0;i<32;i++)
              {
                  P3=tab[num-1][i];
                  delay(100);
              }           
          }   
      }

      void init()
      {
          IAP_CONTR    = EN_EPROM;        //把第7位置1允許EEPROM可以讀寫
          IAP_CMD     = S_MODE;        //待機模式無ISP操作
          IAP_ADDRH    = 0x00;
          IAP_ADDRL    = 0x00;

      }

      uchar read_dat(uchar addr_h,uchar addr_l)
      {
          uchar E_dat = 0x00;
          IAP_CMD     = R_MODE;        //模式選擇為讀EEPROM
          IAP_ADDRH    = addr_h;
          IAP_ADDRL    = addr_l;
          IAP_TRIG    = 0x5A;        //使命令有效
          IAP_TRIG    = 0xA5;        //使命令有效
          E_dat        = IAP_DATA;
          return E_dat;
      }

      void write_dat(uchar addr_h,uchar addr_l,uchar w_dat)
      {
          IAP_CMD     = W_MODE;        //模式選擇為寫EEPROM
          IAP_ADDRH    = addr_h;
          IAP_ADDRL    = addr_l;
          IAP_DATA    = w_dat;
          IAP_TRIG    = 0x5A;        //使命令有效
          IAP_TRIG    = 0xA5;        //使命令有效

      }

      void erase_dat(uchar addr_h,uchar addr_l)
      {
          IAP_CMD     = F_MODE;        //模式選擇為擦除EEPROM
          IAP_ADDRH    = addr_h;
          IAP_ADDRL    = addr_l;
          IAP_TRIG    = 0x5A;        //使命令有效
          IAP_TRIG    = 0xA5;        //使命令有效
      }

      收藏 邀請
      已有6人參與

      會員評論

      • 引用 科技小人 2016-10-3 15:15
        不錯,我也做了一個,用的stc15f104w,航模鋰供電
      • 引用 開心^ω^ 2016-6-24 16:06
      • 引用 renliuxin 2014-4-29 08:03
        關注一下
      • 引用 召淘寶人員 2014-4-28 21:25
        利用閑余時間,給自己找份宅家的網絡差事吧~ ~不限制工作時間,做的越多掙的越多~~每天4 O~1 O O左右 。(寶媽、學生、上班族都可以)有意者【dwz.cn/gkvFd】復制到瀏覽器打開 ~即可報名咨詢 ~會有客服作詳細講解
      • 引用 1007607224 2014-4-28 18:28
        我支持,還行吧

      查看全部評論>>

      推薦閱讀

      QQ|極客迷網 ( ICP09011854

      44030602000010

      © 2009-2016 All Rights Reserved

      GMT+8, 2022-4-16 21:16 , Processed in 0.107964 second(s), 20 queries , Gzip On, Memcache On.