实验内容:
按下图连接器件:
程序如下所示:
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit SDA = P1^1;
sbit SHIFT = P1^2;
sbit ST = P1^0;
#define NOP _nop_()
uchar led[] = {0x5b,0x3f,0x3f,0x6f};
uchar select[] = {0x0fe,0xfd,0xfb,0xf7};
uchar i=0;
void Init( )
{
SDA = 0;
SHIFT = 0;
ST = 0;
}
void delay()
{
uchar jj;
for(jj=0;jj<200;jj++);
while(jj--);
}
void display(uchar dat)
{
uchar ii;
uchar sdata=dat;
for(ii=0;ii<8;ii++)
{
if(sdata&0x80)
SDA=1;
else
SDA = 0;
sdata<<=1;
SHIFT =0;
NOP;
NOP;
SHIFT = 1;
NOP;
NOP;
}
ST = 1;
NOP;
NOP;
ST = 0;
}
void main()
{
Init();
while(1)
{
delay();
delay();
P2 = select[i];
display(led[i]);
i=(i+1)%4;
}
}