P0口怎么都不变 搞了两天思考了 很久 没有办法 来贴吧问问大手子们
#include <reg52.h>
unsigned int NUM[]={0x3f,0x06,0x5b,
0x4f,0x66,0x6d,
0x7d,0x07,0x7f,
0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
sbit COMEA=P2^2;
sbit COMEB=P2^3;
sbit COMEC=P2^4;
unsigned int secge,secshi,minge,minshi,hourge,hourshi;
void delay(unsigned int xms)
{
unsigned int x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--);
}
void Time()
{
while(1)
delay(1000);
secge+1;
{
if(secge==10)
{
secge=0;
secshi+1;
if(secshi==6)
{
secshi=0;
minge+1;
if(minge==10)
{
minge=0;
minshi+1;
if(minshi==6)
{minshi=0;
hourge+1;
if(hourge==10)
{
hourge=0;
hourshi+1;
if(hourge==4,hourshi=2)
{
secge=secshi=minge=minshi=hourge=hourshi=0;
}
}
}
}
}
}
}
}
void display()
{
while(1)
{
COMEA=0;
COMEB=0;
COMEC=0;
delay(1);
COMEA=1;
COMEB=0;
COMEC=0;
delay(1);
COMEA=0;
COMEB=1;
COMEC=0;
delay(1);
COMEA=1;
COMEB=1;
COMEC=0;
delay(1);
COMEA=0;
COMEB=0;
COMEC=1;
delay(1);
COMEA=1;
COMEB=0;
COMEC=1;
delay(1);
}
}
void main(void)
{
Time();
display();
while(1)
{
if(COMEA==0&&COMEB==0&&COMEC==0)
{
P0=NUM[secge];
if(COMEA==1&&COMEB==0&&COMEC==0)
{
P0=NUM[secshi];
if(COMEA==0&&COMEB==1&&COMEC==0)
{
P0=NUM[minge];
if(COMEA==1&&COMEB==1&&COMEC==0)
{
P0=NUM[minshi];
if(COMEA==0&&COMEB==0&&COMEC==1)
{
P0=NUM[hourge];
if(COMEA==1&&COMEB==0&&COMEC==1)
{
P0=NUM[hourshi];
}
}
}
}
}
}
}
}