#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit SCL=P1^0;
sbit SDA=P1^1;
code uchar disptab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f,0x77,0x7c,0x39,0x48};
code uchar bittab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar disnum,key_1_num,month,hour,min,year,day;
uchar dispbuf[6];//显存
uchar shuxian[3]={0x11,0x02,0x03};//临时放数据,放时BCD码
bit t_int0;
void init()
{
TMOD=0x01;
EA=1;
TH0=63266/256;
TL0=63266%256;
TR0=1;
ET0=1;
dula=0;
wela=0;
disnum=1;
}
//**************键盘部分*************************
/*void delay(int n)
{
int z;
for(z=n;z>0;n--);
}
void key_1()
{
key_1_num++;
if(key_1_num==7)
{
key_1_num=0;
}
}void key_2()
{
switch(key_1_num)
{
case 1:shuxian[2]++;
break;
case 2:
{month++;
if(month==13)
month=1;
}break;
case 3:{
day++;
if(day==30)
day=1;
}break;
case 4:{
hour++;
if(hour==25)
hour=0;
}break;
case 5:{
min++;
if(min==61)
min=0;
}break;
case 6:{
}break;
}
}
void key_3()
{
key_1_num=0;
}
void key_4()
{
key_1_num=0;
}
void key()
{
uchar key_value,c;
c=~P1;
key_value=c&0xf0;
delay(1000);
c=~P1;
if((key_value&c)!=1)
{
do
{
c=~P1;
}
while((key_value&c)!=1);
delay(1000);
switch(key_value)
{
case 0x10:key_1();break;
case 0x20:key_1();break;
case 0x30:key_3();break;
case 0x40:key_4();break;
}
}
}
*/
//**************显示部分*************************
void display()
{
static uchar mun;
if(t_int0==1)// 模式一正常显示时间
{
uchar temp;
t_int0=0 ;
TH0=63266/256;
TL0=63266%256;
dispbuf[0]=shuxian[0]>>4&0x7;
dispbuf[1]=shuxian[0]&0x0f;
dispbuf[2]=shuxian[1]>>4&0x7;
dispbuf[3]=shuxian[1]&0x0f;
dispbuf[4]=shuxian[2]>>4&0x7;
dispbuf[5]=shuxian[2]&0x0f;
P0=0xff;
wela=1;
P0=P0&bittab[mun];
wela=0;
temp=dispbuf[mun];
dula=1;
P0=disptab[temp];
dula=0;
mun++;
if(mun==6)
mun=0;
}
}
//**************中断部分*************************
void time_int0() interrupt 1
{
t_int0=1;
TH0=63266/256;
TL0=63266%256;
}
//**************MAIN*************************
void main()
{
init();
while(1)
{
display();
// key();
//guzhang();
}
}
为什么加上键盘部分就MAIN开始地址不是MAIN,不知道为什么?这种情况不知道什么原因 |