erwin4838
Member level 1
- Joined
- Mar 4, 2012
- Messages
- 32
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Tangerang-indonesia
- Activity points
- 1,478
Dear
All my master
i have project with ping sensor this source code for control distance (Jarak) in indonesia language
with code on only can measures multiple 1 cm, can not read distance under 1 cm, i am the aid request so that censor can read in unit mm, for example reads distance 0,50 mm, thank for your kind attention
All my master
i have project with ping sensor this source code for control distance (Jarak) in indonesia language
Code:
'-----------------------------------------------
'
' CHIP : ATMEGA8535
' CLOCK : 16 MHZ
' LCD : PORTC
' SIG SENSOR : PORTA.1
'------------------------------------------------
$regfile = "m8535.dat"
$crystal = 16000000
Dim K As Word , I As Byte , Menu As Byte
Dim Jarak As Word , F_tbl As Bit
Dim Range_min As Word , Range_max As Word
Const E_max = 0
Const E_min = 2
'------- konfigurasi LCD
Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.2 , Db4 = Portc.4 ,
Config Lcdpin = Pin , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7
Config Lcd = 16 * 2
Cursor Off
Cls
Sig Alias Porta.1
Pin_sig Alias Ddra.1
Sig_in Alias Pina.1
Ddrb = &B111
Ddrd = &B0000
Portd = &B1111
Readeeprom Range_max , E_max
If Range_max = &HFFFF Then Range_max = 0
Readeeprom Range_min , E_min
If Range_min = &HFFFF Then Range_min = 0
Lcd "Jarak="
Lowerline
Lcd "Min=" ; Range_min
Lcd " Max=" ; Range_max
Do
Gosub Ukur_jarak
Locate 1 , 7
Lcd Jarak ; " cm "
If Jarak >= Range_min And Jarak <= Range_max Then
Portb = &B001
Elseif Jarak > Range_max Then
Portb = &B010
Elseif Jarak < Range_min Then
Portb = &B100
End If
For I = 0 To 200
Gosub Cek_tombol
Waitms 4
Next
Loop
End
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'
Cek_tombol:
Do
If Pind.0 = 0 And Menu = 1 Then
If Range_min > 0 Then
Decr Range_min
Locate 2 , 11
Lcd Range_min ; " "
Writeeeprom Range_min , E_min
Waitms 250
End If
Elseif Pind.1 = 0 And Menu = 1 Then
Incr Range_min
Locate 2 , 11
Lcd Range_min ; " "
Writeeeprom Range_min , E_min
Waitms 250
Elseif Pind.0 = 0 And Menu = 2 Then
If Range_max > 0 Then
Decr Range_max
Locate 2 , 11
Lcd Range_max ; " "
Writeeeprom Range_max , E_max
Waitms 250
End If
Elseif Pind.1 = 0 And Menu = 2 Then
Incr Range_max
Locate 2 , 11
Lcd Range_max ; " "
Writeeeprom Range_max , E_max
Waitms 250
'-----------------------------------
Elseif Pind.2 = 0 And Menu = 0 Then
Menu = 1
F_tbl = 1
Cls
Lcd "Seting Range Min"
Lowerline
Lcd "Range Min=" ; Range_min
Elseif Pind.2 = 0 And Menu = 1 Then
Menu = 2
Cls
Lcd "Seting Range Max"
Lowerline
Lcd "Range Max=" ; Range_max
Elseif Pind.2 = 0 And Menu = 2 Then
Menu = 0
F_tbl = 0
Cls
Lcd "Jarak="
Lowerline
Lcd "Min=" ; Range_min
Lcd " Max=" ; Range_max
End If
If Pind.3 = 0 Then
Menu = 0
F_tbl = 0
Range_min = 0
Range_max = 0
Writeeeprom Range_max , E_max
Writeeeprom Range_min , E_min
Cls
Lcd "Jarak="
Lowerline
Lcd "Min=" ; Range_min
Lcd " Max=" ; Range_max
Waitms 250
End If
Loop Until F_tbl = 0
Return
'---------------------------------
Ukur_jarak:
Pin_sig = 1
Sig = 0
Jarak = 0
Sig = 1
Waitus 5
Sig = 0
Waitus 760
Pin_sig = 0
Sig = 1
Bitwait Sig_in , Set
For K = 0 To 400
If Sig_in = 1 Then Incr Jarak
Waitus 58
Next
If Jarak > 300 Then Jarak = 300
Return
'---------------------------------
with code on only can measures multiple 1 cm, can not read distance under 1 cm, i am the aid request so that censor can read in unit mm, for example reads distance 0,50 mm, thank for your kind attention