|
使用鎖存主要是為了達(dá)到I/O口復(fù)用的目的,節(jié)省I/O口。如果I/O口夠用當(dāng)然可以不用鎖存器。示例如下:
無標(biāo)題.jpg (180.68 KB, 下載次數(shù): 37)
下載附件
2018-5-22 20:44 上傳
#include <AT89X51.H>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e};
uchar code table1[]={
0x01,0x02,0x04,0x08,
0x10,0x20,0x40,0x80};
void delay(uint k)
{
uint i,j;
for(i=k;i>0;i--)
for(j=114;j>0;j--);
}
void main()
{
uchar i=0;
while(1)
{
for(i=0;i<8;i++)
{
P0=0xff;
P2=table1;
P0=table;
delay(1);
}
}
}
|
|