数码管动态显示 --------位选应在段选之前进行

本文介绍了一种数码管动态显示的方法,通过先进行位选操作,再进行段选来实现显示。代码中展示了使用P2口进行位选,P0口进行段选,并通过延迟函数控制显示刷新,依次点亮四位数码管,最后清零P0口。
摘要由CSDN通过智能技术生成

#include<reg51.H>
#include<intrins.h>

#define LED_1 0x5b
#define LED_2 0x76
#define LED_3 0x3f
#define LED_4 0x3e

#define uchar unsigned char

void delay_ms(uchar);

main(){
    while(1){
  P2 &= 0x3f;                  //选位
  P0 = ~0x01;
  delay_ms(1);
  P2 |= 0xe0;
  _nop_();
  _nop_();
  P2 &= 0x1f;                  //锁存数据并点亮
  P0 = LED_1;
  _nop_();
  _nop_();
  P2 |= 0xe0;
  _nop_();
  _nop_();
  
  P2 &= 0x3f;                  //2
  P0 = ~0x02;
  delay_ms(1);
  P2 |= 0xe0;
  _nop_();
  _nop_();
  P2 &= 0x1f;                   //
  P0 = LED_2;
  _nop_();
  _nop_();
  P2 |= 0xe0;
  _nop_();
  _nop_(); 
  
  P2 &= 0x3f;                    //3
  P0 = ~0x04;
  delay_ms(1);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值