找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4093|回復(fù): 5
打印 上一主題 下一主題
收起左側(cè)

基于51單片機(jī)的光立方自作

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:145172 發(fā)表于 2016-10-30 10:14 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
這是做好后的效果  還是很炫的


制作要的點(diǎn):
1.單片機(jī)必須用STC12C5A60S2  因?yàn)榈退?1根本帶不動(dòng) 它的運(yùn)算速度要求非常高.
2.也就是晶振要用24M的提供高速.
3.硬件制作,很考驗(yàn)?zāi)土Φ钠渲泻?12個(gè)led;
//簡(jiǎn)單控制。用于檢驗(yàn)等的好壞。

需要的可以自行下載 : 888光立方.rar (82.83 KB, 下載次數(shù): 766)

  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. sbit dula0=P2^0; sbit dula1=P2^1;
  5. sbit dula2=P2^2; sbit dula5=P2^5;
  6. sbit dula3=P2^3; sbit dula6=P2^6;
  7. sbit dula4=P2^4; sbit dula7=P2^7;

  8. sbit key0=P3^2;sbit key1=P3^3;sbit key2=P3^4;sbit key3=P3^5;

  9. void delayms(uint xam)
  10. {
  11.   uint x,y;
  12.   for(x=xam;x>0;x--)
  13.      for(y=110;y>0;y--);
  14. }

  15. void keyscan()
  16. {
  17.    if(key0==0)
  18.    {
  19.      delayms(10);
  20.          if(key0==0)
  21.          {
  22.            P1=0x00;P1=0xff;P2=0x00;
  23.            dula0=1;P0=0xff;dula0=0;dula1=1;P0=0xff;dula1=0;
  24.            dula2=1;P0=0xff;dula2=0;dula3=1;P0=0xff;dula3=0;
  25.        dula4=1;P0=0xff;dula4=0;dula5=1;P0=0xff;dula5=0;
  26.            dula6=1;P0=0xff;dula6=0;dula7=1;P0=0xff;dula7=0;
  27.            while(!key0);
  28.           }
  29.         }

  30.         if(key1==0)
  31.         {
  32.           delayms(10);
  33.           if(key1==0)
  34.           {
  35.              P1=0x00;P1=0xFF;dula0=0x00;delayms(3);
  36.                  P1=0X00;P1=0XFF;dula1=0X81;delayms(3);
  37.                  P1=0X00;P1=0X81;dula1=0xff;delayms(3);
  38.                  P1=0X00;P1=0XFF;dula2=0X81;delayms(3);
  39.                  P1=0X00;P1=0X81;dula2=0xff;delayms(3);
  40.                  P1=0X00;P1=0XFF;dula3=0X81;delayms(3);
  41.                  P1=0X00;P1=0X81;dula3=0xff;delayms(3);
  42.                  P1=0X00;P1=0XFF;dula4=0X81;delayms(3);
  43.                  P1=0X00;P1=0X81;dula4=0xff;delayms(3);
  44.                  P1=0X00;P1=0XFF;dula5=0X81;delayms(3);
  45.                  P1=0X00;P1=0X81;dula5=0xff;delayms(3);
  46.                  P1=0X00;P1=0XFF;dula6=0X81;delayms(3);
  47.                  P1=0X00;P1=0X81;dula6=0xff;delayms(3);
  48.                  P1=0X00;P1=0XFF;dula7=0X81;delayms(3);
  49.                  P1=0X00;P1=0X81;dula7=0xff;delayms(3);
  50.                  P1=0x00;P1=0xFF;dula0=0x00;delayms(3);


  51.            while(!key1);
  52.           }
  53.         }

  54.         if(key2==0)
  55.         {
  56.           delayms(10);
  57.           if(key2==0)
  58.           {
  59.             P1=0X00;P1=0x81;P2=0X00;
  60.            dula0=1;P0=0xff;dula0=0;dula1=1;P0=0xff;dula1=0;
  61.            dula2=1;P0=0xff;dula2=0;dula3=1;P0=0xff;dula3=0;
  62.        dula4=1;P0=0xff;dula4=0;dula5=1;P0=0xff;dula5=0;
  63.            dula6=1;P0=0xff;dula6=0;dula7=1;P0=0xff;dula7=0;
  64.            delayms(1);
  65.            P1=0x42;
  66.            dula0=1;P0=0x00;dula0=0;dula1=1;P0=0x81;dula1=0;
  67.            dula2=1;P0=0x00;dula2=0;dula3=1;P0=0x00;dula3=0;
  68.        dula4=1;P0=0x00;dula4=0;dula5=1;P0=0x00;dula5=0;
  69.            dula6=1;P0=0x81;dula6=0;dula7=1;P0=0x00;dula7=0;

  70.            while(!key0);
  71.           }
  72.         }

  73.         if(key3==0)
  74.    {
  75.      delayms(10);
  76.          if(key3==0)
  77.          {
  78.            P1=0x00;P1=0xff;P2=0x00;
  79.            dula0=1;P0=0xff;dula0=0;delayms(10);dula1=1;P0=0xff;dula1=0;
  80.            dula2=1;P0=0xff;dula2=0;delayms(10);dula3=1;P0=0xff;dula3=0;
  81.        dula4=1;P0=0xff;dula4=0;delayms(10);dula5=1;P0=0xff;dula5=0;
  82.            dula6=1;P0=0xff;dula6=0;delayms(10);dula7=1;P0=0xff;dula7=0;
  83.            while(!key3);
  84.           }
  85.         }

  86. }

  87. void main()
  88. {
  89.    while(1)
  90.    {
  91.    keyscan();
  92.    delayms(10);
  93.    }
  94. }


  95. 這是金典的光立方程序
  96. #include <REG52.H>
  97. #include <intrins.h>
  98. #define uchar unsigned char

  99. #define uint unsigned int

  100. uchar display[8][8];

  101. /*rank:A,1,2,3,4,I,心,U*/

  102. uchar code table_cha[8][8]={0x51,0x51,0x51,0x4a,0x4a,0x4a,0x44,0x44,0x18,0x1c,0x18,0x18,0x18,0x18,0x18,0x3c,0x3c,0x66,0x66,0x30,0x18,0xc,0x6,0xf6,0x3c,0x66,0x60,0x38,0x60,0x60,0x66,0x3c,0x30,0x38,0x3c,0x3e,0x36,0x7e,0x30,0x30,0x3c,0x3c,0x18,0x18,0x18,0x18,0x3c,0x3c,0x66,0xff,0xff,0xff,0x7e,0x3c,0x18,0x18,0x66,0x66,0x66,0x66,0x66,0x66,0x7e,0x3c};

  103. /*the "ideasoft"*/

  104. uchar code table_id[40]={0x81,0xff,0x81,0x00,0xff,0x81,0x81,0x7e,0x00,0xff,0x89,0x89,0x00,0xf8,0x27,0x27,0xf8,0x00,0x8f,0x89,0x89,0xf9,0x00,0xff,0x81,0x81,0xff,0x00,0xff,0x09,0x09,0x09,0x01,0x0,0x01,0x01,0xff,0x01,0x01,0x00};

  105. /*railway*/

  106. uchar code dat[128]={0x0,0x20,0x40,0x60,0x80,0xa0,0xc0,0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc,0xdc,0xbc,0x9c,0x7c,0x5c,0x3c,0x1c,0x18,0x14,0x10,0xc,0x8,0x4,0x25,0x45,0x65,0x85,0xa5,0xc5,0xc9,0xcd,0xd1,0xd5,0xd9,0xb9,0x99,0x79,0x59,0x39,0x35,0x31,0x2d,0x29,0x4a,0x6a,0x8a,0xaa,0xae,0xb2,0xb6,0x96,0x76,0x56,0x52,0x4e,0x6f,0x8f,0x93,0x73,0x6f,0x8f,0x93,0x73,0x4a,0x6a,0x8a,0xaa,0xae,0xb2,0xb6,0x96,0x76,0x56,0x52,0x4e,0x25,0x45,0x65,0x85,0xa5,0xc5,0xc9,0xcd,0xd1,0xd5,0xd9,0xb9,0x99,0x79,0x59,0x39,0x35,0x31,0x2d,0x29,0x0,0x20,0x40,0x60,0x80,0xa0,0xc0,0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc,0xdc,0xbc,0x9c,0x7c,0x5c,0x3c,0x1c,0x18,0x14,0x10,0xc,0x8,0x4};

  107. /*railway 2*/

  108. uchar code dat2[28]={0x0,0x20,0x40,0x60,0x80,0xa0,0xc0,0xe0,0xe4,0xe8,0xec,0xf0,0xf4,0xf8,0xfc,0xdc,0xbc,0x9c,0x7c,0x5c,0x3c,0x1c,0x18,0x14,0x10,0xc,0x8,0x4};

  109. /*railway 3*/

  110. uchar code dat3[24]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x16,0x26,0x36,0x46,0x56,0x66,0x65,0x64,0x63,0x62,0x61,0x60,0x50,0x40,0x30,0x20,0x10};

  111. /*3p char*/

  112. uchar code table_3p[3][8]={0xff,0x89,0xf5,0x93,0x93,0xf5,0x89,0xff,0x0e,0x1f,0x3f,0x7e,0x7e,0x3f,0x1f,0x0e,0x18,0x3c,0x7e,0xff,0x18,0x18,0x18,0x18};

  113. /*initializtion

  114. That is to initialize the program .

  115. It is write to set the timer in c52 mcu.

  116. So the program can renovate the led_3d_cube in fixed time use the interrupt function.*/

  117. void sinter()

  118. {

  119.          IE=0x82;

  120.          TCON=0x01;

  121.          TH0=0xc0;

  122.          TL0=0;

  123.          TR0=1;

  124. }

  125. void delay5us(void)   //誤差 -0.026765046296us STC 1T 22.1184Mhz
  126. {
  127.     unsigned char a,b;
  128.     for(b=7;b>0;b--)
  129.         for(a=2;a>0;a--);
  130. }

  131. void delay(uint i)

  132. {                                                                                                     

  133.          while (i--){
  134.                  delay5us();}//12t的mcu 注釋這個(gè)延時(shí)即可
  135. }

  136. /*To judge the num bit*/

  137. uchar judgebit(uchar num,uchar b)

  138. {

  139.          char n;

  140.          num=num&(1<<b);

  141.          if (num)

  142.          n=1;

  143.          else

  144.          n=0;

  145.          return n;

  146. }

  147. /*To figure out the round number*/

  148. uchar abs(uchar a)

  149. {

  150.          uchar b;

  151.          b=a/10;

  152.          a=a-b*10;

  153.          if (a>=5)

  154.          b++;

  155.          return b;

  156. }

  157. /*To figure out the absolute value*/

  158. uchar abss(char a)

  159. {

  160.          if (a<0)

  161.          a=-a;

  162.          return a;

  163. }

  164. /*The function can comparat the character.

  165. And remove the big one to the back.*/

  166. void max(uchar *a,uchar *b)

  167. {

  168.    uchar t;

  169.    if ((*a)>(*b))

  170.    {

  171.                    t=(*a);

  172.                    (*a)=(*b);

  173.                    (*b)=t;   

  174.    }

  175. }

  176. /*The function is to figure out the max number and return it.*/

  177. uchar maxt(uchar a,uchar b,uchar c)

  178. {

  179.          if (a<b)

  180.          a=b;

  181.          if (a<c)

  182.          a=c;

  183.          return a;

  184. }

  185. void clear(char le)

  186. {

  187.          uchar i,j;

  188.          for (j=0;j<8;j++)

  189.          {

  190.                    for (i=0;i<8;i++)

  191.                    display[j][i]=le;

  192.          }

  193. }

  194. void trailler(uint speed)

  195. {

  196.          char i,j;

  197.          for (i=6;i>=-3;i--)

  198.          {

  199.                    if (i>=0)

  200.                    {

  201.                             for (j=0;j<8;j++)

  202.                             display[j][i]=display[j][i+1];

  203.                    }

  204.                    if (i<4)

  205.                    {

  206.                             for (j=0;j<8;j++)

  207.                             display[j][i+4]=0;

  208.                    }

  209.                    delay(speed);

  210.          }

  211. }

  212. void point(uchar x,uchar y,uchar z,uchar le)

  213. {

  214.          uchar ch1,ch0;

  215.          ch1=1<<x;

  216.          ch0=~ch1;

  217.          if (le)

  218.          display[z][y]=display[z][y]|ch1;

  219.          else

  220.          display[z][y]=display[z][y]&ch0;

  221. }

  222. void type(uchar cha,uchar y)

  223. {        

  224.          uchar xx;

  225.          for (xx=0;xx<8;xx++)

  226.          {

  227.          display[xx][y]=table_cha[cha][xx];

  228.          }

  229. }

  230. /*The first variable is the distance from the midpoint.

  231. The second is the layer.

  232. the third is the flash speed of the time between each two point.

  233. The forth is the enable io,it controls weather draw or claen.*/

  234. void cirp(char cpp,uchar dir,uchar le)

  235. {

  236.          uchar a,b,c,cp;

  237.          if ((cpp<128)&(cpp>=0))

  238.          {

  239.                    if (dir)

  240.                    cp=127-cpp;

  241.                    else

  242.                    cp=cpp;

  243.                    a=(dat[cp]>>5)&0x07;

  244.                    b=(dat[cp]>>2)&0x07;

  245.                    c=dat[cp]&0x03;

  246.                    if (cpp>63)

  247.                    c=7-c;

  248.                    point (a,b,c,le);

  249.          }

  250. }

  251. void line(uchar x1,uchar y1,uchar z1,uchar x2,uchar y2,uchar z2,uchar le)

  252. {

  253.          char t,a,b,c,a1,b1,c1,i;

  254.          a1=x2-x1;

  255.          b1=y2-y1;

  256.          c1=z2-z1;

  257.          t=maxt(abss(a1),abss(b1),abss(c1));

  258.          a=x1*10;

  259.          b=y1*10;

  260.          c=z1*10;

  261.          a1=a1*10/t;

  262.          b1=b1*10/t;

  263.          c1=c1*10/t;

  264.          for (i=0;i<t;i++)

  265.          {

  266.                    point(abs(a),abs(b),abs(c),le);

  267.                    a+=a1;

  268.                    b+=b1;

  269.                    c+=c1;

  270.          }

  271.          point(x2,y2,z2,le);

  272. }

  273. void box(uchar x1,uchar y1,uchar z1,uchar x2,uchar y2,uchar z2,uchar fill,uchar le)

  274. {

  275.          uchar i,j,t=0;

  276.          max(&x1,&x2);

  277.          max(&y1,&y2);

  278.          max(&z1,&z2);

  279.          for (i=x1;i<=x2;i++)

  280.                    t|=1<<i;

  281.          if (!le)

  282.                    t=~t;

  283.          if (fill)

  284.          {

  285.                    if (le)

  286.                    {

  287.                             for (i=z1;i<=z2;i++)

  288.                             {

  289.                                      for (j=y1;j<=y2;j++)

  290.                                                display[j][i]|=t;

  291.                             }

  292.                    }

  293.                    else

  294.                    {

  295.                             for (i=z1;i<=z2;i++)

  296.                             {

  297.                                      for (j=y1;j<=y2;j++)

  298.                                                display[j][i]&=t;

  299.                             }

  300.                    }

  301.          }

  302.          else

  303.          {

  304.                    if (le)

  305.                    {

  306.                             display[y1][z1]|=t;

  307.                             display[y2][z1]|=t;

  308.                             display[y1][z2]|=t;

  309.                             display[y2][z2]|=t;

  310.                    }

  311.                    else

  312.                    {

  313.                            display[y1][z1]&=t;

  314.                             display[y2][z1]&=t;

  315.                             display[y1][z2]&=t;

  316.                             display[y2][z2]&=t;

  317.                    }

  318.                    t=(0x01<<x1)|(0x01<<x2);

  319.                    if (!le)

  320.                             t=~t;

  321.                    if (le)

  322.                    {

  323.                             for (j=z1;j<=z2;j+=(z2-z1))

  324.                             {

  325.                                      for (i=y1;i<=y2;i++)

  326.                                                display[i][j]|=t;

  327.                             }

  328.                             for (j=y1;j<=y2;j+=(y2-y1))

  329.                             {

  330.                                      for (i=z1;i<=z2;i++)

  331.                                                display[j][i]|=t;

  332.                             }

  333.                    }

  334.                    else

  335.                    {

  336.                             for (j=z1;j<=z2;j+=(z2-z1))

  337.                             {

  338.                                      for (i=y1;i<=y2;i++)

  339.                                      {

  340.                                      display[i][j]&=t;

  341.                                      }

  342.                             }

  343.                             for (j=y1;j<=y2;j+=(y2-y1))

  344.                             {

  345.                                      for (i=z1;i<=z2;i++)

  346.                                      {

  347.                                      display[j][i]&=t;

  348.                                      }

  349.                             }

  350.                    }

  351.          }

  352. }
復(fù)制代碼







評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:145172 發(fā)表于 2016-10-30 10:19 | 只看該作者
頭文件沒(méi)改過(guò)來(lái) 應(yīng)該是STC12C5A60S2  需要原理圖 PCB的可以聯(lián)系我
回復(fù)

使用道具 舉報(bào)

板凳
ID:145237 發(fā)表于 2016-10-30 18:34 | 只看該作者
頂頂頂,學(xué)習(xí)交流
回復(fù)

使用道具 舉報(bào)

地板
ID:186300 發(fā)表于 2017-4-5 22:47 | 只看該作者
學(xué)習(xí)學(xué)習(xí),厲害了
回復(fù)

使用道具 舉報(bào)

5#
ID:186662 發(fā)表于 2017-4-6 13:56 | 只看該作者
果斷收藏,厲害了
回復(fù)

使用道具 舉報(bào)

6#
ID:187766 發(fā)表于 2017-4-9 22:36 來(lái)自手機(jī) | 只看該作者
小酒壺 發(fā)表于 2016-10-30 10:19
頭文件沒(méi)改過(guò)來(lái) 應(yīng)該是STC12C5A60S2  需要原理圖 PCB的可以聯(lián)系我

樓主,我需要pcb圖,謝謝了。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表