#include "Animate.h"
uint8_t LightFLAG = 0;
uchar layer = 1, column = 1, test_flag = 0;
char remain_max_line = 0;
uint speed = 10;
uint PWMspeed = 1000;
void delay_1ms(uint q)
{
uint i, j;
for (i = 0; i < q; i++)
{
for (j = 0; j < speed; j++);
{
if (0 != test_flag)
return;
}
}
}
void Bind_OFF(void)
{
P3_0 = 0;/*J1*/
P3_1 = 0;/*J2*/
P3_3 = 0;/*J3*/
P3_4 = 0;/*J4*/
P3_5 = 0;/*J5*/
P3_6 = 0;/*J6*/
P3_7 = 0;/*J7*/
P2_0 = 0;/*J8*/
P2_1 = 0;/*J9*/
P2_2 = 0;/*J10*/
P2_3 = 0;/*J11*/
P2_4 = 0;/*J12*/
P2_5 = 0;/*J13*/
P2_6 = 0;/*J14*/
P2_7 = 0;/*J15*/
P4_4 = 0;/*J16*/
}
void LayerData(uint16_t dat)
{
P1_7 = dat & 0x8000;
P1_6 = dat & 0x4000;
P1_5 = dat & 0x2000;
P1_4 = dat & 0x1000;
P1_3 = dat & 0x0800;
P1_2 = dat & 0x0400;
P1_1 = dat & 0x0200;
P4_6 = dat & 0x0100;
P0_7 = dat & 0x0080;
P0_6 = dat & 0x0040;
P0_5 = dat & 0x0020;
P0_4 = dat & 0x0010;
P0_3 = dat & 0x0008;
P0_2 = dat & 0x0004;
P0_1 = dat & 0x0002;
P0_0 = dat & 0x0001;
}
void HankData(uint16_t dat)
{
P3_0 = dat & 0x8000;
P3_1 = dat & 0x4000;
P3_3 = dat & 0x2000;
P3_4 = dat & 0x1000;
P3_5 = dat & 0x0800;
P3_6 = dat & 0x0400;
P3_7 = dat & 0x0200;
P2_0 = dat & 0x0100;
P2_1 = dat & 0x0080;
P2_2 = dat & 0x0040;
P2_3 = dat & 0x0020;
P2_4 = dat & 0x0010;
P2_5 = dat & 0x0008;
P2_6 = dat & 0x0004;
P2_7 = dat & 0x0002;
P4_4 = dat & 0x0001;
}
void dh1()
{
char i, j;
Bind_OFF();
P1_7 = 0;
P1_6 = 0;
P1_5 = 0;
P1_4 = 0;
P1_3 = 0;
P1_2 = 0;
P1_1 = 0;
P4_6 = 0;
P0 = 0X01;
delay_1ms(10);
for (j = 0; j < 7; j++)
{
P0 = (P0 << 1) | 0x01;
delay_1ms(10);
}
P4_6 = 1;
delay_1ms(10);
P1_1 = 1;
delay_1ms(10);
P1_2 = 1;
delay_1ms(10);
P1_3 = 1;
delay_1ms(10);
P1_4 = 1;
delay_1ms(10);
P1_5 = 1;
delay_1ms(10);
P1_6 = 1;
delay_1ms(10);
P1_7 = 1;
for (i = 0; i < 2; i++)
{
P1_7 = 0;
P1_6 = 0;
P1_5 = 0;
P1_4 = 0;
P1_3 = 0;
P1_2 = 0;
P1_1 = 0;
P4_6 = 0;
P0 = 0X01;
delay_1ms(1000);
for (j = 0; j < 7; j++)
{
P0 = (P0 << 1) | 0x01;
delay_1ms(700);
}
P4_6 = 1;
delay_1ms(700);
P1_1 = 1;
delay_1ms(700);
P1_2 = 1;
delay_1ms(700);
P1_3 = 1;
delay_1ms(700);
P1_4 = 1;
delay_1ms(700);
P1_5 = 1;
delay_1ms(700);
P1_6 = 1;
delay_1ms(700);
P1_7 = 1;
delay_1ms(8000);
delay_1ms(8000);
delay_1ms(8000);
delay_1ms(8000);
delay_1ms(8000);
delay_1ms(8000);
}
}
void dh3()
{
char i, j;
int yanshi = 400;
Bind_OFF();
for (i = 0; i < 3; i++)
{
P1_7 = 0;
P1_6 = 0;
P1_5 = 0;
P1_4 = 0;
P1_3 = 0;
P1_2 = 0;
P1_1 = 0;
P4_6 = 0;
P0 = 0X01;
delay_1ms(yanshi);
for (j = 0; j < 7; j++)
{
P0 = (P0 << 1);
delay_1ms(yanshi);
}
P0_7 = 0;
P4_6 = 1;
delay_1ms(yanshi);
P4_6 = 0;
P1_1 = 1;
delay_1ms(yanshi);
P1_1 = 0;
P1_2 = 1;
delay_1ms(yanshi);
P1_2 = 0;
P1_3 = 1;
delay_1ms(yanshi);
P1_3 = 0;
P1_4 = 1;
delay_1ms(yanshi);
P1_4 = 0;
P1_5 = 1;
delay_1ms(yanshi);
P1_5 = 0;
P1_6 = 1;
delay_1ms(yanshi);
P1_6 = 0;
P1_7 = 1;
delay_1ms(yanshi);
P1_6 = 1;
P1_7 = 0;
delay_1ms(yanshi);
P1_5 = 1;
P1_6 = 0;
delay_1ms(yanshi);
P1_4 = 1;
P1_5 = 0;
delay_1ms(yanshi);
P1_3 = 1;
P1_4 = 0;
delay_1ms(yanshi);
P1_2 = 1;
P1_3 = 0;
delay_1ms(yanshi);
P1_1 = 1;
P1_2 = 0;
delay_1ms(yanshi);
P1_1 = 0;
P0_7 = 1;
delay_1ms(yanshi);
P0_6 = 1;
P0_7 = 0;
delay_1ms(yanshi);
P0_5 = 1;
P0_6 = 0;
delay_1ms(yanshi);
P0_4 = 1;
P0_5 = 0;
delay_1ms(yanshi);
P0_3 = 1;
P0_4 = 0;
delay_1ms(yanshi);
P0_2 = 1;
P0_3 = 0;
delay_1ms(yanshi);
P0_1 = 1;
P0_2 = 0;
delay_1ms(yanshi);
}
}
void dh5()
{
char i;
LayerData(0xffff);
for (i = 0; i < 3; i++)
{
P3_0 = 0;
delay_1ms(400);
P3_1 = 0;
delay_1ms(400);
P3_3 = 0;
delay_1ms(400);
P3_4 = 0;
delay_1ms(400);
P3_5 = 0;
delay_1ms(400);
P3_6 = 0;
delay_1ms(400);
P3_7 = 0;
delay_1ms(400);
P2_0 = 0;
delay_1ms(400);
P2_1 = 0;
delay_1ms(400);
P2_2 = 0;
delay_1ms(400);
P2_3 = 0;
delay_1ms(400);
P2_4 = 0;
delay_1ms(400);
P2_5 = 0;
delay_1ms(400);
P2_6 = 0;
delay_1ms(400);
P2_7 = 0;
delay_1ms(400);
P4_4 = 0;
delay_1ms(9000);
delay_1ms(9000);
delay_1ms(9000);
P2 = 0XFF;
P3 = 0XFF;
P4_4 = 1;
}
}
void dh6()
{
char j;
int yanshi = 3000;
LayerData(0xffff);
for (j = 0; j < 20; j++)
{
P3_4 = 1;
P2_0 = 1;
P2_4 = 1;
P4_4 = 1;
P3_0 = 0;
P3_5 = 0;
P2_1 = 0;
P2_5 = 0;
delay_1ms(yanshi);
P3_0 = 1;
P3_5 = 1;
P2_1 = 1;
P2_5 = 1;
P3_1 = 0;
P3_6 = 0;
P2_2 = 0;
P2_6 = 0;
delay_1ms(yanshi);
P3_1 = 1;
P3_6 = 1;
P2_2 = 1;
P2_6 = 1;
P3_3 = 0;
P3_7 = 0;
P2_3 = 0;
P2_7 = 0;
delay_1ms(yanshi);
P3_3 = 1;
P3_7 = 1;
P2_3 = 1;
P2_7 = 1;
P3_4 = 0;
P2_0 = 0;
P2_4 = 0;
P4_4 = 0;
delay_1ms(yanshi);
if (j < 6)
yanshi = yanshi - 400;
}
}
这个程序有没有那个大神看得懂?关于单片机led灯的
void dh9()
{
char i;
Bind_OFF();
LayerData(0x0000);
for (i = 0; i < 5; i++)
{
P1_4 = 0;
P1_3 = 0;
P0_4 = 0;
P0_3 = 0;
P1_7 = 1;
P4_6 = 1;
P0_7 = 1;
P0_0 = 1;
delay_1ms(1000);
P1_7 = 0;
P4_6 = 0;
P0_7 = 0;
P0_0 = 0;
P1_6 = 1;
P1_1 = 1;
P0_6 = 1;
P0_1 = 1;
delay_1ms(1000);
P1_6 = 0;
P1_1 = 0;
P0_6 = 0;
P0_1 = 0;
P1_5 = 1;
P1_2 = 1;
P0_5 = 1;
P0_2 = 1;
delay_1ms(1000);
P1_5 = 0;
P1_2 = 0;
P0_5 = 0;
P0_2 = 0;
P1_4 = 1;
P1_3 = 1;
P0_4 = 1;
P0_3 = 1;
delay_1ms(1000);
}
}
void dh11()
{
code uint16_t tep[16] = {0x0001,0x0003,0x0007,0x000f,0x001f,0x003f,0x007f,0x00ff,
0x01ff,0x03ff,0x07ff,0x0fff,0x1fff,0x3fff,0xffff};
uint8_t i = 0, j = 0, k = 0;
uint16_t temp1 = 0, temp2 = 0;
temp1 = 0xffff;
for(j = 0; j < 16; j++)
{
temp2 = tep[j];
for(i = 0; i < 16; i++)
{
LayerData(temp1);
HankData(temp2 ^ 0xffff);
delay_1ms(800);
temp2 <<= 1;
}
}
temp2 = 0x0000;
for(j = 0; j < 16; j++)
{
temp1 = tep[j];
for(i = 0; i < 16; i++)
{
LayerData(temp1);
HankData(temp2);
delay_1ms(800);
temp1 <<= 1;
}
}
for(j = 0; j < 16; j++)
{
temp1 = 0x0001;
temp2 = tep[j];
for(i = 0; i < 16; i++)
{
LayerData(temp1);
HankData(temp2 ^ 0xffff);
delay_1ms(800);
temp1 <<= 1;
temp2 <<= 1;
}
}
for(k = 0; k < 16; k++)
{
temp1 = tep[k];
for(j = 0; j < 16; j++)
{
temp2 = 0x0001;
for(i = 0; i < 16; i++)
{
LayerData(temp1);
HankData(temp2 ^ 0xffff);
delay_1ms(150);
temp2 <<= 1;
}
temp1 <<= 1;
}
}
for(k = 0; k < 16; k++)
{
temp1 = 0x0001;
for(j = 0; j < 16; j++)
{
temp2 = tep[k];
for(i = 0; i < 16; i++)
{
LayerData(temp1);
HankData(temp2 ^ 0xffff);
delay_1ms(200);
temp2 <<= 1;
}
temp1 <<= 1;
}
}
}
void SHOW(void)
{
dh1();
dh3();
dh5();
dh6();
dh9();
dh11();
}
|