建议先看看595的例子,这个是串行输入,八位并行输出的,
#include<reg51.h>
#include<intrins.h>
#defineNOP()_nop_()
sbitMOSIO=P3^7;
sbitR_CLK=P3^5;
sbitS_CLK=P3^6;
sbiten573=P1^3;
sbitends=P1^2;
voidHC595SendData(unsignedintSendVal);
unsignedintVal;
unsignedcharcodetab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsignedcharcodedigittab[18][8]={
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00},//0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00},//1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00},//2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00},//3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00},//4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00},//5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00},//6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00},//7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00},//8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00},//9
{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00},//P
{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00},//R
{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00},//E
{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00},//C
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00},//H
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00},//I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00},//N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00}
};
unsignedinttimecount;
unsignedcharcnta;
unsignedcharcntb;
voidmain(void)
{
TMOD=0x01;
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
TR0=1;
ET0=1;
EA=1;
cntb=0;
ends=0;
en573=0;
while(1)
{ }
}
voidt0(void)interrupt1using0
{
TH0=(65536-3000)/256;
TL0=(65536-3000)%256;
if(cntb<18)/
{//P1=0xFF;
//P2=tab[cnta];
P0=~digittab[cntb][cnta];
Val=tab[cnta]&0x00ff;
Val<<=8;
Val=Val+0x00ff;
HC595SendData(Val);
}
else
{//P2=0xFF;
//P1=tab[cnta];
P0=~digittab[cntb-18][cnta];
Val=tab[cnta];
Val=Val+0xFF00;
HC595SendData(Val);
}
if(++cnta>=8)cnta=0;
if(++timecount>=333)
{timecount=0;
if(++cntb>=36)cntb=0;
}
}
voidHC595SendData(unsignedintSendVal)
{unsignedchari;
for(i=0;i<16;i++)
{ if((SendVal<<i)&0x8000)MOSIO=1;//setdatalinehigh0X8000
elseMOSIO=0; //MOSIO=1
S_CLK=0;
NOP();
NOP();
S_CLK=1;
}
R_CLK=0;//setdatalinelow
NOP();
NOP();
R_CLK=1;
}
盗版来的程序,你看看参考一下
|