• 車種別
  • パーツ
  • 整備手帳
  • ブログ
  • みんカラ+

おりおんSTの愛車 [ホンダ ストリーム]

整備手帳

作業日:2007年7月16日

自作車載時計

他の整備手帳を見る 他の整備手帳を見る

1
自作した車載時計の回路図です。

・マイコンはPIC16F876です。持ち合わせのを使ったのですが、PIC16F873Aとかでも大丈夫です。(要ソフト変更)
・マイコンポートのRB0~RB7は7セグメントLED点灯用
・同じくRC0~2、RC4~7は7セグメントLEDのダイナミック点灯制御用
・RC3とRC4はリアルタイムクロックとのI2C通信用
・RA2が設定用スイッチ用
・RA0とRA1がロータリーエンコーダー用
・RA4はACC電源を監視し、キーオフ状態となったらマイコンが誤動作しないように止める役目をしています(ソフト上は無限ループに入り、電源が完全に落ちるのを待っている)
・10MHzの発振子は安いセラロックでOK
・リアルタイムクロック「AKI-RTC-8564」のバッテリーバックアップ用に1Fのスーパーキャパシタを使用
・スーパーキャパシタに直列につながっている330Ωの抵抗は、スーパーキャパシタへの充電時にはキャパシタへ流れ込む突入電流を押さえ、放電時はリアルタイムクロックへ流れ込む電流を制限しバックアップ時間を延長する役目をしている
2
これが実態配線図です。

・ECBとかいてあるのはトランジスタ2SC1815
・ここには12Vから5Vを作り出す回路が入っていないですが、わたしは空きランドに無理やり配線しています
・赤い線はハンダ面、緑の線は部品配置面、白い線はジャンパー線です
・7セグメントLEDは2桁用を3つ使っていますが、配線を変えて1桁用を使ってももちろんOKです
3
MikroBasicで作成したプログラムソースです。ここにはりつけるとインデントが消えちゃってとっても見にくいですね。

program carclock

symbol DigitBit0 = 0
symbol DigitBit1 = 1
symbol DigitBit2 = 2
symbol DigitBit3 = 5
symbol DigitBit4 = 6
symbol DigitBit5 = 7
symbol RE1 = 0
symbol RE2 = 1
symbol SSW = 2
symbol VATTERY = 4
symbol VatLow = 1
symbol VatNormal = 0
symbol VL = 7
symbol Century = 7
symbol HIGH = 1
symbol LOW = 0
symbol YMD = 1
symbol HMS = 0

const dptnB = %00000000 ' Blank
const dptn0 = %11101011 ' Number 0
const dptn1 = %10001000 ' Number 1
const dptn2 = %00111011 ' Number 2
const dptn3 = %10111010 ' Number 3
const dptn4 = %11011000 ' Number 4
const dptn5 = %11110010 ' Number 5
const dptn6 = %11110011 ' Number 6
const dptn7 = %11101000 ' Number 7
const dptn8 = %11111011 ' Number 8
const dptn9 = %11111010 ' Number 9

dim TargetDigit as byte

dim DispS as byte
dim DispM as byte
dim DispH as byte

dim DispS1 as byte
dim DispS10 as byte
dim DispM1 as byte
dim DispM10 as byte
dim DispH1 as byte
dim DispH10 as byte

dim Control1 as byte
dim Control2 as byte
dim Seconds as byte
dim Minutes as byte
dim Hours as byte
dim Days as byte
dim Weekdays as byte
dim Months as byte
dim Years as byte
dim VLbit as byte

dim RE1W as byte
dim DispCont as byte

sub procedure wait1ms
Delay_ms(1)
end sub

