Mình có mạch như thế này
code như thế này
#include <REGX51.H>
// Ten cua 3 chan dieu khien IC 74HC595
sbit SDA=P3^2;
sbit STR=P3^1;
sbit SCK=P3^0;
// Ham tao tre a(ms)
void delay(int a)
{
int b,c;
for(b=0;b<a;b++)
{
for(c=0;c<100;c++)
{}
}
}
unsigned char code cot[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}, // Khai bao ma cot
hang[]={ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0x00,0x7E,0x7E,0xBD,0xC3,0xFF, // D
0xFF,0xFF,0xB0,0x7A,0x7A,0xBA,0xC7,0xFF, // 5
0xFF,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0xFF, // _
0xFF,0xFF,0x00,0x7E,0x7E,0xBD,0xC3,0xFF, // D
0xFF,0xC3,0xBD,0x7E,0x7E,0xBD,0xFF,0xFF, // C
0x00,0x00,0xF9,0xF3,0xE7,0xCF,0x00,0x00, // N
0xFF,0xFF,0x19,0x5E,0x5E,0x61,0xFF,0xFF, // 2
};
void quet(unsigned char x)
{int i,temp;
for(i=0;i<8;i++)
{
temp=x;//gan bien
temp=temp&0x80;//lay ra bit dau tien (bit 7)
if
(
temp==0x80)//so sanh bit
SDA=1; //bang 1 thi xuat vao chip =1
else
SDA=0; //nguoc lai bang 0
x*=2; //dich bit lay bit trong so thap
SCK=0; //tao xung tren chan 11
SCK=1; //1 xung dua vào 1 bít
}
STR=0; //xuat du lieu ra output
STR=1;
}
// Ham chinh
void main()
{
// Khai bao 3 bien quet hang,cot
int i,j,k;
while(1) // Vong lap vinh vien
{
for(i=0;i<64;i++) // 168 la so ma trong mang 'hang'
{
for(j=0;j<30;j++) // Vong lap tao tre
{
for(k=0;k<8;k++) // Quet tu cot 1 toi cot 8
{
quet(hang[(i+k+32)%64]); // ma cho led 5
quet(hang[(i+k+24)%64]); // ma cho led 4
quet(hang[(i+k+16)%64]); // ma cho led 3
quet(hang[(i+k+8 )%64]); // ma cho led 2
quet(hang[(i+k)%64]); // ma cho led 1
STR=0;
STR=1; // xung suon len de xuat ra 32 bit
P2=cot[k];// ma cot
delay(2);
P2=0x00;
}
}
}
}
}
bây giờ mình muốn cho chữ nó chạy nhanh hơn thì phải sửa thế nào ạ, cảm ơn mọi người nhiều
code như thế này
#include <REGX51.H>
// Ten cua 3 chan dieu khien IC 74HC595
sbit SDA=P3^2;
sbit STR=P3^1;
sbit SCK=P3^0;
// Ham tao tre a(ms)
void delay(int a)
{
int b,c;
for(b=0;b<a;b++)
{
for(c=0;c<100;c++)
{}
}
}
unsigned char code cot[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}, // Khai bao ma cot
hang[]={ 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0x00,0x7E,0x7E,0xBD,0xC3,0xFF, // D
0xFF,0xFF,0xB0,0x7A,0x7A,0xBA,0xC7,0xFF, // 5
0xFF,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0xFF, // _
0xFF,0xFF,0x00,0x7E,0x7E,0xBD,0xC3,0xFF, // D
0xFF,0xC3,0xBD,0x7E,0x7E,0xBD,0xFF,0xFF, // C
0x00,0x00,0xF9,0xF3,0xE7,0xCF,0x00,0x00, // N
0xFF,0xFF,0x19,0x5E,0x5E,0x61,0xFF,0xFF, // 2
};
void quet(unsigned char x)
{int i,temp;
for(i=0;i<8;i++)
{
temp=x;//gan bien
temp=temp&0x80;//lay ra bit dau tien (bit 7)
if
(
temp==0x80)//so sanh bit
SDA=1; //bang 1 thi xuat vao chip =1
else
SDA=0; //nguoc lai bang 0
x*=2; //dich bit lay bit trong so thap
SCK=0; //tao xung tren chan 11
SCK=1; //1 xung dua vào 1 bít
}
STR=0; //xuat du lieu ra output
STR=1;
}
// Ham chinh
void main()
{
// Khai bao 3 bien quet hang,cot
int i,j,k;
while(1) // Vong lap vinh vien
{
for(i=0;i<64;i++) // 168 la so ma trong mang 'hang'
{
for(j=0;j<30;j++) // Vong lap tao tre
{
for(k=0;k<8;k++) // Quet tu cot 1 toi cot 8
{
quet(hang[(i+k+32)%64]); // ma cho led 5
quet(hang[(i+k+24)%64]); // ma cho led 4
quet(hang[(i+k+16)%64]); // ma cho led 3
quet(hang[(i+k+8 )%64]); // ma cho led 2
quet(hang[(i+k)%64]); // ma cho led 1
STR=0;
STR=1; // xung suon len de xuat ra 32 bit
P2=cot[k];// ma cot
delay(2);
P2=0x00;
}
}
}
}
}
bây giờ mình muốn cho chữ nó chạy nhanh hơn thì phải sửa thế nào ạ, cảm ơn mọi người nhiều