/*********************************************************************************************************************** * DISCLAIMER * This software is supplied by Renesas Electronics Corporation and is only intended for use with Renesas products. * No other uses are authorized. This software is owned by Renesas Electronics Corporation and is protected under all * applicable laws, including copyright laws. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING THIS SOFTWARE, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY * LAW, NEITHER RENESAS ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE FOR ANY DIRECT, * INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR * ITS AFFILIATES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * Renesas reserves the right, without notice, to make changes to this software and to discontinue the availability * of this software. By using this software, you agree to the additional terms and conditions found by accessing the * following link: * http://www.renesas.com/disclaimer * * Copyright (C) 2011, 2021 Renesas Electronics Corporation. All rights reserved. ***********************************************************************************************************************/ /*********************************************************************************************************************** * File Name : r_main.c * Version : CodeGenerator for RL78/G13 V2.05.06.02 [08 Nov 2021] * Device(s) : R5F100LG * Tool-Chain : GCCRL78 * Description : This file implements main function. * Creation Date: 2023/01/13 ***********************************************************************************************************************/ /*********************************************************************************************************************** Includes ***********************************************************************************************************************/ #include "r_cg_macrodriver.h" #include "r_cg_cgc.h" #include "r_cg_port.h" #include "r_cg_serial.h" #include "r_cg_rtc.h" /* Start user code for include. Do not edit comment generated here */ /* End user code. Do not edit comment generated here */ #include "r_cg_userdefine.h" /*********************************************************************************************************************** Global variables and functions ***********************************************************************************************************************/ /* Start user code for global. Do not edit comment generated here */ void wait( unsigned int loop); void init_IIC_lcd(void); void itoa(unsigned char out_str[],uint32_t in_i); void clear_screen(void); void initial_screen(void); void disp_data(void); void disp_time(void); void convert_bcd_to_str(void); void date_set(void); void time_data_set(void); uint8_t iic_Disp_Buf[50]; uint8_t iic_Tx_Buf[10]; uint8_t iic_Rx_Buf[10]; uint32_t Temp; uint32_t Humi; uint8_t Humi_str[7]; uint8_t Temp_str[7]; uint8_t year_hi; uint8_t year_lo; uint8_t month_hi; uint8_t month_lo; uint8_t day_hi; uint8_t day_lo; uint8_t hour_hi; uint8_t hour_lo; uint8_t min_hi; uint8_t min_lo; uint8_t time_set_mode = 0; rtc_counter_value_t temp_time; uint8_t one_min_flug; uint8_t five_sec_flug; uint8_t cnt_60 = 0; /* End user code. Do not edit comment generated here */ void R_MAIN_UserInit(void); /*********************************************************************************************************************** * Function Name: main * Description : This function implements main function. * Arguments : None * Return Value : None ***********************************************************************************************************************/ void main(void) { R_MAIN_UserInit(); /* Start user code. Do not edit comment generated here */ wait(60000); wait(60000); wait(60000); wait(60000); wait(60000); wait(60000); init_IIC_lcd(); clear_screen(); initial_screen(); rtc_counter_value_t time_set; time_set.sec = 0x00; time_set.min = 0x00; time_set.hour = 0x00; time_set.day = 0x1; time_set.week = 0x01; time_set.month = 0x01; time_set.year = 0x23; R_RTC_Set_CounterValue(time_set); disp_time(); wait(10000); while (1U) { // static uint16_t count=0; // wait(1000); time_set_mode = 0; //0:通常時 1:設定モード移行時 time_data_set(); //時刻データ取得 if(one_min_flug == 1){ disp_time(); //時刻表示更新 one_min_flug = 0; } if( five_sec_flug == 1){ five_sec_flug = 0; wait(60000); //60000+30000で実測 90mSec > 80mSec(必要待機時間) wait(30000); // EI(); iic_Tx_Buf[0] = 0xac; iic_Tx_Buf[1] = 0x33; iic_Tx_Buf[2] = 0x00; R_IICA0_Master_Send(0x70,iic_Tx_Buf, 3,1); // P7_bit.no2 =1; //オシロスコープでのwait時間計測用 wait(60000); //60000+30000で実測 90mSec > 80mSec(必要待機時間) // wait(60000); // P7_bit.no2 =0; R_IICA0_Master_Receive(0x70,iic_Rx_Buf, 7,16); wait(60000); //60000+30000で実測 90mSec > 80mSec(必要待機時間) wait(60000); // P7_bit.no2 =1; // wait(1); // P7_bit.no2 =0; Humi = iic_Rx_Buf[1]; Humi <<= 8; Humi |= iic_Rx_Buf[2]; Humi <<= 4; Humi |= ((iic_Rx_Buf[3]>>4)& 0x0f); Humi = (uint32_t)((double)Humi / 10485.76); itoa(Humi_str,Humi); Temp = iic_Rx_Buf[3]&0x0f; Temp <<= 8; Temp |= iic_Rx_Buf[4]; Temp <<= 8; Temp |= iic_Rx_Buf[5]; Temp = (uint32_t)((double)Temp/5242.88 - 50); itoa(Temp_str,Temp); disp_data(); } } /* End user code. Do not edit comment generated here */ } /*********************************************************************************************************************** * Function Name: R_MAIN_UserInit * Description : This function adds user code before implementing main function. * Arguments : None * Return Value : None ***********************************************************************************************************************/ void R_MAIN_UserInit(void) { /* Start user code. Do not edit comment generated here */ R_RTC_Set_ConstPeriodInterruptOn(ONESEC); R_RTC_Start(); EI(); /* End user code. Do not edit comment generated here */ } /* Start user code for adding. Do not edit comment generated here */ //******************** /* タイミングループ */ //******************** void wait( unsigned int loop) { //10000=10mS volatile unsigned int i; volatile unsigned int dummy; volatile unsigned int dummy2; for (i=0;i < loop;i++) { dummy++; dummy2++; } } /***********************************************************/ /* 液晶の初期化*/ /***********************************************************/ void init_IIC_lcd(void){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0x38; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(400); iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0x39; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(400); iic_Disp_Buf[1] = 0x14; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(400); iic_Disp_Buf[1] = 0x74; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(400); iic_Disp_Buf[1] = 0x56; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(400); iic_Disp_Buf[1] = 0x6C; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(60000); //トータル200mSec以上待機 wait(60000); wait(60000); wait(60000); wait(60000); iic_Disp_Buf[1] = 0x38; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(400); iic_Disp_Buf[1] = 0x01; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(6000); iic_Disp_Buf[1] = 0x0d; R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(6000); } //************************************************************************ //数値ー>文字変換 char out_str[10];を用意しておく //************************************************************************ void itoa(unsigned char out_str[],uint32_t in_i) { uint16_t n0,n1,n2,n3; int lp,chk; // 1.Convert Integer to Strings n0 = (uint16_t)(in_i / 1000); n1 = (uint16_t)((in_i % 1000) / 100); n2 = (uint16_t)((in_i % 100) / 10 ); n3 = (uint16_t)((in_i % 10) / 1); out_str[0] = (unsigned char)n0 | 0x30; out_str[1] = (unsigned char)n1 | 0x30; out_str[2] = (unsigned char)n2 | 0x30; out_str[3] = (unsigned char)n3 | 0x30; out_str[4] = 0x00; out_str[5] = 0x00; // return; // 2.Zero sus chk=3; for(lp=0;lp<4;lp++){ if(out_str[lp]!='0'){ chk=lp; break; } } // out_str[0]='0'; if(chk>3)chk=3; for(lp=0;lp以上がr_main.cです。前述しましたように”> 4) & 0x0f)+0x30); year_lo = (uint8_t)(((temp_time.year) & 0x0f)+0x30); month_hi = (uint8_t)(((temp_time.month >> 4) & 0x0f)+0x30); month_lo = (uint8_t)(((temp_time.month) & 0x0f)+0x30); day_hi = (uint8_t)(((temp_time.day >> 4) & 0x0f)+0x30); day_lo = (uint8_t)(((temp_time.day) & 0x0f)+0x30); hour_hi = (uint8_t)(((temp_time.hour >> 4) & 0x0f)+0x30); hour_lo = (uint8_t)(((temp_time.hour) & 0x0f)+0x30); min_hi= (uint8_t)(((temp_time.min >> 4) & 0x0f)+0x30); min_lo = (uint8_t)(((temp_time.min) & 0x0f)+0x30); } //*************************************************************** // 日付・時刻設定 //*************************************************************** void time_data_set(void){ if(P14_bit.no0 == 0 && P14_bit.no1 == 0 && time_set_mode == 0){ //通常動作モードの時に2つのスイッチが両方とも同時に押されて設定モードに入る wait(500); while(P14_bit.no0 == 0 || P14_bit.no1 == 0) //2つのスイッチが両方とも離れて設定モード ; time_set_mode = 1; uint8_t selector = 0; convert_bcd_to_str(); while(time_set_mode == 1){ if(P14_bit.no0 == 1 && P14_bit.no1 == 0){ //b1ボタン:モード切替セレクターの切り替え wait(50000); while(P14_bit.no0 == 1 && P14_bit.no1 == 0) ; selector++; if(selector >10){ selector = 0; } } if(selector == 0){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc2; //2行目3文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; year_hi ++; if(year_hi >= 9+0x30) year_hi = 2+0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(year_hi); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 1){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc3; //2行目4文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; year_lo ++; if(year_lo > 9 + 0x30) year_lo = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(year_lo); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 2){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc5; //2行目6文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; month_hi ++; if(month_hi > 1 + 0x30) month_hi = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(month_hi); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 3){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc6; //2行目7文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; month_lo ++; if(month_lo > 2 + 0x30) month_lo = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(month_lo); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 4){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc8; //2行目9文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; day_hi ++; if(day_hi > 3 + 0x30) day_hi = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(day_hi); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 5){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc9; //2行目10文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; day_lo ++; if(day_lo > 9 + 0x30) day_lo = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(day_lo); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 6){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xcb; //2行目12文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; hour_hi ++; if(hour_hi > 2 + 0x30) hour_hi = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(hour_hi); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 7){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xcc; //2行目13文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; hour_lo ++; if(hour_lo > 9 + 0x30) hour_lo = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(hour_lo); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 8){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xce; //2行目15文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; min_hi ++; if(min_hi > 6 + 0x30) min_hi = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(min_hi); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } else if(selector == 9){ iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xcf; //2行目16文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); if(P14_bit.no0 == 0 && P14_bit.no1 == 1){ //b0ボタン:選択値の変更 wait(50000); while(P14_bit.no0 == 0 && P14_bit.no1 == 1) ; min_lo ++; if(min_lo > 9 + 0x30) min_lo = 0 + 0x30; iic_Disp_Buf[0] = 0x40; iic_Disp_Buf[1] = (uint8_t)(min_lo); // R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); } } if(P14_bit.no0 == 0 && P14_bit.no1 == 0 && time_set_mode == 1){ //sw0 wait(50000); while(P14_bit.no0 == 0 || P14_bit.no1 == 0) //2つのスイッチが両方とも離れて設定モード ; time_set_mode = 0; iic_Disp_Buf[0] = 0x00; iic_Disp_Buf[1] = 0xc0 ; //2行目1文字目に移動 R_IICA0_Master_Send(0x7c,iic_Disp_Buf, 2,16); wait(1000); rtc_counter_value_t time_set; time_set.sec = 0x00; time_set.min = (uint8_t)(((min_hi << 4) & 0xf0) | (min_lo & 0x0f)); time_set.hour = (uint8_t)(((hour_hi << 4) & 0xf0) | (hour_lo & 0x0f)); time_set.day = (uint8_t)(((day_hi << 4)& 0xf0) | (day_lo & 0x0f)); time_set.week = temp_time.week; time_set.month = (uint8_t)(((month_hi << 4) & 0xf0) | (month_lo & 0x0f)); time_set.year = (uint8_t)(((year_hi << 4) & 0xf0) | (year_lo & 0x0f)); R_RTC_Set_CounterValue(time_set); cnt_60 = 0; return; } } } } /* End user code. Do not edit comment generated here */
Copyright © 面白半分