sub procedure ReadRTC
I2C_Start 'Send I2C Start Condition
I2C_Wr(%10100010) 'Send RTC slave address with write mode
I2C_Wr(%00000000) 'Send RTC read address
I2C_Repeated_Start 'Send I2C Restart Condition
I2C_Wr(%10100011) 'Send RTC slave address with read mode
Control1 = I2C_Rd(1) 'Read RTC
Control2 = I2C_Rd(1)
Seconds = I2C_Rd(1)
Minutes = I2C_Rd(1)
Hours = I2C_Rd(1)
Days = I2C_Rd(1)
Weekdays = I2C_Rd(1)
Months = I2C_Rd(1)
Years = I2C_Rd(0)
I2C_Stop
Control2.6 = 0
if Seconds.VL = 1 then
VLbit = 1
else
VLbit = 0
end if
Seconds.VL = 0
Minutes.7 = 0
Hours.6 = 0
Hours.7 = 0
Days.6 = 0
Days.7 = 0
Months.5 = 0
Months.6 = 0
Months.century = 0
Seconds = Bcd2Dec(Seconds)
Minutes = Bcd2Dec(Minutes)
Hours = Bcd2Dec(Hours)
Days = Bcd2Dec(Days)
Months = Bcd2Dec(Months)
Years = Bcd2Dec(Years)
while PORTA.VATTERY = VatLow
wait1ms
wend
end sub

sub procedure WriteRTC
I2C_Start 'Send I2C Start Condition
I2C_Wr(%10100010) 'Send RTC slave address with write mode
I2C_Wr(%00000000) 'Send RTC write address
I2C_Wr(%00100000) 'Write RTC (Control1)
I2C_Wr(%00000000) ' (Control2)
I2C_Wr(Dec2Bcd(Seconds))
I2C_Wr(Dec2Bcd(Minutes))
I2C_Wr(Dec2Bcd(Hours))
I2C_Wr(Dec2Bcd(Days))
I2C_Wr(%00000000) ' (Weekday)
I2C_Wr(Dec2Bcd(Months))
I2C_Wr(Dec2Bcd(Years))
I2C_Wr(%10000000) ' (Minute Alarm)
I2C_Wr(%10000000) ' (Hour Alarm)
I2C_Wr(%10000000) ' (Day Alarm)
I2C_Wr(%10000000) ' (Weekday Alarm)
I2C_Wr(%00000000) ' (CLKOUT Freq)
I2C_Wr(%00000000) ' (Timer control)
I2C_Wr(%00000000) ' (Timer)
I2C_Stop
while PORTA.VATTERY = VatLow
wait1ms
wend
end sub

sub procedure StartRTC
I2C_Start 'Send I2C Start Condition
I2C_Wr(%10100010) 'Send RTC slave address with write mode
I2C_Wr(%00000000) 'Send RTC write address
I2C_Wr(%00000000) 'Write RTC (Control1)
I2C_Stop
while PORTA.VATTERY = VatLow
wait1ms
wend
end sub

sub function led7seg_decode( dim DispD as byte ) as byte
select case DispD
case 0 result = dptn0
case 1 result = dptn1
case 2 result = dptn2
case 3 result = dptn3
case 4 result = dptn4
case 5 result = dptn5
case 6 result = dptn6
case 7 result = dptn7
case 8 result = dptn8
case 9 result = dptn9
case 10 result = dptnB
case else result = dptnB
end select
end sub

sub procedure DISP7SEG
DispH10 = DispH div 10
DispH1 = DispH - (DispH10*10)
DispM10 = DispM div 10
DispM1 = DispM - (DispM10*10)
DispS10 = DispS div 10
DispS1 = DispS - (DispS10*10)
select case TargetDigit
case 0
PORTC.DigitBit5 = 0
PORTC.DigitBit0 = 1
PORTB = led7seg_decode(DispS1)
TargetDigit = 1
case 1
PORTC.DigitBit0 = 0
PORTC.DigitBit1 = 1
PORTB = led7seg_decode(DispS10)
TargetDigit = 2
case 2
PORTC.DigitBit1 = 0
PORTC.DigitBit2 = 1
PORTB = led7seg_decode(DispM1)
TargetDigit = 3
case 3
PORTC.DigitBit2 = 0
PORTC.DigitBit3 = 1
PORTB = led7seg_decode(DispM10)
TargetDigit = 4
case 4
PORTC.DigitBit3 = 0
PORTC.DigitBit4 = 1
PORTB = led7seg_decode(DispH1)
TargetDigit = 5
case 5
PORTC.DigitBit4 = 0
PORTC.DigitBit5 = 1
PORTB = led7seg_decode(DispH10)
TargetDigit = 0
end select
wait1ms
end sub





