//單片機(jī):STC89C52//晶振:22.1184M,下載選擇雙倍時(shí)鐘,否則會(huì)有閃爍!
//顯示屏:HUB08接口16X64單紅點(diǎn)陣
//顯示方式:左移
//作者:振甬電子
//QQ: 1766135164
//網(wǎng)址:www.51hei.com
//時(shí)間:2013-05-13
本文引用地址:http://2s4d.com/article/201611/323717.htm#include
#include"zimo.h"
#define ucharunsigned char
#define uintunsigned int
#define SPEED5//定義速度與數(shù)字成反比 數(shù)字小,速度快
#define NUMBER11//定義要移動(dòng)顯示總16X16漢字個(gè)數(shù),計(jì)算方法:NUMBER=漢字顯示個(gè)數(shù)+4個(gè)空格
uchar word=0,col=0,col1=0,disrow=0,move=0;//wor為要顯字變量,col為位移變量,col1為字節(jié)偏移量,disrow為行變量
uchar BUFF__UP[17];//緩沖字節(jié)數(shù)取值=[2*板點(diǎn)陣寬度/8]+1比較保險(xiǎn),即兩倍板的點(diǎn)陣字節(jié)數(shù).
uchar BUFF__UP0[12];//上半屏顯示緩沖
sbit R1=P0^4;//紅色數(shù)據(jù)1
sbit R2=P3^3;//紅色數(shù)據(jù)2
sbit G1=P3^4;//綠色數(shù)據(jù)1
sbit G2=P3^5;//綠色數(shù)據(jù)
sbit CLK=P0^7; //595時(shí)鐘端口
sbit STB=P0^6; //595鎖存端口
sbit OE =P0^5;//74HC138使能:低有效
//根據(jù)列指針由雙字節(jié)合并為單字節(jié)的子程序模塊
//和點(diǎn)陣的取模方式有關(guān):低位在前,高位在后,但是實(shí)際顯示,高位在前,低位在后!
uchar Combine_2byte(uchar h1,uchar h2)
{
uchar T_date,tempcol;
tempcol=col1;
T_date=(h1>>tempcol)|(h2<<(8-tempcol));
return T_date;
}
//分別裝屏點(diǎn)陣數(shù)據(jù)
void Load_one_line(void)//多加4個(gè)16X16漢字的緩沖
{
BUFF__UP[0]=Table[word][disrow*2+0];//裝載點(diǎn)陣數(shù)據(jù)
BUFF__UP[1]=Table[word][disrow*2+1];
BUFF__UP[2]=Table[word+1][disrow*2+0];
BUFF__UP[3]=Table[word+1][disrow*2+1];
BUFF__UP[4]=Table[word+2][disrow*2+0];
BUFF__UP[5]=Table[word+2][disrow*2+1];
BUFF__UP[6]=Table[word+3][disrow*2+0];
BUFF__UP[7]=Table[word+3][disrow*2+1];
BUFF__UP[8]=Table[word+4][disrow*2+0];
BUFF__UP[9]=Table[word+4][disrow*2+1];
BUFF__UP[10]=Table[word+5][disrow*2+0];
BUFF__UP[11]=Table[word+5][disrow*2+1];
BUFF__UP[12]=Table[word+6][disrow*2+0];
BUFF__UP[13]=Table[word+6][disrow*2+1];
BUFF__UP[14]=Table[word+7][disrow*2+0];
BUFF__UP[15]=Table[word+7][disrow*2+1];
}
//發(fā)送屏一線點(diǎn)陣數(shù)據(jù)
void Send_one_line(void)
{
char s;
uchar temp,i,inc;
if(col<8)inc=0;
if(8<=col&&col<16)inc=1;
for(s=0+inc;s<=8+inc;s++)
{
temp=Combine_2byte(BUFF__UP[s],BUFF__UP[s+1]);
for(i=0;i<8;i++)
{
R1=~(temp>>i)&0x01;//取出最低位
R2=0xff;//不顯示
G1=0xff;
G2=0xff;
CLK=0;
CLK=1;//移位時(shí)鐘
}
}
}
//左移函數(shù)
void LEFT_MOVE()
{
uchar i;
for(col=0;col<16;col++)//循環(huán)16次,點(diǎn)亮并移動(dòng)一個(gè)漢字,步進(jìn)是一位
{
col1=col%8;//一個(gè)字節(jié)移動(dòng)位數(shù)
for(i=0;i
{
for(disrow=0;disrow<16;disrow++)//掃描16行
{
Load_one_line();//裝載一行點(diǎn)陣數(shù)據(jù)
Send_one_line();//發(fā)送一行點(diǎn)陣數(shù)據(jù)
OE=1;
STB=1;// 輸出鎖存
STB=0;
P0=disrow;// 行掃描
OE=0;
}
}
}
word=word+1;// 一個(gè)漢字移動(dòng)后,指向下一個(gè)漢字
if(word>=NUMBER)
{
word=0;//移動(dòng)完NUMBER個(gè)漢字后重新開始
}
}
//主函數(shù)入口
void main(void)
{
R1=0;//數(shù)據(jù)初始化
R2=0;
G1=0;
G2=0;
while(1)
{
LEFT_MOVE(); //左移
}
}
zimo.h
unsigned char code Table[][32]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//空白
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
評(píng)論