AT89C51串并轉(zhuǎn)換驅(qū)動數(shù)碼管實驗指導
實驗內(nèi)容:
按下圖連接器件:
程序如下所示:
C程序
#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;jj200;jj++);
while(jj--);
}
void display(uchar dat)
{
uchar ii;
uchar sdata=dat;
for(ii=0;ii8;ii++)
{
if(sdata0x80)
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;
}
}
評論