$regfile = "m88def.dat" $crystal = 8000000 $hwstack = 40 $swstack = 40 $framesize = 40 $baud = 19200 'Baud = 19200 '##### RFM12 interrupt inputs ##### '################################### Config Portc.2 = Output Cut Alias Portc.2 Cut = 1 Config Pind.2 = Input Pind.2 = 1 Config Pinc.3 = Input Nirq Alias Pinc.3 Config Portd.6 = Output Ws2801 Alias Portd.6 Config Pind.5 = Input Lr Alias Pind.5 Config Adc = Free , Prescaler = Auto , Reference = Internal '##### variables ##### '####################### Dim Leer As Byte Dim Analogwert As Word Dim Checks As Byte Dim Count As Byte Dim Temp As Byte Dim Rx(41) As Byte Dim Cmd(2) As Byte Dim Fifo(4) As Byte Dim Temp2 As Single Declare Sub Rf_cmd(byval Wert As Word) Dim R As Byte Dim G As Byte Dim B As Byte '##### SPIconfig RFM12 ##### '############################## Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 64 , Noss = 0 , Spiin = &HB0 Spiinit Enable Int0 Config Int0 = Falling On Int0 Intempfangen Enable Interrupts Print "start" Waitms 200 '##### RFM12 settings ##### '############################ Waitms 100 Call Rf_cmd(&H0000) 'read status Call Rf_cmd(&Hc0e0) 'low battery, clock 10 MHz Call Rf_cmd(&H80e7) 'Configuration: 868MHzband, 12pf Call Rf_cmd(&H82d8) 'power management: enable receiver, enable clock output Call Rf_cmd(&Hc2ac) 'data filter command Call Rf_cmd(&Ha686) 'Frequency: 868,35MHz Call Rf_cmd(&Hc611) 'Datarate: 19,2 kbit Call Rf_cmd(&H94a1) 'receiver setting: 134kHz, -97dbm Call Rf_cmd(&Hc2ac) 'data filter: Call Rf_cmd(&Hc483) 'AFC: Call Rf_cmd(&H9850) 'TX control Call Rf_cmd(&He000) 'wake-up Call Rf_cmd(&Hc800) 'low duty-cycle Call Rf_cmd(&Hca81) 'Reset FIFO Call Rf_cmd(&Hca83) 'enable FIFO Call Rf_cmd(&H0000) 'read status '##### main loop ##### '####################### Do For Count = 1 To 41 Bitwait Nirq , Reset Spiin Fifo(1) , 2 Rx(count) = Fifo(2) Next Count Call Rf_cmd(&H0000) 'read status Call Rf_cmd(&Hca81) 'Reset FIFO Call Rf_cmd(&Hca83) 'enable FIFO Checks = Crc8(rx(1) , 40) If Checks = Rx(41) Then If Lr = 1 Then 'links Temp2 = Rx(4) * 0.6 'Rotkorrektur LED2 Rx(4) = Round(temp2) 'Rotkorrektur LED2 Temp2 = Rx(7) * 0.6 'Rotkorrektur LED3 Rx(7) = Round(temp2) 'Rotkorrektur LED3 Temp2 = Rx(10) * 0.6 'Rotkorrektur LED4 Rx(10) = Round(temp2) 'Rotkorrektur LED4 Ws2801 = 1 ' For Count = 13 To 1 Step -3 ' Spiout Rx(count) , 3 ' Next Count Spiout Rx(13) , 1 Spiout Rx(14) , 1 Spiout Rx(15) , 1 Spiout Rx(10) , 1 Spiout Rx(11) , 1 Spiout Rx(12) , 1 Spiout Rx(7) , 1 Spiout Rx(8) , 1 Spiout Rx(9) , 1 Spiout Rx(4) , 1 Spiout Rx(5) , 1 Spiout Rx(6) , 1 Spiout Rx(1) , 1 Spiout Rx(2) , 1 Spiout Rx(3) , 1 Ws2801 = 0 Else 'rechts Temp2 = Rx(16) * 0.5 'Rotkorrektur LED1 Rx(16) = Round(temp2) 'Rotkorrektur LED1 Ws2801 = 1 ' For Count = 28 To 16 Step -3 ' Spiout Rx(count) , 3 ' Next Count Spiout Rx(28) , 1 Spiout Rx(29) , 1 Spiout Rx(30) , 1 Spiout Rx(25) , 1 Spiout Rx(26) , 1 Spiout Rx(27) , 1 Spiout Rx(22) , 1 Spiout Rx(23) , 1 Spiout Rx(24) , 1 Spiout Rx(19) , 1 Spiout Rx(20) , 1 Spiout Rx(21) , 1 Spiout Rx(16) , 1 Spiout Rx(17) , 1 Spiout Rx(18) , 1 Ws2801 = 0 End If End If Analogwert = Getadc(1) If Analogwert <= 268 Then Incr Leer Else Decr Leer '3,3V If Leer = 255 Then Leer = 0 If Leer > 10 Then Cut = 0 Loop End '##### subroutine ##### '######################## Sub Rf_cmd(byval Wert As Word) Cmd(2) = Wert And 255 Shift Wert , Right , 8 Cmd(1) = Wert Spiout Cmd(1) , 2 End Sub Intempfangen: Waitms 100 If Pind.2 = 0 Then Portc.2 = 0 Return