控制数码管显示的思路

1、锁存端:高电平时输入输出连通,低电平时不连通,保持原来的值

2、控制数码管显示的思路_第1张图片P0端都要接上上拉电阻(由于I/O口输出i很弱,不到1mA,若不加上拉电阻,无法点亮发光二极管),接法如图所示

3、思路:先让位选锁存端(WELA)P2.7为高电平1,P0口送数,选中某一数码管后,将位选锁存端变为低电平;

再让段选锁存端(DULA)P2.6为高电平1,P0口送数,再把段选锁存端变为低电平。

4、例:6个数码管依次显示数字,而且显示的数字为0~f

#include "reg52.h"
#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80
unsigned char i = 0;
unsigned char j = 0;
unsigned char tt = 0;
unsigned char code distab[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//不带标点符号 0~f
unsigned char code distab1[]={
0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};
//带标点符号  0.~f.
unsigned char code wei[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
void init(){     
    TMOD |= BIT0;
    TH0 = (65536-50000)/256;
    TL0 = (65536-50000)%256;
    EA = 1;
    ET0 = 1;
}
void main(){
   init();
   TR0 = 1;
   while(1);
}
void shumaguan() interrupt 1{
   tt++;
   TH0 = (65536-50000)/256;
   TL0 = (65536-50000)%256;
   if(tt==20){
        tt=0;
        P2 |= BIT7;
        P0 = wei[i];
	P2 &= ~BIT7;
        P2 |= BIT6;
        P0 = distab[j];
        P2 &= ~BIT6;
        i++;
	j++;
        if(i==6)i=0;
    	if(j==16)j=0;
     }
}

 

你可能感兴趣的:(控制数码管显示的思路)