#include <reg52.h>
unsigned char code Number[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
sbit wei1=P2^4;
sbit wei2=P2^5;
sbit wei3=P2^6;
sbit wei4=P2^7;
void main(){
wei1=0;
wei2=0;
wei3=0;
wei4=0;
while(1){
wei1=1;
P0=Number[12];
wei1=0;
wei2=1;
P0=Number[5];
wei2=0;
wei3=1;
P0=Number[1];
wei3=0;
wei4=1;
P0=Number[6];
wei4=0;
}
}
为什么我只开一个数码管的时候,显示很清晰。开两个以上就不清晰了,而且也不对,总有不该显的段显示出来了,要是加延时,干脆就不显了
此帖出自
小平头技术问答
#define uint unsigned int
#define uchar unsigned char
uchar code Number[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uchar code wei[]=
{0x8F,0x4F,0x2F,0x1F};
uchar OneNumber[]=
{0,0,0,0};
int i;
sbit D1=P1^0;
//sbit beep=P2^3;
uint Counter;
uint minut;
uint second;
uint Time;
void init();
void display(uchar, uint);
uint setTime();
void desp(uint);
void main(){
init();
while(1){
for(i=0;i<4;i++)
display(i,OneNumber[i]);
//if(Time==1000)
if(Counter==1800) D1=1;
if(Counter==3600){
Counter=0;
Time=setTime();
desp(Time);
D1=0;
}
}
}
void init(){
P2=0xFF;
D1=0;
Counter=0;
minut=0;
second=0;
Time=0;
EA=1;
ET0=1;
TMOD=0x02;
TH0=0;
TL0=0;
TR0=1;
}
void display(uchar p, uint Num){
P2=wei[p];
P0=Number[Num];
P2=0x0F;
P0=0x00;
}
uint setTime(){
second++;
if(second==60){
minut++;
second=0;
}
if(minut==60) minut=0;
return minut*100+second;
}
void desp(uint Num){
for(i=0;i<4;i++){
OneNumber[i]= Num%10;
Num=Num/10;
}
}
void inter0() interrupt 1
{
Counter++;
}
终于做出了我想要的计时器,昨天的显示问题解决了,
一周热门 更多>