//............................................................................. // // ニキシー管 温度計 コントロール・プログラム // 2006.4 (Ver. 2.0) //............................................................................. // // 無許可転載・転用を禁止します。 // 転載・転用許可は必ず office@nixie-tube.com までご連絡ください。 // Copyright 2006(C)nixie-tube.com. All rights Reserved. // Never reproduce or republicate without written permission. // // 万一、このプログラムを使用した結果に生じた損害などは一切補償いたしません。 // //............................................................................. // 関連パーツの扱いは下記にて行っております。 // http://nixie-tube.com/cq // 携帯専用サイトからもどうぞ // http://nixie-tube.com/shop/m //............................................................................. //............................................................................. // 配線を少なくするために、数字と記号の配線を下記のように共用しています。 // 6 dot // 7 oC // 8 minus //............................................................................. #include<16f648a.h> #fuses HS,NOWDT,NOLVP #use delay(clock = 20000000) #use i2c(MASTER, SCL=PIN_A0 ,SDA=PIN_A1) //............................................................................. int a0 = 0; int a1 = 0; int a2 = 0; int disp_0 = 0; int disp_1 = 0; signed int t1; int t2; int dynamic = 200; //ダイナミック点灯用タイマの値 int disp_sel_flag = 0; int minus = 0; int range_error = 0; long make_sec = 0; // 1Sec カウント用 int sec_flag = 1; // 1Sec カウント用 //............................................................................. //............................................................................. //表示切替用に約1秒を作る //............................................................................. #int_timer0 void sec_interval() { make_sec++; if (make_sec > 7500){ sec_flag = 1; make_sec = 0; } } //............................................................................. //............................................................................. // PICの初期化 //............................................................................. void pin_init() { // PICのピンをすべてOutput set_tris_b(0b00000000); output_b(11); output_low(PIN_B4); output_low(PIN_B5); // タイマ関係の初期化 setup_timer_0(RTCC_INTERNAL | RTCC_DIV_4); set_timer0(0); // 割り込み開始 enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); } //............................................................................. //............................................................................. // 温度センサーの初期化 //............................................................................. void init_temp() { i2c_start(); i2c_write(0x90); ////write to i2c_write(0x01); ////pointer i2c_write(0x40); ////config data i2c_stop(); delay_ms(10); i2c_start(); i2c_write(0x90); ////write to i2c_write(0x00); ////pointer i2c_stop(); delay_ms(10); } //............................................................................. //............................................................................. // ニキシー管表示ルーチン //............................................................................. void nixie_disp() { // 数字部分の表示 output_b(disp_0); output_high(PIN_B4); delay_us(dynamic); output_low(PIN_B4); output_b(11); delay_us(dynamic); output_b(disp_1); output_high(PIN_B5); delay_us(dynamic); output_low(PIN_B5); output_b(11); delay_us(dynamic); // マイナスの表示 if (minus == 1 ){ output_b(8); // 8 = minus output_high(PIN_B5); delay_us(dynamic); output_low(PIN_B5); output_b(11); delay_us(dynamic); } else{ // ℃の表示 output_b(7); // 7 = ℃ output_high(PIN_B5); delay_us(dynamic); output_low(PIN_B5); output_b(11); delay_us(dynamic); } } //............................................................................. //............................................................................. // 表示内容切り替え用Flagのセット //............................................................................. void inc_sel_flag() { disp_sel_flag++; if (disp_sel_flag == 3){ disp_sel_flag = 0; } } //............................................................................. //............................................................................. //ここで各ニキシー管の表示内容をセットする //............................................................................. void disp_set() { switch (disp_sel_flag) { case 0: // お休み { return; } case 1: // 小数点以上を表示 { disp_0=a0; disp_1=a1; if (range_error == 1){ disp_0 = 11; disp_1 = 11; } return; } case 2: // 小数点以下を表示 { disp_0=a2; disp_1=6; if (range_error == 1){ disp_0 = 11; } return; } } } //............................................................................. //............................................................................. // 温度センサーからのデータを解析して、温度がレンジ内かをチェック //............................................................................. void range_check() { if (t1 >= 60 || t1 <= -56){ range_error = 1; } else{ range_error = 0; } } //............................................................................. //............................................................................. // 温度センサーからのデータを解析して、マイナス温度かをチェック //............................................................................. void sign_check() { if (bit_test(t1, 7)){ t1 = t1 ^ 0xff ; minus = 1; } else{ minus = 0; } } //............................................................................. //............................................................................. // 温度センサーからのデータをコンバート //............................................................................. void temp_conv() { i2c_start(); i2c_write(0x91); // read data t1 = i2c_read(); t2 = i2c_read(0); i2c_stop(); range_check(); sign_check(); a0 = t1 % 10; a1 = t1 / 10; a2 = t2 % 10; } //............................................................................. //............................................................................. // 基本処理 //............................................................................. void main() { pin_init(); // PICを初期化 init_temp(); // 温度センサを初期化 while(1) { if (sec_flag == 1){ // 1秒おきに表示内容を切り替えている sec_flag = 0; inc_sel_flag(); temp_conv(); disp_set(); } if(disp_sel_flag != 0){ nixie_disp(); } } } //.............................................................................