Main:
' CMCON = %00000111 [A]Type (ex. PIC16F876A) only
ADCON0 = %00000000
ADCON1 = %00000110
TRISA = %00011111
TRISB = %00000000
TRISC = %00011000
PORTC = 0
TargetDigit = 0
I2C_Init(100000)

wait1ms

while PORTA.VATTERY = VatLow
wait1ms
wend

RE1W = PORTA.RE1
DispCont = HMS

if PORTA.SSW = LOW then
do
wait1ms
loop until PORTA.SSW = LOW
wait1ms
goto InitDateTime
end if

DispTime:
ReadRTC
if VLbit = 1 then
goto InitDateTime
else
if PORTA.SSW = LOW then
goto SetDate
end if
if (PORTA.RE1 = LOW) and (RE1W = HIGH) then
if PORTA.RE2 = HIGH then
DispCont = YMD
else
DispCont = HMS
end if
end if
if DispCont = HMS then
DispH = Hours
DispM = Minutes
DispS = Seconds
else
DispH = Years
DispM = months
DispS = Days
end if
RE1W = PORTA.RE1
DISP7SEG
end if
goto DispTime

InitDateTime:
Years = 08
Months = 01
Days = 01
Weekdays = 0
Hours = 00
Minutes = 00
Seconds = 00

SetDate:
DISP7SEG
if PORTA.SSW = LOW then
goto SetDate
end if
DISP7SEG
DispH = Years
DispM = Months
DispS = Days
SetDate010:
do 'Wait RE1 HIGH
while PORTA.RE1 = LOW
if PORTA.SSW = LOW then
goto SetDate020
end if
DISP7SEG
wend
Disp7SEG
loop until PORTA.RE1 = HIGH
do 'Wait RE1 LOW
while PORTA.RE1 = HIGH
if PORTA.SSW = LOW then
goto SetDate020
end if
DISP7SEG
wend
DISP7SEG
loop until PORTA.RE1 = LOW
select case PORTA.RE2
case HIGH 'Inc. Date
select case DispM
case 01
if DispS = 31 then
DispS = 01
DispM = 02
else
DispS = DispS + 1
end if
case 02
if (DispH mod 4) = 0 then
if DispS = 29 then
DispS = 01
DispM = 03
else
DispS = DispS + 1
end if
else
if DispS = 28 then
DispS = 01
DispM = 03
else
DispS = DispS + 1
end if
end if
case 03
if DispS = 31 then
DispS = 01
DispM = 04
else
DispS = DispS + 1
end if
case 04
if DispS = 30 then
DispS = 01
DispM = 05
else
DispS = DispS + 1
end if
case 05
if DispS = 31 then
DispS = 01
DispM = 06
else
DispS = DispS + 1
end if
case 06
if DispS = 30 then
DispS = 01
DispM = 07
else
DispS = DispS + 1
end if
case 07
if DispS = 31 then
DispS = 01
DispM = 08
else
DispS = DispS + 1
end if
case 08
if DispS = 31 then
DispS = 01
DispM = 09
else
DispS = DispS + 1
end if
case 09
if DispS = 30 then
DispS = 01
DispM = 10
else
DispS = DispS + 1
end if
case 10
if DispS = 31 then
DispS = 01
DispM = 11
else
DispS = DispS + 1
end if
case 11
if DispS = 30 then
DispS = 01
DispM = 12
else
DispS = DispS + 1
end if
case 12
if DispS = 31 then
DispS = 01
DispM = 01
if DispH = 99 then
DispH = 00
else
DispH = DispH + 1
end if
else
DispS = DispS + 1
end if
end select
case LOW 'Dec. Date
if DispS = 01 then
select case DispM
case 01 DispS = 31 '12
case 02 DispS = 31 ' 1
case 03
if (DispH mod 4) = 0 then
DispS = 29 ' 2
else
DispS = 28 ' 2
end if
case 04 DispS = 31 ' 3
case 05 DispS = 30 ' 4
case 06 DispS = 31 ' 5
case 07 DispS = 30 ' 6
case 08 DispS = 31 ' 7
case 09 DispS = 31 ' 8
case 10 DispS = 30 ' 9
case 11 DispS = 31 '10
case 12 DispS = 30 '11
end select
if DispM = 1 then
DispM = 12
if DispH = 0 then
DispH = 99
else
DispH = DispH - 1
end if
else
DispM = DispM - 1
end if
else
DispS = DispS - 1
end if
end select
goto SetDate010
SetDate020:
DISP7SEG
if PORTA.SSW = LOW then
goto SetDate020
end if
Years = DispH
Months = DispM
Days = DispS

