Microcontroller › 8051 › Interfacing DS1302(RTC) with an 8051… The time display on Lcd can run but there are problems!! Need some help and guide.
- This topic has 0 replies, 1 voice, and was last updated 13 years, 7 months ago by Ang wei qiang.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
May 9, 2011 at 6:33 am #3843Ang wei qiangParticipant
For all the 1,3,5,7,9mins and so on…or maybe i should say is the oddmins.It will display something like the patterns shown below for the 1minute.Here is a example of 85error that it display.The first 5 patterns of the "1 hr and 5min"01:85:00""01:05:01""01:85:02""01:05:03""01:85:04"
As for all the 2,4,6,8,10mins and so on…or maybe i should say is theeven mins.It will display something like the patterns shown below for the first59 second and the 1 hour.For the first 59 second,i show first five patterns of it."00:85:00""85:00:01""00:85:02""85:00:03""00:85:04"...."85:00:59"For the starting of 1 minute,i show first five patterns of it."00:85:00""00:01:01""00:85:02""00:01:03""00:85:04"....For the starting of 1 hour,i show first five patterns of it."01:85:00""85:00:01""01:85:02""85:00:03""01:85:04"....
On top is the error that i face,im not sure how can i solve it.The DS1302 header file,i got on a website and i have modify it to make the time to run.What can be the problem that causing this??Let me know anything that i could try to solve this problem.Please,I need some guide and help with it.I will paste the header file. Let me know if you want to see my c code. ~~ THx ~~Below is the modified header file code: (There are some part of it which i do not understand)/***************************************************************************/#ifndef _REAL_TIMER_DS1302_2003_7_21_#define _REAL_TIMER_DS1302_2003_7_21_#define DS1302_CLK P1_7 //ʵʱʱÖÓʱÖÓÏßÒý½Å#define DS1302_IO P1_6 //ʵʱʱÖÓÊý¾ÝÏßÒý½Å#define DS1302_RST P1_5 //ʵʱʱÖÓ¸´Î»ÏßÒý½Åsbit ACC0 = ACC^0 ;sbit ACC7 = ACC^7 ;typedef struct __SYSTEMTIME__{unsigned char Second;unsigned char Minute;unsigned char Hour;unsigned char Week;unsigned char Day;unsigned char Month;unsigned char Year;unsigned char DateString[9];unsigned char TimeString[9];}SYSTEMTIME; //¶¨ÒåµÄʱ¼äÀàÐÍ#define AM(X) X#define PM(X) (X+12) // ת³É24СʱÖÆ#define DS1302_SECOND 0x80#define DS1302_SECOND_READ 0x81#define DS1302_MINUTE 0x82#define DS1302_MINUTE_READ 0x83#define DS1302_HOUR 0x84#define DS1302_HOUR_READ 0x85#define DS1302_WEEK 0x8A#define DS1302_WEEK_READ 0x8B#define DS1302_DAY 0x86#define DS1302_DAY_READ 0x87#define DS1302_MONTH 0x88#define DS1302_MONTH_READ 0x89#define DS1302_YEAR 0x8C#define DS1302_YEAR_READ 0x8D#define DS1302_RAM(X) (0xC0+(X)*2) //ÓÃÓÚ¼ÆËã DS1302_RAM µØÖ·µÄºêvoid DS1302InputByte(unsigned char d) //ʵʱʱÖÓдÈëÒ»×Ö½Ú(ÄÚ²¿º¯Êý){unsigned char i;ACC = d;for(i=8; i>0; i–){DS1302_IO = ACC0; //Ï൱ÓÚ»ã±àÖÐµÄ RRCDS1302_CLK = 1;DS1302_CLK = 0;ACC = ACC >> 1;}}unsigned char DS1302OutputByte(void) //ʵʱʱÖÓ¶ÁÈ¡Ò»×Ö½Ú(ÄÚ²¿º¯Êý){unsigned char i;for(i=8; i>0; i–){ACC = ACC >>1; //Ï൱ÓÚ»ã±àÖÐµÄ RRCACC7 = DS1302_IO;DS1302_CLK = 1;DS1302_CLK = 0;}return(ACC);}void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302µØÖ·, ucData: ҪдµÄÊý¾Ý{DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr); // µØÖ·£¬ÃüÁîDS1302InputByte(ucDa); // д1ByteÊý¾ÝDS1302_CLK = 1;DS1302_RST = 0;}unsigned char Read1302(unsigned char ucAddr) //¶ÁÈ¡DS1302ijµØÖ·µÄÊý¾Ý{unsigned char ucData;DS1302_CLK = 0;DS1302_RST = 1;DS1302InputByte(ucAddr); // µØÖ·£¬ÃüÁîucData = DS1302OutputByte(); // ¶Á1ByteÊý¾ÝDS1302_CLK = 1;DS1302_RST = 0;return(ucData);}void DS1302_SetProtect(bit flag) //ÊÇ·ñд±£»¤{if(flag)Write1302(0x8E,0x80);elseWrite1302(0x8E,0x00);}void DS1302_SetTime(unsigned char Address, unsigned char Value) // ÉèÖÃʱ¼äº¯Êý{DS1302_SetProtect(0);Write1302(Address, ((Value/10)<<4 | (Value%10)));DS1302_SetProtect(1);}void DS1302_GetTime(SYSTEMTIME *Time){unsigned char ReadValue;ReadValue = Read1302(DS1302_SECOND_READ);Time->Second = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = Read1302(DS1302_MINUTE_READ);Time->Minute = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = Read1302(DS1302_HOUR_READ);Time->Hour = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = Read1302(DS1302_DAY_READ);Time->Day = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = Read1302(DS1302_WEEK_READ);Time->Week = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = Read1302(DS1302_MONTH_READ);Time->Month = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);ReadValue = Read1302(DS1302_YEAR_READ);Time->Year = ((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);}void DateToStr(SYSTEMTIME *Time){Time->DateString[0] = Time->Year/10 + '0';Time->DateString[1] = Time->Year%10 + '0';Time->DateString[2] = '-';Time->DateString[3] = Time->Month/10 + '0';Time->DateString[4] = Time->Month%10 + '0';Time->DateString[5] = '-';Time->DateString[6] = Time->Day/10 + '0';Time->DateString[7] = Time->Day%10 + '0';Time->DateString[8] = '