74HC595驅(qū)動程序
74HC595時序圖如下
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar code DAT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
sbit SDATA_595=P1^0; //串行數(shù)據(jù)輸入
sbit SCLK_595 =P1^1; //移位時鐘脈沖
sbit RCK_595 =P1^2; //輸出鎖存器控制脈沖
uchar temp;
void delay(int ms)
{
int k;
while(ms--)
{
for(k=0; k<250; k++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void WR_595(void)
{
uchar j;
for (j=0;j<8;j++)
{
temp=temp<<1 ;
SDATA_595=CY;
SCLK_595=1; //上升沿發(fā)生移位
_nop_();
_nop_();
SCLK_595=0;
}
}
void OUT_595(void)
{
RCK_595=0;
_nop_();
_nop_();
RCK_595=1; //上升沿將數(shù)據(jù)送到輸出鎖存器
_nop_();
_nop_();
_nop_();
RCK_595=0;
}
main()
{
SCLK_595=0;
RCK_595=1;
while(1)
{
uchar i;
for (i=0; i<8; i++)
{
temp=DAT[ i ]; //取顯示數(shù)據(jù)
WR_595();
OUT_595();
delay(100);
}
}
}