Professional Documents
Culture Documents
TX23 Anemometar Za Specijalisticki
TX23 Anemometar Za Specijalisticki
**
' Meteoroska stanica. Mikrokontroler obradjuje podatke sa senzora TX-23 (anemometar
*
' i pravac vetra) i senzora kolicine padavina.Mikrokontroler proziva TX-23 za poda-
*
' tke o vetru a podatak o kolicini padavina dobija preko interapta. Izmerene
vredno-*
' sti salje serijski (za ESP8266) u formatu TaskValueSet 1, x, x
*
'
*
'
*
' Ovo je deo celog sistema meteoroloske stanice sa autonomnim napajanjem koja jos
*
' meri spoljnu temperaturu, vlaznost vazduha, vazdusni pritisak i kontrolno napon
*
' baterije i struju punjenja baterija
*
'
*
' rev.7 23.04.2017 Velja V. Cvetkovic
*
'**********************************************************************************
**
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 128
$swstack = 128
$framesize = 128
$baud = 115200
$prog &HFF , &HFF , &HDB , &HFE ' Fuse bitovi (Opis u
prilogu)
Enable Interrupts
Enable Int1
Enable Timer0
'Resetovanje pocetnih
vrednosti
Kisa = 0
Cekanje = 0
Cekanje2 = 0
J = 0
Start: 'Koristi se kod
testiranja za proveru serijske komunikacije
Do
End If
Loop
Sub Tx23_reading:
Gosub Tx23_reset
Gosub Bit_width
Gosub Tx23_receiving
Gosub Tx23_calculating
End Sub
Sub Tx23_reset:
Marker = 0 'Pokazuje neregularan
izlazak
Config Portd.2 = Output 'Prvo master obara data
liniju u roku 500ms
Portd.2 = 0
Waitms 500
Portd.2 = 1
Config Tx23_data = Input ' Oslobadja data liniju
i postaje ulaz i "osluskuje"
For Z = 0 To 1000
Waitus 2
If Tx23_data = 1 Then 'bitwait tx23_data, set
Exit For
End If
If Z = 500 Then
Marker = 1
End If
Next Z
For Z = 0 To 2000
Waitus 2
If Tx23_data = 0 Then 'bitwait tx23_data,
reset
Exit For
End If
If Z = 1000 Then
Marker = 2
End If
Next Z
End Sub
Vreme_impulsa1 = 0
Vreme_impulsa2 = 0
Timer1 = 0 'pokrece tajmer za
merenje vremena
Start Timer1
For Z = 0 To 1000
Waitus 2
If Tx23_data = 1 Then 'bitwait tx23_data, set
Exit For
End If
If Z = 500 Then
End If
Next Z
Vreme_impulsa1 = Timer1
Waitus 240
For Z = 0 To 2000
Waitus 2
If Tx23_data = 0 Then 'bitwait tx23_data,
reset
Exit For
End If
If Z = 1000 Then
End If
Next Z
Vreme_impulsa2 = Timer1
Stop Timer1
W = Vreme_impulsa2 - Vreme_impulsa1
W = W / 80
W = W - 2 'Dodatna korekcija da
bi vrednost bila sto tacnija
For Z = 0 To 1000
Waitus 2
If Tx23_data = 1 Then 'bitwait tx23_data, set
Exit For
End If
If Z = 500 Then
End If
Next Z
End Sub
Sub Tx23_receiving:
'*********Wind_direction:************'
Wind_dir = 0
For I = 1 To 4
Shift Wind_dir , Left
If Tx23_data = 1 Then
Incr Wind_dir
End If
Gosub Cekam
Next I
'**********Wind_speed**************'
Wind_speed = 0
For I = 1 To 12
Shift Wind_speed , Left
If Tx23_data = 1 Then
Incr Wind_speed
End If
Gosub Cekam
Next I
'***********Checksum***************'
Ch_sum = 0
For I = 1 To 4
Shift Ch_sum , Left
If Tx23_data = 1 Then
Incr Ch_sum
End If
Gosub Cekam
Next I
'*******Wind_dir_negated************'
Wind_dir_negated = 0
For I = 1 To 4
Shift Wind_dir_negated , Left
If Tx23_data = 1 Then
Incr Wind_dir_negated
End If
Gosub Cekam
Next I
'**********Wind_speed****************'
Wind_speed_negated = 0
For I = 1 To 12
Shift Wind_speed_negated , Left
If Tx23_data = 1 Then
Incr Wind_speed_negated
End If
Gosub Cekam
Next I
End Sub
Sub Tx23_calculating:
Temp_byte1 = Wind_dir
Gosub Byte_mirroring
Wind_dir = Temp_byte2
Shift Wind_dir , Right , 4
Temp_word3 = Wind_speed
Temp_word1 = Wind_speed
Shift Temp_word1 , Left , 4 ' zato sto se koriste
12 bitova pa da pocne od pocetka
Gosub Word_mirroring
Wind_speed = Temp_word2
Wind_speed = Wind_speed And &B0000000111111111 ' samo 9 bitova je
vazno
S = Wind_speed ' pretvaranje word u
single
L = S / 10 ' dobijanje decimalne
vrednosti
Temp_byte3 = Ch_sum
Temp_byte1 = Ch_sum
Gosub Byte_mirroring
Ch_sum = Temp_byte2
Shift Ch_sum , Right , 4
Temp_byte1 = Wind_dir_negated
Gosub Byte_mirroring
Wind_dir_negated = Temp_byte2
Wind_dir_negated = Not Wind_dir_negated
Shift Wind_dir_negated , Right , 4
Temp_word1 = Wind_speed_negated
Shift Temp_word1 , Left , 4
Gosub Word_mirroring
Wind_speed_negated = Temp_word2
Wind_speed_negated = Not Wind_speed_negated
Wind_speed_negated = Wind_speed_negated And &B0000000111111111 ' samo 9
bitova je vazno
'**********************************************'
' Racunanje smera vetra
'**********************************************'
End Sub
Sub Word_mirroring
'**********************************************
'Word mirroring
'**********************************************
' Temp_word1 ' Vrednost koja se mirroruje
Temp_word2 = 0
For J = 1 To 16
Next J
'***********************************************
End Sub
Sub Byte_mirroring
'**********************************************
'Word mirroring
'**********************************************
'Temp_byte1 ' Vrednost koja se mirroruje
Temp_byte2 = 0
For J = 1 To 8
Next J
'***********************************************
End Sub
Sub Slanje_na_esp8266
End Sub
'***************************
' Inerrupt service routine
'***************************
Rain:
Disable Int1
Debounce Pind.3 , 0 , Skok
Skok:
Kisa = Kisa + 0.57
Enable Int1
Return
Vreme1:
Disable Timer0
Incr Cekanje
If Cekanje = 65500 Then 'prva petlja oko
22minuta
Incr Cekanje2
If Cekanje2 = 10 Then
Set Signal
Cekanje2 = 0
End If
Cekanje = 0
End If
Timer0 = 0
Enable Timer0
Return
End