Mình đã làm mạch mô phỏng và viết code...nhưng chạy chưa được...có lẽ là code bị sai...mọi người xem hộ mình cái nhé ! Thanks.
File đính kèm:http://www.mediafire.com/?o62tiz7in45nx23
Code: http://www.mediafire.com/download.php?hlnnm4wghjbvpnj
---------------------------------
#include<at89x51.h>
#include<string.h>
//-------------Khai bao bien-------------
sbit SCH=P3^0;
sbit DATA=P3^1;
sbit LATCH=P3^2;
int m,n,t,k;
//--------------Khai bao mang------------
unsigned char manghang[]={
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//led tat
0xFF,0x00,0x00,0xEF,0xEF,0x00,0x00,0xFF,//chu H
0xFF,0xFF,0x7E,0x00,0x00,0x7E,0xFF,0xFF,//chu I
0xFF,0x00,0x00,0x6E,0x6E,0x6E,0x7E,0xFF,//chu E
0xFF,0x01,0x00,0xFE,0xFE,0x00,0x01,0xFF,//chu U
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
unsigned char mangcot1[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01},mangcot2[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//-------------Ham tre-----------------
void tre(long t)
{
int i=0,j;
for(;i<=10;i++)
for(j=0;j<=t;j++);
}
//-----------Ham cho phep ghi vao thanh ghi HC595---------------
void Data_bit()
{
SCH=1;
SCH=0;
}
//------------Ham viet 8 bit vao thanh ghi HC595--------------
void data_byte(unsigned char x)
{
unsigned char temp,i;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80;
if(temp==0x80)
DATA=1;
else
DATA=0;
x*=2;
Data_bit();
}
}
//-------------Ham xuat gia tri tu thanh ghi ra cong ra HC595--------------
void xuat()
{
LATCH=1;
LATCH=0;
}
//-------------Ham hien thi ra LED ma tran-----------------
void hienthi()
{
for(n=0;n<=7;n++)
{
data_byte(manghang[n+m]);
if(n+m>=8)data_byte(manghang[n+m-8]);
if(n+m>=16)data_byte(manghang[n+m-16]);
if(n+m>=24)data_byte(manghang[n+m-24]);
//tre(2);
P1=mangcot1[n];
xuat();
tre(2);
}
}
//-----------Ham chinh------------------
void main(void)
{
m=0;
while(1)
{
for(k=0;k<strlen(manghang)-1;k++)
{
hienthi();
tre(2);
}
m++;
if(m==strlen(manghang)-2)m=0;
}
}
File đính kèm:http://www.mediafire.com/?o62tiz7in45nx23
Code: http://www.mediafire.com/download.php?hlnnm4wghjbvpnj
---------------------------------
#include<at89x51.h>
#include<string.h>
//-------------Khai bao bien-------------
sbit SCH=P3^0;
sbit DATA=P3^1;
sbit LATCH=P3^2;
int m,n,t,k;
//--------------Khai bao mang------------
unsigned char manghang[]={
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//led tat
0xFF,0x00,0x00,0xEF,0xEF,0x00,0x00,0xFF,//chu H
0xFF,0xFF,0x7E,0x00,0x00,0x7E,0xFF,0xFF,//chu I
0xFF,0x00,0x00,0x6E,0x6E,0x6E,0x7E,0xFF,//chu E
0xFF,0x01,0x00,0xFE,0xFE,0x00,0x01,0xFF,//chu U
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};
unsigned char mangcot1[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01},mangcot2[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//-------------Ham tre-----------------
void tre(long t)
{
int i=0,j;
for(;i<=10;i++)
for(j=0;j<=t;j++);
}
//-----------Ham cho phep ghi vao thanh ghi HC595---------------
void Data_bit()
{
SCH=1;
SCH=0;
}
//------------Ham viet 8 bit vao thanh ghi HC595--------------
void data_byte(unsigned char x)
{
unsigned char temp,i;
for(i=0;i<8;i++)
{
temp=x;
temp=temp&0x80;
if(temp==0x80)
DATA=1;
else
DATA=0;
x*=2;
Data_bit();
}
}
//-------------Ham xuat gia tri tu thanh ghi ra cong ra HC595--------------
void xuat()
{
LATCH=1;
LATCH=0;
}
//-------------Ham hien thi ra LED ma tran-----------------
void hienthi()
{
for(n=0;n<=7;n++)
{
data_byte(manghang[n+m]);
if(n+m>=8)data_byte(manghang[n+m-8]);
if(n+m>=16)data_byte(manghang[n+m-16]);
if(n+m>=24)data_byte(manghang[n+m-24]);
//tre(2);
P1=mangcot1[n];
xuat();
tre(2);
}
}
//-----------Ham chinh------------------
void main(void)
{
m=0;
while(1)
{
for(k=0;k<strlen(manghang)-1;k++)
{
hienthi();
tre(2);
}
m++;
if(m==strlen(manghang)-2)m=0;
}
}
Comment