'============================================================================== 'Honda BEAT Fuel Cust Mater Ver1.13 -2008/05/19- '---- Produce By MMRHOME.NET Created -ELS- ----- 'Option->Enviromens->Fontで日本語フォントを使用するとエディタで日本語が使えます ' 'このプログラムは8Mhz専用です '============================================================================== ' '============================================================================== 'バージョンアップ履歴 ' '08/05 Ver1.13J一部メッセージをカタカナ表示へ '08/04 Ver1.10 プログラム見直し '08/02 Ver1.00 設定ボタン関係のプログラムを追加 '07/12 Ver0.90 小型基板用製作につきポート関係を見直し ' Ver0.50 LCD 16*2版にて作成しなおし ' Ver0.30 プログラム構造見直しハードウェア割り込みを使用 '07/10 Ver0.20 実装テスト用 ' Ver0.15 燃費計測機能の他に走行距離・燃料消費量を追加 ' Ver0.10 燃費計測機能追加 ' Ver0.09 速度パルス・インジェクションパルス取得テスト用 '07/09 Ver0.01 初版製作 LCD20*4版のハードウェアの動作チェック用 '============================================================================== $regfile = "m48def.dat" $crystal = 8000000 Osccal = 186 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db7 = Portb.1 , Db6 = Portb.2 Config Lcdpin = Pin , Db5 = Portb.3 , Db4 = Portb.4 Config Lcdpin = Pin , E = Portb.5 , Rs = Portd.5 Config Int0 = Falling Config Int1 = Change Config Timer1 = Timer , Prescale = 8 Config Portd.2 = Input 'スピードパルス(INT0) Config Portd.3 = Input 'インジェクション(INT1) Config Portd.7 = Output 'LED表示 Config Portd.6 = Input 'MENU UP Config Portb.0 = Input 'MENU SW Config Portc.5 = Input 'MENU DOWN Config Portc.4 = Input 'セッティング用スイッチ '--ポート名を設定------------------------------------------------------------- Port_speed_pls Alias Portd.2 Port_inj_pls Alias Pind.3 Port_led1 Alias Portd.7 Port_lcd_sw Alias Pinb.0 Port_lcd_up Alias Pind.6 Port_lcd_down Alias Pinc.5 Port_seting_sw Alias Pinc.4 Set Port_inj_pls Set Port_speed_pls Set Port_led1 Set Port_lcd_sw Set Port_lcd_up Set Port_lcd_down Set Port_seting_sw '--変数型設定------------------------------------------------------------------ Dim Inj_frg As Bit Dim Display_mode As Byte Dim Inject_time As Long Dim Inject2_time As Long Dim Inject3_time As Long Dim Speed_plus As Long Dim Speed2_plus As Long Dim Speed3_plus As Long Dim Speed_plus_chk As Long Dim Lcd_cnt As Integer Dim Engine_stop As Bit Dim Lcd_wait As Integer Dim Fuel As Long Dim Fuel_str As String * 3 Dim Fuel_work As Long Dim Fuel_keisuu As Integer Dim Fuel_keisuu_str As String * 4 Dim Run As Long Dim Run_str As String * 5 Dim Run_work As Long Dim Run_keisuu As Integer Dim Run_keisuu_str As String * 4 Dim Fuel_cust As Long Dim Fuel_cust_str As String * 4 '--初期設定------------------------------------------------------------------- '------------------------------------------------------------------------------ '燃料噴射量の設定 'エンジン気筒数とインジェクター容量から噴射量を算出 'インジェクター容量÷60×気筒数×10 '数値が小さくなるほど燃費が良く表示されます '例)ビートの場合 210÷60×3×10=105 '------------------------------------------------------------------------------ Fuel_keisuu = 111 '------------------------------------------------------------------------------ '車速度パルス1個あたりの走行距離 単位はミリメートル '通常は392です。自動車のODOメータを見ながら調整します '数値が大きくなるほど走行距離が増えます 'デバックモードでSPD数を調べて 走行距離÷SPDで計算します 'ナビ補正値は383 ODOメータでは392? '------------------------------------------------------------------------------ Run_keisuu = 392 Lcd_wait = 100 Fuel_cust = 0 Gosub Data_clear Reset Engine_stop '--EEPROMの初期化とEEPROMからデータの読み込み--------------------------- '--変数はなんでも良かったのでとりあえずFuel_custを使っているだけ-------------- Readeeprom Fuel_cust , 1 If Fuel_cust <> 1 Then Fuel_cust = 1 Writeeeprom Fuel_cust , 1 Gosub Wr_eeprom End If '--EEPROMからデータの読み込み------------------------------------------- Readeeprom Fuel_keisuu , 7 Readeeprom Run_keisuu , 9 Readeeprom Inject_time , 11 Readeeprom Speed_plus , 15 Readeeprom Inject2_time , 11 Readeeprom Speed2_plus , 15 '--割り込み等の許可---------------------------------------------------------- Stop Timer1 Timer1 = 0 Enable Interrupts Enable Timer1 Enable Int0 Enable Int1 On Int0 Speedcnt On Int1 Inj_cnt '--スタート時の表示----------------------------------------------------------- Cls Cursor Off Display_mode = 8 Gosub Lcd_write1 While Port_inj_pls = 1 Wend Display_mode = 1 '--メインプログラム----------------------------------------------------------- Do '--エンジン停止確認----------------------------------------------------------- If Speed_plus_chk = Speed_plus And Timer1 > 20000 Then If Engine_stop = 0 Then Gosub Lcd_write1 Gosub Wr_eeprom Set Engine_stop End If End If If Lcd_cnt > Lcd_wait Then Lcd_cnt = 0 Gosub Lcd_write1 If Engine_stop = 1 Then Toggle Port_led1 Lcd_wait = 15000 Else Lcd_wait = 5000 End If Else Incr Lcd_cnt End If Debounce Port_lcd_sw , 0 , Lcdmode_sw , Sub Debounce Port_lcd_up , 0 , Lcdmode_up , Sub Debounce Port_lcd_down , 0 , Lcdmode_down , Sub Loop end '--LCD表示切り替え------------------------------------------------------------ Lcdmode_sw: Cls Incr Display_mode If Port_seting_sw = 1 Then If Display_mode > 7 Then Display_mode = 1 End If Else If Display_mode > 3 Then Display_mode = 1 End If End If Return Lcdmode_up: Select Case Display_mode Case 5 Incr Run_keisuu Case 6 Incr Fuel_keisuu End Select Return Lcdmode_down: Select Case Display_mode Case 3 Gosub Data_clear Gosub Wr_eeprom Display_mode = 1 Case 5 Decr Run_keisuu Case 6 Decr Fuel_keisuu Case 7 Gosub Wr_eeprom Display_mode = 1 End Select Return '--インジェクター時間の計測用------------------------------------------------ Inj_cnt: If Port_inj_pls = 0 And Inj_frg = 0 Then Set Inj_frg Set Port_led1 Speed_plus_chk = Speed_plus Timer1 = 0 Start Timer1 End If If Port_inj_pls = 1 And Inj_frg = 1 Then Reset Inj_frg Reset Port_led1 Reset Engine_stop Speed_plus_chk = 0 Stop Timer1 If Timer1 < 20000 Then Timer1 = Timer1 / 1000 Inject_time = Inject_time + Timer1 End If End If Return '--スピードパルス計測用------------------------------------------------------- Speedcnt: Incr Speed_plus Return 'EEPROMデータ書き込み-------------------------------------------------------- Wr_eeprom: Disable Interrupts Stop Timer1 Writeeeprom Fuel_keisuu , 7 Writeeeprom Run_keisuu , 9 Writeeeprom Inject_time , 11 Writeeeprom Speed_plus , 15 Enable Interrupts Start Timer1 Return '--データクリア-------------------------------------------------------------- Data_clear: Inject_time = 0 Speed_plus = 0 Inject2_time = 0 Speed2_plus = 0 Return '--各種計算------------------------------------------------------------------ Keisan: Select Case Display_mode Case 1 Inject3_time = Inject_time Speed3_plus = Speed_plus Case 2 Inject3_time = Inject_time - Inject2_time Speed3_plus = Speed_plus - Speed2_plus End Select Fuel_work = Inject3_time / 100 Fuel_work = Fuel_work * Fuel_keisuu Fuel = Fuel_work / 10000 Fuel_str = Str(fuel) Run_work = Speed3_plus * Run_keisuu Fuel_cust = Run_work / Fuel_work Fuel_cust_str = Str(fuel_cust) Run = Run_work / 100000 Run_str = Str(run) '--オーバーフロー処理--------------------------------------------------------- '燃料消費が99Lになった時に、全データをリセット ' If Fuel > 999 Then Gosub Data_clear Run_str = "-----" Fuel_cust_str = "---" Fuel_str = "---" End If Return '--LCD表示用-------------------------------------------------------------- Lcd_write1: Gosub Keisan Select Case Display_mode Case 1 '燃費表示 'Upperline : Lcd "TOTAL AVG " ; Format(fuel_cust_str , "00.0") ; "Km" Upperline : Lcd "{186}{222}{179}{185}{178}{200}{221}{203}{223} " ; Format(fuel_cust_str , "00.0") ; "Km" Lowerline : Lcd "R" ; Format(run_str , "0000.0") ; "Km F" ; Format(fuel_str , "00.0") ; "L" Case 2 '今回燃費 Upperline : Lcd "{186}{221}{182}{178}{200}{221}{203}{223} " ; Format(fuel_cust_str , "00.0") ; "Km" Lowerline : Lcd "R" ; Format(run_str , "0000.0") ; "Km F" ; Format(fuel_str , "00.0") ; "L" Case 3 'メータリセット Upperline : Lcd "-DATA CLEAR OK?-" Lowerline : Lcd "DownKEY = CLEAR " Case 4 'デバック用 Upperline : Lcd "SPD=" ; Speed_plus Lowerline : Lcd "INJ=" ; Inject_time Case 5 Run_keisuu_str = Str(run_keisuu) Upperline : Lcd "SET Speed PULS " Lowerline : Lcd Format(run_keisuu_str , " 0000") Case 6 'インジェクションパルス補正値 Fuel_keisuu_str = Str(fuel_keisuu) Upperline : Lcd "SET Inject Puls " Lowerline : Lcd Format(fuel_keisuu_str , " 0000") Case 7 '設定値の書き込み Upperline : Lcd "-DATA WRITE OK?-" Lowerline : Lcd "DownKEY = Write " Case 8 'オープニング画面 Upperline : Lcd "--{200}{221}{203}{223} {185}{178}{191}{184}{212}{219}{179}--" '燃費計測野郎 Lowerline : Lcd "PROGRAM Ver1.13J" End Select Return End