#include <reg51.H>
#include <stdio.H>
sbit _SCK = P1^1; //74LS164的时钟信号
sbit DI = P1^0; //74LS164数据输入
unsigned char code Led_Show[]=
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x41,0xc4,0xf0,0x4c,0xe0,0xe1
,0xff};//数码管显示码表(共阳)
void Hc164(unsigned char temp );
main()
{char i;
for(i=0;i<8;i++)
Hc164(i);
}
/*-------------------------------------------------
功能:数码管显示子程序
-------------------------------------------------*/
void Hc164(unsigned char temp )
{
unsigned char i,temp1;
temp1 = Led_Show[temp];
for(i = 0;i < 8;i++ )
{
_SCK = 0;
if( (temp1 & 0x80) != 0x80 )
DI = 0;
else
DI = 1;
_SCK = 1;
temp1 <<=1;
}
}
程序中 if( (temp1 & 0x80) != 0x80 )为什么要用0x80呢???
最后一句 temp1 <<=1;小弟知是移位,,但在整个程序中起什么作用??
这是用P1脚模拟串行口对74LS164发送时钟信号和数据输入的,模拟串行口和用真正的串行口有什么分别不??
谢谢各位大侠 |