相关代码:
#include “STC15F2K60S2.H”
#include “intrins.h”
unsigned char i,j,k;
void Delay100ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 5;
j = 52;
k = 195;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void InitHC138(unsigned char n)
{
// P2=0x1f | n << 5;
// P2=0x1f;
switch(n)
{
case 4:
P2=(P2&0x1f)|0x80;
break;
case 5:
P2=(P2&0x1f)|0xa0;
break;
case 6:
P2=(P2&0x1f)|0xc0;
break;
case 7:
P2=(P2&0x1f)|0xe0;
break;
}
}
void main()
{
while(1)
{
InitHC138(4);
for(i=0;i<3;i++)
{
P0=0x00;
Delay100ms();
Delay100ms();
P0=0xff;
Delay100ms();
Delay100ms();
}
for(i=1; i<=8; i++)
{
P0=0xff<<i;
Delay100ms();
Delay100ms();
}
for(i=0;i<8;i++)
{
P0=~(0xff<<i);
Delay100ms();
Delay100ms();
}
}
}