8*8點(diǎn)陣流水顯示程序與原理
首先是讓漢字能夠靜態(tài)顯示,顯示一段時(shí)間后(時(shí)間可能很短)把所顯示的漢字編碼移一位重新送出,比如要向左移動(dòng),原本顯示在第一列的數(shù)據(jù)就丟棄了,把第二列的數(shù)據(jù)送到第一列上顯示,依次移動(dòng)顯示一屏,顯示一段時(shí)間再進(jìn)行一次移動(dòng),人們看起來(lái)也就是移動(dòng)的了。
這是程序:調(diào)試過(guò)的
硬件連接可以去這里:
#include
//sbit A=P2^0;
//sbit B=P2^1;
//sbit C=P2^2;
//sbit select=P2^3;
sbit clk=P3^0; //595串行時(shí)鐘端
sbit da=P3^1; //595串行數(shù)據(jù)端
sbit enable=P3^2;
/************************************字庫(kù)**********************************************/
unsigned char code stable[]={/*-- 文字: 天 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0x80,0x40,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x06,0x42,0x01,0xFE,
0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x30,0x42,0x60,0x42,0x20,0x40,0x00,0x00,
/*-- 文字: 天 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0x80,0x40,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x06,0x42,0x01,0xFE,
0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x30,0x42,0x60,0x42,0x20,0x40,0x00,0x00,
/*-- 文字: 快 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x70,0x00,0x00,0xFF,0xFF,0x00,0x08,0x80,0xB0,0x40,0x88,0x30,0x88,0x0E,0x88,
0x01,0xFF,0x06,0x88,0x08,0x88,0x30,0x88,0x60,0xF8,0xC0,0x80,0x40,0x80,0x00,0x00,
/*-- 文字: 樂(lè) --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0x20,0x00,0x18,0x40,0x0C,0xFC,0x07,0x44,0x12,0x44,0x20,0x44,0x40,0x46,
0x3F,0xFA,0x00,0x42,0x00,0x43,0x02,0x43,0x0C,0x42,0x38,0x40,0x10,0x00,0x00,0x00,
/*-- 文字: ! --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0xDF,0xFC,
0xDF,0xFC,0x01,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 歡 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x20,0x14,0x10,0x24,0x4C,0x44,0x43,0x84,0x43,0x64,0x2C,0x1C,0x20,0x20,0x10,0x18,
0x0C,0x0F,0x03,0xE8,0x06,0x08,0x18,0x08,0x30,0x28,0x60,0x18,0x20,0x08,0x00,0x00,
/*-- 文字: 迎 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x40,0x40,0x20,0x41,0x1F,0xCE,0x20,0x04,0x40,0x00,0x47,0xFC,0x42,0x04,0x41,0x02,
0x40,0x02,0x5F,0xFC,0x40,0x04,0x42,0x04,0x44,0x04,0x43,0xFC,0x40,0x00,0x00,0x00,
/*-- 文字: 來(lái) --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x20,0x00,0x20,0x80,0x10,0x84,0x10,0x84,0x08,0x94,0x04,0xA4,0x02,0xC4,0xFF,0xFF,
0x01,0x84,0x02,0xC4,0x04,0xB4,0x08,0x94,0x18,0x84,0x30,0x84,0x10,0x80,0x00,0x00,
/*-- 文字: 我 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x04,0x20,0x04,0x20,0x42,0x22,0x82,0x22,0x7F,0xFE,0x01,0x21,0x01,0x21,0x10,0x20,
0x10,0x20,0x08,0xFF,0x07,0x20,0x1A,0x22,0x21,0xAC,0x40,0x20,0xF0,0x20,0x00,0x00,
/*-- 文字: 的 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0x7F,0xF8,0x10,0x8C,0x10,0x8B,0x10,0x88,0x3F,0xF8,0x00,0x40,0x00,0x30,
0x00,0x8F,0x03,0x08,0x26,0x08,0x40,0x08,0x20,0x08,0x1F,0xF8,0x00,0x00,0x00,0x00,
/*-- 文字: 空 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x10,0x40,0x0C,0x40,0x84,0x41,0x44,0x41,0x24,0x41,0x14,0x41,0x05,0x7F,0x06,
0x41,0x04,0x41,0x14,0x41,0x24,0x41,0x44,0x40,0x84,0x40,0x14,0x00,0x0C,0x00,0x00,
/*-- 文字: 間 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0xFF,0xF8,0x00,0x01,0x00,0x06,0x00,0x00,0x07,0xF0,0x04,0x92,0x04,0x92,
0x04,0x92,0x04,0x92,0x07,0xF2,0x40,0x02,0x80,0x02,0x7F,0xFE,0x00,0x00,0x00,0x00,
/*-- 文字: 天 --*/
/*-- 宋體12; 此字體下對(duì)應(yīng)的點(diǎn)陣為:寬x高=16x16 --*/
0x00,0x00,0x80,0x40,0x40,0x42,0x20,0x42,0x10,0x42,0x08,0x42,0x06,0x42,0x01,0xFE,
0x02,0x42,0x04,0x42,0x08,0x42,0x10,0x42,0x30,0x42,0x60,0x42,0x20,0x40,0x00,0x00,
};
/***************************************************************************************
行顯示子程序
實(shí)質(zhì)是給當(dāng)前行中的所有列傳送兩字節(jié)的數(shù)據(jù)
***************************************************************************************/
void hang_disp(unsigned char temp1,unsigned char temp2)
{
unsigned char i;
for(i=0;i<16;i++)
{
if(i==8)temp2=temp1; /***前8位即一字節(jié)傳送完之后,傳送該行的第二字節(jié)***/
if(temp2&0x01)da=1; /****數(shù)據(jù)從端口輸出****/
else da=0; /****生成一上升沿,595上升沿接受數(shù)據(jù)****/
clk=0;clk=1;clk=0;
temp2=temp2>>1;
}
enable=0;enable=1;enable=0; /****595并行輸出使能****/
}
/***************************************************************************************
清行子程序
如果沒(méi)有清行程序,該行顯示完轉(zhuǎn)到下一行時(shí)595的輸出還沒(méi)有變,還是上一行的數(shù)據(jù) ,因?yàn)槌绦蛑惺窍冗x定行,
再向595傳數(shù)據(jù)的,所以下一行開(kāi)始時(shí)有一段時(shí)間是顯示合一行的內(nèi)容的,這段時(shí)間就是向595傳兩個(gè)字節(jié)數(shù)據(jù)的時(shí)間。
/***************************************************************************************/
void hang_clear()
{
unsigned char i;
for(i=0;i<16;i++)
{
da=0; /***595的輸出連接的是點(diǎn)陣的陰極,所以讓595輸出高電平,可以使得該行的LED熄滅****/
clk=0;clk=1;clk=0;
}
enable=0;enable=1;enable=0;
}
/***************************************************************************************/
/***************************************************************************************/
unsigned int count=0;
unsigned char move=0;
void disp()
{
unsigned char i;
unsigned int j;
count++;
for(i=0;i<16;i++)
{
P2=i; /*****選定行*****/
//hang_disp(stable[2*(i+move)],stable[2*(i+move)+1]); /***從字庫(kù)中取數(shù)據(jù)****/
hang_disp(~stable[2*(i+move)],~stable[2*(i+move)+1]); /***從字庫(kù)中取數(shù)據(jù)再取反,能實(shí)現(xiàn)反顯****/
for(j=0;j<10;j++); /***顯示和清零間加以延時(shí),以便顯示明顯,可以自行調(diào)節(jié),也可以去掉***/
hang_clear();
}
if(count==10) /***調(diào)節(jié)移動(dòng)的速度***/
{
count=0;
move++;
if(move==192) /***調(diào)節(jié)移動(dòng)的字?jǐn)?shù)***n=move/16***/
{
move=0;
}
}
}
/***************************************************************************************/
/***************************************************************************************/
main()
{
while(1)
{
disp();
}
}
/***************************************************************************************/
/***************************************************************************************/