为什么我的一个万年历程序,编译能通过,但运行却没有反应?求指点,程序如下:
1.1初始化程序及宏定义
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uint tunt1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
sbit P1_6=P1^6;
sbit P1_7=P1^7;
sbit key_y_h=P2^0;
sbit key_m_m=P2^1;
sbit key_d_s=P2^2;
sbit key_set=P2^3;
uint yearh=20;
uchar flag,flag1,flag2,sec;
uint week=1;
uint min=30;
uint hour=15;
uint day=16;
uint month=12;
uchar flag2=0;
uint year=13;uchar sec_l,sec_h,min_l,min_h,hour_l,hour_h;
uchar day_l,day_h,month_l,month_h,year_l,year_h;
uchar code tab[]={
0x3F,/*0*/
0x06,/*1*/
0x5B,/*2*/
0x4F,/*3*/
0x66,/*4*/
0x6D,/*5*/
0x7D,/*6*/
0x07,/*7*/
0x7F,/*8*/
0x6F,/*9*/
};
// 1.2延时子程序
void delay(uint ms)
{
uchar i;
while(ms--)
for(i=0;i<123;i++);
}
//1.3主程序
void main()
{
while(1)
{
TMOD=0x02; //设置模式为定时器T0的模式2 (8位自动重装计数初值的计数值)
TH0=0x06; //设置计数器初值,靠TH0存储重装的计数值X0=256-250=6
TL0=0x06;
TR0=1; //启动T0
ET0=1; //开启定时器T0中断允许
EA=1;
}
}
void t0(void) interrupt 1 using 0 //t0的中断程序
{
tunt1++;
if(tunt1==4000)//定时器的定时计数,4000次250us为1秒
{
tunt1=0;
sec++;
if(sec==60)
{
sec=0;
min++;
if(min==60)
{
min=0;
hour++;
if(hour==24)
{
hour=0;
day++;
week++;
if(month==2&&((year==0&&yearh%4==0)||(year!=0&&year%4==0))&&day==30)day=1;
else if(month==2&&day==29)day=1;
else if((month==4||month==6||month==9||month==11)&&day==31)day=1;
else if(day==32)day=1;
if(day==1)
{
month++;
if(month==13)
{
month=1;
year++;
if(year==100)
{
year=0;
yearh++;
if(yearh==100)
{
yearh=20;
}
}
}
}
}
}
}
}
}
// 1.4显示子程序
void disp()
{
sec_h=sec/10; //时分秒的数码管显示,年月日类似
sec_l=sec%10;
min_h=min/10;
min_l=min%10;
hour_h=hour/10;
hour_l=hour%10;
day_h=day/10;
day_l=day%10;
month_h=month/10;
month_l=month%10;
year_h=year/10;
year_l=year%10;
P1_2=0;
if(flag2==1)
P0=tab[day_l];
else if(flag2==0)
P0=tab[sec_l];
else if(flag2==2)
P0=tab[week];
delay(1);
P1_2=1;
P1_3=0;
if(flag2==1)
P0=tab[day_h];
if(flag2==0)
P0=tab[sec_h];
else P0=tab[0];
delay(1);
P1_3=1;
P1_4=0;
if(flag2==1)
P0=tab[month_l]|0x80;
else if(flag2==0)
P0=tab[min_l]|0x80;
else if(flag2==2)
P0=tab[0];
delay(1);
P1_4=1;
P1_5=0;
if(flag2==1)
P0=tab[month_h];
else if(flag2==0)
P0=tab[min_h];
else if(flag2==2)
P0=tab[0];
delay(1);
P1_5=1;
P1_6=0;
if(flag2==1)
P0=tab[year_l]|0x80;
else if(flag2==0)
P0=tab[hour_l]|0x80;
else if(flag2==2)
P0=tab[0];
delay(1);
P1_6=1;
P1_7=0;
if(flag2==1)
P0=tab[year_h];
else if(flag2==0)
P0=tab[hour_h];
else if(flag2==2)
P0=tab[0];
delay(1);
P1_7=1;
}
// 1.5 按键子程序
void key_scan()
{
disp();
while(!key_set) //日期/时间键
{
disp( );
if(key_set)
{
flag2=!flag2;
}
}
while(!key_y_h) //年/时键
{
disp( );
if(key_y_h)
{
if(flag2==1) //对年份进行调节
{
year_l++;
if(year_l==10)
{
year_l=0;
year_h++;
}
year=year_l+year_h*10;
}
else if(flag2==0) //对小时进行调节
{
hour_l++;
if(hour_l==10)
{
hour_l=0;
hour_h++;
}
if(hour_l==4&&hour_h==2)
{
hour_l=0;
hour_h=0;
}
}
hour=hour_h*10+hour_l;
}
}
}
此程序在porteus keill编译都能正常通过,但仿真却一动不动。 |