0
本帖最后由 eehome 于 2013-1-5 09:53 编辑
我自己写的1602显示可调的万年历,利用24C02存储数据,断电后再上电应该可从断电前的时间点显示,可显示不了,而且编译出现1个警告,警告如下: 求大神指导啊!!!!!!!!!
Build target 'Target 1'
assembling STARTUP.A51...
compiling 8.8.2.c...
linking...
*** WARNING L15: MULtiPLE CALL TO SEGMENT
SEGMENT: ?PR?RESPONS?8_8_2
CALLER1: ?C_C51STARTUP
CALLER2: ?PR?TIME0?8_8_2
Program Size: data=23.0 xdata=0 code=2969
creating hex file from "8.12.5"...
"8.12.5" - 0 Error(s), 1 Warning(s).
#include
#define uchar unsigned char
char code a0[]="-";
char code a1[]=":";
char code a2[]="SUN MON TUE WED THI FRI SAT";
char k,num,yue,ri,xq,shi,fen,miao;
int nian;
***it scl=P1^5; //AT24C02
***it sda=P3^6; //AT24C02
***it rs=P2^5; //1602
***it rw=P2^6; //1602
***it e=P2^7; //1602
***it key1=P3^2; //独立键盘
***it key2=P3^3; //独立键盘
***it key3=P3^4; //独立键盘
void delay1()
{;;}
void delay(uchar t)
{
uchar i,j;
for(i=0;i
for(j=0;j<111;j++);
}
//I2C初始化
void chu()
{
scl=1;
delay1();
sda=1;
delay1();
}
//I2C启动
void start()
{
sda=1;
delay1();
scl=1;
delay1();
sda=0;
delay1();
scl=0;
delay1();
}
//I2C应答
void respons()
{
uchar i;
scl=1;
delay1();
while((sda==1)&&(i<25))
i++;
scl=0;
delay1();
}
//I2C终止
void stop()
{
scl=1;
delay1();
sda=0;
delay1();
sda=1;
delay1();
scl=0;
delay1();
}
//24C02写字节
void writebyte(char date)
{
char i,c;
c=date;
for(i=0;i<8;i++)
{
c=c<<1;
sda=CY;
scl=1;
delay1();
scl=0;
delay1();
}
sda=1;
delay1();
}
//24C02读字节
char readbyte()
{
char i,j;
for(j=0;j<8;j++)
{
scl=1;
delay1();
i=(i<<1)|sda;
scl=0;
delay1();
}
sda=1;
delay1();
return i;
}
//24C02写数据
void writeadd(uchar add,char date)
{
start();
writebyte(0xa0);
respons();
writebyte(add);
respons();
writebyte(date);
respons();
stop();
}
//24C02读数据
char readadd(uchar add)
{
char date;
start();
writebyte(0xa0);
respons();
writebyte(add);
respons();
start();
writebyte(0xa1);
respons();
date=readbyte();
stop();
return date;
}
//初始读出存储数据
void initdu()
{
char c,d,e,f,g,h;
c=readadd(1);
d=readadd(2);
e=c/10;
f=c%10;
g=d/10;
h=d%10;
nian=((e*1000)+(f*100)+(g*10)+h);
yue=readadd(3);
ri=readadd(4);
xq=readadd(5);
if((xq>=8)||(xq<=0))
xq=1;
shi=readadd(6);
fen=readadd(7);
miao=readadd(8);
}
//1602写命令
void write_com(uchar com)
{
rs=0;
rw=0;
e=0;
P0=com;
delay(5);
e=1;
delay(5);
e=0;
delay(5);
}
//1602写数据
void write_date(char date)
{
rs=1;
rw=0;
e=0;
P0=date;
delay(5);
e=1;
delay(5);
e=0;
delay(5);
}
//写星期
void writexq(char n)
{
uchar i;
if(n==1)
{
for(i=0;i<3;i++)
write_date(a2);
}
if(n==2)
{
for(i=4;i<7;i++)
write_date(a2);
}
if(n==3)
{
for(i=8;i<11;i++)
write_date(a2);
}
if(n==4)
{
for(i=12;i<15;i++)
write_date(a2);
}
if(n==5)
{
for(i=16;i<19;i++)
write_date(a2);
}
if(n==6)
{
for(i=20;i<23;i++)
write_date(a2);
}
if(n==7)
{
for(i=24;i<27;i++)
write_date(a2);
}
}
//在1602上显示从存储单元读出的数据
void xianshi()
{
write_com(0x80+1);
write_date(0x30+(nian/1000));
write_date(0x30+(nian/100%10));
write_date(0x30+(nian/10%10));
write_date(0x30+(nian%10));
write_date(a0[0]);
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
write_date(a0[0]);
write_date(0x30+(ri/10));
write_date(0x30+(ri%10));
write_com(0x80+12);
writexq(xq);
write_com(0x80+0x40+4);
write_date(0x30+(shi/10));
write_date(0x30+(shi%10));
write_date(a1[0]);
write_date(0x30+(fen/10));
write_date(0x30+(fen%10));
write_date(a1[0]);
write_date(0x30+(miao/10));
write_date(0x30+(miao%10));
}
//1602初始化及初显存储模块数据
void init1602()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
initdu();
xianshi();
}
//定时器0初始化
void inittime0()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
}
//键盘扫描
void keyscan()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
while(!key1);
TR0=0;
num++;
if(num==7)
{
write_com(0x80+0x40+10);
}
if(num==6)
write_com(0x80+0x40+7);
if(num==5)
write_com(0x80+0x40+4);
if(num==4)
write_com(0x80+12);
if(num==1)
{
write_com(0x80+1);
write_com(0x0f);
}
if(num==2)
write_com(0x80+6);
if(num==3)
write_com(0x80+9);
if(num==8)
{
num=0;
write_com(0x0c);
inittime0();
TR0=1;
}
}
}
if(num==7)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
miao++; //加秒
if(miao==60)
miao=0;
write_date(0x30+(miao/10));
write_date(0x30+(miao%10));
write_com(0x80+0x40+10);
writeadd(8,miao);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
miao--; //减秒
if(miao==-1)
miao=59;
write_date(0x30+(miao/10));
write_date(0x30+(miao%10));
write_com(0x80+0x40+10);
writeadd(8,miao);
}
}
}
if(num==6)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2); //加分
fen++;
if(fen==60)
fen=0;
write_date(0x30+(fen/10));
write_date(0x30+(fen%10));
write_com(0x80+0x40+7);
writeadd(7,fen);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
fen--; //减分
if(fen==-1)
fen=59;
write_date(0x30+(fen/10));
write_date(0x30+(fen%10));
write_com(0x80+0x40+7);
writeadd(7,fen);
}
}
}
if(num==5)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
shi++; //加时
if(shi==24)
shi=0;
write_date(0x30+(shi/10));
write_date(0x30+(shi%10));
write_com(0x80+0x40+4);
writeadd(6,shi);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3); //减时
shi--;
if(shi==-1)
shi=23;
write_date(0x30+(shi/10));
write_date(0x30+(shi%10));
write_com(0x80+0x40+4);
writeadd(6,shi);
}
}
}
if(num==4)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
xq++; //加星期
if(xq==8)
xq=0;
writexq(xq);
write_com(0x80+12);
writeadd(5,xq);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
xq--; //减星期
if(xq==0)
xq=7;
writexq(xq);
write_com(0x80+12);
writeadd(5,xq);
}
}
}
if(num==1)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
nian++; // 加年
write_date(0x30+(nian/1000));
write_date(0x30+(nian%1000/100));
write_date(0x30+(nian%100/10));
write_date(0x30+(nian%10));
write_com(0x80+1);
writeadd(1,(nian/100));
writeadd(2,(nian%100));
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
nian--; //减年
write_date(0x30+(nian/1000));
write_date(0x30+(nian%1000/100));
write_date(0x30+(nian%100/10));
write_date(0x30+(nian%10));
write_com(0x80+1);
writeadd(1,(nian/100));
writeadd(2,(nian%100));
}
}
}
if(num==2)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
yue++; //加月
if(yue==13)
yue=1;
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
write_com(0x80+6);
writeadd(3,yue);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
yue--; //减月
if(yue==0)
yue=12;
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
write_com(0x80+6);
writeadd(3,yue);
}
}
}
if(num==3)
{
if(key2==0)
{
delay(10);
if(key2==0)
{
while(!key2);
ri++; //加日
if((yue==1)||(yue==3)||(yue==5)||(yue==7)||(yue==8)||(yue==10)||(yue==12))
{
if(ri==32)
ri=1;
}
else
{
if(yue!=2)
{
if(ri==31)
ri=1;
}
if(yue==2)
{
if(((nian%4)==0)&&((nian%100)!=0)||((nian%400)==0))
{
if(ri==30)
ri=1;
}
else
if(ri==29)
ri=1;
}
}
write_date(0x30+(ri/10));
write_date(0x30+(ri%10));
write_com(0x80+9);
writeadd(4,ri);
}
}
if(key3==0)
{
delay(10);
if(key3==0)
{
while(!key3);
ri--; //减日
if((yue==1)||(yue==3)||(yue==5)||(yue==7)||(yue==8)||(yue==10)||(yue==12))
{
if(ri==0)
ri=31;
}
else
{
if(yue!=2)
{
if(ri==0)
ri=30;
}
if(yue==2)
{
if(((nian%4)==0)&&((nian%100)!=0)||((nian%400)==0))
{
if(ri==0)
ri=29;
}
else
if(ri==0)
ri=28;
}
}
write_date(0x30+(ri/10));
write_date(0x30+(ri%10));
write_com(0x80+9);
writeadd(4,ri);
}
}
}
}
void main()
{
chu();
init1602();
inittime0();
TR0=1;
while(1)
{
keyscan();
}
}
void time0() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
k++;
if(k>=20)
{
k=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
ri++;
xq++;
if(xq==8)
xq=1;
if((yue==1)|(yue==3)|(yue==5)|(yue==7)|(yue==8)|(yue==10)|(yue==12))
{
if(ri==32)
{
ri=1;
yue++;
if(yue>=13)
{
yue=1;
nian++;
write_com(0x80+1);
write_date(0x30+(nian/1000));
write_date(0x30+(nian%1000/100));
write_date(0x30+(nian%100/10));
write_date(0x30+(nian%10));
writeadd(1,(nian/100));
writeadd(2,(nian%100));
}
write_com(0x80+6);
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
writeadd(3,yue);
}
}
else
{
if(yue!=2)
{
if(ri==31)
{
ri=1;
yue++;
write_com(0x80+6);
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
writeadd(3,yue);
}
}
else
{
if(((nian%400)==0)||(((nian%4)==0)&&((nian%100)!=0)))
{
if(ri==30)
{
ri=1;
yue++;
write_com(0x80+6);
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
writeadd(3,yue);
}
}
else
{
if(ri==29)
{
ri=1;
yue++;
write_com(0x80+6);
write_date(0x30+(yue/10));
write_date(0x30+(yue%10));
writeadd(3,yue);
}
}
}
}
write_com(0x80+9);
write_date(0x30+(ri/10));
write_date(0x30+(ri%10));
writeadd(4,ri);
write_com(0x80+12);
writexq(xq);
writeadd(5,xq);
}
write_com(0x80+0x40+4);
write_date(0x30+(shi/10));
write_date(0x30+(shi%10));
writeadd(6,shi);
}
write_com(0x80+0x40+7);
write_date(0x30+(fen/10));
write_date(0x30+(fen%10));
writeadd(7,fen);
}
write_com(0x80+0x40+10);
write_date(0x30+(miao/10));
write_date(0x30+(miao%10));
writeadd(8,miao);
}
}
|
|