Elektroda.pl
Elektroda.pl
X
Arrow Multisolution Day
Proszę, dodaj wyjątek www.elektroda.pl do Adblock.
Dzięki temu, że oglądasz reklamy, wspierasz portal i użytkowników.

Komunikacja attiny atmega8 bascom

pini0 07 Lut 2008 13:54 2464 2
  • #1 07 Lut 2008 13:54
    pini0
    Poziom 14  

    Witam .
    Mam taki problem od 3 dni próbuje napisać program w bascomie , i nie wychodzi mi komunikacja procesorów .
    Atmega8 ma sprawdzić adc rc5 wyświetlać na lcd i wybrać się do etykiety tu jest ok ,
    natomiast attint2313 ma sterować 4pwr , led rgb i odbierać 4 klawisze .
    Próbowałem z rs232 i gubiło mi dane , i z i2c + pamięć 2402 .
    no i nie wiem co zrobić

    0 2
  • Arrow Multisolution Day
  • #2 07 Lut 2008 14:03
    Tomasz.W
    Poziom 35  

    Do wróżki Szanowny Kolego, musisz udać się do wróżki. Z tego co napisałeś nic nie wynika. Wybacz, ale nikt nie będzie się domyślał co to za układ i jak podłączony. Wstaw jakiś schemat, i napisz DOKŁADNIE jak powinno to działać.
    Pozdrowienia z Gdańska
    P.S.
    Z wróżkami ostatnio same problemy, masowo opuszczają nasz piękny kraj. Pewnie przez pogodę

    0
  • Arrow Multisolution Day
  • #3 07 Lut 2008 14:35
    pini0
    Poziom 14  

    Dzięki za pozdrowienia i za odpowiedź .
    A co do układu to jest automat do pokoju i ma sterować światłem rgb , halogenami , klawiatura umieszczona we włączniku+ dioda rgb ma sygnalizować jaka funkcja światła zostanie zmieniona , odczytać i zapisać i2c to zadanie dla attiny2313 .
    A atmega8 ma wyświetlać na wyświetlaczu co jest obecnie za funkcja , pobierać 2-wie temperatury , jasność , zasłaniać roletę , odczytywać i zapisywać w pamięci i2c bo zapamiętuje ustawienia .
    Problem polega na tym że attiny2313 jak odczytuje pamięć to porostu się nie mogą podzielić pamięcią .
    Pozdrowienia z Wejherowa

    Code:
    $regfile = "attiny2313.dat"
    
    $crystal = 8000000



    Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte)
    Declare Sub Read_eeprom(byval Adres As Byte , Value As Byte)


    Declare Sub Klawiatura
    Dim Pled As Byte
    Dim Led As Byte
    Dim A As Integer
    Dim Cz As Integer
    Dim Z As Integer
    Dim N As Byte
    Dim B As Byte
    Dim Q As Byte
    Dim Av As Byte

    Enable Interrupts
    Ddrb = &B11111111        'Oc0a,Oc1a,Oc1b = Output
    Ddrd = &B00100010        'Oc0b = Output
    Set Portd.2
    Set Portd.3
    Set Portd.4
    Set Portd.6



    Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down       ', Prescale = 8
     'Config Timer0 = Pwm , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down       'Up
    Tccr0a = &B11110001      '      &B00000000
    Ocr0a = 50
    Compare1a = 100          'OCR1AL=100,OCR1AH=0
    Ocr0b = 150
    Compare1b = 200          'OCR1BL=200,OCR1BH=0

      'Counter1 = 3   'synchronizacja T1 z T0
    Config Sda = Portb.6
    Config Scl = Portb.7
    Set Tccr0b.0             'Timer0 prescale=1       Reset
    Set Tccr1b.0             'Timer1 prescale=1    Reset
    A = 255
      Led = 12
      Q = 12
      Av = 1
    Q = 12
    B = 255
    N = 255
    Do

    Select Case Q
        Case Is <= 11 : Gosub Offf
        Case 12 : Gosub Przejscie
        Case 13 : Gosub Czerwony
        Case 14 : Gosub Niebieski
        Case 15 : Gosub Zielony
        Case 16 : Gosub Bialy
        Case Is > 17 : Gosub Offf
      End Select

    Loop


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''




    Przejscie:


    For Cz = 0 To A Step 1
    Pwm1a = Cz
    Waitus 10
    Call Klawiatura
    Next



    For N = 0 To A Step 1
    Pwm0a = N
    Waitus 10
    Call Klawiatura
    Next


    For Z = 0 To A Step 1
    Pwm1b = Z
    Waitus 10
    Call Klawiatura
    Next

    For Cz = A To 0 Step -1
    Pwm1a = Cz
    Waitus 10
    Call Klawiatura
    Next


    For N = A To 0 Step -1
    Pwm0a = N
    Waitus 10
    Call Klawiatura
    Next

    For Z = A To 0 Step -1
    Pwm1b = Z
    Waitus 10
    Call Klawiatura
    Next


    Return

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Czerwony:
    Call Klawiatura
    Pwm1a = Av



    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Niebieski:
    Call Klawiatura
    Pwm0a = Av






    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Zielony:
    Call Klawiatura
    Pwm1b = Av





    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Bialy:
    Call Klawiatura
    Pwm0b = Av


    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sub Klawiatura
    Disable Interrupts
    Set Portb.0

    If Pind.6 = 0 Then
    Waitms 20
    End If

    If Pind.2 = 0 Then
    Waitms 20
    End If

    If Pind.3 = 0 Then
    Waitms 20
    End If

    If Pind.4 = 0 Then
    Waitms 20
    End If
    'Set Portd.0


    Set Portb.1
    If Q = 12 Then
    Select Case Av
        Case Is < 1 : Av = 1
        Case 2 : Waitus 10
        Case 3 : Waitus 30
        Case 4 : Waitus 70
        Case 5 : Waitus 150
        Case 6 : Waitus 310
        Case 7 : Waitus 630
        Case 8 : Waitus 1270
        Case Is > 8 : Av = 8
      End Select
    End If

    Set Portd.0
    If Pind.0 = 0then
     Call Read_eeprom(1 , Led)
     Call Read_eeprom(2 , Q)
     Call Read_eeprom(q , Av)
    End If




    If Led = 12 Then
    'Incr Pled
    Set Portb.0
    Set Portb.1
    Set Portb.5
     Else
      Reset Portb.0
      Reset Portb.1
      Reset Portb.5
     End If
    If Led = 13 Then
    Set Portb.0
     Else
      Reset Portb.0
     End If
    If Led = 14 Then
    Set Portb.1
     Else
      Reset Portb.1
     End If
    If Led = 15 Then

     Else
      Reset Portb.5
     End If
    If Led = 16 Then
    Set Portb.0
    Set Portb.1
    Set Portb.5
     Else
      Reset Portb.0
      Reset Portb.1
      Reset Portb.5
     End If

    End Sub
    Enable Interrupts

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Offf:
    Set Portd.1
    Pwm0b = 255
    Pwm1b = 0
    Pwm0a = 255
    Pwm1a = 0
    Call Klawiatura
    Waitms 1
    Reset Portd.1
    Return

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Sub Read_eeprom(byval Adres As Byte , Value As Byte)
             I2cstart
             I2cwbyte 160
             I2cwbyte Adres
             I2cstart
             I2cwbyte 161
             I2crbyte Value , Nack
             I2cstop
          End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Sub Write_eeprom(adres As Byte , Value As Byte)

             I2cstart
             I2cwbyte 160
             I2cwbyte Adres
             I2cwbyte Value
             I2cstop
             Waitms 10

          End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    Code:
                          ' Program obsługi wbudowanego w mikrokontroler '
    
    '10-bitowego przetwornika A/C

    $regfile = "m8def.dat"   'informuje kompilator o pliku
          'dyrektyw mikrokontrolera
    $crystal = 8000000       'informuje kompilator
    $baud = 9600

          'o częstotliwości oscylatora
          'taktującego mikrokontroler
    Config Lcd = 20 * 2
    Config Lcdbus = 4
    Config Portd = &B11110000
    Config Pinb.0 = Output
    Config Pinb.1 = Output
    Config Int0 = Low Level  ' rs232 wyjście
    Config Adc = Single , Prescaler = Auto , Reference = Avcc       'konfiguracja wewnętrznego przetwornika A/C

    Config Sda = Portc.3
    Config Scl = Portc.4

    Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Byte)
    Declare Sub Read_eeprom(byval Adres As Byte , Value As Byte)

    Dim Addressw As Byte     'slave write address
    Dim Addressr As Byte     'slave read address
    'Dim Wyraz As String * 10
    Dim B1 As Byte , Adres As Byte , Value As Byte , T As Byte       'dim byte

    Config Rc5 = Pind.3 [timer2]
    Set Portd.3
    Config Serialout = Buffered , Size = 40
    '$baud = 2400
    '$lib "mcsbyte.lbx"
    'Config Int0 = Low Level
    Enable Interrupts




    Dim A As Byte

    Dim Wart_ac0 As Word     'zmienna na wartość odczytaną
    Dim Wart_ac1 As Integer
    Dim Wart_ac2 As Integer  'Word
    Dim Wart_ac3 As Integer
    Dim Wart_ac4 As Integer
    Dim Wart_ac5 As Integer

    'Dim V0 As Single
    Dim V1 As Single
    Dim V2 As Single
    Dim V3 As Single         ' Integer        Double         '
    Dim V4 As Single
    Dim V5 As Single

    Dim Wart_temp0 As Integer
    Dim Wart_temp1 As String * 3
    Dim Wart_temp2 As String * 3
    Dim Wart_temp3 As String * 3       ' Integer
    Dim Wart_temp4 As String * 3
    Dim Wart_temp5 As String * 3

    Dim Address As Byte , Command As Byte
    Dim Meni As Byte
    Dim Vol As Byte

    Dim M As Byte
    Dim Ms As Byte
    Ms = 5
    M = 1
    Cls
    Lcd "<=PINIO=> POKOJ.M8"
    Wait 1
    Cls
    Lcd "Szukam urzadzen ";
    Lowerline
    Lcd "na szynie I2C   ";
    Set Portd.2
    For Addressw = 2 To 254 Step 2
       I2cstart
       I2cwbyte Addressw
       I2cstop
       If Err = 0 Then Exit For
    Next
    Cls
    If Addressw < 255 Then
       Lcd "Adres &H" ; Hex(addressw);
       Lowerline
       Lcd "odpowiedzial ACK";
       Addressr = Addressw + 1
       Wait 2
       Cls
       Lcd "Addressr=" ; Addressr
       Lowerline
       Lcd "Addressw=" ; Addressw
    Else
       Lcd "Urzadzenia nie";
       Lowerline
       Lcd "odpowiadaja :(";
       Stop
    End If
    Print " super "
    Waitms 2
    Sound Pinb.1 , 100 , 10
    Reset Portd.2


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'Goto Witaj
    Portb.0 = 0
    Do
    Start Adc
     Wart_ac0 = Getadc(0)    'sztuczna masa temperatura bateri
     Wart_ac1 = Getadc(1)    'foto dioda
     Wart_ac2 = Getadc(2)    'lm35 out
     Wart_ac3 = Getadc(3)    'lm35 in room
     Wart_ac4 = Getadc(4)    '???
     Wart_ac5 = Getadc(5)    'batery
     Stop Adc
    ''''''''''''''''''''''OBLICZANIE''''''''''''''''''''''''''''''''''''''''''''''''
       Wart_temp0 = 277 - Wart_ac0
       Wart_ac1 = Wart_ac1 - Wart_ac0       'foto dioda
       V5 = Wart_ac5 * 0.05  'napięcie baterii'

      If Wart_ac2 < Wart_ac0 Then V2 = V2 * -1       'czujnik 1 najpierw sprawdzam czy adc1 jest mniejsze od masy(adc0)
       Wart_ac2 = Wart_ac2 - Wart_ac0
        V2 = Wart_ac2 * 0.5
        ' Wart_temp2 =

      If Wart_ac3 < Wart_ac0 Then V3 = V3 * -1       'czujnik 2 najpierw sprawdzam czy adc1 jest mniejsze od masy(adc0)
       Wart_ac3 = Wart_ac3 - Wart_ac0
        V3 = Wart_ac3 * 0.5
        ' Wart_temp3 = Fusing(v3 , "#.&&")


    '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Enable Interrupts
    Getrc5(address , Command)
    Command = Command And &B01111111

    If Address <> 255 Then
    Waitms 20
    Sound Pinb.1 , 100 , 20
    Sound Pinb.1 , 100 , 30
    Cls
    Lcd Command
    Select Case Command
        Case 32 : Meni = Meni + 1
        Case 33 : Meni = Meni - 1
        Case 15 : Gosub Odczyttemp
        Case 13 : Gosub Bateria
        Case 38 : Gosub Odczyttemp
        Case 12 : Toggle Portb.0
        Case 16 : Vol = Vol + 1
        Case 17 : Vol = Vol - 1
      End Select
      End If


    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Select Case Meni
        Case Is < 1 : Meni = 0
        Case 0 : Gosub Offf
        Case 1 : Gosub Bateria
        Case 2 : Gosub Przejscie
        Case 3 : Gosub Czerwony
        Case 4 : Gosub Niebieski
        Case 5 : Gosub Zielony
        Case 6 : Gosub Bialy
        Case 7 : Gosub Roleta
        Case 8 : Gosub Odczyttemp
        Case 9 : Gosub Witaj
        Case Is > 9 : Meni = 9
     End Select

    Loop
    End

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Odczyttemp:
     Print "jasnosc=" ; Wart_ac1
     Waitms 50               'opóźnienie 100 ms
     Print "t1=" ; Fusing(v2 , "  #.&") ; "`C"
     Print "t2=" ; Fusing(v3 , "  #.&") ; "`C"
     Print "tempB" ; Wart_temp0 ; "`C"
    Cls
    Home Upper
     Lcd "jasnosc=" ; Wart_ac1 ; "tempB" ; Wart_temp0 ; "`C"

     Lowerline

     Lcd "t1=" ; Fusing(v2 , "  #.&") ; "`C" ; " t2=" ; Fusing(v3 , "  #.&") ; "`C"       ' Wart_ac2 ;  Wart_temp2    Wart_ac1
     '
     Call Write_eeprom(2 , 11)
       Call Write_eeprom(5 , 25)
       Call Write_eeprom(9 , 111)
       Call Read_eeprom(t , B1)
       Wait 1
       Cls
       Lcd "ADRES" ; T ; "WYNIK" ; B1
    '   If B1 = &HFF Or B1 = 0 Or T > 10 Then Exit Do
     '  Wyraz = Wyraz + Chr(b1)
       Incr T


    ' Waitms 2

     'Waitms 2


     Return

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Witaj:
     'Dim A As Byte
    'Do
    Cls                      'kasujemy LCD
    Lcd "Witaj swiecie"      'wydrukujemy tekst w górnej linii
    Print " witaj "
    Waitms 20
    Lowerline                'wybieramy drugą linię
    Waitms 20
    Lcd "   Pinio    "       'wydrukujemy to w drugiej linii

    Waitms 20

    For A = 1 To 10
       Shiftlcd Right        'przesuniemy tekst w prawo
       Waitms 20             'czekamy aż wykona
    Next

    For A = 1 To 10
       Shiftlcd Left         'przesuniemy tekst w lewo
       Waitms 20             'czekamy aż wykona
    Next


    Cursor Off Noblink       'chowamy kursor
    Waitms 20                'czekamy
    'Cursor On Blink          'pokazujemy kursor

    'Waitms 20                'czekamy
    'Display Off              'wyłączamy wyświetlacz

    'Waitms 20                 'czekamy
    'Display On

    Cls                      'wybieramy Data RAM

    Return

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''



    Bateria:


    If V5 < 12 Then Portb.0 = 1
    If V5 > 14 Then Portb.0 = 0
    If Wart_temp0 > 35 Then Portb.0 = 0
    'Cls
    'Lcd "bat=" ; Fusing(v5 , "  #.&&") ; " temp=" ; Wart_temp0 ; " =" ; Portd.2

    Waitms 100
    Print "bat =" ; Fusing(v5 , "#.&&")
    Print "temp =" ; Wart_temp0
    Print "ładowanie =" ; Portd.2

    Return

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    Offf:
    Call Write_eeprom(2 , 10)
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


    Przejscie:
    Cls
    Lcd "PRZEJŚCIE ="
      Call Read_eeprom(12 , B1)
      If B1 > 8 Then B1 = 8

      Call Write_eeprom(1 , 12)
      If Command = 16 Then
      Call Write_eeprom(2 , 12)
      Call Write_eeprom(12 , Vol)
      End If
      If Command = 17 Then
      Call Write_eeprom(2 , 12)
      Call Write_eeprom(12 , Vol)
      End If
      Vol = B1
    Lcd B1
    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Czerwony:
    Cls
    Lcd "CZERWONY ="
      Call Read_eeprom(13 , B1)
      Call Read_eeprom(2 , T)
      Call Write_eeprom(1 , 13)
      If Command = 16 Then
      Call Write_eeprom(2 , 13)
       Call Write_eeprom(13 , Vol)
      End If

      'End If
      If Command = 17 Then
       Call Write_eeprom(2 , 13)
      Call Write_eeprom(13 , Vol)
      End If
      Vol = B1
    Lcd B1 ; " " ; T
    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Niebieski:
    Cls
    Lcd "NIEBIESKI"
      Call Read_eeprom(14 , B1)

      Call Write_eeprom(1 , 14)
        If Command = 16 Then
        Call Write_eeprom(2 , 14)
        Call Write_eeprom(14 , Vol)
      End If

      'End If
      If Command = 17 Then
      Call Write_eeprom(2 , 14)
      Call Write_eeprom(14 , Vol)
      End If
      Vol = B1
    Lcd B1
    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Zielony:
    Cls
    Lcd "ZIELONY"
      Call Read_eeprom(15 , B1)

      Call Write_eeprom(1 , 15)
        If Command = 16 Then
        Call Write_eeprom(2 , 15)
        Call Write_eeprom(15 , Vol)
      End If

      'End If
      If Command = 17 Then
      Call Write_eeprom(2 , 15)
      Call Write_eeprom(15 , Vol)
      End If
      Vol = B1
    Lcd B1
    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Bialy:
    Cls
    Lcd "BIAŁY"
    Call Read_eeprom(16 , B1)

      Call Write_eeprom(1 , 16)
         If Command = 16 Then
          Call Write_eeprom(2 , 16)
         Call Write_eeprom(16 , Vol)
      End If

      'End If
      If Command = 17 Then
        Call Write_eeprom(2 , 16)
      Call Write_eeprom(16 , Vol)
      End If
     Vol = B1
    Lcd B1
    Return
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Roleta:
    Portb.0 = 1
    Waitms 20
    Cls
    Lcd "ROLETA"

    If Command = 17 Then

    Do
    Toggle Portb.0
    Portd = &B00010000
    Waitms Ms
    Portd = &B00110010
    Waitms Ms
    Portd = &B00100000
    Waitms Ms
    Portd = &B01100000
    Waitms Ms
    Portd = &B01000000
    Waitms Ms
    Portd = &B11000010
    Waitms Ms
    Portd = &B10000000
    Waitms Ms
    Portd = &B10010000
    Waitms Ms
    If M = 1 Then
    'Cls
    Lcd " TRYB NOCNY "
    Lowerline
    Lcd " PROSZĘ CZEKAĆ "    'ROLETA
    Waitms 50
    Print "ROLETA NA DÓŁ PROSZĘ CZEKAĆ"
    End If
    M = M + 1
    Ms = Ms - 1
    If Ms <= 1 Then Ms = 1
    Loop Until M = 100       'Until M <> 60
    Portd = &B00000000
    Ms = 5

    Waitms 50
    Print "ZAKOŃCZONO"
    Cls
    Lcd "ZAKOŃCZONO"
    End If


    If Command = 16 And M = 100 Then
    Do
    Toggle Portb.0

    Portd = &B00010000
    Waitms Ms
    Portd = &B10010000
    Waitms Ms
    Portd = &B10000000
    Waitms Ms
    Portd = &B11000000
    Waitms Ms
    Portd = &B01000000
    Waitms Ms
    Portd = &B01100000
    Waitms Ms
    Portd = &B00100000
    Waitms Ms
    Portd = &B00110000
    Waitms Ms
    If M = 100 Then
    'Cls
    Lcd " TRYB DZIENNY "
    Lowerline
    Lcd " PROSZĘ CZEKAĆ "    ' ROLETA  W GURE
    'Waitms 50
    Print "ROLETA W GURE PROSZĘ CZEKAĆ"
    End If
    M = M - 1
    Ms = Ms - 1
    If Ms <= 1 Then Ms = 1

    Loop Until M = 1
    Portd = &B00000000
    Ms = 5
    Waitms 50
    Print "ZAKOŃCZONO"
    Cls
    Lcd "ZAKOŃCZONO"
    End If

    Return

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    'Program wykonujący odczyt z pamięci EEPROM
    Sub Read_eeprom(byval Adres As Byte , Value As Byte)
    If Pind.2 = 1 Then
    Set Portd.2
    I2cstart
    I2cwbyte Addressw
    I2cwbyte Adres
    I2cstart
    I2cwbyte Addressr
    I2crbyte Value , Nack
    I2cstop
    Waitms 5
    Reset Portd.2
    End Sub
    End If
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Sub Write_eeprom(adres As Byte , Value As Byte)
     If Pind.2 = 1 Then
             Set Portd.2
             I2cstart
             I2cwbyte Addressw
             I2cwbyte Adres
             I2cwbyte Value
             I2cstop
             Waitms 10
             Reset Portd.2
         End Sub
     End If

    0