Học liệu

Chạy chữ quảng cáo Led ma trận

  • 10/09/2019
  • Học liệu

#include "io430.h"

void CLR_Column();
void Ck2();
void ChongLem();
//unsigned char k;
union reg {
struct bit {
unsigned char b0:1;
unsigned char b1:1;
unsigned char b2:1;
unsigned char b3:1;
unsigned char b4:1;
unsigned char b5:1;
unsigned char b6:1;
unsigned char b7:1;
}_BIT;
unsigned char _BYTE;
};
union reg*p1_dir=(union reg*)0x22;
union reg*p1_out=(union reg*)0x21;
union reg*p2_dir=(union reg*)0x2A;
union reg*p2_out=(union reg*)0x29;

 

void Toogle_All_Led();
void Turn_On_All_Led();
void Mo_Man();
void KeoMan();


void main(void)
{
unsigned int i;
unsigned char j;
unsigned char k;
unsigned char m;

BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
p1_dir->_BYTE = 0xFF; // Set P1 to output direction
p1_out->_BYTE = 0x00;

while(1){

unsigned char MaLed1[]={0xCD,0xCD,0x79,0x31,0x31,0x31,0x37,0x37}; //Ma cho MoRong_P1
unsigned char MaLed2[]={0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9F,0x9F}; //Ma cho MoRong_P2
unsigned char MaLed3[]={0x6C,0x6C,0x7C,0x38,0x38,0x7C,0x6C,0x6C}; //Ma cho MoRong_P3
unsigned char MaLed4[]={0xDB,0xDB,0xDB,0xDB,0xDB,0xDF,0xCE,0xC4}; //Ma cho MoRong_P4

unsigned char MaLedY[]={0XCC,0XCC,0X78,0X30,0X30,0X30,0X30,0X30}; //Ma cho MoRongP1
unsigned char MaLedL2[]={0X01,0X01,0X01,0X01,0X01,0X01,0X07,0X07}; //Ma cho MoRongP4
unsigned char MaLedL1[]={0X80,0X80,0X80,0X80,0X80,0X80,0X80,0X80 }; //Ma cho MoRongP3
unsigned char MaLedU[]={0X1B,0X1B,0X1B,0X1B,0X1B,0X1B,0X1F,0X1F }; //Ma cho MoRongP3
unsigned char MaLedX[]={ 0X6C,0X6C,0X7C,0X38,0X38,0X7C,0X6C,0X6C }; //Ma cho MoRongP2
unsigned char MaLedV[]={0x1B,0x1B,0x1B,0x1B,0x1B,0x1F,0x0E,0x04}; //Ma cho MoRongP1
unsigned char MaLedI[]={0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC0,0XC0}; //Ma cho MoRongP1


p1_out->_BIT.b6 = 0; //OE = 0;
p1_out->_BIT.b6 = 1; //CLR = 1;
//Hieu ung Led cho tat (2 lan)
// Toogle_All_Led();
//Bat dau hieu ung mo mang
// Turn_On_All_Led();
//************************Hieu ung mo man*******************************************************
// Mo_Man();
//***********************************************************************************
for(j=0;j<4;j++)
{
for(m=0;m<56;m++)
{
i=0;

{
Ck2(); //
if(m<8) //V
{
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(MaLedV[i]);
}
if((m>=8)&(m<16)) //VI
{
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(MaLed4[i]);
}
if((m>=16)&(m<24)) //VI X
{
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(MaLedX[i]);
MoRong_P1(MaLed4[i]);
}
if((m>=24)&(m<32)) //VI XU
{
MoRong_P1(0x00);
MoRong_P1(MaLedU[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
}
if((m>=32)&(m<40)) //VI XU L
{
MoRong_P1(MaLedL2[i]);
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
}
if((m>=40)&(m<48)) //VI XU L
{
MoRong_P1(MaLed1[i]);
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
}
if(m>=48) //VI XU LY
{
MoRong_P1(MaLed1[i]);
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
}

p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
// Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
CLR_Column();
__delay_cycles(500000);
}



for(j=0;j<5;j++) //Toggle 'VI XU LY'
{
//-------Hien chu--------
for(m=0;m<30;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2();
MoRong_P1(MaLed1[i]);
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
// Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
//-------Tat chu---------
CLR_Column();
__delay_cycles(500000);
}
////////////////////////////////TAT HIEN CHU VI XU LY////////////////////////////////////

CLR_Column();
__delay_cycles(1000000);

/////////////////////////////////////HIEN CHU TU TRAI SANG PHAI//////////////////////
// CLR_Column();
// __delay_cycles(500000);
/////////////////////////////////////SWITCH//////////////////////////////////////////
for(j=0;j<3;j++) //So lan Toggle (4 lan)
{
//******TEXT BRIGHT**********
for(m=0;m<60;m++)
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8) //Quet 8 hang
{
Ck2();
MoRong_P1(MaLed1[i]);
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
// Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
//**********TEXT OFF*********
for(m=0;m<60;m++)
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)// //Quet 8 hang
{
Ck2(); //
MoRong_P1(~MaLed1[i]);
MoRong_P1(~MaLed2[i]);
MoRong_P1(~MaLed3[i]);
MoRong_P1(~MaLed4[i]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
}
}

}

/////////////////////////////////////SWITCH//////////////////////////////////////////
CLR_Column();
__delay_cycles(1000000);
///////////////////////////////////VI -> VI XU -> VI XU LY////////////////////////////////////////////////////////////////////////////////
for(j=0;j<4;j++)
{
for(m=0;m<24;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(m<8)
{
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(MaLed4[i]);
}
if((m>=8)&(m<16))
{
MoRong_P1(0x00);
MoRong_P1(MaLedU[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
}
if(m>=16)
{
MoRong_P1(MaLed1[i]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
}

p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
// Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
CLR_Column();
// __delay_cycles(100000);
}


///////////////////////////////////VI -> VI XU -> VI XU LY////////////////////////////////////////////////////////////////////////////////
//CLR_Column();
//**************************************CHU DUNG YEN************************************
for(m=0;m<50;m++) //
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8) //Quet 8 hang
{
Ck2(); //
MoRong_P1(MaLed1[i]); //
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
//**************************************CHU DUNG YEN************************************
//////////////////////////HIEU UNG LUOI_SWITCH_XOA MAN HINH//////////////////////////////////
int t;
for(j=0;j<15;j++) //So lan Toggle (4 lan)
{
t ^= 0x55;
for(m=0;m<4;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2();
if(i%2==0) //k=7 i=1 ma=0,i=2 ma=1,k=8 i=0 ma=0
{
MoRong_P1(t);
MoRong_P1(t);
MoRong_P1(t);
MoRong_P1(t);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
}
else
{
MoRong_P1(~t);
MoRong_P1(~t);
MoRong_P1(~t);
MoRong_P1(~t);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
}
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
}
}

//**********TEXT OFF*********
/* for(m=0;m<4;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
i=0;
//j=0;
p1_out->_BIT.b6 = 1; //clr = 1
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(i%2==0) //k=7 i=1 ma=0,i=2 ma=1,k=8 i=0 ma=0
{
MoRong_P1(~0xAA); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(~0xAA);
MoRong_P1(~0xAA);
MoRong_P1(~0xAA);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
else
{
MoRong_P1(~0x55); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(~0x55);
MoRong_P1(~0x55);
MoRong_P1(~0x55);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
}
} */

}
//////////////////////////HIEU UNG LUOI_SWITCH_XOA MAN HINH////////////////////////////
CLR_Column();
__delay_cycles(1000000);

/////////////////////////////////////SANG DAN TU DUOI LEN//////////////////////////////////////////////////
k=0;
for(m=0;m<8;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
k++;
for(j=0;j<50;j++) //Thoi gian delay moi lan sang dan = so lan quet moi lan sang dan
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2();
if(i>=8-k) //k=7 i=1 ma=1
{
MoRong_P1(MaLed1[i]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
p1_out->_BIT.b3 = 1;
i++;

}
}
}
/////////////////////////////////////SANG SAN TU DUOI LEN//////////////////////////////////////////////////
__delay_cycles(1000000);
////////////////////////////////////////DICH CHU TU DUOI LEN///////////////////////////////////////////////
//------Dich len 1-------
k=0;
for(m=0;m<8;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
// i=0;
k++;
for(j=0;j<20;j++) //Thoi gian delay moi lan sang dan = so lan quet moi lan sang dan = Shift Speed
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(i>=8-k) //k=7 i=1 ma=0,i=2 ma=1,k=8 i=0 ma=0
{
MoRong_P1(MaLed1[(k-1)-(7-i)]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[(k-1)-(7-i)]);
MoRong_P1(MaLed3[(k-1)-(7-i)]);
MoRong_P1(MaLed4[(k-1)-(7-i)]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
p1_out->_BIT.b3 = 1;
i++;

}
}
}
//------------Dich len 2---------
k=1;
for(m=0;m<7;m++) //Cho k = 1 va m<7 (Thay vi k = 1 va m<8) de bo di mot lan lap lai chu VI XU LY, de dong bo voi ----Dich len 1----
{
// i=0;
k++;
for(j=0;j<20;j++) //Thoi gian delay moi lan sang dan = so lan quet moi lan sang dan = Shift Speed
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(i<=8-k) //k=1 i=0 ma=0,k=7 i=0 ma=6
{
MoRong_P1(MaLed1[i+(k-1)]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i+(k-1)]);
MoRong_P1(MaLed3[i+(k-1)]);
MoRong_P1(MaLed4[i+(k-1)]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
p1_out->_BIT.b3 = 1;
i++;

}
}
}

////////////////////////////////////////DICH CHU TU DUOI LEN///////////////////////////////////////////////
CLR_Column();
__delay_cycles(1000000);
///////////////////////////////////V X L -> I U Y////////////////////////////////////////////////////////////////////////////////
for(j=0;j<4;j++)
{
for(m=0;m<18;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(m<9)
{
MoRong_P1(MaLedL2[i]);
MoRong_P1(MaLedL1[i]);
MoRong_P1(MaLedX[i]);
MoRong_P1(MaLedV[i]);
}
if(m>=9)
{
MoRong_P1(MaLedY[i]);
MoRong_P1(MaLedU[i]);
MoRong_P1(0x00);
MoRong_P1(MaLedI[i]);
}
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
//Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
}


///////////////////////////////////V X L -> I U Y////////////////////////////////////////////////////////////////////////////////
CLR_Column();
////////////////////////////////////////DICH CHU TU TREN XUONG///////////////////////////////////////////////
//------Dich xuong 1-------
k=0;
for(m=0;m<8;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
// i=0;
k++;
for(j=0;j<20;j++) //Thoi gian delay moi lan sang dan = so lan quet moi lan sang dan = Shift Speed
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(i<k) //k=1 i=0 ma=7, k=7 i=5 ma=6, k=8 i=7 ma=7
{
MoRong_P1(MaLed1[i+8-k]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i+8-k]);
MoRong_P1(MaLed3[i+8-k]);
MoRong_P1(MaLed4[i+8-k]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
p1_out->_BIT.b3 = 1;
i++;

}
}
}
//------------Dich xuong 2---------
k=1;
for(m=0;m<7;m++) //Cho k = 1 va m<7 (Thay vi k = 1 va m<8) de bo di mot lan lap lai chu VI XU LY, de dong bo voi ----Dich len 1----
{
// i=0;
k++;
for(j=0;j<20;j++) //Thoi gian delay moi lan sang dan = so lan quet moi lan sang dan = Shift Speed
{
i=0;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
if(i>=k-1) //
{
MoRong_P1(MaLed1[i-(k-1)]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i-(k-1)]);
MoRong_P1(MaLed3[i-(k-1)]);
MoRong_P1(MaLed4[i-(k-1)]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
p1_out->_BIT.b3 = 1;
i++;

}
}
}

////////////////////////////////////////DICH CHU TU TREN XUONG///////////////////////////////////////////////
CLR_Column();
__delay_cycles(1000000);

//////////////////SANG DAN TU DUOI LEN + MUA ROI_GIAI THUAT 1_CHINH XAC HON_NHUNG_CHI DIEU CHINH DUOC TOC DO DICH/////////////////
unsigned int dem,w;
for(int q=0;q<2;q++)
{
k=0;
for(m=0;m<9;m++) //m<9 de xuat luon ma cua hang dau tjen do cau dk if((i>=8-k+1)) phia duoi da + them 1 o "k"
{
k++;

for(j=0;j<1;j++) //Thoi gian delay moi lan sang dan = so lan quet moi lan sang dan
{
dem=0;
w=7;
while((w>0)) //Delay dich,dau tien k=1,q chay tu hang 0 den hang 6 (truoc ma dau tien)
{
i=0;
dem++;
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
//if((j<1)&(i<8-w)&(i>=7-w)&(i<8-k)) //tuong duong dong if duoi
if((j<1)&(i==7-w)&(i<8-k)&(k<9)) //k=1 0=<i<1,1=<i<2,2=<i<3....6=<i<7 ;k=2 i<1,0<i<2,1<i<3....4<i<6
{ //j<1 de chj dich 1 lan, thu bo se bjet(neu bo no se dich laj nhjeu lan)
//k<9 de bo dong djch du thua o cuoj, thu bo se bjet
//7-w de dam bao moi lan chi hien 1 hang dich
//i<8-k la else cua dieu kien xuat ma hien chu
MoRong_P1(MaLed1[8-k]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[8-k]); //8-k la ma tren cung khi Sang dan tu duoi len
MoRong_P1(MaLed3[8-k]);
MoRong_P1(MaLed4[8-k]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
//Delay(50000);

}
//Delay(10);
if((i>=8-k+1)) //k=1 i=7 ma=7,k=7 i=1 ma=1 //w=7 k=1, w=6 k=2 //Lan dau tien (k=1) khong xuat
{
MoRong_P1(MaLed1[i]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
// Delay(160);
}

ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1; //
p1_out->_BIT.b3 = 1;
i++;

}
if((dem%2==0)) //dem%2 <=> dem % Shift Speed of Rain
{
w--;
}
}

}
}
}
///////////////SANG DAN TU DUOI LEN + MUA ROI_GIAI THUAT 1_CHINH XAC HON_NHUNG_CHI DIEU CHINH DUOC TOC DO DICH//////////////
//**************************************CHU DUNG YEN************************************
for(m=0;m<50;m++) //Quet 100 lan (tuc la hien chu 100 lan moi co the nhin thay)
{
i=0;
//j=0;
//p1_out->_BIT.b6 = 1; //clr = 1
p1_out->_BIT.b3 = 0; //Set du lieu vao DS de quet hang 0
while(i<8)//for(i=0;i<16;i++) //Quet 8 hang
{
Ck2(); //
MoRong_P1(MaLed1[i]); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(MaLed2[i]);
MoRong_P1(MaLed3[i]);
MoRong_P1(MaLed4[i]);

p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
// Delay(160);
p1_out->_BIT.b3 = 1;
i++;
ChongLem();
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra tat ca data of Ham MoRong
p1_out->_BIT.b2 = 1;
}
}
//**************************************CHU DUNG YEN************************************
CLR_Column();




}
}
//******************************************************************************

//***********************Xoa du lieu con luu trong cot****************************************************
void CLR_Column()
{
unsigned int u;
for(u=0;u<32;u++) //Xoa du lieu con luu lai o ngo ra (cot) cua 74595 do hieu ung truoc
{
p1_out->_BIT.b0 = 1;
p1_out->_BIT.b1 = 0; //Ck11
p1_out->_BIT.b1 = 1;
p1_out->_BIT.b2 = 0; //Ck12 => Xuat ra ngo ra 74595 quet cot
p1_out->_BIT.b2 = 1;
}
}

////////////////////////////////////////////////
void Ck2()
{
p1_out->_BIT.b4 = 0; //Ck21
p1_out->_BIT.b4 = 1; //
p1_out->_BIT.b5 = 0; //Ck22 => Xuat ra ngo ra 74595 quet hang
p1_out->_BIT.b5 = 1;
}

////////////////////CHONG LEM/////////////////

///////////////////////////////////
void ChongLem()
{
MoRong_P1(0x00); //Lay ma hien chu ra Led ma tran tuong ung voi so hang i //MoRongP1 va MoRongP2 phai lien tiep
MoRong_P1(0x00);
MoRong_P1(0x00);
MoRong_P1(0x00);
}
/////////////////////CHONG LEM///////////////
//*************CAC HIEU UNG***************************************

////////////////////////MO MAN/////////////////////////
/*void Mo_Man()
{
unsigned int j,k;
Delay(50000);
Delay(50000);
k = 15;
while(k > 0)//for(m=0;m<16;m++)
{
for(j=0;j<k;j++) //Cho cot 17 den 31 = 1 (Moi lan giam mot cot)
{
p1_out->_BIT.b0 = 0;
p1_out->_BIT.b1 = 0; //Ck11
p1_out->_BIT.b1 = 1;
}
for(j=0;j<31-k*2+1;j++) //Cho cot 15, 16 = 0 (Moi lan giam 2 cot)
{
p1_out->_BIT.b0 = 1;
p1_out->_BIT.b1 = 0; //Ck11
p1_out->_BIT.b1 = 1;
}
for(j=0;j<k;j++) //Cho cot 0 den 14 = 1 (Moi lan giam 1 cot)
{
p1_out->_BIT.b0 = 0;
p1_out->_BIT.b1 = 0; //Ck11
p1_out->_BIT.b1 = 1;
}
p1_out->_BIT.b2 = 0; //Ck12 //Xuat ra (bat dau mo man)
p1_out->_BIT.b2 = 1;
/* for(m=0;m<200;m++) //So vong lap chinh la thoi gian moi lan giam 2 cot de mo man cua LED
{
MoRongP1(0xFF); //Toogle Row to All Led On with high frequency
MoRongP1(0x00); //If All Led On Continous is 2803's current isn't enought supply for All Led
Delay(10);
}
Delay(50000); //Don't use this stament, if use => it's time On All Led => Wrong because it isn't enough current as above
k--; //Giam k de tiep tuc keo man (bo 2 cot giua tiep theo) (moi lan giam 2 cot sang)
}
} */
////////////////////////MO MAN/////////////////////////
////////////////////////KEO MAN////////////////////////
/*void KeoMan()
{
unsigned int k,j;
Delay(50000);
Delay(50000);
k = 16;
while(k > 0)//for(m=0;m<16;m++)
{
for(j=0;j<17-k;j++) //Cho cot 31 = 1 (Moi lan tang mot cot)
{
p1_out->_BIT.b0 = 0;
p1_out->_BIT.b1 = 0;
p1_out->_BIT.b1 = 1;
}
for(j=0;j<32-(17-k)*2;j++) //Cho cot 15, 16 = 0 (Moi lan giam 2 cot)
{
p1_out->_BIT.b0 = 1;
p1_out->_BIT.b1 = 0;
p1_out->_BIT.b1 = 1;
}
for(j=0;j<17-k;j++) //Cho cot 0 = 1 (Moi lan tang 1 cot)
{
p1_out->_BIT.b0 = 0;
p1_out->_BIT.b1 = 0;
p1_out->_BIT.b1 = 1;
}
p1_out->_BIT.b2 = 0; //Xuat ra (bat dau mo man)
p1_out->_BIT.b2 = 1;
/* for(m=0;m<200;m++) //So vong lap chinh la thoi gian moi lan giam 2 cot de mo man cua LED
{
MoRongP1(0xFF); //Toogle Row to All Led On with high frequency
MoRongP1(0x00); //If All Led On Continous is 2803's current isn't enought supply for All Led
__delay_cycles(10);//Delay(100);
}
//Delay(50000);
k--; //Giam k de tiep tuc keo man (bo 2 cot giua tiep theo) (moi lan giam 2 cot sang)
}
} */
///////////////////////////////WIDEN PORT FOR SCANNING ROW/////////////////////////////
void MoRong_P1(unsigned int e)
{
volatile unsigned int g,h; // Bien khai bao trong RAM
unsigned int f;
f=0x80; // 32 bit vi co 32 cot (o day chi 8 bit)
g=8; // Vi co 32 cot
while(g>0) //
{
h = e&f; // h = e and f
if ( h == f) // Neu h=f
{
p1_out->_BIT.b0=0; // qua ULN2803 thanh muc 1
}
else //
{
p1_out->_BIT.b0=1; // qua ULN2803 thanh muc 0
}
p1_out->_BIT.b1=1; //Ck21
p1_out->_BIT.b1=0; //
f=f>>1; // Xoay phai f
g--; //Lay bit ke tiep cua ma
}
}

Các tin khác