標題:
基于51單片機的光立方自作
[打印本頁]
作者:
小酒壺
時間:
2016-10-30 10:14
標題:
基于51單片機的光立方自作
這是做好后的效果 還是很炫的
制作要的點:
1.單片機必須用STC12C5A60S2 因為低速51根本帶不動 它的運算速度要求非常高.
2.也就是晶振要用24M的提供高速.
3.硬件制作,很考驗耐力的其中焊512個led;
//簡單控制。用于檢驗等的好壞。
需要的可以自行下載 :
888光立方.rar
(82.83 KB, 下載次數(shù): 766)
2016-10-30 11:15 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula0=P2^0; sbit dula1=P2^1;
sbit dula2=P2^2; sbit dula5=P2^5;
sbit dula3=P2^3; sbit dula6=P2^6;
sbit dula4=P2^4; sbit dula7=P2^7;
sbit key0=P3^2;sbit key1=P3^3;sbit key2=P3^4;sbit key3=P3^5;
void delayms(uint xam)
{
uint x,y;
for(x=xam;x>0;x--)
for(y=110;y>0;y--);
}
void keyscan()
{
if(key0==0)
{
delayms(10);
if(key0==0)
{
P1=0x00;P1=0xff;P2=0x00;
dula0=1;P0=0xff;dula0=0;dula1=1;P0=0xff;dula1=0;
dula2=1;P0=0xff;dula2=0;dula3=1;P0=0xff;dula3=0;
dula4=1;P0=0xff;dula4=0;dula5=1;P0=0xff;dula5=0;
dula6=1;P0=0xff;dula6=0;dula7=1;P0=0xff;dula7=0;
while(!key0);
}
}
if(key1==0)
{
delayms(10);
if(key1==0)
{
P1=0x00;P1=0xFF;dula0=0x00;delayms(3);
P1=0X00;P1=0XFF;dula1=0X81;delayms(3);
P1=0X00;P1=0X81;dula1=0xff;delayms(3);
P1=0X00;P1=0XFF;dula2=0X81;delayms(3);
P1=0X00;P1=0X81;dula2=0xff;delayms(3);
P1=0X00;P1=0XFF;dula3=0X81;delayms(3);
P1=0X00;P1=0X81;dula3=0xff;delayms(3);
P1=0X00;P1=0XFF;dula4=0X81;delayms(3);
P1=0X00;P1=0X81;dula4=0xff;delayms(3);
P1=0X00;P1=0XFF;dula5=0X81;delayms(3);
P1=0X00;P1=0X81;dula5=0xff;delayms(3);
P1=0X00;P1=0XFF;dula6=0X81;delayms(3);
P1=0X00;P1=0X81;dula6=0xff;delayms(3);
P1=0X00;P1=0XFF;dula7=0X81;delayms(3);
P1=0X00;P1=0X81;dula7=0xff;delayms(3);
P1=0x00;P1=0xFF;dula0=0x00;delayms(3);
while(!key1);
}
}
if(key2==0)
{
delayms(10);
if(key2==0)
{
P1=0X00;P1=0x81;P2=0X00;
dula0=1;P0=0xff;dula0=0;dula1=1;P0=0xff;dula1=0;
dula2=1;P0=0xff;dula2=0;dula3=1;P0=0xff;dula3=0;
dula4=1;P0=0xff;dula4=0;dula5=1;P0=0xff;dula5=0;
dula6=1;P0=0xff;dula6=0;dula7=1;P0=0xff;dula7=0;
delayms(1);
P1=0x42;
dula0=1;P0=0x00;dula0=0;dula1=1;P0=0x81;dula1=0;
dula2=1;P0=0x00;dula2=0;dula3=1;P0=0x00;dula3=0;
dula4=1;P0=0x00;dula4=0;dula5=1;P0=0x00;dula5=0;
dula6=1;P0=0x81;dula6=0;dula7=1;P0=0x00;dula7=0;
while(!key0);
}
}
if(key3==0)
{
delayms(10);
if(key3==0)
{
P1=0x00;P1=0xff;P2=0x00;
dula0=1;P0=0xff;dula0=0;delayms(10);dula1=1;P0=0xff;dula1=0;
dula2=1;P0=0xff;dula2=0;delayms(10);dula3=1;P0=0xff;dula3=0;
dula4=1;P0=0xff;dula4=0;delayms(10);dula5=1;P0=0xff;dula5=0;
dula6=1;P0=0xff;dula6=0;delayms(10);dula7=1;P0=0xff;dula7=0;
while(!key3);
}
}
}
void main()
{
while(1)
{
keyscan();
delayms(10);
}
}
這是金典的光立方程序
#include <REG52.H>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar display[8][8];
/*rank:A,1,2,3,4,I,心,U*/
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};
/*the "ideasoft"*/
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};
/*railway*/
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};
/*railway 2*/
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};
/*railway 3*/
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};
/*3p char*/
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};
/*initializtion
That is to initialize the program .
It is write to set the timer in c52 mcu.
So the program can renovate the led_3d_cube in fixed time use the interrupt function.*/
void sinter()
{
IE=0x82;
TCON=0x01;
TH0=0xc0;
TL0=0;
TR0=1;
}
void delay5us(void) //誤差 -0.026765046296us STC 1T 22.1184Mhz
{
unsigned char a,b;
for(b=7;b>0;b--)
for(a=2;a>0;a--);
}
void delay(uint i)
{
while (i--){
delay5us();}//12t的mcu 注釋這個延時即可
}
/*To judge the num bit*/
uchar judgebit(uchar num,uchar b)
{
char n;
num=num&(1<<b);
if (num)
n=1;
else
n=0;
return n;
}
/*To figure out the round number*/
uchar abs(uchar a)
{
uchar b;
b=a/10;
a=a-b*10;
if (a>=5)
b++;
return b;
}
/*To figure out the absolute value*/
uchar abss(char a)
{
if (a<0)
a=-a;
return a;
}
/*The function can comparat the character.
And remove the big one to the back.*/
void max(uchar *a,uchar *b)
{
uchar t;
if ((*a)>(*b))
{
t=(*a);
(*a)=(*b);
(*b)=t;
}
}
/*The function is to figure out the max number and return it.*/
uchar maxt(uchar a,uchar b,uchar c)
{
if (a<b)
a=b;
if (a<c)
a=c;
return a;
}
void clear(char le)
{
uchar i,j;
for (j=0;j<8;j++)
{
for (i=0;i<8;i++)
display[j][i]=le;
}
}
void trailler(uint speed)
{
char i,j;
for (i=6;i>=-3;i--)
{
if (i>=0)
{
for (j=0;j<8;j++)
display[j][i]=display[j][i+1];
}
if (i<4)
{
for (j=0;j<8;j++)
display[j][i+4]=0;
}
delay(speed);
}
}
void point(uchar x,uchar y,uchar z,uchar le)
{
uchar ch1,ch0;
ch1=1<<x;
ch0=~ch1;
if (le)
display[z][y]=display[z][y]|ch1;
else
display[z][y]=display[z][y]&ch0;
}
void type(uchar cha,uchar y)
{
uchar xx;
for (xx=0;xx<8;xx++)
{
display[xx][y]=table_cha[cha][xx];
}
}
/*The first variable is the distance from the midpoint.
The second is the layer.
the third is the flash speed of the time between each two point.
The forth is the enable io,it controls weather draw or claen.*/
void cirp(char cpp,uchar dir,uchar le)
{
uchar a,b,c,cp;
if ((cpp<128)&(cpp>=0))
{
if (dir)
cp=127-cpp;
else
cp=cpp;
a=(dat[cp]>>5)&0x07;
b=(dat[cp]>>2)&0x07;
c=dat[cp]&0x03;
if (cpp>63)
c=7-c;
point (a,b,c,le);
}
}
void line(uchar x1,uchar y1,uchar z1,uchar x2,uchar y2,uchar z2,uchar le)
{
char t,a,b,c,a1,b1,c1,i;
a1=x2-x1;
b1=y2-y1;
c1=z2-z1;
t=maxt(abss(a1),abss(b1),abss(c1));
a=x1*10;
b=y1*10;
c=z1*10;
a1=a1*10/t;
b1=b1*10/t;
c1=c1*10/t;
for (i=0;i<t;i++)
{
point(abs(a),abs(b),abs(c),le);
a+=a1;
b+=b1;
c+=c1;
}
point(x2,y2,z2,le);
}
void box(uchar x1,uchar y1,uchar z1,uchar x2,uchar y2,uchar z2,uchar fill,uchar le)
{
uchar i,j,t=0;
max(&x1,&x2);
max(&y1,&y2);
max(&z1,&z2);
for (i=x1;i<=x2;i++)
t|=1<<i;
if (!le)
t=~t;
if (fill)
{
if (le)
{
for (i=z1;i<=z2;i++)
{
for (j=y1;j<=y2;j++)
display[j][i]|=t;
}
}
else
{
for (i=z1;i<=z2;i++)
{
for (j=y1;j<=y2;j++)
display[j][i]&=t;
}
}
}
else
{
if (le)
{
display[y1][z1]|=t;
display[y2][z1]|=t;
display[y1][z2]|=t;
display[y2][z2]|=t;
}
else
{
display[y1][z1]&=t;
display[y2][z1]&=t;
display[y1][z2]&=t;
display[y2][z2]&=t;
}
t=(0x01<<x1)|(0x01<<x2);
if (!le)
t=~t;
if (le)
{
for (j=z1;j<=z2;j+=(z2-z1))
{
for (i=y1;i<=y2;i++)
display[i][j]|=t;
}
for (j=y1;j<=y2;j+=(y2-y1))
{
for (i=z1;i<=z2;i++)
display[j][i]|=t;
}
}
else
{
for (j=z1;j<=z2;j+=(z2-z1))
{
for (i=y1;i<=y2;i++)
{
display[i][j]&=t;
}
}
for (j=y1;j<=y2;j+=(y2-y1))
{
for (i=z1;i<=z2;i++)
{
display[j][i]&=t;
}
}
}
}
}
復制代碼
作者:
小酒壺
時間:
2016-10-30 10:19
頭文件沒改過來 應(yīng)該是STC12C5A60S2 需要原理圖 PCB的可以聯(lián)系我
作者:
在路上adc
時間:
2016-10-30 18:34
頂頂頂,學習交流
作者:
1048577012
時間:
2017-4-5 22:47
學習學習,厲害了
作者:
w515748522
時間:
2017-4-6 13:56
果斷收藏,厲害了
作者:
lolop
時間:
2017-4-9 22:36
小酒壺 發(fā)表于 2016-10-30 10:19
頭文件沒改過來 應(yīng)該是STC12C5A60S2 需要原理圖 PCB的可以聯(lián)系我
樓主,我需要pcb圖,謝謝了。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1