SHARE
TWEET

micro-hw06

a guest Dec 16th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unsigned int morning;
  2.  
  3. void SetupRTCTime(void)
  4. {
  5.     unsigned int tyear[2] = {1, 9}, tmon = 10, tday[2] = { 3, 0}, tweek = 1;
  6.     unsigned int thour[2] = {1, 2}, tmin[2] = { 5, 9 }, tsec[2] = {5, 8};
  7.  
  8.     // Initialize RTC (Real Time Clock)
  9.     RTC_YEAR = (tyear[0] << 4) | tyear[1];      // fill in op
  10.     RTC_MONTH =  tmon;
  11.     RTC_DAY = (tday[0] << 4) | tday[1];         // fill in op
  12.     RTC_WEEK = tweek;
  13.  
  14.     RTC_HOUR = (thour[0] << 4) | thour[1];
  15.     RTC_MIN = (tmin[0] << 4) | tmin[1];
  16.     RTC_SEC = (tsec[0] << 4) | tsec[1];
  17.  
  18. }
  19.  
  20. void DisplayTime(void)
  21. {
  22.     char week_array[7][4] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
  23.     int i;
  24.  
  25.     unsigned int year = RTC_YEAR, mon = RTC_MONTH, day = RTC_DAY;
  26.     unsigned int hour = RTC_HOUR, min = RTC_MIN, sec = RTC_SEC;
  27.     unsigned int week = RTC_WEEK;
  28.  
  29.     unsigned int tmp_hour[2] = {((hour >> 4) & 0xF), (hour & 0xF)};
  30.     unsigned int tmp = tmp_hour[0]*10 + tmp_hour[1];
  31.  
  32.     if(tmp < 12)
  33.     {
  34.         morning = 1;
  35.         if(tmp == 0) tmp = 12;
  36.     }
  37.     else
  38.     {
  39.         morning = 0;
  40.         if(tmp > 12) tmp %= 12;
  41.     }
  42.  
  43.     tmp_hour[0] = tmp / 10;
  44.     tmp_hour[1] = tmp % 10;
  45.     hour = (tmp_hour[0] << 4) | tmp_hour[1];
  46.  
  47.     SetCursor(0, 0x6); //WriteIns(0x8000); //STN LCM,第一列
  48.  
  49.     WriteData(0x32); //字元"2"
  50.     WriteData(0x30); //字元"0"
  51.     WriteData(((year >> 4) & 0x000F) + To_ASCII);
  52.     WriteData((year & 0x000F) + To_ASCII);
  53.     WriteData(0x3A); //":"符號
  54.  
  55.     WriteData(((mon & 0x000F) / 10) + To_ASCII);
  56.     WriteData(((mon & 0x000F) % 10) + To_ASCII);
  57.     WriteData(0x3A); //":"符號
  58.  
  59.     WriteData(((day >> 4) & 0x000F) + To_ASCII);
  60.     WriteData((day & 0x000F) + To_ASCII);
  61.  
  62.     SetCursor(1, 0x0); //WriteIns(0xC000); //STN LCM,第二列
  63.  
  64.     for(i=0;i<3;i++) WriteData(week_array[(int)week][i]);
  65.     WriteData('.'); //"."符號
  66.     WriteData(0x20);
  67.  
  68.     WriteData(((hour >> 4) & 0x000F) + To_ASCII);
  69.     WriteData((hour & 0x000F) + To_ASCII);
  70.     WriteData(0x3A); //":"符號
  71.  
  72.     WriteData(((min >> 4) & 0x000F) + To_ASCII);
  73.     WriteData((min & 0x000F) + To_ASCII);
  74.     WriteData(0x3A); //":"符號
  75.  
  76.     WriteData(((sec >> 4) & 0x000F) + To_ASCII);
  77.     WriteData((sec & 0x000F) + To_ASCII);
  78.     WriteData(0x20);
  79.  
  80.     if(morning) WriteData('A');
  81.     else WriteData('P');
  82.     WriteData('M');
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top