何処にいるのソナー 1 何処にいるのソナー 3 何処にいるのソナー 4 何処にいるのソナー 5 |
|
★ (*´Д`)ハァハァハァハァ =ε=ε=ε=┏(; ̄▽ ̄)┛ ズサ━━━━⊂(゚Д゚⊂⌒`つ≡≡≡━━━━!!!!★ | |
実際にプログラムを動かさないと分からないので こんなモノ作りました。 |
|
でも、実際の部品で試さないと よく分からないので プロトタイプを作成 左端のピンは、プログラム書き換え用の コネクターです、実際には必要ありません。 今回から、振動を検知する機構を機械的なスイッチから 圧電素子に切り替えました、 振動を電圧として、それをマイコンで A/D変換させて、振動を検知します。 マクドナルドのおもちゃからヒントを得ました。 |
'//////////////////// プログラムです //////////////////// 'DOG SONAR Ver.1.1 2008/12/25 'Running Beep None $regfile = "ATtiny45.dat" $crystal = 1000000 Config Portb.0 = Output 'BEEP Config Portb.1 = Output 'LED Config Portb.2 = Output 'NC Config Portb.3 = Input 'MAIN SW Config Portb.4 = Input 'SIGNAL Config Adc = Single , Prescaler = Auto Dim SIGNAL As Word '0 to 65535 Dim COUNT1 As Word '0 to 65535 Dim COUNT11 As Byte '0 to 255 Dim COUNT2 As Word '0 to 65535 Dim COUNT22 As Byte '0 to 255 Dim SS As Byte '0 to 255 SS = 55 'SIGNAL = SS MAIN: Gosub STARTP P1: 'POINT 1 ////////// COUNT1 = 0 COUNT11 = 0 P2: 'POINT 2 ////////// Debounce Pinb.3 , 1 , ENDP , Sub 'MAIN S/W CHECK Start Adc SIGNAL = Getadc(2) If SIGNAL > SS Then 'SIGNAL > 5 / 1024 Defo COUNT1 = COUNT1 + 1 COUNT11 = COUNT11 + 1 Portb.1 = 1 'LED ON Waitms 100 'LED ON Portb.1 = 0 'LED OFF Else COUNT1 = COUNT1 + 1 End IF If COUNT1 = 30000 Then '5 sec Goto P3 Else Goto P2 End IF P3: 'POINT 3 ////////// If COUNT11 > 1 Then 'COUNT11 > 1 Goto P1 Else Goto P4 End IF P4: 'POINT 4 ////////// Gosub BEEPA COUNT2 = 0 COUNT22 = 0 P5: 'POINT 5 ////////// Debounce Pinb.3 , 1 , ENDP , Sub 'MAIN S/W CHECK If SIGNAL > SS Then 'SIGNAL > 5 / 1024 Defo COUNT2 = COUNT2 + 1 COUNT22 = COUNT22 + 1 Portb.1 = 1 'LED ON Waitms 100 'LED ON Portb.1 = 0 'LED OFF Else COUNT2 = COUNT2 + 1 End IF If COUNT2 = 5000 Then '1 sec Goto P6 Else Goto P5 End IF P6: 'POINT 6 ////////// If COUNT22 > 1 Then 'COUNT22 > 1 Goto P1 Else Goto P4 End IF End '//////////////////// PROGRAM //////////////////// '//////////////////// BEEPA //////////////////// BEEPA: Dim BEEP1 As Word For BEEP1 = 1 To 500 '1sec at 1kHz = 1000 palse Portb.0 = 1 Waitus 200 'Wait 200 usec Portb.0 = 0 Gosub T1KHZ 'Wait time 718msec Next BEEP1 Dim WAIT100 As Word 'Waitms 100 For WAIT100 = 1 To 100 '200msec = Wait X 46 + 24 usec X 4347 Gosub T1MSEC 'Wait 1 msec Next WAIT100 'Waitms 100 Dim BEEP2 As Word For BEEP2 = 1 To 500 '1sec at 1kHz = 1000 palse Portb.0 = 1 Waitus 200 'Wait 200 usec Portb.0 = 0 Gosub T1KHZ 'Wait time 718msec Next BEEP2 Return '//////////////////// BEEPA //////////////////// '//////////////////// WAIT1KHZ 28 + 46 usec //////////////////// T1KHZ: Start Adc SIGNAL = Getadc(2) Dim M1 As Byte For M1 = 1 To 15 '1sicle = 46 usec If SIGNAL > 99 Then 'SIGNAL > 5 / 1024 Defo Portb.1 = 1 'LED ON Waitms 100 'LED ON Portb.1 = 0 'LED OFF Goto P1 End IF Next M1 Return '//////////////////// WAIT1KHZ 1KHz 28 + 46 usec //////////////////// '//////////////////// WAIT1MS 28 + 46 usec //////////////////// T1MSEC: Start Adc SIGNAL = Getadc(2) Dim M2 As Byte For M2 = 1 To 21 '1sicle = 46 usec If SIGNAL > SS Then 'SIGNAL > 5 / 1024 Defo Portb.1 = 1 'LED ON Waitms 100 'LED ON Portb.1 = 0 'LED OFF Goto P1 End IF Next M2 Return '//////////////////// WAIT1MS 28 + 46 usec //////////////////// '//////////////////// START //////////////////// STARTP: Dim ST_1 As Byte '4-DO 0.2sec For ST_1 = 1 To 209 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 756 Next ST_1 Dim ST_2 As Byte '4-RE 0.2sec For ST_2 = 1 To 235 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 652 Next ST_2 Dim ST_3 As Word '4-MI 0.2sec For ST_3 = 1 To 264 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 558 Next ST_3 Dim ST_4 As Word '4-FA 0.2sec For ST_4 = 1 To 279 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 516 Next ST_4 Dim ST_5 As Word '4-SO 0.2sec For ST_5 = 1 To 314 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 438 Next ST_5 Dim ST_6 As Word '4-RA 0.2sec For ST_6 = 1 To 314 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 368 Next ST_6 Dim ST_7 As Word '4-SI 0.2sec For ST_7 = 1 To 395 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 306 Next ST_7 Dim ST_8 As Word '5-DO 1sec For ST_8 = 1 To 2092 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 278 Next ST_8 Return '//////////////////// START //////////////////// '//////////////////// ENDP //////////////////// ENDP: Dim BY_1 As Word '5-DO 0.2sec For BY_1 = 1 To 418 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 278 Next BY_1 Dim BY_2 As Word '4-SI 0.2sec For BY_2 = 1 To 395 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 306 Next BY_2 Dim BY_3 As Word '4-RA 0.2sec For BY_3 = 1 To 314 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 368 Next BY_3 Dim BY_4 As Word '4-SO 0.2sec For BY_4 = 1 To 314 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 438 Next BY_4 Dim BY_5 As Word '4-FA 0.2sec For BY_5 = 1 To 279 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 516 Next BY_5 Dim BY_6 As Word '4-MI 0.2sec For BY_6 = 1 To 264 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 558 Next BY_6 Dim BY_7 As Byte '4-RE 0.2sec For BY_7 = 1 To 235 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 652 Next BY_7 Dim BY_8 As Word '4-DO 1sec For BY_8 = 1 To 1047 Portb.0 = 1 Waitus 200 Portb.0 = 0 Waitus 756 Next BY_8 Wait 1 'WAIT 1 Sec Do Debounce Pinb.3 , 1 , PWRON , Sub 'MAIN S/W CHECK Loop Return '//////////////////// ENDP //////////////////// '//////////////////// POWER ON //////////////////// PWRON: Goto MAIN Return '//////////////////// POWER ON //////////////////// |