74ls164驱动数码管(共阳)

本文介绍使用74LS164芯片驱动数码管显示数字的方法,包括非串口方式、串口方式及74LS164级联的应用。通过具体的电路图与代码示例,详细讲解了不同场景下的实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2008-06-30 17:05

74ls164为8 位移位寄存器(串行输入,并行输出),常用于扩展并行口。其原理详见芯片资料。这里简单总结其驱动数码管的用法和相关代码。

(一)非串口方式

proteus仿真图

 

代码:

#include "reg52.h"
#define uint unsigned int
#define uchar unsigned char
sbit DAT=P2^3;
sbit CLK=P2^0;
uchar code tab[]={0x01,0x4f,0x12,0x06,0x4c,0x24,0x20,0x0f,0x00,0x04,0x7f};//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<11;h++){
        delay_50ms(1);
        sendbyte(h);
   delay_50ms(10);
   }
   h=0;
     }
   
}

(二)串口方式

proteus仿真图:

 

代码:

#include "reg52.h"
#define uint unsigned int
#define uchar unsigned char

uchar code tab[]={0x01,0x4f,0x12,0x06,0x4c,0x24,0x20,0x0f,0x00,0x04,0x7f};//0-9,-,全灭

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

main()
{
unsigned char h;
TMOD=0x20;    //T1方式1
SCON=0x00;    //串口方式0输出,输出的内容送RXD脚输出,移位脉冲由TXD引脚输出
EA=1;
TR1=1;


while(1){
   for(h=0;h<11;){
        
   delay_50ms(5);
        
   if(TI==0)SBUF=tab[h];   //写数据
   else{
     TI=0;
     h++;     //下一个数
   }

    delay_50ms(5);
    }
    h=0;
}
}

(三)74ls164级联

静态显示数字10

电路图:

 

代码:

#include "reg52.h"
#define uint unsigned int
#define uchar unsigned char

uchar code tab[]={0x01,0x4f};//0-1

main()       //显示10
{
unsigned char h;
SCON=0x00;    //串口方式0输出,输出的内容送RXD脚输出,移位脉冲由TXD引脚输出

for(h=0;h<2;){   
   SBUF=tab[h]; //写数据
   while(TI==0);
    TI=0;
    h++;     //下一个数(十位)
   }
while(1);
}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值