1.Proteus 8 仿真器
2.keil 5 编辑器
多位数码管不论是共阳还是共阴都有着段选(显示内容)和位选(显示位置)引脚
16进制 | 显示 | 16进制 | 显示 |
0xC0 | 0 | 0x88 | A |
0xF9 | 1 | 0x83 | b |
0xA4 | 2 | 0xC6 | C |
0xB0 | 3 | 0xA1 | d |
0x99 | 4 | 0x86 | E |
0x92 | 5 | 0x8E | F |
0x82 | 6 | 0x89 | H |
0xF8 | 7 | 0xC7 | L |
0x80 | 8 | 0xBF | - |
0x90 | 9 | 0x7F | . |
1.只位选最低位,段选循环显示
#include <reg52.h>
#include "DELAY.h"
sbit DLE = P2^0; //段选
sbit WLE = P2^1; //位选
//段
unsigned char Darr[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xC7,0xBF,0x7F};
main(void)
{
while(1)
{
unsigned char i;
for(i=0;i<20;i++)
{
P0 = Darr[i];
DLE = 1;
DLE = 0; //段选锁存
P0 = 0x01;
WLE = 1;
WLE = 0; //位选锁存
delay_ms(100);
}
}
}
2.按位依次显示0~7
#include <reg52.h>
#include "DELAY.h"
sbit DLE = P2^0; //段选
sbit WLE = P2^1; //位选
//段
unsigned char Darr[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xC7,0xBF,0x7F};
main(void)
{
while(1)
{
unsigned char i;
for(i=0;i<8;i++)
{
P0 = Darr[i];
DLE = 1;
DLE = 0; //段选锁存
P0 = 0x01<<1;
WLE = 1;
WLE = 0; //位选锁存
delay_ms(100);
}
}
}
3.全部显示(实际上是2的基础上刷新的快了而已并不是同时显示)
#include <reg52.h>
#include "DELAY.h"
sbit DLE = P2^0; //段选
sbit WLE = P2^1; //位选
//段
unsigned char Darr[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0x89,0xC7,0xBF,0x7F};
main(void)
{
while(1)
{
unsigned char i;
for(i=0;i<8;i++)
{
P0 = 0x00;
delay_ms(1);
WLE = 1;
WLE = 0; //位选锁存
DLE = 0; //段选锁存
P0 = Darr[i];
DLE = 1;
DLE = 0; //段选锁存
WLE = 0; //位选锁存
P0 = 0x01<<i;
WLE = 1;
WLE = 0; //位选锁存
}
}
}
注意:要先将位选关掉后并锁存?阻止数码管受到P0口信号的影响。 ??
1.只位选最低位,段选循环显示
2.按位依次显示0~7
3.全部显示