//----------------------------------------------------------------------------- // RTC_CaptureTimer () //----------------------------------------------------------------------------- // // Return Value : U32 capture time // Parameters : none // // This function will read the 32-bit capture value. // //----------------------------------------------------------------------------- U32 RTC_CaptureTimer (void) { UU32 timer; U8 control; SFRPAGE = LEGACY_PAGE; control = RTC_Read(RTC0CN); if((control&0x80)==0) return 0xFFFF; // error RTC must be enabled RTC_Write(RTC0CN, (control|0x05)); // capture using F960 fast mode // wait for capture bit to go to zero while(((RTC_Read(RTC0CN))&0x01)==0x01); // read using auto-increment RTC0ADR = (0x80 | CAPTURE0); // read CAPTURE0 timer.U8[b0]= RTC0DAT; timer.U8[b1]= RTC0DAT; timer.U8[b2]= RTC0DAT; timer.U8[b3]= RTC0DAT; return timer.U32; }
//============================================================================= // Timer Set and Capture Functions using new F960 fast mode. //----------------------------------------------------------------------------- // RTC_SetTimer () //----------------------------------------------------------------------------- // // Parameters : U32 Timer set time // Return Value : U8 returns 0xFF for error. // // This function will write to the Capture registers and set the timer. // //----------------------------------------------------------------------------- U8 RTC_SetTimer(U32 time) { UU32 value; U8 control; value.U32 = time; SFRPAGE = LEGACY_PAGE; control = RTC_Read(RTC0CN); if((control&0x80)==0) return 0xFF; // error RTC must be enabled // write using auto-increment RTC0ADR = 0x00; RTC0DAT = value.U8[b0]; RTC0DAT = value.U8[b1]; RTC0DAT = value.U8[b2]; RTC0DAT = value.U8[b3]; RTC_Write(RTC0CN, (control|0x06)); // set using F960 fast mode // wait for set bit to go to zero while(((RTC_Read(RTC0CN))&0x02)==0x02); return 0; }
void display(void) { ss = RTC_Read(0x00); mm = RTC_Read(0x01); hh = RTC_Read(0x02); EE = RTC_Read(0x03); DD = RTC_Read(0x04); MM = RTC_Read(0x05); YY = RTC_Read(0x06); LCD_SetCursor(0, 0); // 表示位置を設定する LCD_Putc(YY / 16 + '0'); LCD_Putc(YY % 16 + '0'); LCD_Putc('/'); LCD_Putc(MM / 16 + '0'); LCD_Putc(MM % 16 + '0'); LCD_Putc('/'); LCD_Putc(DD / 16 + '0'); LCD_Putc(DD % 16 + '0'); LCD_SetCursor(0, 1); // 表示位置を設定する LCD_Putc(hh / 16 + '0'); LCD_Putc(hh % 16 + '0'); LCD_Putc(':'); LCD_Putc(mm / 16 + '0'); LCD_Putc(mm % 16 + '0'); LCD_Putc('-'); LCD_Putc(ss / 16 + '0'); LCD_Putc(ss % 16 + '0'); }
/* ----------------------------------------------------------------------- */ static inline void RTC_ReadTm (struct tm *date, int *century) { while (RTC_OnUpdate()); date->tm_sec = RTC_Read(RTC_SECONDS); date->tm_min = RTC_Read(RTC_MINUTES); date->tm_hour = RTC_Read(RTC_HOURS); date->tm_wday = RTC_Read(RTC_DAY_WEEK); date->tm_mday = RTC_Read(RTC_DAY_MONTH); date->tm_mon = RTC_Read(RTC_MONTH); date->tm_year = RTC_Read(RTC_YEAR); if (RTC_CENTURY) (*century) = RTC_Read(RTC_CENTURY); }
//----------------------------------------------------------------------------- // RTC_Init () //----------------------------------------------------------------------------- // // Return Value : None // Parameters : None // // //----------------------------------------------------------------------------- void RTC_Init (void) { SEGMENT_VARIABLE(Is_RTC_Ready, static U8, SEG_XDATA) = FALSE; if (!Is_RTC_Ready) { RTC0KEY = 0xA5; // unlock the RTC interface RTC0KEY = 0xF1; RTC_Write (RTC0XCN, 0x60); // Configure the smaRTClock // oscillator for crystal mode // Bias Doubling Enabled // AGC Disabled RTC_Write (RTC0XCF, CAP_AUTO_STEP|LOAD_CAP_VALUE); // load capacitance value from rtc.h RTC_Write (RTC0CN, 0x80); // enable RTC rtcDelay(150); // wait for clock ready while ((RTC_Read (RTC0XCN) & 0x10)== 0x00); rtcDelay(150); // wait 1 ms // wait for cap ready while ((RTC_Read (RTC0XCF) & 0x40)== 0x00); RTC_Write (RTC0XCN, 0x40); // disable bias doubling //RTC_Write (RTC0CN, 0xC0); // Enable Missing clock detector RTC_ClearCapture (); // clear CAPTUREn registers RTC_ClearAlarm (); // clear ALARMn registers RTC_Write (RTC0CN, 0xC2); // transfer capture to clock RTC_Write (RTC0CN, 0xD0); // enable RTC run Is_RTC_Ready = TRUE; } }
/* ----------------------------------------------------------------------- */ struct tm RTC_GetTime () { struct tm date; struct tm last; int century; int regB; RTC_ReadTm (&date, ¢ury); /* Check if we got it right */ do { last = date; RTC_ReadTm (&date, ¢ury); } while (!RTC_Equals(&last, &date)); regB = RTC_Read(RTC_REGISTER_B); /* Convert BCD to binary values */ if (!(regB & 0x04)) { date.tm_sec = (date.tm_sec & 0x0F) + ((date.tm_sec / 16) * 10); date.tm_min = (date.tm_min & 0x0F) + ((date.tm_min / 16) * 10); date.tm_hour = ( (date.tm_hour & 0x0F) + (((date.tm_hour & 0x70) / 16) * 10) ) | (date.tm_hour & 0x80); date.tm_mday = (date.tm_mday & 0x0F) + ((date.tm_mday / 16) * 10); date.tm_mon = (date.tm_mon & 0x0F) + ((date.tm_mon / 16) * 10); date.tm_year = (date.tm_year & 0x0F) + ((date.tm_year / 16) * 10); if (RTC_CENTURY) century = (century & 0x0F) + ((century / 16) * 10); } /* Convert 12 hour clock to 24 hour clock */ if (!(regB & 0x02) && (date.tm_hour & 0x80)) { date.tm_hour = ((date.tm_hour & 0x7F) + 12) % 24; } /* Calculate the full (4-digit) year */ if (RTC_CENTURY != 0) { date.tm_year += century * 100; } else { date.tm_year += CURRENT_CENTURY * 100; } /* FIXME Compute the rest of tm struct */ date.tm_yday = 0; date.tm_isdst = 0; date.tm_year -= 1900; date.tm_mon--; date.tm_wday = date.tm_wday % 7; /* date.tm_mon = date.tm_mon % 12; */ return date; }
/** * @brief RTC IRQHandler. * @param None. * @return None. */ void RTC_IRQHandler() { S_DRVRTC_TIME_DATA_T sCurTime; DEBUG_MSG("RTC_IRQHandler running...\n"); /* RTC Tick interrupt */ if ((RTC->RIER & RTC_RIER_TIER) && (RTC->RIIR & RTC_RIIR_TIS)) { DEBUG_MSG("RTC Tick Interrupt.\n"); RTC->RIIR = RTC_RIIR_TIS; if((g_u32RTC_Count %2 ) == 0) LCD_DisableSegment(3, 29); else LCD_EnableSegment(3, 29); g_u32RTC_Count++; /* increase RTC tick count */ } /* RTC Alarm interrupt */ if ((RTC->RIER & RTC_RIER_AIER) && (RTC->RIIR & RTC_RIIR_AIS)) { DEBUG_MSG("RTC Alarm Interrupt.\n"); RTC->RIIR = RTC_RIIR_AIS; RTC_Read(&sCurTime); DEBUG_MSG("Current Time:%d/%02d/%02d %02d:%02d:%02d\n",sCurTime.u32Year,sCurTime.u32cMonth,sCurTime.u32cDay,sCurTime.u32cHour,sCurTime.u32cMinute,sCurTime.u32cSecond); showTime(sCurTime.u32cHour, sCurTime.u32cMinute); sCurTime.u8IsEnableWakeUp = 0; /* RTC tick shouldn't wake up CPU */ planNextRTCInterrupt(&sCurTime); } if ((RTC->RIER & RTC_RIER_SNOOPIER) && (RTC->RIIR & RTC_RIIR_SNOOPIS)) /* snooper interrupt occurred */ { RTC->RIIR = RTC_RIIR_SNOOPIS; } }
void timeset(uint8_t *value, uint8_t min_num, uint8_t max_num, uint8_t Reg, uint8_t column, uint8_t row) { sw_RA0.flags = 0; sw_RA1.flags = 0; while (!sw_RA0.flag.press) { if (cnt_t1 % 16 >= 8) { LCD_SetCursor(column, row); // 表示位置を設定する LCD_Puts(" "); } else { *value = RTC_Read(Reg); display(); LCD_SetCursor(column, row); // 表示位置を設定する LCD_Putc(*value / 16 + '0'); LCD_Putc(*value % 16 + '0'); } if (sw_RA1.flag.press) { sw_RA1.flag.press = 0; uint8_t t = *value % 16 + (*value / 16)*10; if (t >= max_num) { t = min_num; } else { t++; } *value = t % 10 + (t / 10)* 16; RTC_Write(Reg, *value); } if (sw_RA1.flag.long_holding_1) { sw_RA1.flag.long_holding_1 = 0; uint8_t t = *value % 16 + (*value / 16)*10; if (t + 9 >= max_num) { t = t % 10; } else { t += 10; } *value = t % 10 + (t / 10)* 16; RTC_Write(Reg, *value); } } sw_RA0.flags = 0; }
static int32_t Main_Work( void ) { static uint32_t mode=0; static uint32_t setpoint=30; static uint8_t curidx=0; int32_t retval=TICKS_MS(500); char buf[22]; int len; uint32_t keyspressed=Keypad_Get(); // Sort out this "state machine" if(mode==5) { // Run reflow uint32_t ticks=RTC_Read(); //len = snprintf(buf,sizeof(buf),"seconds:%d",ticks); //LCD_disp_str((uint8_t*)buf, len, 13, 0, FONT6X6); len = snprintf(buf,sizeof(buf),"%03u",Reflow_GetSetpoint()); LCD_disp_str((uint8_t*)"SET", 3, 110, 7, FONT6X6); LCD_disp_str((uint8_t*)buf, len, 110, 13, FONT6X6); len = snprintf(buf,sizeof(buf),"%03u",Reflow_GetActualTemp()); LCD_disp_str((uint8_t*)"ACT", 3, 110, 20, FONT6X6); LCD_disp_str((uint8_t*)buf, len, 110, 26, FONT6X6); len = snprintf(buf,sizeof(buf),"%03u",ticks); LCD_disp_str((uint8_t*)"RUN", 3, 110, 33, FONT6X6); LCD_disp_str((uint8_t*)buf, len, 110, 39, FONT6X6); if(Reflow_IsDone() || keyspressed & KEY_S) { // Abort reflow if( Reflow_IsDone() ) Buzzer_Beep( BUZZ_1KHZ, 255, TICKS_MS(100) * NV_GetConfig(REFLOW_BEEP_DONE_LEN) ); mode=0; Reflow_SetMode(REFLOW_STANDBY); retval = 0; // Force immediate refresh } } else if(mode==4) { // Select profile int curprofile = Reflow_GetProfileIdx(); LCD_FB_Clear(); if(keyspressed & KEY_F1) { // Prev profile curprofile--; } if(keyspressed & KEY_F2) { // Next profile curprofile++; } Reflow_SelectProfileIdx(curprofile); Reflow_PlotProfile(-1); LCD_BMPDisplay(selectbmp,127-17,0); len = snprintf(buf,sizeof(buf),"%s",Reflow_GetProfileName()); LCD_disp_str((uint8_t*)buf, len, 13, 0, FONT6X6); if(keyspressed & KEY_S) { // Select current profile mode=0; retval = 0; // Force immediate refresh } } else if(mode==3) { // Bake LCD_FB_Clear(); LCD_disp_str((uint8_t*)"MANUAL/BAKE MODE", 16, 0, 0, FONT6X6); int keyrepeataccel = keyspressed >> 17; // Divide the value by 2 if( keyrepeataccel < 1) keyrepeataccel = 1; if( keyrepeataccel > 30) keyrepeataccel = 30; if(keyspressed & KEY_F1) { // Setpoint- setpoint -= keyrepeataccel; if(setpoint<30) setpoint = 30; } if(keyspressed & KEY_F2) { // Setpoint+ setpoint += keyrepeataccel; if(setpoint>300) setpoint = 300; } len = snprintf(buf,sizeof(buf),"- SETPOINT %uC +",setpoint); LCD_disp_str((uint8_t*)buf, len, 64-(len*3), 10, FONT6X6); LCD_disp_str((uint8_t*)"F1", 2, 0, 10, FONT6X6 | INVERT); LCD_disp_str((uint8_t*)"F2", 2, 127-12, 10, FONT6X6 | INVERT); len = snprintf(buf,sizeof(buf),"ACTUAL %.1fC",Reflow_GetTempSensor(TC_AVERAGE)); LCD_disp_str((uint8_t*)buf, len, 64-(len*3), 18, FONT6X6); len = snprintf(buf,sizeof(buf),"L %.1fC",Reflow_GetTempSensor(TC_LEFT)); LCD_disp_str((uint8_t*)buf, len, 32-(len*3), 26, FONT6X6); len = snprintf(buf,sizeof(buf),"R %.1fC",Reflow_GetTempSensor(TC_RIGHT)); LCD_disp_str((uint8_t*)buf, len, 96-(len*3), 26, FONT6X6); if( Reflow_IsTempSensorValid(TC_EXTRA1) ) { len = snprintf(buf,sizeof(buf),"X1 %.1fC",Reflow_GetTempSensor(TC_EXTRA1)); LCD_disp_str((uint8_t*)buf, len, 32-(len*3), 34, FONT6X6); } if( Reflow_IsTempSensorValid(TC_EXTRA2) ) { len = snprintf(buf,sizeof(buf),"X2 %.1fC",Reflow_GetTempSensor(TC_EXTRA2)); LCD_disp_str((uint8_t*)buf, len, 96-(len*3), 34, FONT6X6); } if( Reflow_IsTempSensorValid(TC_COLD_JUNCTION) ) { len = snprintf(buf,sizeof(buf),"COLD-JUNCTION %.1fC",Reflow_GetTempSensor(TC_COLD_JUNCTION)); } else { len = snprintf(buf,sizeof(buf),"NO COLD-JUNCTION TS!"); } LCD_disp_str((uint8_t*)buf, len, 64-(len*3), 42, FONT6X6); LCD_BMPDisplay(stopbmp,127-17,0); // len = snprintf(buf,sizeof(buf),"heat=0x%02x fan=0x%02x",heat,fan); // LCD_disp_str((uint8_t*)buf, len, 0, 63-5, FONT6X6); // Add timer for bake at some point Reflow_SetSetpoint(setpoint); if(keyspressed & KEY_S) { // Abort bake mode=0; Reflow_SetMode(REFLOW_STANDBY); retval = 0; // Force immediate refresh } } else if(mode==2 || mode==1) { // Edit ee1 or 2
//----------------------------------------------------------------------------- // RTC_StartCapture () //----------------------------------------------------------------------------- // // Return Value : 1 if capture pending 0 if capture is complete // Parameters : none // //----------------------------------------------------------------------------- U8 RTC_CapturePending (void) { return (RTC_Read(RTC0CN) & 0x01); }