|
樓主 |
發表於 2012-7-17 00:00:02
|
顯示全部樓層
這次亮多了!!! 主要原因在 DELAY 用錯位置!!
#include<reg52.h>
#include <intrins.h> //use nop
#include <delay.h>
sbit LATCH = P1^0; //byte 1 green Byte 2 RED
sbit SRCLK= P1^1;
sbit SER = P1^2;// Lo active pull down LED cathode to ground
sbit LATCH_B = P2^2;//LED commond Lo active
sbit SRCLK_B= P2^1;
sbit SER_B= P2^0;// LED commond Lo active to supply 5V to LED
unsigned char code tab[96]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //諾跡
0x00,0xfE,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 //諾跡
};
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
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);
}
void Out595(void)
{
LATCH=0;
_nop_();
LATCH=1;
}
void main()
{
unsigned char i,datx,l,k;
// unsigned char j,temp,dat;
while(1)
{
for(k=0;k<88;k++) //流動方向 由左到右 88>>0
{
for(l=0;l<5;l++)
{
datx=0x00;//fe;//low active
for(i=24;i>0;i--) // 字型會反轉 (正 24>>0)
{
SRCLK_B=0;//----- sendseg start
SER_B=datx;//&0x80;
SRCLK_B=1;
LATCH_B=0; //
_nop_();
LATCH_B=1;
datx<<=1;
datx|=0x01;//------ sendseg end
//*************************************************
Send2Byte(~tab[i+k+8],0xff,0);//"~" 明暗反轉 第一字紅色後面 第二字前面綠色
// DelayUs2x(100);
//原先在這裡 DELAYMS(1);
Out595();
DelayMs(1);//
Send2Byte(0xff,0xff,0);// 0 字正 1 字顛倒
Out595();
}//for i
}//for l
}//for k
}//while
}//main |
|