e đang lay hoay vs cái matrix 8x8 mãi mà ko ghép được phần cứng. mà có ghép xong rồi cũng ko být đung hay sai ra sao nữa. e dùng chân P0 để quét cột và p2 để quét hàng. code của e post dưới. các bác giúp e cái phần mạch nhé: thanks các b nhiều
\#include <REGX51.H>
void delay(long time)
{
long n;
for(n=0; n<time; n++)
{
;
}
}
unsigned char kytu1[9];// Mang 9 phan tu chua gia tri cac hang day ra cong 2
unsigned char k=0;// Bien xac dinh cac ky tu
/* Ham nap gia tri hien thi cac ky tu vao mang kytu1
co 8 gia tri dua ra va 1 gia tri khong bat den nao de cac ky tu cach nhau 1 cot */
void mahoa(unsigned char x)
{
switch(x)
{
// Dau trang
case 0: { kytu1[0]=0x00; kytu1[1]=0x00; kytu1[2]=0x00; kytu1[3]=0x00;
kytu1[4]=0x00; kytu1[5]=0x00; kytu1[6]=0x00; kytu1[7]=0x00; kytu1[8]=0x00; break; }
// Chu M
case 1: { kytu1[0]=0x00; kytu1[1]=0xFF; kytu1[2]=0x02; kytu1[3]=0x04;
kytu1[4]=0x08; kytu1[5]=0x04; kytu1[6]=0x02; kytu1[7]=0xFF; kytu1[8]=0x00; break;
}
// Chu T
case 2: { kytu1[0]=0x00; kytu1[1]=0x01; kytu1[2]=0x01; kytu1[3]=0x01;
kytu1[4]=0xFF; kytu1[5]=0x01; kytu1[6]=0x01; kytu1[7]=0x01; kytu1[8]=0x00; break;
}
// Chu C
case 3: { kytu1[0]=0x00; kytu1[1]=0x7E; kytu1[2]=0x81; kytu1[3]=0x81;
kytu1[4]=0x81; kytu1[5]=0x81; kytu1[6]=0x42; kytu1[7]=0x00; kytu1[8]=0x00; break; }
// Dau trang
case 4: { kytu1[0]=0x00; kytu1[1]=0x00; kytu1[2]=0x00; kytu1[3]=0x00;
kytu1[4]=0x00; kytu1[5]=0x00; kytu1[6]=0x00; kytu1[7]=0x00; kytu1[8]=0x00; break; }
}
}
/* Ham quet led ma tran_ vua hien thi vua dich ky tu dan sang trai*/
void hienthi(void)
{
unsigned char n,m,lap;
unsigned char cot[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; // Cac phan tu
for(m=0; m<8 ; m++)// Dich hien thi
{
for(lap=0; lap<10; lap ++) // Lap hien thi
{
for(n=0; n<8 ; n++)// Quet cot
{
if((n+m)<9 )// Neu n+m < 9 hien thi ky tu 1
{
mahoa(k); // Nap cac gia tri ma hoa ky tu dua ra cac hang (Cong 2)
P0=cot[n]; // Day gia tri 0V ra cong 0 (cac cot)
P2=kytu1[n+m];// Day cac gia tri cac hang (ma hoa ky tu) ra cong 2(cac hang)
delay(45);// Tre du de led sang
}
if((n+m) > 7)// Neu n+m >7 hien thi ky tu 2
{
mahoa(k+1);// Nap gia tri ma hoa ky tu tiep de dua ra cac hang(Cong 2)
P0=cot[n];// Day gia tri logic 0V ra cong 0(cac cot)
P2=kytu1[n+m-8];// Day cac gia tri cac hang (ma hoa ky tu) ra cong 2(cac hang)
delay(45);// Tre du de led sang
}
P0=0xFF;// Day cac cot len cao
P2=0x00;// Dua cac hang xuong thap de tat toan bo cac led.
}
}
}
}
void main(void)
{
while(1)// Vong lap vo han.
{
hienthi(); // Hien thi 2 ky tu dau tien dau trang va chu M
k=k+1; // Tang k de hien thi chu M va chu T lan tiep
if(k==4) k=0;// Quay vong hien thi
}
}
\#include <REGX51.H>
void delay(long time)
{
long n;
for(n=0; n<time; n++)
{
;
}
}
unsigned char kytu1[9];// Mang 9 phan tu chua gia tri cac hang day ra cong 2
unsigned char k=0;// Bien xac dinh cac ky tu
/* Ham nap gia tri hien thi cac ky tu vao mang kytu1
co 8 gia tri dua ra va 1 gia tri khong bat den nao de cac ky tu cach nhau 1 cot */
void mahoa(unsigned char x)
{
switch(x)
{
// Dau trang
case 0: { kytu1[0]=0x00; kytu1[1]=0x00; kytu1[2]=0x00; kytu1[3]=0x00;
kytu1[4]=0x00; kytu1[5]=0x00; kytu1[6]=0x00; kytu1[7]=0x00; kytu1[8]=0x00; break; }
// Chu M
case 1: { kytu1[0]=0x00; kytu1[1]=0xFF; kytu1[2]=0x02; kytu1[3]=0x04;
kytu1[4]=0x08; kytu1[5]=0x04; kytu1[6]=0x02; kytu1[7]=0xFF; kytu1[8]=0x00; break;
}
// Chu T
case 2: { kytu1[0]=0x00; kytu1[1]=0x01; kytu1[2]=0x01; kytu1[3]=0x01;
kytu1[4]=0xFF; kytu1[5]=0x01; kytu1[6]=0x01; kytu1[7]=0x01; kytu1[8]=0x00; break;
}
// Chu C
case 3: { kytu1[0]=0x00; kytu1[1]=0x7E; kytu1[2]=0x81; kytu1[3]=0x81;
kytu1[4]=0x81; kytu1[5]=0x81; kytu1[6]=0x42; kytu1[7]=0x00; kytu1[8]=0x00; break; }
// Dau trang
case 4: { kytu1[0]=0x00; kytu1[1]=0x00; kytu1[2]=0x00; kytu1[3]=0x00;
kytu1[4]=0x00; kytu1[5]=0x00; kytu1[6]=0x00; kytu1[7]=0x00; kytu1[8]=0x00; break; }
}
}
/* Ham quet led ma tran_ vua hien thi vua dich ky tu dan sang trai*/
void hienthi(void)
{
unsigned char n,m,lap;
unsigned char cot[8]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F}; // Cac phan tu
for(m=0; m<8 ; m++)// Dich hien thi
{
for(lap=0; lap<10; lap ++) // Lap hien thi
{
for(n=0; n<8 ; n++)// Quet cot
{
if((n+m)<9 )// Neu n+m < 9 hien thi ky tu 1
{
mahoa(k); // Nap cac gia tri ma hoa ky tu dua ra cac hang (Cong 2)
P0=cot[n]; // Day gia tri 0V ra cong 0 (cac cot)
P2=kytu1[n+m];// Day cac gia tri cac hang (ma hoa ky tu) ra cong 2(cac hang)
delay(45);// Tre du de led sang
}
if((n+m) > 7)// Neu n+m >7 hien thi ky tu 2
{
mahoa(k+1);// Nap gia tri ma hoa ky tu tiep de dua ra cac hang(Cong 2)
P0=cot[n];// Day gia tri logic 0V ra cong 0(cac cot)
P2=kytu1[n+m-8];// Day cac gia tri cac hang (ma hoa ky tu) ra cong 2(cac hang)
delay(45);// Tre du de led sang
}
P0=0xFF;// Day cac cot len cao
P2=0x00;// Dua cac hang xuong thap de tat toan bo cac led.
}
}
}
}
void main(void)
{
while(1)// Vong lap vo han.
{
hienthi(); // Hien thi 2 ky tu dau tien dau trang va chu M
k=k+1; // Tang k de hien thi chu M va chu T lan tiep
if(k==4) k=0;// Quay vong hien thi
}
}