main() { char szOut[100]; int nYear,nMonth,nDate,nHour,nMinute,nSecond,nOldSec = 0; rtc_init(); set_date_time(2005,6,3,10,58,55); while(1) { get_date_time(&nYear,&nMonth,&nDate,&nHour,&nMinute,&nSecond); memset(szOut,0,sizeof(szOut)); if (nOldSec != nSecond) { nOldSec = nSecond; goto_xy(1,0); memset(szOut,0,sizeof(szOut)); sprintf(szOut,"%04d/%02d/%02d %02d:%02d:%02d",nYear,nMonth,nDate,nHour,nMinute,nSecond); printf(szOut); } } date time from rtc is ok,but sprintf sometimes ok sometime error(printf result is "2005/06/03 32423423/59/02","2005/06/03 10/324234/384083" ).I selected the ups3354dv from the device database. please help me? thanks.
If you're using the small memory model you're passing too many parameters to sprintf(). From memory I think the maximum number of bytes that can be passed to a variadic function is 15.
Are you sure that get_date_time() is putting valid values into all the variables? How have you checked? As an aside, surely it would be more efficient to put all these things into a structure, and pass a single pointer, rather than passing six individual pointers...?!
A.W. Neil,thank you for your advise。 I think the problem may be result from the memory mapping。 here is my settings: Memory Model:Large code ram size:Large 64k program Off-chip code memory:0x0000~0xFFFF off-chip xdata memory:0x3000~0x6000 not selected code banking
can you give me some advise about memory mapping.
"I think the problem may be result from the memory mapping" What makes you think that?
"What makes you think that? " that is a big array in my application,while i cutted down the array the problem disapplear. but i don't konw how or why it occure. I remember i had seen this problem in the discussion forum before. FYI: http://www.keil.com/forum/docs/thread601.asp http://www.keil.com/forum/docs/thread3002.asp