/*===============================================================*/
/* 第二组级联74LS595_2数码管驱动程序 */
/*===============================================================*/
#ifndef _LS595_2driver_H_
#define _LS595_2driver_H_
sbit RCK_595_2 = P0^4; //第二组级联595的并行输出时钟
sbit DS_595_2 = P0^3; //第二组级联595数据线
sbit CLK_595_2 = P0^5; //第二组级联595移位输入时钟
unsigned char code countupseg[] = //第二组595中定义0~9,高亮低灭
{// 0 1 2 3 4 5 6 7 8 9
0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F
};
unsigned char code roundseg[6]={0x01,0x02,0x04,0x08,0x10,0x20}; //花式旋转
/*延时函数 1ms为单位*/
void Delay_ms(unsigned int t) //延时函数,t/ms
{
unsigned int a,b;
for(a=0;a<t;a++)
{
for(b=0;b<100;b++)
{
_nop_();
}
}
}
/* 向1个LS595_2写入1个字节*/
void Send1byte_595_2(unsigned char dat)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(dat&0x80)
DS_595_2 = 1;
else
DS_595_2 = 0;
dat <<=1;
CLK_595_2 = 0;
_nop_();
CLK_595_2 = 1;
}
}
/* 向3个级联LS595_2写入3个字节*/
void Send3byte_595_2(unsigned char dat1,unsigned char dat2,unsigned char dat3)
{
Send1byte_595_2(dat1);
Send1byte_595_2(dat2);
Send1byte_595_2(dat3);
}
/*允许将LS595输出并行数据*/
void Out_595_2()
{
RCK_595_2 = 0;
_nop_();
RCK_595_2 = 1;
}
/*显示倒计时 3位*/
void Displaycountupnum(unsigned int num)
{
unsigned int units,tens,hundreds;
units = num%10;
tens = (num/10)%10;
hundreds = num/100;
Send3byte_595_2(countupseg[hundreds],countupseg[tens],countupseg[units]); //显示倒计时的个、十、百位
Out_595_2();
}
/*大字花式转圈*/
void Displayround()
{
unsigned char j;
for(j=0;j<5;j++)
{
Send3byte_595_2(roundseg[j],roundseg[j],roundseg[j]);
Out_595_2();
Delay_ms(800);
}
}
#endif |