文章最后面附有:数码管一些特殊运用。
数码管电路图
数码管原理和结构图
真值表,编程时用的到,这边先列出来。
下面就是点亮大数码管(共阳级)的代码:
//七段数码管显示实验
//2018.7.22
#include <reg51.h>
#include <Delay.h>
#define DataPort P1 // 换接口,只需修改这里
sbit Seg_Latch = P2^2; //段锁存
sbit Bit_Latch = P2^3; //位锁存
unsigned char code Seg_Code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code Bit_Code[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//段码,位码
void main()
{
int i;
while(1)
{
for(i = 0;i < 16;i++)
{
P1 = ~Seg_Code[i];
DelayMs(255);
}
}
}
点亮大数码管(共阴级)的代码:
//七段数码管显示实验
//2018.7.22
#include <reg51.h>
#include <Delay.h>
#define DataPort P1 // 换接口,只需修改这里
sbit Seg_Latch = P2^2; //段锁存
sbit Bit_Latch = P2^3; //位锁存
unsigned char code Seg_Code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char code Bit_Code[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
//段码,位码
void main()
{
unsigned char i;
unsigned char j;
while(1)
{
DataPort