$regfile = "m32def.dat"
$crystal = 8000000
$hwstack = 128
$swstack = 64
$framesize = 128
$baud = 9600
'*******************************pierdoly****************************************
$projecttime = 15
$version 0 , 0 , 12
Dim Firmware As String * 6
Firmware = "1.0A"
Config Submode = New
'Debug On
'*****************************Serial_0******************************************
Config Serialin = Buffered , Size = 100
'**************************Wyswietlacz******************************************
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2
Config Lcd = 20 * 4
'*****************************Zmienne*******************************************
Dim Sds011_rx_frame(10) As Byte
Dim Pm25_raw As Word At Sds011_rx_frame(3) Overlay 'nakladka na komorke 3 i 4 jeszcze przed indianinem
Dim Pm10_raw As Word At Sds011_rx_frame(5) Overlay 'nakladka na komorke 5 i 6 jeszcze przed indianinem
Dim Pm25_tmp As Word
Dim Pm10_tmp As Word
Dim Pm25 As Word
Dim Pm10 As Word
'******************************Stale********************************************
Const Naglowek = &HAA 'naglowek hex AA dziesietnie 170
Const Komenda = &HC0
'******************************Takie tam ***************************************
Enable Interrupts
Cursor Off
Cls
Wait 1
Locate 1 , 1 : Lcd "czekam na dane: "
Locate 2 , 1 : Lcd "PM2.5= " ; Pm25 'wyswietl
Locate 3 , 1 : Lcd "PM10= " ; Pm10 'wyswietl
'*******************************SUBY********************************************
'*************************SUB sprawdz UART ************************************
Sub Sds011_rx() 'v0.1A '
'******************************nasza ranka z danymi*****************************
'AA C0 71 01 88 02 99 AC 41 AB
'Sds011_rx_frame(1) = &HAA 'Naglowek
'Sds011_rx_frame(2) = &HC0 'ID
'Sds011_rx_frame(3) = &H71 'PM2.5_Low
'Sds011_rx_frame(4) = &H01 'PM2.5_high
'Sds011_rx_frame(5) = &H88 'PM10_low
'Sds011_rx_frame(6) = &H02 'PM10_high
'Sds011_rx_frame(7) = &H99 'Id_byte1
'Sds011_rx_frame(8) = &HAC 'Id_byte2
'Sds011_rx_frame(9) = &H41 'CRC
'Sds011_rx_frame(10) = &HAB 'Termiantor
'*******************************************************************************
While Ischarwaiting() <> 0 'gdy dane w buforze
Inputbin , Sds011_rx_frame(1) , 1 'odbierz pierwszy bajt
'Locate 1 , 1 : Lcd "odebralem: " ; Sds011_rx_frame(1)
Select Case Sds011_rx_frame(1) 'sprawdzenie zawartosci pierwszej komorki
'**********************************************************************
Case Naglowek: 'jelsi nag³owek to AA
Inputbin Sds011_rx_frame(2) , 9 'odbierz reszte
'tu mozna by sprawdzic CRC ale olej my to narazie
'mozemy jeszcze sprawdzic czy comenda i stopka sie zgadza
If Sds011_rx_frame(2) = &HC0 And Sds011_rx_frame(10) = &HAB Then
'mamy juz dane teraz trzeba zrobic endianina
Swap Pm25_raw 'maly endian na duzego
Pm25_tmp = Pm25_raw / 10
If Pm25_tmp <> Pm25 Then
Pm25 = Pm25_tmp
Locate 2 , 1 : Lcd "PM2.5= " ; Pm25 'wyswietl
End If
Swap Pm10_raw 'maly endian na duzego
Pm10_tmp = Pm10_raw / 10
If Pm10_tmp <> Pm10 Then
Pm10 = Pm10_tmp
Locate 3 , 1 : Lcd "PM10= " ; Pm10 'wyswietl
End If
Else
Cls
Locate 4 , 1 : Lcd "blad ramki"
End If
'************************************************************************
Case Else:
Cls
Locate 1 , 1 : Lcd "blad naglowka"
Clear Serialin 'change the serila number to clear correct buffer
Locate 2 , 1 : Lcd "odebralem: " ; Sds011_rx_frame(1)
End Select
Wend
End Sub
'*******************************************************************************
Do
Call Sds011_rx
Loop
End