Poniżej przedstawiam kod nieszczęsnego programu:
Kod: Zaznacz cały
Config Lcd = 16 * 2
Config Timer1 = Timer , Mode = 1 , Gate = Internal
Deflcdchar 0 , 32 , 16 , 24 , 28 , 30 , 28 , 24 , 16
Deflcdchar 1 , 32 , 1 , 3 , 7 , 15 , 7 , 3 , 1
Dim M As Byte
Dim S As Byte
Dim H As Byte
Dim Vol As Integer
Dim Wartosc As Byte
Dim Flaga As Byte
Dim Subaddress As Byte
Dim Command As Byte
Dim Zmienna As Byte
Dim Ster As Byte
Dim Kod As Bit
Dim Wskaznik As Bit
Dim Wskaznik2 As Bit
Dim Funkcja As String * 14
Declare Sub Obslugatimera
Enable Timer1
Enable Int0
Enable Interrupts
On Int0 Recrc5
On Timer1 Zliczaj
I2cstart
I2cwbyte 130
I2cwbyte 0
I2cwbyte 212
I2cstart
I2cwbyte 130
I2cwbyte 1
I2cwbyte 212
I2cstart
I2cwbyte 130
I2cwbyte 2
I2cwbyte 246
I2cstart
I2cwbyte 130
I2cwbyte 3
I2cwbyte 246
I2cstart
I2cwbyte 130
I2cwbyte 8
I2cwbyte 206
I2cstop
Vol = -80
Wartosc = 212
Meni Alias P3.0
Up Alias P3.1
Down Alias P3.3
Selekt Alias P3.4
Wskaznik2 = 0
Do
Enable Interrupts
Set Meni
Set Up
Set Down
Set Selekt
If Kod = 1 Then
If Subaddress = 0 Then
Zmienna = Command
Kod = 0
Else
End If
End If
If Up = 0 Or Zmienna = 16 Then
Waitms 20
Gosub Starttimera
Gosub Volup
Zmienna = 0
End If
If Down = 0 Or Zmienna = 17 Then
Waitms 20
Gosub Starttimera
Gosub Voldown
Zmienna = 0
End If
If Meni = 0 Or Zmienna = 43 Then
Set Wskaznik2
Zmienna = 0
End If
If Wskaznik2 = 1 Then
Wait 1
Gosub Menu
End If
Gosub Zegar
Loop
End
Recrc5:
Disable Interrupts
Getrc5(subaddress , Command)
Kod = 1
Return
Starttimera:
Set Wskaznik
Flaga = 0
Stop Timer1
Load Timer1 , 0
Start Timer1
Return
Zegar:
I2cstart
I2cwbyte 162
I2cwbyte 2
I2cstart
I2cwbyte 163
I2crbyte S , Ack
I2crbyte M , Ack
I2crbyte H , Nack
I2cstop
H = Makedec(h)
M = Makedec(m)
S = Makedec(s)
Cls
If H < 10 Then
Locate 1 , 6
Else
Locate 1 , 5
End If
If M < 10 And S < 10 Then
Lcd H ; ":0" ; M ; ":0" ; S
Elseif M < 10 And S > 9 Then
Lcd H ; ":0" ; M ; ":" ; S
Elseif M > 9 And S < 10 Then
Lcd H ; ":" ; M ; ":0" ; S
Elseif M > 9 And S > 9 Then
Lcd H ; ":" ; M ; ":" ; S
End If
'If Wskaznik = 1 Then
'Lowerline
'Lcd " Vol = " ; Vol ; "dB"
'Else
'If Kod = 1 Then
Lowerline
Lcd "S: " ; Subaddress ; "C: " ; Command
'End If
'End If
Cursor Off Noblink
Waitms 80
Return
Volup:
If Wartosc = 255 Then
Else
Vol = Vol + 2
Incr Wartosc
End If
Gosub Zapisz
Return
Voldown:
If Wartosc = 212 Then
Else
Vol = Vol - 2
Decr Wartosc
End If
Gosub Zapisz
Return
Zapisz:
I2cstart
I2cwbyte 130
I2cwbyte 0
I2cwbyte Wartosc
I2cstart
I2cwbyte 130
I2cwbyte 1
I2cwbyte Wartosc
I2cstop
Return
$large
Sub Obslugatimera
Incr Flaga
Waitms 1
If Flaga = 70 Then
Reset Wskaznik
Flaga = 0
End If
End Sub
Return
Zliczaj:
Call Obslugatimera
Return
Menu:
Ster = 3
Do
Enable Interrupts
Set Meni
Set Up
Set Down
Set Selekt
If Kod = 1 Then
If Subaddress = 0 Then
Zmienna = Command
Kod = 0
Else
End If
End If
If Up = 0 Or Zmienna = 42 Then
Incr Ster
If Ster = 3 Then
End If
Zmienna = 0
End If
If Down = 0 Or Zmienna = 46 Then
Decr Ster
If Ster = 0 Then
End If
Zmienna = 0
End If
If Ster = 3 Then Funkcja = "Clock setup "
If Ster = 2 Then Funkcja = "Trebble "
If Ster = 1 Then Funkcja = "bas "
If Ster = 0 Then Funkcja = "Sound mode "
Cls
Locate 1 , 7
Lcd "Menu"
Gosub Dolnalinia
Waitms 80
If Meni = 0 Or Zmienna = 43 Then
Reset Wskaznik2
Zmienna = 0
Wait 1
End If
Loop Until Wskaznik2 = 0
Return
Dolnalinia:
Lowerline
Lcd Chr(0) ; Funkcja ; Chr(1)
Return