74HC595單片機(jī)C51驅(qū)動(dòng)(源程序)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
#include"reg52.h"
#defineucharunsignedchar
sbitHC595_CS=P1^0;//STcp////鎖存時(shí)鐘-----74HC59512#
sbitHC595_CLK=P1^1;//SHcp////移位時(shí)鐘-----74HC59511#
sbitHC595_DAT=P1^2;//Ds////數(shù)據(jù)---------74HC59514#
//延時(shí)子程序
voidmDelay(ucharDelay)
{uchari;
for(;Delay>0;Delay--)
{
for(i=0;i<123;i++);
}
}
voidSetHC595(ucharkk)
{
uchari;
HC595_CS=0;
for(i=0;i<8;i++)
{
HC595_DAT=(bit)(kk&0x80);//串行輸出一位數(shù)據(jù)
HC595_CLK=0;//移位時(shí)鐘
kk=kk<<1;
HC595_CLK=1;
}
//HC595_CS=1;
}
main()
{
ucharj;
while(1)
{
for(j=0;j<255;j++)
{
SetHC595(j);
SetHC595(1);
HC595_CS=1;
mDelay(255);
mDelay(255);
}
}
}