We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Source code: union Time { unsigned char year,month,day; unsigned char hour,minute,second; }; xdata struct structure2 { unsigned int FileNum_InDay; union Time Current; } GPS; ...... void GetCurrentTime(unsigned char *ptr1) { /* Caculated out: GPS.Current.hour GPS.Current.minute GPS.Current.second */ unsigned char xdata H_Temp; unsigned char xdata M_Temp; unsigned char xdata S_Temp; float xdata temp1,temp2; temp1 = DataConver64(ptr1); temp2 = temp1 / 3600; H_Temp = temp2; temp1 = temp2 - H_Temp; temp2 = temp1 * 60; M_Temp = temp2; temp1 = temp2 - M_Temp; S_Temp = temp1 * 60; GPS.Current.hour = H_Temp; //a //******* Something Wrong********// GPS.Current.minute = M_Temp; //b GPS.Current.second = S_Temp; //c } ...... void Main(void) { unsigned char i,m,hour; unsigned int xdata POWER1=0,POWER2=0,POWER3= 0; float xdata Tim = 0; unsigned char p[8] = { 0x00, 0x00, 0x00, 0x00, 0xFE, 0x74, 0x22, 0x41 }; unsigned char l[4] = { 0x85,0xac,0x41,0x42}; WDTCN = 0x07; // Watchdog Timer Control Register WDTCN = 0xDE; // Disable WDT WDTCN = 0xAD; Tim = DataConver32(l); Tim = DataConver64(p); GetCurrentTime(p); hour = GPS.Current.hour; //d ...... The data structure is defined in public. When the program step to flag 'a' in subroutine,all value is right. To 'b',GPS.Current.hour equal to 0xA7.But ,when step to 'c',the value of GPS.Current.hour change to GPS.Current.minute ,which equal to 0x3b.So,step to 'd' ,the result is that 'hour == 0x3b'.Lately,I found that three variable ( GPS.Current.hour / minute / second ) all be stored at the same location(0x0435) in the assembler. How can I transfer this data_struct to another subroutine? If a mcu is mutiplex Serial UART, how can I use the macro ' printf ' ? Thanks for help.
"printf() is a function that uses the function putchar() to write each character to the serial port. If you want to use different serial ports, you have to provide your own putchar() version. Try a search for "second UART" on this forum." The interrupt-driven serial IO example in the support area shows you how to write your own putchar() & getchar(): http://www.keil.com/download/docs/intsio.zip.asp