微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > ks0108与ds1302的可调时钟出现了问题

ks0108与ds1302的可调时钟出现了问题

时间:10-02 整理:3721RD 点击:
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#define uint unsigned int
#define uchar unsigned char
extern void  LCD_Init();
extern void display_char(uchar P,uchar L,uchar *M);
extern void display_word(uchar P,uchar L,uchar *M);
extern bit Rev_display;
sbit SDA=P1^0;
sbit CLK=P1^1;
sbit RST=P1^2;
sbit K1=P3^4;
sbit K2=P3^5;
sbit K3=P3^6;
sbit K4=P3^7;
uchar tCount=0;
code uchar Days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
uchar DateTime[7];
char Adjust_Index=-1;
uchar H_offset=10,V_offset=0;
uchar code DateTime_words[]={/*--  文字:  年  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
/*--  文字:  月  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,
/*--  文字:  日  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,
/*--  文字:  星  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,
0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,0x00,0x00,
/*--  文字:  期  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00,
/*--  文字:  时  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00,
/*--  文字:  分  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x80,0x40,0x20,0x90,0x88,0x86,0x80,0x80,0x80,0x83,0x8C,0x10,0x20,0x40,0x80,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
/*--  文字:  秒  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0xC0,0x38,0x00,0xFF,0x00,0x08,0x10,0x60,0x00,
0x08,0x06,0x01,0xFF,0x01,0x06,0x81,0x80,0x40,0x40,0x27,0x10,0x0C,0x03,0x00,0x00,
};
uchar code Week_words[]={/*--  文字:  日  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,
/*--  文字:  一  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--  文字:  二  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
/*--  文字:  三  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
/*--  文字:  四  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,
/*--  文字:  五  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,0x00,
0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x00,
/*--  文字:  六  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,0x00,0x00,
};
uchar code Num[]={/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*--  文字:  3  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*--  文字:  4  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*--  文字:  5  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*--  文字:  6  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*--  文字:  7  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*--  文字:  8  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*--  文字:  9  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
};
void Write_byte(uchar x)
{
uchar i;
for(i=0;i<8;i++)
{
  SDA=x&0x01;
  CLK=1;
  CLK=0;
  x>>=1;
}
}
uchar Get_byte()
{
uchar i,b,t;
for(i=0;i<8;i++)
{
  b>>=1;
  t=SDA;
  b|=t<<7;
  CLK=1;
  CLK=0;
}
    return b/16*10+b%16;
}
uchar Read_Data(uchar addr)
{
uchar dat;
RST=0;
CLK=0;
RST=1;
Write_byte(addr);
dat=Get_byte();
CLK=1;
RST=0;
return dat;
}
void Write_Ds1302(uchar addr,uchar dat)
{
CLK=0;
RST=1;
Write_byte(addr);
Write_byte(dat);
CLK=0;
RST=0;
}
void SET_Ds1302()
{
uchar i;
Write_Ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
   Write_Ds1302(0x80+2*i,(DateTime[i]/10<<4)|(DateTime[i]%10));
}
  Write_Ds1302(0x8e,0x80);
}
void GetTime()
{
uchar i;
for(i=0;i<7;i++)
DateTime[i]=Read_Data(0x81+2*i);
}
void isLeapYear(uint y)
{
return (y%4==0&&y%100!=0)||(y%400==0);
}
void RefreshWeekDay()
{
uint y,i,d,w=5;
y=2000+DateTime[6];
for(i=2000;i<y;i++)
{
  d=(isLeapYear(i)) ? 366:365;
  w=(w+d)%7;
}
d=0;
for(i=1;i<DateTime[4];i++)
  {
   d+=Days[i];
   if(i==2&&isLeapYear(y))
   d++;
  }
d+=DateTime[3];
DateTime[5]=(w+d)%7+1;

}
void DateTime_Adjust(char x)
{
uchar d;
switch(Adjust_Index)
{
  case 6:
    if(x==1&&DateTime[6]<99)
    DateTime[6]++;
    if(x==-1&&DateTime[6]>0)
    DateTime[6]--;
    if(DateTime[4]==2&&DateTime[3]==29)
    DateTime[3]=28;
    RefreshWeekDay();
    break;
  case 4:
    if(x==1&&DateTime[4]<12)
    DateTime[4]++;
    if(x==-1&&DateTime[4]>1)
    DateTime[4]--;
    if(DateTime[4]==2&&DateTime[3]==29)
    DateTime[3]=28;
    RefreshWeekDay();
    break;
  case 3:
    d=Days[DateTime[4]];
    if(isLeapYear(2000+DateTime[6])&&DateTime[4]==2)
     d=29;
    if(x==1&&DateTime[3]<d)
     DateTime[3]++;
    if(x==-1&&DateTime[3]>1)
    DateTime[3]--;
    RefreshWeekDay();
    break;
  case 2:
    if(DateTime[2]<23&&x==1)
    DateTime[2]++;
    if(DateTime[2]>0&&x==-1)
    DateTime[2]--;
       break;
  case 1:
    if(DateTime[1]<59&&x==1)
    DateTime[1]++;
    if(DateTime[1]>0&&x==-1)
    DateTime[1]--;
       break;
  case 0:
    case 2:
    if(DateTime[1]<59&&x==1)
    DateTime[0]++;
    if(DateTime[1]>0&&x==-1)
    DateTime[0]--;
       break;
}
}
void Int_T0() interrupt 1
{
TH0=-50000>>8;
TL0=-50000&0xff;
if(++tCount!=2)
return ;
tCount=0;
Rev_display=Adjust_Index==6;
display_char(V_offset,16+H_offset,Num+DateTime[6]/10*16);
display_char(V_offset,24+H_offset,Num+DateTime[6]%10*16);

Rev_display=Adjust_Index==4;
display_char(V_offset,48+H_offset,Num+DateTime[4]/10*16);
display_char(V_offset,56+H_offset,Num+DateTime[4]%10*16);
Rev_display=Adjust_Index==3;
display_char(V_offset,80+H_offset,Num+DateTime[3]/10*16);
display_char(V_offset,88+H_offset,Num+DateTime[3]%10*16);
Rev_display=0;
display_word(V_offset+2,96+H_offset,Week_words+(DateTime[5]-1)*32);
Rev_display=Adjust_Index==2;
display_char(V_offset+5,16+H_offset,Num+DateTime[2]/10*16);
display_char(V_offset+5,24+H_offset,Num+DateTime[2]%10*16);
Rev_display=Adjust_Index==1;
display_char(V_offset+5,48+H_offset,Num+DateTime[1]/10*16);
display_char(V_offset+5,56+H_offset,Num+DateTime[1]%10*16);
Rev_display=Adjust_Index==0;
display_char(V_offset+5,80+H_offset,Num+DateTime[0]/10*16);
display_char(V_offset+5,88+H_offset,Num+DateTime[0]%10*16);

}
void EX_INT0() interrupt 0
{
if(K1==0)
{
  if(Adjust_Index ==-1||Adjust_Index==0)
  Adjust_Index=7;
  if(--Adjust_Index==5)
  Adjust_Index=4;
}
else if(K2==0)
  DateTime_Adjust(1);
else if(K3==0)
  DateTime_Adjust(-1);
else if(K4==0)
  {
   SET_Ds1302();
   Adjust_Index=-1;
  }
}
void main()
{
LCD_Init();
display_char(V_offset,0+H_offset,Num+2*16);
display_char(V_offset,8+H_offset,Num);
display_word(V_offset,32+H_offset,DateTime_words+0*32);
display_word(V_offset,64+H_offset,DateTime_words+1*32);
display_word(V_offset,96+H_offset,DateTime_words+2*32);
display_word(V_offset+2,64+H_offset,DateTime_words+3*32);
display_word(V_offset+2,80+H_offset,DateTime_words+4*32);
display_word(V_offset+5,32+H_offset,DateTime_words+5*32);
display_word(V_offset+5,64+H_offset,DateTime_words+6*32);
display_word(V_offset+5,96+H_offset,DateTime_words+7*32);
IE=0x83;
IP=0x01;
IT0=0x01;
TH0=-50000>>8;
TL0=-50000&0xff;
TR0=1;
while(1)
{
  if(Adjust_Index==-1)
  GetTime();
}
}
编译的时候出现如下问题
#include <reg52.h>
#include <intrins.h>
#include <string.h>
#define uint unsigned int
#define uchar unsigned char
extern void  LCD_Init();
extern void display_char(uchar P,uchar L,uchar *M);
extern void display_word(uchar P,uchar L,uchar *M);
extern bit Rev_display;
sbit SDA=P1^0;
sbit CLK=P1^1;
sbit RST=P1^2;
sbit K1=P3^4;
sbit K2=P3^5;
sbit K3=P3^6;
sbit K4=P3^7;
uchar tCount=0;
code uchar Days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
uchar DateTime[7];
char Adjust_Index=-1;
uchar H_offset=10,V_offset=0;
uchar code DateTime_words[]={/*--  文字:  年  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x20,0x18,0xC7,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0x04,0x00,0x00,
0x04,0x04,0x04,0x07,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
/*--  文字:  月  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0xFE,0x00,0x00,0x00,
0x80,0x40,0x30,0x0F,0x02,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,
/*--  文字:  日  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,
/*--  文字:  星  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,
0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,0x00,0x00,
/*--  文字:  期  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0x00,
0x88,0x48,0x2F,0x09,0x09,0x19,0xAF,0x48,0x30,0x0F,0x02,0x42,0x82,0x7F,0x00,0x00,
/*--  文字:  时  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00,
/*--  文字:  分  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x80,0x40,0x20,0x90,0x88,0x86,0x80,0x80,0x80,0x83,0x8C,0x10,0x20,0x40,0x80,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,
/*--  文字:  秒  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0xC0,0x38,0x00,0xFF,0x00,0x08,0x10,0x60,0x00,
0x08,0x06,0x01,0xFF,0x01,0x06,0x81,0x80,0x40,0x40,0x27,0x10,0x0C,0x03,0x00,0x00,
};
uchar code Week_words[]={/*--  文字:  日  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x00,0xFE,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x00,0x00,0x00,0x00,
/*--  文字:  一  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*--  文字:  二  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x00,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00,
/*--  文字:  三  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x04,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x04,0x00,0x00,
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
/*--  文字:  四  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0xFC,0x00,0x00,
0x00,0x7F,0x28,0x24,0x23,0x20,0x20,0x20,0x20,0x21,0x22,0x22,0x22,0x7F,0x00,0x00,
/*--  文字:  五  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x00,0x02,0x42,0x42,0x42,0xC2,0x7E,0x42,0x42,0x42,0x42,0xC2,0x02,0x02,0x00,0x00,
0x40,0x40,0x40,0x40,0x78,0x47,0x40,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x00,
/*--  文字:  六  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=16x16   --*/
0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x22,0x2C,0x20,0x20,0x20,0x20,0x20,0x20,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x01,0x02,0x04,0x18,0x60,0x00,0x00,
};
uchar code Num[]={/*--  文字:  0  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,
/*--  文字:  1  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,
/*--  文字:  2  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,
/*--  文字:  3  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,
/*--  文字:  4  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,
/*--  文字:  5  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,
/*--  文字:  6  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,
/*--  文字:  7  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,
/*--  文字:  8  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,
/*--  文字:  9  --*/
/*--  宋体12;  此字体下对应的点阵为:宽x高=8x16   --*/
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,
};
void Write_byte(uchar x)
{
uchar i;
for(i=0;i<8;i++)
{
  SDA=x&0x01;
  CLK=1;
  CLK=0;
  x>>=1;
}
}
uchar Get_byte()
{
uchar i,b,t;
for(i=0;i<8;i++)
{
  b>>=1;
  t=SDA;
  b|=t<<7;
  CLK=1;
  CLK=0;
}
    return b/16*10+b%16;
}
uchar Read_Data(uchar addr)
{
uchar dat;
RST=0;
CLK=0;
RST=1;
Write_byte(addr);
dat=Get_byte();
CLK=1;
RST=0;
return dat;
}
void Write_Ds1302(uchar addr,uchar dat)
{
CLK=0;
RST=1;
Write_byte(addr);
Write_byte(dat);
CLK=0;
RST=0;
}
void SET_Ds1302()
{
uchar i;
Write_Ds1302(0x8e,0x00);
for(i=0;i<7;i++)
{
   Write_Ds1302(0x80+2*i,(DateTime[i]/10<<4)|(DateTime[i]%10));
}
  Write_Ds1302(0x8e,0x80);
}
void GetTime()
{
uchar i;
for(i=0;i<7;i++)
DateTime[i]=Read_Data(0x81+2*i);
}
void isLeapYear(uint y)
{
return (y%4==0&&y%100!=0)||(y%400==0);
}
void RefreshWeekDay()
{
uint y,i,d,w=5;
y=2000+DateTime[6];
for(i=2000;i<y;i++)
{
  d=(isLeapYear(i)) ? 366:365;
  w=(w+d)%7;
}
d=0;
for(i=1;i<DateTime[4];i++)
  {
   d+=Days[i];
   if(i==2&&isLeapYear(y))
   d++;
  }
d+=DateTime[3];
DateTime[5]=(w+d)%7+1;

}
void DateTime_Adjust(char x)
{
uchar d;
switch(Adjust_Index)
{
  case 6:
    if(x==1&&DateTime[6]<99)
    DateTime[6]++;
    if(x==-1&&DateTime[6]>0)
    DateTime[6]--;
    if(DateTime[4]==2&&DateTime[3]==29)
    DateTime[3]=28;
    RefreshWeekDay();
    break;
  case 4:
    if(x==1&&DateTime[4]<12)
    DateTime[4]++;
    if(x==-1&&DateTime[4]>1)
    DateTime[4]--;
    if(DateTime[4]==2&&DateTime[3]==29)
    DateTime[3]=28;
    RefreshWeekDay();
    break;
  case 3:
    d=Days[DateTime[4]];
    if(isLeapYear(2000+DateTime[6])&&DateTime[4]==2)
     d=29;
    if(x==1&&DateTime[3]<d)
     DateTime[3]++;
    if(x==-1&&DateTime[3]>1)
    DateTime[3]--;
    RefreshWeekDay();
    break;
  case 2:
    if(DateTime[2]<23&&x==1)
    DateTime[2]++;
    if(DateTime[2]>0&&x==-1)
    DateTime[2]--;
       break;
  case 1:
    if(DateTime[1]<59&&x==1)
    DateTime[1]++;
    if(DateTime[1]>0&&x==-1)
    DateTime[1]--;
       break;
  case 0:
    case 2:
    if(DateTime[1]<59&&x==1)
    DateTime[0]++;
    if(DateTime[1]>0&&x==-1)
    DateTime[0]--;
       break;
}
}
void Int_T0() interrupt 1
{
TH0=-50000>>8;
TL0=-50000&0xff;
if(++tCount!=2)
return ;
tCount=0;
Rev_display=Adjust_Index==6;
display_char(V_offset,16+H_offset,Num+DateTime[6]/10*16);
display_char(V_offset,24+H_offset,Num+DateTime[6]%10*16);

Rev_display=Adjust_Index==4;
display_char(V_offset,48+H_offset,Num+DateTime[4]/10*16);
display_char(V_offset,56+H_offset,Num+DateTime[4]%10*16);
Rev_display=Adjust_Index==3;
display_char(V_offset,80+H_offset,Num+DateTime[3]/10*16);
display_char(V_offset,88+H_offset,Num+DateTime[3]%10*16);
Rev_display=0;
display_word(V_offset+2,96+H_offset,Week_words+(DateTime[5]-1)*32);
Rev_display=Adjust_Index==2;
display_char(V_offset+5,16+H_offset,Num+DateTime[2]/10*16);
display_char(V_offset+5,24+H_offset,Num+DateTime[2]%10*16);
Rev_display=Adjust_Index==1;
display_char(V_offset+5,48+H_offset,Num+DateTime[1]/10*16);
display_char(V_offset+5,56+H_offset,Num+DateTime[1]%10*16);
Rev_display=Adjust_Index==0;
display_char(V_offset+5,80+H_offset,Num+DateTime[0]/10*16);
display_char(V_offset+5,88+H_offset,Num+DateTime[0]%10*16);

}
void EX_INT0() interrupt 0
{
if(K1==0)
{
  if(Adjust_Index ==-1||Adjust_Index==0)
  Adjust_Index=7;
  if(--Adjust_Index==5)
  Adjust_Index=4;
}
else if(K2==0)
  DateTime_Adjust(1);
else if(K3==0)
  DateTime_Adjust(-1);
else if(K4==0)
  {
   SET_Ds1302();
   Adjust_Index=-1;
  }
}
void main()
{
LCD_Init();
display_char(V_offset,0+H_offset,Num+2*16);
display_char(V_offset,8+H_offset,Num);
display_word(V_offset,32+H_offset,DateTime_words+0*32);
display_word(V_offset,64+H_offset,DateTime_words+1*32);
display_word(V_offset,96+H_offset,DateTime_words+2*32);
display_word(V_offset+2,64+H_offset,DateTime_words+3*32);
display_word(V_offset+2,80+H_offset,DateTime_words+4*32);
display_word(V_offset+5,32+H_offset,DateTime_words+5*32);
display_word(V_offset+5,64+H_offset,DateTime_words+6*32);
display_word(V_offset+5,96+H_offset,DateTime_words+7*32);
IE=0x83;
IP=0x01;
IT0=0x01;
TH0=-50000>>8;
TL0=-50000&0xff;
TR0=1;
while(1)
{
  if(Adjust_Index==-1)
  GetTime();
}
}
1.C(205): error C174: return-expression on void-function
1.C(213): error C215: illegal type conversion
1.C(234): error C187: not an lvalue
1.C(236): error C187: not an lvalue
1.C(243): error C187: not an lvalue
1.C(245): error C187: not an lvalue
1.C(255): error C187: not an lvalue
1.C(257): error C187: not an lvalue
1.C(262): error C187: not an lvalue
1.C(264): error C187: not an lvalue
1.C(268): error C187: not an lvalue
1.C(270): error C187: not an lvalue
1.C(275): error C187: not an lvalue
1.C(277): error C187: not an lvalue

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top