|
發表於 2012-6-23 16:59:17
|
顯示全部樓層
雄爸:
實驗版的程式
#include<reg52.h> //婦漪芛恅璃ㄛ珨啜ロ錶祥剒猁蜊雄ㄛ芛恅璃婦漪杻忷髡夔敵湔け腔隅砱
#include <intrins.h>
#include <delay.h>
unsigned char segout[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //8蹈
/*unsigned char code tab[96]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //諾跡
0x00,0x7E,0xFF,0xC3,0xC3,0xFF,0x7E,0x00, //趼睫0
0x00,0x00,0x43,0xFF,0xFF,0x03,0x00,0x00, //趼睫1
0x00,0x63,0xC7,0xCF,0xDB,0xF3,0x63,0x00, //趼睫2
0x00,0x42,0xDB,0xDB,0xDB,0xFF,0x66,0x00, //趼睫3
0x00,0x3E,0x46,0xFF,0xFF,0x06,0x06,0x00, //趼睫4
0x00,0xF6,0xF7,0xD3,0xD3,0xDF,0xDE,0x00, //趼睫5
0x00,0x7E,0xFF,0xDB,0xDB,0xDF,0x4E,0x00, //趼睫6
0x00,0xC0,0xC0,0xC7,0xFF,0xF8,0xC0,0x00, //趼睫7
0x00,0xFF,0xFF,0xDB,0xDB,0xFF,0xFF,0x00, //趼睫8
0x00,0x72,0xFB,0xDB,0xDB,0xFF,0x7E,0x00, //趼睫9
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 //諾跡
};*/
unsigned char tab[85]={
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //諾跡},
0x00, 0x70, 0x20, 0x20, 0x20, 0x20, 0x20, 0xa0, 0x40, 0x00, 0x00,//J
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,//.
0x00, 0xf8, 0x48, 0x50, 0x70, 0x50, 0x40, 0x40, 0xe0, 0x00, 0x00,//F
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,//.
0x00, 0xe0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x48, 0xf8, 0x00, 0x00,//L
0x00, 0xf8, 0x48, 0x50, 0x70, 0x50, 0x40, 0x48, 0xf8, 0x00, 0x00,//E
0x00, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00//U
};
/*------------------------------------------------
茞璃傷諳隅砱
------------------------------------------------*/
sbit LATCH = P1^0; //
sbit SRCLK= P1^1;
sbit SER = P1^2;
sbit LATCH_B = P2^2;
sbit SRCLK_B= P2^1;
sbit SER_B= P2^0;
/*------------------------------------------------
楷冞趼誹最唗
湍衄源砃統杅ㄛ褫眕恁寁植詢弇誹迡フ麼氪腴弇迡フ
------------------------------------------------*/
void SendByte(unsigned char dat,bit direction)
{
unsigned char i,temp;
if(direction==0)
temp=0x80;
else
temp=0x01;
for(i=0;i<8;i++)
{
SRCLK=0;
SER=dat&temp;
if(direction==0)
dat<<=1;
else
dat>>=1;
SRCLK=1;
}
}
/*------------------------------------------------
楷冞邧趼誹最唗
------------------------------------------------*/
void Send2Byte(unsigned char dat1,unsigned char dat2,bit direction)
{
SendByte(dat1,direction);
SendByte(dat2,direction);
}
/*------------------------------------------------
595坶湔最唗
------------------------------------------------*/
void Out595(void)
{
LATCH=0;
_nop_();
LATCH=1;
}
/*------------------------------------------------
楷冞弇鎢趼誹最唗
妏蚚鍚俋珨⑵等黃595
------------------------------------------------*/
void SendSeg(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++) //楷冞趼誹
{
SRCLK_B=0;
SER_B=dat&0x80;
dat<<=1;
SRCLK_B=1;
}
LATCH_B=0; //坶湔
_nop_();
LATCH_B=1;
}
/*------------------------------------------------
翋最唗
------------------------------------------------*/
void main()
{
unsigned char i,k,l;
while(1)
{
for(k=0;k<=77;k++) //shift 88 byte
for(l=10;l>0;l--) //cycle times for same display word
for(i=7;i>0;i--) //fill up 8x8 LED
{
SendSeg(segout[i]);
Send2Byte((~(*(tab+i+k))),0xff,0);
Out595();
DelayMs(1);
Send2Byte(0xff,0xff,0);//delay(10); //滅砦笭荌
Out595();
}
for(k=0;k<=77;k++) //垀衄腔趼睫跺杅
for(l=8;l>0;l--) //晊奀酗僅,蜊曹森硉褫眕蜊曹霜雄厒僅
for(i=7;i>0;i--) //8蹈珆尨
{
SendSeg(segout[7-i]);
Send2Byte(0xff,~(*(tab+i+k)),0); //迡フ趼誹源砃蜊曹
Out595();
DelayMs(1);
Send2Byte(0xff,0xff,0);//delay(10); //滅砦笭荌
Out595();
}
}
}
|
|