#include<reg52.h> 
#include 
<intrins.h>        //
空语句调用头文件
 
#include"zimo.h"  
#define uchar unsigned char 
#define uint unsigned int  
/**********************************************************************/ 
sbit DS=P1^0;  
/**********************************************************************/ 
  
/**********************************************************************/ 
sbit CLK=P1^1;  //74HC595
的
SH-CP
(
11
脚)
  
sbit STB=P1^2;  //74HC595
的时钟和输出锁存
(12
脚
)  
/**********************************************************************/ 
 
 
 
 
/*
坐标数组
*/  
/**********************************************************************/ 
uchar 
code  shu[8]={0,1,2,3,4,5,6,7};                        //
十进制数选
 
uchar 
code   x1[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//595
数据
 
uchar 
code   y1[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//595
使能
 
uchar 
code   z1[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//
层扫描
  
/************************************************************************/ 
 
 
 
    /*
亮度调节延时
*/  
/************************************************************************/ 
void delay(unsigned int i) 
{ 
 
unsigned int j; 
 
for(;i>0;i--) 
 
{ 
 
 
 
for(j=5;j>0;j--); 
 
}   
}  
/**********************************************************************/ 
                             /*ms
延时
*/  
/**********************************************************************/ 
void delayms(uchar xms) 
{ 
 
uchar i,j; 
 
for(i=0;i<xms;i++) 
 
{ 
 
 
for(j=0;j<110;j++); 
 
}
}  
/************************************************************************/ 
 
 
 
    /*
亮度调整
*/  
/************************************************************************/ 
/*void PWM_LIGHT(unsigned char p) 
{ 
 
OE=0; 
 
delay(p); 
 
OE=1; 
 
delay(10-p); 
}  */  
/***********************************************************************/ 
 
 
 
     /*595
发送一字节
*/  
/***********************************************************************/ 
void Set595(unsigned char xie) 
{ 
 
unsigned char i; 
 
unsigned int temp; 
 
temp=xie; 
 
for(i=0;i<8;i++) 
 
{ 
 
 
if(temp&0x01) 
 
 
{ 
 
 
 
DS=1; 
 
 
} 
 
 
else DS=0; 
 
 
temp=temp>>1; 
 
 
CLK=0; 
 
 
_nop_(); 
 
 
_nop_(); 
 
 
CLK=1;     //
移位上升沿有效
? 
 
} 
 
}  
/**********************************************************************/ 
  
/**********************************************************************/ 
void dis595(void) 
{ 
 
STB=0; 
 
_nop_(); 
 
_nop_(); 
 
STB=1;         //
串行输出上升沿有效
 
}  
/**********************************************************************/  
/**********************************************************************/ 
void Set595_1(unsigned char xie,unsigned char xie1) 
{ 
 
unsigned char i; 
 
for(i=0;i<8;i++) 
 
{ 
 
 
DS=xie&0x01; 
 
 
DS=xie1&0x01; 
 
 
DS=0; 
 
 
DS=1; 
 
 
xie>>=1; 
 
 
xie1>>=1; 
 
 
     //
移位上升沿有效
? 
 
} 
 
}  
/**********************************************************************/ 
   
 
 
     /*
倒计时
*/  
/**********************************************************************/ 
void daojishi(void) 
{ 
 
uchar i,j,k; 
 
for(j=0;j<8;j++) 
 
{ 
 
 
for(k=0;k<60;k++) 
 
 
for(i=0;i<8;i++) 
 
 
{ 
 
 
 
Set595(shuzi[7][i]); 
 
 
 
Set595(shuzi[6][i]); 
 
 
 
Set595(shuzi[5][i]); 
 
 
 
Set595(shuzi[4][i]); 
 
 
 
Set595(shuzi[3][i]); 
 
 
 
Set595(shuzi[2][i]); 
 
 
 
Set595(shuzi[1][i]); 
 
 
 
Set595(shuzi[0][i]); 
 
 
 
P1=y1[j]; 
 
 
 
P2=z1[7-i]; 
 
 
 
dis595(); 
 
 
} 
 
} 
 
}  
/**********************************************************************/ 
 
 
 
    /*
方框缩放
*/  
/**********************************************************************/  
void suofang() 
{ 
 
uchar x,y,z,w,e,r,a,s; 
 
for(y=0;y<8;y++) 
 
{ 
 
 
for(x=0;x<8;x++) 
 
 
{ 
 
 
 
if((z==0)&&(y==0)||(z==0)&&(y==7)) 
 
 
 
{ 
 
 
 
 
P1=y1[y]; 
 
 
     
 
P2=z1[0]; 
 
 
 
 
Set595(x1[x]); 
 
 
 
 
dis595(); 
 
 
 
 
}   
 
 
 
} 
 
}    
 
for(e=0;e<8;e++) 
 
{ 
 
 
for(r=0;r<8;r++) 
 
 
{ 
 
 
 
if((w==0)&&(e==0)||(w==0)&&(e==7)) 
 
 
 
{ 
 
 
 
 
P1=y1[e]; 
 
 
     
 
P2=z1[r]; 
 
 
 
 
Set595(x1[0]); 
 
 
 
 
dis595(); 
 
 
 
 
} 
 
 
 
 
} 
 
} 
 
 
 
for(e=0;e<8;e++) 
 
{ 
 
 
for(r=0;r<8;r++) 
 
 
{ 
 
 
 
if((w==0)&&(e==0)||(w==0)&&(e==7)) 
 
 
 
{ 
 
 
 
 
P1=y1[e]; 
 
 
     
 
P2=z1[r]; 
 
 
 
 
Set595(x1[7]); 
 
 
 
 
dis595(); 
 
 
 
 
} 
 
 
 
 
} 
 
}   
 
for(a=0;a<8;a++)  
{ 
 
 
P1=y1[a]; 
     
 
P2=z1[7]; 
 
 
Set595(x1[0]); 
 
 
dis595(); 
 
 
P1=y1[a]; 
     
 
P2=z1[7]; 
 
 
Set595(x1[7]); 
 
 
dis595(); 
 
} 
 
for(s=0;s<8;s++) 
 
{ 
 
 
P1=y1[s]; 
     
 
P2=z1[0]; 
 
 
Set595(x1[0]); 
 
 
dis595(); 
 
 
P1=y1[s]; 
     
 
P2=z1[0]; 
 
 
Set595(x1[7]); 
 
 
dis595(); 
 
} 
 
for(y=0;y<8;y++) 
 
{ 
 
 
for(x=0;x<8;x++) 
 
 
{ 
 
 
 
if((z==0)&&(y==0)||(z==0)&&(y==7)) 
 
 
 
{ 
 
 
 
 
P1=y1[y]; 
 
 
     
 
P2=z1[7]; 
 
 
 
 
Set595(x1[x]); 
 
 
 
 
dis595(); 
 
 
 
 
}   
 
 
 
} 
 
} 
}  
/**********************************************************************/ 
void xingdian() 
{ 
 
uchar x,y,z; 
 
for(z=0;z<8;z++) 
 
for(y=0;y<8;y++) 
 
{ 
 
 
for(x=0;x<8;x++) 
 
 
{  
if((y==0)||(y==2)||(y==4)||(y==6)||(y==1)||(y==3)||(y==5)||(y==7)) 
 
 
 
{ 
 
 
 
 
P1=y1[y]; 
 
 
     
 
P2=z1[z]; 
 
 
 
 
Set595(x1[x]); 
 
 
 
 
dis595(); 
 
 
 
 
 
 
 
 
 
} 
 
 
 
   
 
 
} 
 
 
 
 
 
delayms(20000); 
 
} 
 
} 
 
 
 
 
 
/*
主函数
*/  
/**********************************************************************/ 
void main() 
{ 
 
uchar j; 
 
while(1) 
 
{ 
 
 
daojishi(); 
 
//
倒计时
7
—
0 
 
 
for(j=0;j<50;j++) 
 
 
{ 
 
 
 
suofang(); 
 
//
方框缩放
 
 
 
} 
 
// 
xingdian(); 
   
//
星点
 
 
} 
} 
  
这是
595
的程序,实现
0
—
9
倒数。
 
 
 
 
  
#include<reg52.h> 
  
 
#define uint unsigned int 
 
#define uchar unsigned char 
  void delay(uint z); 
  
 
void main() 
 
{ 
 
 
 
 
while(1)  
{ 
 
 
P3=0x00; 
 
 
delay(10); 
 
 
P2=0x00; 
 
 
delay(5); 
 
 
P1=0x00; 
 
} 
 
} 
  
 
void delay(uint z) 
 
{  
 
 
uchar x,y; 
 
for(x=0;x<z;x++) 
 
 
for(y=0;y<121;y++); 
 
}