2 qq 36170518 qq_36170518 于 2016.09.18 18:27 提问

程序怎么不能调时,第一次写,请大神们帮忙看看

#include
#define uchar unsigned char
#define uint unsigned int
//uchar duma[]={0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x40};
//uchar wema[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
char j,button;
char h_num,m_num,s_num;
//char h_shi,h_ge,m_shi,m_ge,s_shi,s_ge,key,button;
sbit fm=P3^4;
void delay(uint time);
void display(char h_shi,h_ge,m_shi,m_ge,s_shi,s_ge);
void inter_init();
void time24();

void delay(uint time)
{
char a,b;
for(a=time;a>0;a--)
for(b=100;b>0;b--);
}

void inter_init() //定时器初始化
{
EA=1;
EX0=1;
ET0=1;
TMOD=0x01;
TCON=0x00;
IP=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TR0=1;
}

void display(char h_shi,h_ge,m_shi,m_ge,s_shi,s_ge) //显示函数
{ uchar duma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};
uchar wema[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
P2=duma[h_shi];
P1=wema[0];
delay(8);
P2=duma[h_ge];
P1=wema[1];
delay(8);

P2=duma[10];
P1=wema[2];
delay(8);

P2=duma[m_shi];
P1=wema[3];
delay(8);
P2=duma[m_ge];
P1=wema[4];
delay(8);
P2=duma[10];
P1=wema[5];
delay(8);


P2=duma[s_shi];
P1=wema[6];
delay(8);
P2=duma[s_ge];
P1=wema[7];
delay(8);

}

void time24() //24小时时间转换
{ char h_shi,h_ge,m_shi,m_ge,s_shi,s_ge;
//inter_init();
s_num=00;
m_num=00;
h_num=00;
while(1)
{

if(j==20)
{
j=0;
if(s_num==59)
{

s_num=-1;
if(m_num==59)
{

m_num=-1;
if(h_num==24)
h_num=-1;
h_num++;
fm=0;
delay(200);
fm=1;
}
m_num++;
}
s_num++;
}
h_shi=h_num/10;
h_ge=h_num%10;
m_shi=m_num/10;
m_ge=m_num%10;
s_shi=s_num/10;
s_ge=s_num%10;
display(h_shi,h_ge,m_shi,m_ge,s_shi,s_ge);
}
}

void time()interrupt 1 using 1 //定时器0
{

TH0=(65535-50000)/256;
TH0=(65535-50000)%256;
j++;
}

void key_scan(uchar button) //按键扫描
{

uchar key_l,key_h,key;
P0=0xf0;
key_l=P0;
key_l=key_l&0xf0;
if(key_l!=0xf0)
{ delay(10);
if(key_l!=0xf0)
{ key_l=key_l&0xf0;
key_l=key_l|0x0f;
P3=key_l;
key_h=P3;
key_h=key_h&0x0f;
key_l=key_l&0xf0;
key=key_l+key_h;
}

}
switch(key)
{

case 0xee: button=1; break;
case 0xde: button=2; break;
case 0xbe: button=3; break;
case 0x7e: button=4; break;
case 0xed: button=5; break;
case 0xdd: button=6; break;
case 0xbd: button=7; break;
case 0x7d: button=8; break;
case 0xeb: button=9; break;
case 0xdb: button=10;break;
case 0xbb: button=11;break;
case 0x7b: button=12;break;
case 0xe7: button=13;break;
case 0xd7: button=14;break;
case 0xb7: button=15;break;
case 0x77: button=16;break;
}

}

void key_time() //按键调时
{ void key_scan(uchar button);

if(button==3)//3是进入调时键
{
EA=0;
s_num=0;
while(1)
{
display();
if(button=4)//4是退出调时键
{

EA=1;
break;
}
if(button==7) //7是秒增加键
{

delay(1);
if(button==7)
{
s_num++;
//while(button!=7)
//{
if(s_num==60)
{
s_num=0;
}
//}
}
}
if(button==11) //11是分增加键
{
delay(80);
if(button==11)
{
m_num++;

              if(m_num==60)
              {
                 m_num=0;
              }

           }
        }
        if(button==15)
        {
           delay(80);
           if(button==15)
           {
              h_num++;
              //while(button!=15)

             // {
              if(h_num==60)
              {
                 h_num=0;    
              }
             // }
           }
        }
   }
} 

}

void main()
{
inter_init();
while(1)
{
time24();
key_time();
display();
}
}

1个回答

shihengzhen101
shihengzhen101   Rxr 2016.09.18 18:42

你第一次就写这么大的程序?

Csdn user default icon
上传中...
上传图片
插入图片