Mình đang làm đồ án 2, sử dụng msp430g2553. Code của mình sử dụng với 1 con 8x8 thì chạy chữ rất chuẩn, nhưng khi đặt 5 con led 8x8 vào lại vẫn chạy như 1 con (chạy giống hệt nhau), các bạn giúp mình sửa code này với nhé. Giờ mình làm xong mạch rồi, nhưng code thì lại bị như vậy.
Code:
#include "msp430g2553.h"
int m,n,k;
// KHAI BAO CHAN /////////////
// PORT2.0 == data
// PORT2.1 == clk
// PORT2.2 == chot
//---------chuong trình con delay ----------
void delay(unsigned int t)
{
unsigned int i, a;
for(i=0;i<t;i++)
{
for(a=0; a<125; a++)
{}
}
}
///////////////////////////////////////////
//------------------ khai báo du lieu trên hang ------------
unsigned char hang[]={
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0xff, // I
//0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, // L
0x81, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x81, 0xff, // O
0xe0, 0xdf, 0xbf, 0x7f, 0xbf, 0xdf, 0xe0, 0xff, // V
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0xff, 0xff, // E
//0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfc, 0x7b, 0xb7, 0xcf, 0xef, 0xf7, 0xfb, 0xfc, // Y
0x81, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x81, 0xff, // O
0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x80, 0xff, // 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 cot[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//////////////////////////////////////////////////////////////
//--------- Chuyen doi noi tiep sang song song --------
void convert(unsigned char data_out)
{
unsigned char i,tg;
for(i=0;i<8;i++)
{
tg = data_out&0x80;
if(tg == 0x80)
P2OUT|=BIT0;
else
P2OUT&=~BIT0;
data_out *= 2;
P2OUT&=~BIT1;
P2OUT|=BIT1;
}
P2OUT&=~BIT2;
P2OUT|=BIT2;
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// KHAI BAO SU DUNG THACH ANH NOI 1MHZ
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// KHAI BAO VAO RA CHO PORT1 VA PORT 2
P1DIR|=(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
P2DIR|=(BIT0+BIT1+BIT2);
// KHAI BAO GPIO CHO PORT 2
P2SEL = 0xf8;
P2SEL2 = 0xf8;
// KHAI BAO GPIO CHO PORT 1
P1SEL = 0x00;
P1SEL2 = 0x00;
while(1)
{
for(m=0;m<120;m++)
{
for(k=0;k<5;k++)
{
for(n=0;n<8;n++)
{
convert(hang[n+m+16]);
convert(hang[n+m+8]);
convert(hang[n+m]);
P2OUT&=~BIT2;
P2OUT|=BIT2;
P1OUT = cot[n];
delay(2);
P1OUT = 0x00;
}
}
}
}
}
https://www.dropbox.com/s/6g05mi5osq..._MATRIX2.1.rar
Code:
#include "msp430g2553.h"
int m,n,k;
// KHAI BAO CHAN /////////////
// PORT2.0 == data
// PORT2.1 == clk
// PORT2.2 == chot
//---------chuong trình con delay ----------
void delay(unsigned int t)
{
unsigned int i, a;
for(i=0;i<t;i++)
{
for(a=0; a<125; a++)
{}
}
}
///////////////////////////////////////////
//------------------ khai báo du lieu trên hang ------------
unsigned char hang[]={
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7e, 0x7e, 0x7e, 0x00, 0x7e, 0x7e, 0x7e, 0xff, // I
//0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, // L
0x81, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x81, 0xff, // O
0xe0, 0xdf, 0xbf, 0x7f, 0xbf, 0xdf, 0xe0, 0xff, // V
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0xff, 0xff, // E
//0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xfc, 0x7b, 0xb7, 0xcf, 0xef, 0xf7, 0xfb, 0xfc, // Y
0x81, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x81, 0xff, // O
0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x80, 0xff, // 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 cot[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
//////////////////////////////////////////////////////////////
//--------- Chuyen doi noi tiep sang song song --------
void convert(unsigned char data_out)
{
unsigned char i,tg;
for(i=0;i<8;i++)
{
tg = data_out&0x80;
if(tg == 0x80)
P2OUT|=BIT0;
else
P2OUT&=~BIT0;
data_out *= 2;
P2OUT&=~BIT1;
P2OUT|=BIT1;
}
P2OUT&=~BIT2;
P2OUT|=BIT2;
}
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
// KHAI BAO SU DUNG THACH ANH NOI 1MHZ
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
// KHAI BAO VAO RA CHO PORT1 VA PORT 2
P1DIR|=(BIT0+BIT1+BIT2+BIT3+BIT4+BIT5+BIT6+BIT7);
P2DIR|=(BIT0+BIT1+BIT2);
// KHAI BAO GPIO CHO PORT 2
P2SEL = 0xf8;
P2SEL2 = 0xf8;
// KHAI BAO GPIO CHO PORT 1
P1SEL = 0x00;
P1SEL2 = 0x00;
while(1)
{
for(m=0;m<120;m++)
{
for(k=0;k<5;k++)
{
for(n=0;n<8;n++)
{
convert(hang[n+m+16]);
convert(hang[n+m+8]);
convert(hang[n+m]);
P2OUT&=~BIT2;
P2OUT|=BIT2;
P1OUT = cot[n];
delay(2);
P1OUT = 0x00;
}
}
}
}
}
https://www.dropbox.com/s/6g05mi5osq..._MATRIX2.1.rar
Comment