/*===============================================================*/
/* ????鼶??74LS595_2????????????? */
/*===============================================================*/
#ifndef _LS595_2driver_H_
#define _LS595_2driver_H_
unsigned char flag_fu=0; //???????????λ
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}; //??????
char code_func[]={0x98,0xbd,0xbf,0xd8};//E,r,-,C
/*??????? 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)
{
signed 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 |