1.相关知识
2.链接图
3.数码管原理图
4.代码实现
//数码管显示数字 使用P0口
#include<reg51.h>
#define DIG P0
//RAM ROM
//0=00111111
//1=00000110
//2=01011011
//3=01001111
//4=01100110
//5=01101101
//6=01111101
//7=00000111
//8=01111111
//9=01101111
//前面第一个0代表 数字后面的小数点
//unsigned char code 中的 code 的作用是:告诉编译器 这个数组是保存程序存储空间
unsigned char code DIG_CODE[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//主函数
void main()
{
while(1)
{
//如果数字显示不正确,有可能你是共阴的,可以添加 "~" DIG=~DIG_CODE[2]; 即可
DIG=DIG_CODE[2];
}
}
5.动态数码管
//数码管显示数字 使用P0口
#include<reg51.h>
#define DIG P0
//RAM ROM
//0=00111111
//1=00000110
//2=01011011
//3=01001111
//4=01100110
//5=01101101
//6=01111101
//7=00000111
//8=01111111
//9=01101111
//前面第一个0代表 数字后面的小数点
//unsigned char code 中的 code 的作用是:告诉编译器 这个数组是保存程序存储空间
unsigned char code DIG_CODE[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void Delay10ms(unsigned int c);
//主函数
void main()
{
unsigned char i=0;
while(1)
{
//如果数字显示不正确,有可能你是共阴的,可以添加 "~" DIG=~DIG_CODE[2]; 即可
//DIG=DIG_CODE[0];
//P1=DIG_CODE[1];
DIG=DIG_CODE[i];
i++;
if(i==10){
i=0;
}
Delay10ms(50);
}
}
//延时函数
void Delay10ms(unsigned int c)
{
unsigned int a,b;
for(;c>0;c--){
for(b=38;b>0;b--){
for(a=130;a>0;a--);
}
}
}