//............................................................................. // // 6桁表示 ニキシー管時計 コントロール・プログラム // 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 //............................................................................. #include <16F84A.h> #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (> 4mhz) #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #use delay(clock=12800000) #use fast_io(A) #use fast_io(B) //............................................................................. long make_sec; int sec_flag = 0; int h10 = 0, h1 = 0, m10 = 0, m1 = 0, s10 = 0, s1 = 0; long dynamic = 200; // ダイナミック点灯用タイマ int mode = 0; //0:Clock mode, 1:Set min1, 2:Set min10, 3:Set hour int blink = 0; //............................................................................. //............................................................................. #int_timer0 void sec_interval() { make_sec++; if(mode == 0){ if (make_sec >= 3125) //1sec { sec_flag = 1; make_sec = 0; } } else{ if (make_sec >= 1562) //0.5sec(時刻設定時の点滅用) { sec_flag = 1; make_sec = 0; } } } //............................................................................. //............................................................................. void enable_int() //割り込み開始 { enable_interrupts(INT_TIMER0); enable_interrupts(GLOBAL); } //............................................................................. //............................................................................. void disable_int() //割り込み停止 { disable_interrupts(GLOBAL); disable_interrupts(INT_TIMER0); } //............................................................................. //............................................................................. void init() { set_tris_a(0b00011100); set_tris_b(0b00000000); setup_timer_0(RTCC_INTERNAL | RTCC_DIV_4); set_timer0(0); enable_int(); } //............................................................................. //............................................................................. // 時刻表示 //............................................................................. void nixie_disp(int n5, int n4, int n3, int n2, int n1, int n0, int delay) { // Display Nixie 0 output_b(n0); output_high(PIN_B4); delay_us(delay); output_low(PIN_B4); output_b(0x0f); delay_us(delay); // Display Nixie 1 output_b(n1); output_high(PIN_B5); delay_us(delay); output_low(PIN_B5); output_b(0x0f); delay_us(delay); // Display Nixie 2 output_b(n2); output_high(PIN_B6); delay_us(delay); output_low(PIN_B6); output_b(0x0f); delay_us(delay); // Display Nixie 3 output_b(n3); output_high(PIN_B7); delay_us(delay); output_low(PIN_B7); output_b(0x0f); delay_us(delay); // Display Nixie 4 output_b(n4); output_high(PIN_A0); delay_us(delay); output_low(PIN_A0); output_b(0x0f); delay_us(delay); // Display Nixie 5 output_b(n5); output_high(PIN_A1); delay_us(delay); output_low(PIN_A1); output_b(0x0f); delay_us(delay); } //............................................................................. //............................................................................. // 時刻表示(blink_digitの値によって点滅の桁を決定する) //............................................................................. void blink_nixie_disp(int n5, int n4, int n3, int n2, int n1, int n0, int delay, int blink_digit) { // Display Nixie 0 output_b(n0); output_high(PIN_B4); delay_us(delay); output_low(PIN_B4); output_b(0x0f); delay_us(delay); // Display Nixie 1 output_b(n1); output_high(PIN_B5); delay_us(delay); output_low(PIN_B5); output_b(0x0f); delay_us(delay); // Display Nixie 2 if(blink_digit == 1){ output_b(0x0f); output_low(PIN_B6); } else{ output_b(n2); output_high(PIN_B6); } delay_us(delay); output_low(PIN_B6); output_b(0x0f); delay_us(delay); // Display Nixie 3 if(blink_digit == 2){ output_b(0x0f); output_low(PIN_B7); } else{ output_b(n3); output_high(PIN_B7); } delay_us(delay); output_low(PIN_B7); output_b(0x0f); delay_us(delay); // Display Nixie 4 if(blink_digit == 3){ output_b(0x0f); output_low(PIN_A0); } else{ output_b(n4); output_high(PIN_A0); } delay_us(delay); output_low(PIN_A0); output_b(0x0f); delay_us(delay); // Display Nixie 5 if(blink_digit == 3){ output_b(0x0f); output_low(PIN_A1); } else{ output_b(n5); output_high(PIN_A1); } delay_us(delay); output_low(PIN_A1); output_b(0x0f); delay_us(delay); } //............................................................................. //............................................................................. // 1秒から1分、1時間を作る //............................................................................. void make_time() { s1++; if(s1 == 10){ s10++; s1 = 0; } if(s10 == 6){ m1++; s10 = 0; } if(m1 == 10){ m10++; m1 = 0; } if(m10 == 6){ h1++; m10 = 0; } if(h10 == 0 || h10 == 1){ if(h1 == 10){ h10++; h1 = 0; } } if(h10 == 2){ if(h1 == 4){ h10 = 0; h1 = 0; } } } //............................................................................. //............................................................................. // 時刻設定時、ボタンを押し続けた時に自動的に+-されるスピードの調整 //............................................................................. void disp_wait() { long i; for(i=0;i<0x40;i++){ //ここの値で時刻設定時の自動+-のスピードを調整 nixie_disp(h10, h1, m10, m1, s10, s1, dynamic); } make_sec = 0; } //............................................................................. //............................................................................. // スイッチの監視 //............................................................................. void check_sw() { int i; // mode switch if(input(PIN_A2) == 0){ for(i=0;i<100;i++){ //チャタリング用タイマ nixie_disp(h10, h1, m10, m1, s10, s1, dynamic); } while(!(input(PIN_A2))) { nixie_disp(h10, h1, m10, m1, s10, s1, dynamic); } mode++; //mode = 0:Clock mode, 1:Set min1, 2:Set min10, 3:Set hour blink = 1; if(mode == 4){ //時刻設定モードを抜ける mode = 0; // 00秒にセット s10 = 0; S1 = 0; make_sec = 0; sec_flag = 0; } return; } // +,- Switch switch(mode) { case 0: //clock mode & reset sec { if(input(PIN_A3) == 0){ //00秒にセット s10 = 0; S1 = 0; make_sec = 0; sec_flag = 0; return; } if(input(PIN_A4) == 0){ //30秒にセット s10 = 3; S1 = 0; make_sec = 0; sec_flag = 0; return; } } case 1: // Set min1 { if(input(PIN_A3) == 0){ blink = 1; m1++; if(m1 == 10){ m1 = 0; } disp_wait(); return; } if(input(PIN_A4) == 0){ blink = 1; if(m1 == 0){ m1 = 9; } else{ m1--; } disp_wait(); return; } } case 2: // Set min10 { if(input(PIN_A3) == 0){ blink = 1; m10++; if(m10 == 6){ m10 = 0; } disp_wait(); return; } if(input(PIN_A4) == 0){ blink = 1; if(m10 == 0){ m10 = 5; } else{ m10--; } disp_wait(); return; } } case 3: // Set hour { if(input(PIN_A3) == 0){ blink = 1; h1++; if(h10 == 0 || h10 == 1){ if(h1 == 10){ h1 = 0; h10++; } } if(h10 == 2){ if(h1 == 4){ h1 = 0; h10 = 0; } } disp_wait(); return; } if(input(PIN_A4) == 0){ blink = 1; if(h1 == 0){ if(h10 == 0){ h10 = 2; h1 = 3; } else{ h10--; h1 =9; } } else{ h1--; } disp_wait(); return; } } } } //............................................................................. //............................................................................. // 時刻表示 //............................................................................. void clock_works() { if(sec_flag == 1){ make_time(); sec_flag = 0; } nixie_disp(h10, h1, m10, m1, s10, s1, dynamic); } //............................................................................. //............................................................................. // 0.5秒おきに選択桁を点滅させるための仕組み //............................................................................. void set_time() { if(sec_flag == 1){ sec_flag = 0; if(blink){ blink = 0; } else{ blink = 1; } } if(!(blink)){ blink_nixie_disp(h10, h1, m10, m1, s10, s1, dynamic, mode); //選択桁を非表示 } else{ nixie_disp(h10, h1, m10, m1, s10, s1, dynamic); } } //............................................................................. //............................................................................. // 全体の処理 //............................................................................. void main() { init(); //初期化 while(1) { check_sw(); //スイッチが押されたかをチェック switch(mode) { case 0:{ clock_works(); //時刻表示 continue; } default:{ set_time(); //時刻設定時の点滅表示 } } } } //.............................................................................