Mình nghi có lỗi ở mảng nhập hang[] từ text,mong các bạn chữa hộ mình ! Thanks.
File Attach :Led8x8.rar
------------------------------------------
#include<at89x52.h>
#include<string.h>
#include<font8x8.c>
//-------------Khai bao bien-------------
sbit SCK=P3^0;
sbit DATA=P3^1;
sbit LATCH=P3^2;
int m,n,k,a;
//--------------Khai bao mang------------
unsigned char xdata hang[200];
unsigned char cot[] ={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char text[]="LE TRUNG HIEU ";//Nhap text vao day de hien thi
//--------------Ham xu ly text-------------
xuly()
{
unsigned char data i,j,l;
l=strlen(text);
for(i=0;i<l;i++)
{
for(j=0;j<=7;j++)
{
if(text[i]==20){hang[8*i+j]=font2[j];}
else {hang[8*i+j]=font2[8*(text[i]-32)+j];}
}
}
}
//-------------Ham tre-----------------
delay(long t)
{
int i=0,j;
for(;i<=10;i++)
for(j=0;j<=t;j++);
}
//-----------Ham cho phep ghi vao thanh ghi HC595---------------
Data_bit()
{
SCK=1;
SCK=0;
}
//------------Ham viet 8 bit vao thanh ghi HC595--------------
void data_byte(unsigned char x)
{
unsigned char data temp,i;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80;
if(temp==0x80)
DATA=1;
else
DATA=0;
x=x<<1;
Data_bit();
}
}
//-------------Ham xuat gia tri tu thanh ghi ra cong ra HC595--------------
xuat()
{
LATCH=1;
LATCH=0;
}
//-------------Ham hien thi ra LED ma tran-----------------
hienthi()
{
for(n=0;n<=7;n++)
{
if(n+m>=24)data_byte(hang[n+m-24]);
else data_byte(hang[n]);
if(n+m>=16)data_byte(hang[n+m-16]);
else data_byte(hang[n]);
if(n+m>=8)data_byte(hang[n+m-8]);
else data_byte(hang[n]);
if(n+m<=a-1)data_byte(hang[n+m]);
else data_byte(hang[n]);
P1=cot[n];
xuat();
delay(2);
}
}
//-----------Ham chinh------------------
main(void)
{
int i;
xuly();
a=0;
for(i=0;i<strlen(hang);i++){if(hang[i]!='\0')a++;};
m=0;
while(1)
{
for(k=0;k<=8;k++)
{
hienthi();
delay(2);
}
m++;
if(m==a-1)m=0;
}
}
File Attach :Led8x8.rar
------------------------------------------
#include<at89x52.h>
#include<string.h>
#include<font8x8.c>
//-------------Khai bao bien-------------
sbit SCK=P3^0;
sbit DATA=P3^1;
sbit LATCH=P3^2;
int m,n,k,a;
//--------------Khai bao mang------------
unsigned char xdata hang[200];
unsigned char cot[] ={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char text[]="LE TRUNG HIEU ";//Nhap text vao day de hien thi
//--------------Ham xu ly text-------------
xuly()
{
unsigned char data i,j,l;
l=strlen(text);
for(i=0;i<l;i++)
{
for(j=0;j<=7;j++)
{
if(text[i]==20){hang[8*i+j]=font2[j];}
else {hang[8*i+j]=font2[8*(text[i]-32)+j];}
}
}
}
//-------------Ham tre-----------------
delay(long t)
{
int i=0,j;
for(;i<=10;i++)
for(j=0;j<=t;j++);
}
//-----------Ham cho phep ghi vao thanh ghi HC595---------------
Data_bit()
{
SCK=1;
SCK=0;
}
//------------Ham viet 8 bit vao thanh ghi HC595--------------
void data_byte(unsigned char x)
{
unsigned char data temp,i;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80;
if(temp==0x80)
DATA=1;
else
DATA=0;
x=x<<1;
Data_bit();
}
}
//-------------Ham xuat gia tri tu thanh ghi ra cong ra HC595--------------
xuat()
{
LATCH=1;
LATCH=0;
}
//-------------Ham hien thi ra LED ma tran-----------------
hienthi()
{
for(n=0;n<=7;n++)
{
if(n+m>=24)data_byte(hang[n+m-24]);
else data_byte(hang[n]);
if(n+m>=16)data_byte(hang[n+m-16]);
else data_byte(hang[n]);
if(n+m>=8)data_byte(hang[n+m-8]);
else data_byte(hang[n]);
if(n+m<=a-1)data_byte(hang[n+m]);
else data_byte(hang[n]);
P1=cot[n];
xuat();
delay(2);
}
}
//-----------Ham chinh------------------
main(void)
{
int i;
xuly();
a=0;
for(i=0;i<strlen(hang);i++){if(hang[i]!='\0')a++;};
m=0;
while(1)
{
for(k=0;k<=8;k++)
{
hienthi();
delay(2);
}
m++;
if(m==a-1)m=0;
}
}