找回密码
 注册会员
搜索附件  
MCU资讯论坛 附件中心 单片机论坛 51单片机论坛 74LS164在2051单片机LED显示电路中的应用.rar

74LS164在2051单片机LED显示电路中的应用.rar

 

51单片机与74ls164/74HC164静态显示接口,共阳数码管的演示程序:
下面是 74ls164 驱动 共阳数码管的演示程序,电路请看附件

#i nclude<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit DAT=P1^1; //模拟串口数据发送端
sbit CLK=P1^2;//模拟时钟控制端
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};//0-9,-,全灭 (共阳字段表)

void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{
CLK=0;
DAT=num&0x80; //(0x80即十进制的128, 二进制的10000000 按位发送)
CLK=1;
num<<=1;


}

}


void delay_50ms(unsigned int t) //50MS演示程序
{
unsigned int j;
for(;t>0;t--)
for(j=6245;j>0;j--)
{;}
}

main()
{

unsigned char h;
while(1){
for(h=0;h<10;h++){
delay_50ms(1);
sendbyte(h);
delay_50ms(10);
}
h=0;
}
}

下面这段是74ls164 驱动共阴数码管的程序源码

#i nclude<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit DAT=P1^1;
sbit CLK=P1^2;
uchar code tab[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xff,0xf6};//0-9,-,全灭

void sendbyte(uchar byte)
{
uchar num,c;
num=tab[byte];
for(c=0;c<8;c++)
{
CLK=0;
DAT=num&0x01;
CLK=1;
num>>=1;


}

}


void delay_50ms(unsigned int t)
{
unsigned int j;
for(;t>0;t--)
for(j=6245;j>0;j--)
{;}
}

main()
{


unsigned char h;
while(1){
for(h=0;h<10;h++){
delay_50ms(1);
sendbyte(h);
delay_50ms(10);
}
h=0;
}

}

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-12-28 20:36 , Processed in 0.041489 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部