#include <STC15.H>
sbit STCP=P1^0;
sbit SHCP=P1^1;
sbit DS=P1^2;
unsigned char code DisplayHex[]={0xC0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x40,0x79,0x24,0x30,0x19,0x12,0X02,0x78,0x00,0x10,0xff,0};
unsigned char disp[4]={1,2,3,4};
unsigned char x[]={22,22,22,22};
unsigned char y[]={21,21,21,21};
unsigned char code w[]={0xff};
unsigned char code t[]={0};
void Delay(unsigned int i)
{
unsigned char j;
while(i)
{
i--;
for (j=255;j>0;j--)
{
}
}
}
void Send595(unsigned char * pdat)
{
unsigned char i,j;
j=0x80;
for (i=0;i<8;i++)
{
if ((*pdat)&j) DS = 1;
else DS = 0;
SHCP = 0;
SHCP = 1;
j>>=1;
}
}
void DisplayBy595(unsigned char *pdat)
{
unsigned char i;
for (i=0;i<4;i++)
{
Send595(&DisplayHex[*(pdat+i)]);
}
STCP=0;
STCP=1;
}
void Sends595(unsigned char * pdat)
{
unsigned char i,j;
j=0xff;
for (i=0;i<8;i++)
{
if ((*pdat)&j) DS = 1;
else DS = 0;
SHCP = 0;
SHCP = 1;
j>>=1;
}
}
void DissplayBy595(unsigned char *pdat)
{
unsigned char i;
for (i=0;i<4;i++)
{
Sends595(&w[*(pdat+i)]);
}
STCP=0;
STCP=1;
}
void main()
{
P0M0 = 0XFF;P0M1 = 0;
P1M0 = 0XFF;P1M1 = 0;
while (1)
{
DisplayBy595(disp);
Delay(3000);
DissplayBy595(0);
Delay(3000);
}
}