Index: asp3_tinet_ecnl_rx/trunk/app5_temp_sensor/src/echonet_main.c
===================================================================
--- asp3_tinet_ecnl_rx/trunk/app5_temp_sensor/src/echonet_main.c	(revision 351)
+++ asp3_tinet_ecnl_rx/trunk/app5_temp_sensor/src/echonet_main.c	(revision 364)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2014-2018 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,9 +32,9 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
 
-/* 
+/*
  *  サンプルプログラム(1)の本体
  */
@@ -51,4 +51,6 @@
 #include "echonet_cfg.h"
 #include "target_kernel_impl.h"
+#include "adafruit_ssd1306.h"
+#include "draw_font.h"
 
 /* TODO: メーカーコードを設定 */
@@ -107,10 +109,10 @@
 
 	/* サイズが１以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	*anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* ONの場合 */
 	case 0x30:
@@ -122,5 +124,5 @@
 		data[1] = *(uint8_t *)src;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 1;
@@ -141,10 +143,10 @@
 {
 	/* サイズが１以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	*anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* 異常発生ありの場合 */
 	case 0x41:
@@ -172,15 +174,15 @@
 
 	/* サイズが2以外は受け付けない */
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
 	value = (((uint8_t *)src)[0] << 8) | (((uint8_t *)src)[1] & 0xFF);
 
-	if((value >= -2732) && (value <= 32766)){
+	if ((value >= -2732) && (value <= 32766)) {
 		eobj->propertyE0 = value;
 		/* メインタスクに通知 */
 		data[0] = 0xE0;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 2;
@@ -188,5 +190,5 @@
 	}
 	/* 上記以外は受け付けない */
-	else{
+	else {
 		return 0;
 	}
@@ -195,5 +197,5 @@
 }
 
-/* 
+/*
  * 温度計測値取得関数
  */
@@ -204,5 +206,5 @@
 
 	/* サイズが2以外は受け付けない */
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
@@ -236,10 +238,10 @@
 
 	ret2 = get_tim(&now);
-	if (ret2 != E_OK){
+	if (ret2 != E_OK) {
 		syslog(LOG_ERROR, "get_tim");
 		return;
 	}
 
-	for(;;){
+	for (;;) {
 		prev = now;
 
@@ -249,5 +251,5 @@
 		/* 応答電文待ち */
 		ret = ecn_trcv_esv(&esv, timer);
-		if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)){
+		if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)) {
 			syslog(LOG_ERROR, "ecn_trcv_esv");
 			break;
@@ -255,5 +257,5 @@
 
 		ret2 = get_tim(&now);
-		if (ret2 != E_OK){
+		if (ret2 != E_OK) {
 			syslog(LOG_ERROR, "get_tim");
 			break;
@@ -270,5 +272,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_rel_esv");
 				break;
@@ -279,5 +281,5 @@
 			/* 応答電文待ちの割り込みデータ取得 */
 			ret = ecn_get_brk_dat(esv, brkdat, sizeof(brkdat), &len);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_get_brk_dat");
 				break;
@@ -289,5 +291,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_rel_esv");
 				break;
@@ -300,6 +302,4 @@
 }
 
-bool_t started = false;
-
 void echonet_change_netif_link(uint8_t link_up, uint8_t up)
 {
@@ -309,14 +309,10 @@
 		return;
 
-	if (up && !started) {
-		started = true;
-
-		/* ECHONETミドルウェアを起動 */
-		ret = ecn_sta_svc();
-		if (ret != E_OK)
-			return;
-
-		/* ECHONETミドルウェアを起動するのを待つ */
-		dly_tsk(100);
+	if (up) {
+		/* インスタンスリスト通知の送信 */
+		ret = ecn_ntf_inl();
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "ecn_ntf_inl");
+		}
 	}
 
@@ -332,32 +328,14 @@
 }
 
-enum main_state_t{
+enum main_state_t {
+	main_state_start,
 	main_state_idle,
 };
 
 int main_timer = TMO_FEVR;
-enum main_state_t main_state = main_state_idle;
-
-enum main_led_state_t{
-	main_led_state_idle,
-	main_led_state_on_o,
-	main_led_state_on_n,
-	main_led_state_off_o,
-	main_led_state_off_f1,
-	main_led_state_off_f2,
-	main_led_state_space1,
-	main_led_state_tmpr_minus,
-	main_led_state_tmpr_100,
-	main_led_state_tmpr_10,
-	main_led_state_tmpr_1,
-	main_led_state_space2,
-	main_led_state_humid_10,
-	main_led_state_humid_1,
-	main_led_state_space3,
-};
-
-int main_led_timer = TMO_FEVR;
-enum main_led_state_t main_led_state = main_led_state_idle;
-bool_t main_led_update;
+enum main_state_t main_state = main_state_start;
+
+int main_lcd_timer = TMO_FEVR;
+int main_lcd_state = 0;
 
 bool_t main_btn1_state;
@@ -365,4 +343,6 @@
 bool_t main_btn2_state;
 int main_btn2_count = 0;
+
+LCD_Handler_t lcd;
 
 /*
@@ -387,17 +367,12 @@
 	sil_wrb_mem((uint8_t *)0x0008C02D, 0xC0);
 
-	/* 10ms後にボタン状態を確認 */
-	main_timer = 10 * 1000;
+	/* ECHONETミドルウェアを起動するのを待つ */
+	main_state = main_state_start;
+	main_timer = 1000 * 1000;
 
 	/* 12bitADC初期化 */
 	sil_wrh_mem((uint16_t *)S12AD_ADEXICR_ADDR, 0x0000);	/* 温度センサ出力、内部基準電圧非選択 */
-	sil_wrh_mem((uint16_t *)S12AD_ADANS0_ADDR, 0x0001);		/* 変換ポートAN000選択、AN001～AN015非選択 */
+	sil_wrh_mem((uint16_t *)S12AD_ADANS0_ADDR, 0x0007);		/* 変換ポートAN000選択、AN001～AN015非選択 */
 	sil_wrh_mem((uint16_t *)S12AD_ADANS1_ADDR, 0x0000);		/* 変換ポートAN016～AN020非選択 */
-
-	if(temperature_sensor1_data.property80 == 0x30)
-		main_led_state = main_led_state_on_o;
-	else
-		main_led_state = main_led_state_off_o;
-	main_led_timer = 0;
 
 	/* ボタン状態読み込み */
@@ -407,4 +382,20 @@
 	main_btn2_state = (btn2 & 0x80) != 0;
 
+	i2c_init(&lcd.i2c, I2C_SDA, I2C_SCL);
+	i2c_frequency(&lcd.i2c, 100000);
+
+	lcd_init3(&lcd, NC);
+
+	lcd_begin(&lcd, SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS, true);
+
+	lcd_clearDisplay(&lcd);
+
+	lcd_display(&lcd);
+
+	/* 1秒後にLCD表示を更新 */
+	main_lcd_state = 10;
+	main_lcd_timer = 1000 * 1000;
+
+	/* メインタスクを起動 */
 	ER ret = act_tsk(MAIN_TASK);
 	if (ret != E_OK) {
@@ -420,7 +411,7 @@
 	int result = main_timer;
 
-	if((result == TMO_FEVR)
-		|| ((main_led_timer != TMO_FEVR) && (main_led_timer < result))){
-		result = main_led_timer;
+	if ((result == TMO_FEVR)
+		|| ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))) {
+		result = main_lcd_timer;
 	}
 
@@ -433,15 +424,15 @@
 static void main_progress(int interval)
 {
-	if(main_timer != TMO_FEVR){
+	if (main_timer != TMO_FEVR) {
 		main_timer -= interval;
-		if(main_timer < 0){
+		if (main_timer < 0) {
 			main_timer = 0;
 		}
 	}
 
-	if(main_led_timer != TMO_FEVR){
-		main_led_timer -= interval;
-		if(main_led_timer < 0){
-			main_led_timer = 0;
+	if (main_lcd_timer != TMO_FEVR) {
+		main_lcd_timer -= interval;
+		if (main_lcd_timer < 0) {
+			main_lcd_timer = 0;
 		}
 	}
@@ -463,14 +454,14 @@
 
 	ret = ecn_itr_ini(&enm, esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_itr_ini");
 		return;
 	}
 
-	for(;;) {
-		while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
+	for (;;) {
+		while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
 			switch (epc) {
 			case 0xE0:
-				if(in_get && (esv->hdr.edata.esv == ESV_SET_GET_RES)){
+				if (in_get && (esv->hdr.edata.esv == ESV_SET_GET_RES)) {
 					check_response(pdc, p_edt);
 				}
@@ -478,9 +469,9 @@
 			}
 		}
-		if(ret != E_BOVR){
+		if (ret != E_BOVR) {
 			syslog(LOG_ERROR, "ecn_itr_nxt");
 			break;
 		}
-		if(enm.is_eof)
+		if (enm.is_eof)
 			break;
 
@@ -501,5 +492,5 @@
 
 	if ((len == 2) && (brkdat[0] == 0x80)) {
-		switch(brkdat[1]){
+		switch (brkdat[1]) {
 		/* ONの場合 */
 		case 0x30:
@@ -514,21 +505,8 @@
 		}
 	}
-
-	switch(main_led_state){
-	case main_led_state_idle:
-		if(temperature_sensor1_data.property80 == 0x30)
-			main_led_state = main_led_state_on_o;
-		else
-			main_led_state = main_led_state_off_o;
-		main_led_timer = 0;
-		break;
-	default:
-		main_led_update = true;
-		break;
-	}
 }
 
 static void main_ontimer();
-static void main_led_ontimer();
+static void main_lcd_ontimer();
 
 /*
@@ -537,34 +515,44 @@
 static void main_timeout()
 {
-	if(main_timer == 0){
+	if (main_timer == 0) {
 		main_ontimer();
 	}
 
-	if(main_led_timer == 0){
-		main_led_ontimer();
-	}
-}
-
-static int16_t main_ad_tempr = 200;
-static uint16_t main_ad_table[64];
-#define main_ad_table_count (sizeof(main_ad_table) / sizeof(main_ad_table[0]))
+	if (main_lcd_timer == 0) {
+		main_lcd_ontimer();
+	}
+}
+
+#define main_ad_count 3
+#define main_ad_table_count 64
+static int16_t main_ad_tempr[main_ad_count] = { 200, 200, 200 };
+static uint16_t main_ad_table[main_ad_count][main_ad_table_count];
 static int main_ad_pos = 0;
-static uint32_t main_ad_avelage;
-static int main_count;
-
-static void main_ad_change();
+static uint32_t main_ad_avelage[main_ad_count];
+static int main_count[main_ad_count];
+
+static void main_ad_change(int no, int adv);
 static void main_btn1_change(bool_t push);
 static void main_btn2_change(bool_t push);
 
-uint8_t led_disp[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };
-
 static void main_ontimer()
 {
+	ER ret;
 	uint8_t btn1, btn2;
 	uint16_t ad_value;
 	int16_t ad_tempr;
-	uint8_t sseg = sil_reb_mem((uint8_t *)0x0008C02A) & ~0x07;
-
-	switch(main_state){
+
+	switch (main_state) {
+	case main_state_start:
+		/* ECHONETミドルウェアを起動 */
+		ret = ecn_sta_svc();
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "ecn_sta_svc");
+		}
+
+		/* 10ms後にボタン状態を確認 */
+		main_state = main_state_idle;
+		main_timer = 10 * 1000;
+		break;
 	case main_state_idle:
 		/* 10ms後にボタン状態を確認 */
@@ -572,37 +560,39 @@
 
 		/* ADCの変換結果取得 */
-		if((sil_reb_mem((uint8_t *)S12AD_ADCSR_ADDR) & S12AD_ADCSR_ADST_BIT) == 0){
-			main_ad_avelage -= main_ad_table[main_ad_pos];
-			ad_value = sil_reh_mem((uint16_t *)S12AD_ADDR0_ADDR);
-			main_ad_table[main_ad_pos] = ad_value;
-			main_ad_avelage += ad_value;
+		if ((sil_reb_mem((uint8_t *)S12AD_ADCSR_ADDR) & S12AD_ADCSR_ADST_BIT) == 0) {
+			for (int i = 0; i < main_ad_count; i++) {
+				main_ad_avelage[i] -= main_ad_table[i][main_ad_pos];
+				ad_value = sil_reh_mem(&((uint16_t *)S12AD_ADDR0_ADDR)[i]);
+				main_ad_table[i][main_ad_pos] = ad_value;
+				main_ad_avelage[i] += ad_value;
+			}
 
 			main_ad_pos++;
-			if(main_ad_pos >= main_ad_table_count){
+			if (main_ad_pos >= main_ad_table_count) {
 				main_ad_pos = 0;
 			}
 
-			ad_tempr = ((int16_t)(((main_ad_avelage / main_ad_table_count) >> 3) & 0x1FF)) - 100;
-			if(main_ad_tempr != ad_tempr){
-				/* １秒変化が続いたら */
-				if(main_count < 100){
-					main_count++;
+			for (int i = 0; i < main_ad_count; i++) {
+				ad_tempr = ((int16_t)(((main_ad_avelage[i] / main_ad_table_count) >> 3) & 0x1FF)) - 100;
+				if (main_ad_tempr[i] != ad_tempr) {
+					/* １秒変化が続いたら */
+					if (main_count[i] < 100) {
+						main_count[i]++;
+					}
+					else {
+						main_count[i] = 0;
+						main_ad_tempr[i] = ad_tempr;
+
+						/* ADC状態変化処理 */
+						main_ad_change(i + 1, ad_tempr);
+					}
 				}
-				else{
-					main_ad_tempr = ad_tempr;
-
-					/* ADC状態変化処理 */
-					main_ad_change();
+				else {
+					main_count[i] = 0;
 				}
-			}
-			else{
-				main_count = 0;
-			}
-
-			/* LEDに温度計測値を表示 */
-			sil_wrb_mem((uint8_t *)0x0008C02A, sseg | led_disp[(main_ad_avelage / main_ad_table_count) >> 9]);
-
-			/* 変換開始（シングルスキャンモード） */
-			sil_wrb_mem((uint8_t *)S12AD_ADCSR_ADDR, S12AD_ADCSR_ADST_BIT);
+
+				/* 変換開始（シングルスキャンモード） */
+				sil_wrb_mem((uint8_t *)S12AD_ADCSR_ADDR, S12AD_ADCSR_ADST_BIT);
+			}
 		}
 
@@ -612,7 +602,7 @@
 
 		/* ボタン１の処理 */
-		if(((btn1 & 0x20) != 0) && !main_btn1_state){
+		if (((btn1 & 0x20) != 0) && !main_btn1_state) {
 			main_btn1_count++;
-			if(main_btn1_count > 10){
+			if (main_btn1_count > 10) {
 				main_btn1_count = 0;
 				main_btn1_state = true;
@@ -621,7 +611,7 @@
 			}
 		}
-		else if(((btn1 & 0x20) == 0) && main_btn1_state){
+		else if (((btn1 & 0x20) == 0) && main_btn1_state) {
 			main_btn1_count++;
-			if(main_btn1_count > 10){
+			if (main_btn1_count > 10) {
 				main_btn1_count = 0;
 				main_btn1_state = false;
@@ -632,7 +622,7 @@
 
 		/* ボタン２の処理 */
-		if(((btn2 & 0x80) != 0) && !main_btn2_state){
+		if (((btn2 & 0x80) != 0) && !main_btn2_state) {
 			main_btn2_count++;
-			if(main_btn2_count > 10){
+			if (main_btn2_count > 10) {
 				main_btn2_count = 0;
 				main_btn2_state = true;
@@ -641,7 +631,7 @@
 			}
 		}
-		else if(((btn2 & 0x80) == 0) && main_btn2_state){
+		else if (((btn2 & 0x80) == 0) && main_btn2_state) {
 			main_btn2_count++;
-			if(main_btn2_count > 10){
+			if (main_btn2_count > 10) {
 				main_btn2_count = 0;
 				main_btn2_state = false;
@@ -654,134 +644,94 @@
 }
 
-uint8_t led_num[] = { 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90 };
-uint8_t led_onf[] = { 0xA3, 0xAB, 0x8E };
-
-static void main_led_ontimer()
+static char temp1[] = "温度1：+000.0℃";
+static char temp2[] = "温度2：+000.0℃";
+static char humid[] = "湿度 ：+000.0％";
+
+static void main_lcd_ontimer()
 {
 	int temp;
 
-	switch(main_led_state){
-	case main_led_state_idle:
-		/* 7segに' 'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, 0xFF);
-		main_led_timer = TMO_FEVR;
-		return;
-	case main_led_state_on_o:
-		/* 7segに'o'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_onf[0]);
-		main_led_state = main_led_state_on_n;
-		break;
-	case main_led_state_on_n:
-		/* 7segに'n'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_onf[1]);
-		main_led_state = main_led_state_space1;
-		break;
-	case main_led_state_off_o:
-		/* 7segに'o'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_onf[0]);
-		main_led_state = main_led_state_off_f1;
-		break;
-	case main_led_state_off_f1:
-		/* 7segに'f'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_onf[2]);
-		main_led_state = main_led_state_off_f2;
-		break;
-	case main_led_state_off_f2:
-		/* 7segに'f'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_onf[2]);
-		main_led_state = main_led_state_space1;
-		break;
-	case main_led_state_space1:
-		/* 7segに' 'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, 0xFF);
-		if(temperature_sensor1_data.propertyE0 >= 0){
-			main_led_state = main_led_state_tmpr_10;
-		}
-		else{
-			main_led_state = main_led_state_tmpr_minus;
-		}
-		break;
-	case main_led_state_tmpr_minus:
-		/* 7segに'-'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, 0xBF);
-		if((temperature_sensor1_data.propertyE0 >= 100)
-			|| (temperature_sensor1_data.propertyE0 <= -100))
-			main_led_state = main_led_state_tmpr_100;
-		else
-			main_led_state = main_led_state_tmpr_10;
-		break;
-	case main_led_state_tmpr_100:
+	switch (main_lcd_state) {
+	case 0:
+		temp1[10] = (temperature_sensor1_data.propertyE0 >= 0) ? ' ' : '-';
 		temp = (temperature_sensor1_data.propertyE0 / 1000) % 10;
-		if(temp < 0)
+		if (temp < 0)
 			temp = -temp;
-		/* 7segに温度計測値10の位を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_num[temp]);
-		main_led_state = main_led_state_tmpr_10;
-		break;
-	case main_led_state_tmpr_10:
+		temp1[11] = '0' + temp;
 		temp = (temperature_sensor1_data.propertyE0 / 100) % 10;
-		if(temp < 0)
+		if (temp < 0)
 			temp = -temp;
-		/* 7segに温度計測値10の位を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_num[temp]);
-		main_led_state = main_led_state_tmpr_1;
-		break;
-	case main_led_state_tmpr_1:
+		temp1[12] = '0' + temp;
 		temp = (temperature_sensor1_data.propertyE0 / 10) % 10;
-		if(temp < 0)
+		if (temp < 0)
 			temp = -temp;
-		/* 7segに温度計測値10の位を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_num[temp] & (~0x80));
-		main_led_state = main_led_state_space2;
-		break;
-	case main_led_state_space2:
-		/* 7segに' 'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, 0xFF);
-		main_led_state = main_led_state_humid_10;
-		break;
-	case main_led_state_humid_10:
-		temp = humidity_sensor_data.propertyE0 / 10;
-		/* 7segに湿度計測値10の位を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_num[temp]);
-		main_led_state = main_led_state_humid_1;
-		break;
-	case main_led_state_humid_1:
-		temp = humidity_sensor_data.propertyE0 % 10;
-		/* 7segに湿度計測値10の位を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, led_num[temp] & (~0x80));
-		main_led_state = main_led_state_space3;
-		break;
-	case main_led_state_space3:
-		/* 7segに' 'を表示 */
-		if(temperature_sensor1_data.property80 == 0x30)
-			/* 7segに'.'を表示 */
-			sil_wrb_mem((uint8_t *)0x0008C02D, 0x7F);
-		else
-			/* 7segに' 'を表示 */
-			sil_wrb_mem((uint8_t *)0x0008C02D, 0xFF);
-
-		if(main_led_update){
-			main_led_update = false;
-
-			if(temperature_sensor1_data.property80 == 0x30)
-				main_led_state = main_led_state_on_o;
-			else
-				main_led_state = main_led_state_off_o;
-		}
-		else{
-			main_led_state = main_led_state_idle;
-			main_led_timer = TMO_FEVR;
-			return;
-		}
+		temp1[13] = '0' + temp;
+		temp = (temperature_sensor1_data.propertyE0 / 1) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp1[15] = '0' + temp;
+		lcd_drawString(&lcd, &temp1[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), WHITE, BLACK);
+		main_lcd_state++;
+		break;
+	case 1:
+		temp2[10] = (temperature_sensor2_data.propertyE0 >= 0) ? ' ' : '-';
+		temp = (temperature_sensor2_data.propertyE0 / 1000) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp2[11] = '0' + temp;
+		temp = (temperature_sensor2_data.propertyE0 / 100) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp2[12] = '0' + temp;
+		temp = (temperature_sensor2_data.propertyE0 / 10) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp2[13] = '0' + temp;
+		temp = (temperature_sensor2_data.propertyE0 / 1) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp2[15] = '0' + temp;
+		lcd_drawString(&lcd, &temp2[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), WHITE, BLACK);
+		main_lcd_state++;
+		break;
+	case 2:
+		humid[10] = ' ';
+		humid[11] = ' ';
+		temp = (humidity_sensor_data.propertyE0 / 100) % 10;
+		humid[12] = '0' + temp;
+		temp = (humidity_sensor_data.propertyE0 / 10) % 10;
+		humid[13] = '0' + temp;
+		temp = (humidity_sensor_data.propertyE0 / 1) % 10;
+		humid[15] = '0' + temp;
+		lcd_drawString(&lcd, &humid[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), WHITE, BLACK);
+		main_lcd_state++;
+		break;
+	case 3:
+	case 4:
+	case 5:
+	case 6:
+	case 7:
+	case 8:
+		main_lcd_state++;
+		break;
+	case 9:
+		lcd_display(&lcd);
+		main_lcd_state = 0;
+		break;
+	case 10:
+		lcd_drawString(&lcd, "温度湿度計", X_LINE_TO_PIX(&lcd, 5), Y_ROW_TO_PIX(&lcd, 0), WHITE, BLACK);
+		lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 0 + 2), WHITE, BLACK);
+		lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 1 + 2), WHITE, BLACK);
+		lcd_drawString(&lcd, humid, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 2 + 2), WHITE, BLACK);
+		lcd_display(&lcd);
+		main_lcd_state = 0;
 		break;
 	default:
-		/* 7segに' 'を表示 */
-		sil_wrb_mem((uint8_t *)0x0008C02D, 0xFF);
-		main_led_state = main_led_state_idle;
-		main_led_timer = TMO_FEVR;
-		return;
-	}
-
-	main_led_timer = 500 * 1000;
+		main_lcd_state = 10;
+		break;
+	}
+
+	/* 100ms後にLCD表示を更新 */
+	main_lcd_timer = 100 * 1000;
 }
 
@@ -789,16 +739,31 @@
  * ADC状態変化処理
  */
-static void main_ad_change()
+static void main_ad_change(int no, int adv)
 {
 	ER ret;
 	T_EDATA *esv;
 	uint8_t p_edt[2];
-
-	p_edt[0] = ((uint16_t)main_ad_tempr) >> 8;
-	p_edt[1] = ((uint16_t)main_ad_tempr) & 0xFF;
+	uint8_t eobj;
+
+	switch (no) {
+	case 1:
+		eobj = TEMP_SENSOR_01_EOBJ;
+		break;
+	case 2:
+		eobj = TEMP_SENSOR_02_EOBJ;
+		break;
+	case 3:
+		eobj = HUMIDITY_SENSOR_EOBJ;
+		break;
+	default:
+		return;
+	}
+
+	p_edt[0] = ((uint16_t)adv) >> 8;
+	p_edt[1] = ((uint16_t)adv) & 0xFF;
 
 	/* プロパティ設定電文作成 */
-	ret = ecn_esv_setc(&esv, TEMP_SENSOR_01_EOBJ, 0xE0, 2, p_edt);
-	if(ret != E_OK){
+	ret = ecn_esv_setc(&esv, eobj, 0xE0, 2, p_edt);
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return;
@@ -806,5 +771,8 @@
 
 	/* 電文送信 */
-	ecn_snd_esv(esv);
+	ret = ecn_snd_esv(esv);
+	if (ret != E_OK) {
+		syslog(LOG_ERROR, "ecn_snd_esv");
+	}
 }
 
@@ -822,10 +790,10 @@
 
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
 	/* 温度計測値 */
 	main_tmpr -= 10;	/* - 1.0℃ */
-	if(main_tmpr < -100)	/* -10.0℃までとする */
+	if (main_tmpr < -100)	/* -10.0℃までとする */
 		main_tmpr = -100;
 
@@ -835,5 +803,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成 */
 	ret = ecn_esv_set_get(&esv, TEMP_SENSOR_02_EOBJ, 0xE0, 2, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return;
@@ -844,5 +812,5 @@
 	/* 書き込みプロパティ追加 */
 	ret = ecn_add_edt(esv, 0x80, 1, p_edt);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_edt");
 		goto error;
@@ -851,5 +819,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：折り返し指定 */
 	ret = ecn_trn_set_get(esv, &trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_trn_set_get");
 		goto error;
@@ -858,5 +826,5 @@
 	/* 読み出しプロパティ追加 */
 	ret = ecn_add_epc(esv, 0xE0);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_epc");
 		goto error;
@@ -865,5 +833,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：終了指定 */
 	ret = ecn_end_set_get(esv, trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_end_set_get");
 		goto error;
@@ -872,5 +840,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -879,5 +847,5 @@
 	/* 領域解放 */
 	ret = ecn_rel_esv(esv);
-	if (ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_rel_esv");
 	}
@@ -895,10 +863,10 @@
 
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
 	/* 温度計測値 */
 	main_tmpr += 10;	/* + 1.0℃ */
-	if(main_tmpr > 400)	/* +40.0℃までとする */
+	if (main_tmpr > 400)	/* +40.0℃までとする */
 		main_tmpr = 400;
 
@@ -908,5 +876,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成 */
 	ret = ecn_esv_set_get(&esv, TEMP_SENSOR_02_EOBJ, 0xE0, 2, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return;
@@ -917,5 +885,5 @@
 	/* 書き込みプロパティ追加 */
 	ret = ecn_add_edt(esv, 0x80, 1, p_edt);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_edt");
 		goto error;
@@ -924,5 +892,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：折り返し指定 */
 	ret = ecn_trn_set_get(esv, &trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_trn_set_get");
 		goto error;
@@ -931,5 +899,5 @@
 	/* 読み出しプロパティ追加 */
 	ret = ecn_add_epc(esv, 0xE0);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_epc");
 		goto error;
@@ -938,5 +906,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：終了指定 */
 	ret = ecn_end_set_get(esv, trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_end_set_get");
 		goto error;
@@ -945,5 +913,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -952,5 +920,5 @@
 	/* 領域解放 */
 	ret = ecn_rel_esv(esv);
-	if (ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_rel_esv");
 	}
@@ -962,8 +930,7 @@
 static bool_t check_response(uint8_t pdc, uint8_t *p_edt)
 {
-	if((pdc != 2)
+	if ((pdc != 2)
 		|| (p_edt[0] != ((uint16_t)main_tmpr) >> 8)
-		|| (p_edt[1] != ((uint16_t)main_tmpr) & 0xFF))
-	{
+		|| (p_edt[1] != ((uint16_t)main_tmpr) & 0xFF)) {
 		syslog(LOG_WARNING, "epc_set_get response NG");
 		return false;