SetTime:
DISP7SEG
DispH = Hours
DispM = Minutes
DispS = 00
SetTime010:
do 'Wait RE1 HIGH
while PORTA.RE1 = LOW
if PORTA.SSW = LOW then
goto SetTime020
end if
DISP7SEG
wend
DISP7SEG
loop until PORTA.RE1 = HIGH
do 'Wait RE1 LOW
while PORTA.RE1 = HIGH
if PORTA.SSW = LOW then
goto SetTime020
end if
DISP7SEG
wend
DISP7SEG
loop until PORTA.RE1 = LOW
select case PORTA.RE2
case HIGH
DispM = DispM + 1
if DispM = 60 then
DispM = 0
DispH = DispH + 1
if DispH = 24 then
DispH = 0
end if
end if
case LOW
if DispM = 0 then
DispM = 59
if DispH = 0 then
DispH = 23
else
DispH = DispH - 1
end if
else
DispM = DispM - 1
end if
end select
goto SetTime010
SetTime020:
DISP7SEG
if PORTA.SSW = LOW then
goto SetTime020
end if
Hours = DispH
Minutes = DispM
Seconds = DispS

WriteRTC
StartRTC

DISP7SEG

goto DispTime

end.
4
うひょ! 画像が小さく変換されて、なにがなんだかよくわからないですね。

興味がある方には別途データをメールしますのでご連絡下さい。

イイね!0件




関連コンテンツ

関連整備ピックアップ

ヘッドライト磨き

難易度: ★★

サマータイヤに交換

難易度:

FCR-062 3回目連続投入

難易度:

ヘッドライト磨き直し

難易度: ★★★

2年ぶりのワイパーゴム交換

難易度:

春のオイル交換祭り 153,846km

難易度:

関連リンク

この記事へのコメント

コメントはありません。

プロフィール

愛車ストリームに自作の回路を組み込んで楽しんでいます。オートドアロック、リバース連動ハザード、リバース連動ミラー、オートライト、オートミラークローズなどです ^...
みんカラ新規会員登録

ユーザー内検索

リンク・クリップ

ヤフーブログ 
カテゴリ:その他(カテゴリ未設定)
2007/05/10 06:12:13
 

愛車一覧

ホンダ ストリーム ホンダ ストリーム
自作の回路を組み込んで楽しんでいます。オートライト、オートミラークローズ、車速感応ドアロ ...
ヘルプ利用規約サイトマップ

あなたの愛車、今いくら?

複数社の査定額を比較して愛車の最高額を調べよう!

あなたの愛車、今いくら?
メーカー
モデル
年式
走行距離(km)
© LY Corporation