Mình có cái mạch led ma trận 8x32 dùng 89c52 + hc595, về nguyên và cách hoạt động của mạch thì mình hiểu rồi, cái đoạn code thì mình không hiểu lắm, do mới tập tành code C. Mấy bác ghi chú thích kỹ sau các lệnh để cho mình hiểu đoạn code này hơn được không, mình cảm ơn nhiều lắm hì hì
#include<reg52.h>
sbit SCK=P1^0;
sbit STR=P1^1;
sbit SDA=P1^2;
unsigned char code cot[]=
{
/*------------------------------------------------------------------------------
; If font display distortion, please check Fonts format of setup.
; Source file / text :
; Width x Height (pixels) :64X8
; Font Format/Size : Monochrome LCD Fonts ,Horizontal scan ,Big endian order/64Byte
; Font make date : 8/30/2013 4:19:39 PM
------------------------------------------------------------------------------*/
//0x40,0x08,0x08,//Width pixels,Height pixels,Width bytes
0x38,0x3E,0x0F,0x87,0xC1,0xF1,0xF8,0x78,0x00,0x00, 0x00,
0x44,0x21,0x10,0x44,0x21,0x01,0x00,0x80,0x00,0x00, 0x00,
0x82,0x21,0x10,0x04,0x11,0x01,0x00,0x80,0x00,0x00, 0x00,
0x82,0x3E,0x10,0x04,0x11,0xF1,0xF0,0x80,0x00,0x00, 0x00,
0xFE,0x21,0x10,0x04,0x11,0x01,0x00,0x9E,0x00,0x00, 0x00,
0x82,0x21,0x10,0x04,0x11,0x01,0x00,0x84,0x00,0x00, 0x00,
0x82,0x21,0x10,0x44,0x21,0x01,0x00,0x84,0x00,0x00, 0x00,
0x82,0x3E,0x0F,0x87,0xC1,0xF1,0x00,0x78,0x00,0x00, 0x00,
};
// Xem mang tren nhu mang 2 chieu,11 cot va 8 hang
char hang[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay(int t)
{
int a,b;
for(a=0;a<t;a++)
{
for(b=0;b<120;b++);
}
}
void quet(unsigned char d)
{
unsigned char i,t;
for(i=0;i<8;i++)
{
t=d&0x80;
if(t==0x80)
SDA=1;
else SDA=0;
d=d<<1;
SCK=0;
SCK=1;
}
}
unsigned char buffer(unsigned char x,unsigned char y,char i)
{
unsigned char temp;
temp=(x<<i)|(y>>(8-i));
return temp;
}
void main()
{
char i,j,k,m;
while(1)
{
for(k=0;k<7;k++)
{
for(i=0;i<8;i++)
{
for(j=0;j<20;j++)
{
for(m=0;m<8;m++)
{
quet(buffer(cot[m*11+k+3],cot[m*11+k+4],i)); // "m*11": 11 la so cot cua mang
quet(buffer(cot[m*11+k+2],cot[m*11+k+3],i));
quet(buffer(cot[m*11+k+1],cot[m*11+k+2],i));
quet(buffer(cot[m*11+k],cot[m*11+k+1],i));
STR=0;
STR=1;
P0=~hang[m];
delay(5);
P0=0xFF;
}
}
}
}
}
}
#include<reg52.h>
sbit SCK=P1^0;
sbit STR=P1^1;
sbit SDA=P1^2;
unsigned char code cot[]=
{
/*------------------------------------------------------------------------------
; If font display distortion, please check Fonts format of setup.
; Source file / text :
; Width x Height (pixels) :64X8
; Font Format/Size : Monochrome LCD Fonts ,Horizontal scan ,Big endian order/64Byte
; Font make date : 8/30/2013 4:19:39 PM
------------------------------------------------------------------------------*/
//0x40,0x08,0x08,//Width pixels,Height pixels,Width bytes
0x38,0x3E,0x0F,0x87,0xC1,0xF1,0xF8,0x78,0x00,0x00, 0x00,
0x44,0x21,0x10,0x44,0x21,0x01,0x00,0x80,0x00,0x00, 0x00,
0x82,0x21,0x10,0x04,0x11,0x01,0x00,0x80,0x00,0x00, 0x00,
0x82,0x3E,0x10,0x04,0x11,0xF1,0xF0,0x80,0x00,0x00, 0x00,
0xFE,0x21,0x10,0x04,0x11,0x01,0x00,0x9E,0x00,0x00, 0x00,
0x82,0x21,0x10,0x04,0x11,0x01,0x00,0x84,0x00,0x00, 0x00,
0x82,0x21,0x10,0x44,0x21,0x01,0x00,0x84,0x00,0x00, 0x00,
0x82,0x3E,0x0F,0x87,0xC1,0xF1,0x00,0x78,0x00,0x00, 0x00,
};
// Xem mang tren nhu mang 2 chieu,11 cot va 8 hang
char hang[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay(int t)
{
int a,b;
for(a=0;a<t;a++)
{
for(b=0;b<120;b++);
}
}
void quet(unsigned char d)
{
unsigned char i,t;
for(i=0;i<8;i++)
{
t=d&0x80;
if(t==0x80)
SDA=1;
else SDA=0;
d=d<<1;
SCK=0;
SCK=1;
}
}
unsigned char buffer(unsigned char x,unsigned char y,char i)
{
unsigned char temp;
temp=(x<<i)|(y>>(8-i));
return temp;
}
void main()
{
char i,j,k,m;
while(1)
{
for(k=0;k<7;k++)
{
for(i=0;i<8;i++)
{
for(j=0;j<20;j++)
{
for(m=0;m<8;m++)
{
quet(buffer(cot[m*11+k+3],cot[m*11+k+4],i)); // "m*11": 11 la so cot cua mang
quet(buffer(cot[m*11+k+2],cot[m*11+k+3],i));
quet(buffer(cot[m*11+k+1],cot[m*11+k+2],i));
quet(buffer(cot[m*11+k],cot[m*11+k+1],i));
STR=0;
STR=1;
P0=~hang[m];
delay(5);
P0=0xFF;
}
}
}
}
}
}