8位数码管逐位显示8个字符的程序及详解
1.(现象)
8位数码管从最低位开始到最高位,逐位显示字符0.1.2.3.4.5.6.7,并且不断循环显示
2.(程序说明)
程序在运行时,单片机从WMtable表格中选择第一个位码(i=0时),并从P0.7-P0.0引脚输出位码送到锁存器,位码从锁存器输出后送到8位数码管的位引脚,选中第一位,让他处于待显状态,然后单片机从P2.3引脚输出位码锁存信号送到位锁存器,锁定其输出端位码不变
下面直接上代码:::
#include<reg51.h>
#define WDM P0
sbit Duansuo=P2^2;
sbit Weisuo=P2^3;
void Delay (unsigned int t);
unsigned char code DMtable[]={0x3f,0x06,0x5b,0x4f
0x66,0x6d,0x7d,0x07};
unsigned char code WMtable[]={0xfe,0xfd,0xfb,0xf7
0xef,0xdf,0xbf,0x7f};
main(){
unsigned char i=0;
while(1){
WDM=WMtable [i];
DuanSuo=1;
WeiSuo=0;
WDM=DMtable [i];
DuanSuo=1;
WeiSuo=0;
Delay(60000);
i++;
if(i==8)
{
i=0;}
}
}
void Delay (unsigned int t)
{
while(--t);
}
8位数码管同时显示8个字符的程序及详解
(1)现象
8位数码管同时显示字符01234567
(2)程序说明
与上面方法基本类似,仅是将Delay函数的输入参数t的值由60000改成100,这样显示一个字符后隔很短的时间就会显示下一个字符。
上代码::::
#include<reg51.h>
#define WDM P0
sbit Duansuo=P2^2;
sbit Weisuo=P2^3;
void Delay (unsigned int t);
unsigned char code DMtable[]={0x3f,0x06,0x5b,0x4f
0x66,0x6d,0x7d,0x07};
unsigned char code WMtable[]={0xfe,0xfd,0xfb,0xf7
0xef,0xdf,0xbf,0x7f};
main(){
unsigned char i=0;
while(1){
WDM=WMtable [i];
DuanSuo=1;
WeiSuo=0;
WDM=DMtable [i];
DuanSuo=1;
WeiSuo=0;
Delay(100);
i++;
if(i==8)
{
i=0;}
}
}
void Delay (unsigned int t)
{
while(--t);
}
8为数码管动态显示8个字符以上1字符的程序及详解
1.(现象)
8位数码管依次显示01234567、12345678、23456789、.....89Abcdef? 并且不断循环
(2)程序说明
程序先定义两个表格,一个表格按顺序存放0-F的段码,另一个表格按地位到高位的顺序存放8位数码管的各位位码
上代码!!!!
#include<reg51.h>
#define WDM P0
sbit Duansuo=P2^2;
sbit Weisuo=P2^3;
void Delay (unsigned int t);
unsigned char code DMtable[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x7d,0x7c.
0x39,0x5e,0x79,0x71};
unsigned char code WMtable[]={0xfe,0xfd,0xfb,0xf7
0xef,0xdf,0xbf,0x7f};
main(){
unsigned char i=0,num;
unsigned int j;
while(1){
WDM=WMtable [i];
DuanSuo=1;
WeiSuo=0;
WDM=DMtable [i];
DuanSuo=1;
WeiSuo=0;
Delay(100);
i++;
if(i==8)
{
i=0;}
if(j==600){
j=0;
num++;
if(num==9){num=0;}
}
}
}
void Delay (unsigned int t)
{
while(--t);
}
|