自己尝试写的旋转led的程序
#include <STC15F2K60S2.H>
#define uint unsigned int
#define uchar unsigned char
void delay(int ms)
{ uint i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<5;j++);
}
//a??????????
uchar num_a[]={0x24,0x24,0x25,0x7F,0xC4,0x44,0x00,0x7C,0x44,0x44,0x44,0x44,0x44,0x7C,0x00,0x00,/*????????*/
0x00,0x00,0x3F,0x20,0x20,0x20,0x28,0xA8,0x6A,0x29,0x2A,0x2C,0x28,0x20,0x20,0x00,/*????????*/
0x04,0x0C,0x35,0xC6,0x04,0x18,0x10,0x12,0x12,0x12,0xFE,0x12,0x12,0x12,0x10,0x00,/*????????*/
0x08,0x08,0x0B,0xFF,0x09,0x08,0x02,0x0C,0xF0,0x13,0x10,0x10,0x10,0x1F,0x00,0x00,/*?????????*/
0x02,0x02,0x42,0x33,0x00,0x02,0x05,0x79,0x41,0x41,0x41,0x79,0x05,0x04,0x04,0x00, /*????????*/
0x02,0x02,0x42,0x33,0x00,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x02,0x02,0x02,0x00, /*????????*/
};
//b??????°???
uchar num_b[]={0x10,0x60,0x80,0xFF,0x80,0x60,0x02,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x82,0x00,/*????°???*/
0x02,0x0C,0xF0,0x00,0x80,0x80,0x80,0x82,0x81,0xFE,0x80,0x80,0x80,0xA0,0xC0,0x00,/*????°???*/
0x44,0xE6,0x44,0x48,0x48,0x48,0x00,0x7F,0x42,0x42,0x42,0x42,0x42,0x7F,0x00,0x00,/*????°???*/
0x20,0xC0,0x00,0xFF,0x00,0xC0,0x00,0x30,0xD0,0x10,0x52,0x39,0x02,0xFC,0x00,0x00, /*?????°???*/
0x00,0x00,0x00,0xFC,0x09,0x11,0x02,0xC2,0x34,0x08,0x14,0x62,0x82,0x01,0x01,0x00, /*????°???*/
0x00,0x00,0x00,0xFE,0x04,0x08,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, /*????°???*/
};
uchar num_c[]={0x00,0x00,0x0F,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x08,0x08,0x0F,0x00,0x00,0x00,/*?е??????*/
0x00,0x3F,0x04,0x24,0x15,0xFF,0x15,0x24,0x00,0x3F,0x22,0x22,0x23,0x42,0x02,0x00,/*????????*/
0x00,0x00,0x44,0x4C,0x54,0x65,0x45,0x46,0x84,0x88,0x90,0x81,0x80,0x00,0x00,0x00,/*????????*/
0x04,0x0C,0x35,0xC6,0x0C,0x00,0x11,0x13,0x15,0x99,0x71,0x11,0x15,0x13,0x11,0x00,/*????????*/
};
uchar num_d[]={0x00,0x00,0xF0,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x20,0x20,0xF0,0x00,0x00,0x00,/*?е??°???*/
0x00,0xFC,0x44,0x84,0x04,0xF4,0x04,0xC5,0x06,0xF8,0x00,0x00,0xFF,0x00,0x00,0x00,/*????°???*/
0x00,0x42,0x44,0xC8,0xD0,0x42,0x41,0x7E,0x40,0x40,0x50,0x48,0xC4,0x62,0x00,0x00,/*????°???*/
0x44,0xE6,0x44,0x48,0x48,0x01,0x02,0x0C,0xF0,0x00,0x00,0xFC,0x02,0x02,0x8E,0x00,/*????°???*/
};
uint i=0;
uint k=0;
void zhongduan() interrupt 0 //?ж???????????????
{
display();
}
void display()
{
k++;
if(k<200)
display_1();
else if(k<400)
display_2();
else if(k<600)
display_3();
}
void display_1()
{
P0=0x00;
P1=0x00;
p2=0x00;
P4^5=0;
} //???
void display_2()
{
uint m;
for(m=0;m<192;m++)
{
P0=~num_a[16*(m/16)+16-(m%16)];
p1=~num_b[16*(m/16)+16-(m%16)];
p2=oxff;
P4^5=1;
delay(30);
}
} //???????????
void display_3()
{ uint l;
for(l=0;l<192;l++)
{
P0=~num_c[16*((l+i)/16)+16-((l+i)%16)%192];
p1=~num_d[16*((l+i)/16)+16-((l+i)%16)%192];
p2=oxff;
P4^5=1;
delay(30);
}
i++;
}
void main()
{
P0=0xff;
P1=0xff;
P2=0xff;
P4^5=1;
EA=1;//允许中断
IT0=1;//int0中断
EX0=1;
}
|