Chciałbym by program wyglądał tak:
-Program startuje z 0000 na wyś. Led gdzie pierwsze 2 zera to minuty a następne dwa to sek.
-Program odczytuje stan 3 przycisków : plus, minus, Enter(start odliczania)
i w tym miejscu mam problem gdyż:
oprogramowanie tych zmiennych wyświetlanych na led się wszystko krzaczy, przy dodawaniu jest jeszcze ok ale przy odejmowaniu zwalnia jakby procek był zajęty czymś innym a jak dojdzie do zera to się nie zatrzymuje tylko wkakują jakieś inne nie ustalone liczby, program ten ma obsługiwać naświetlarkę uv
Prosił bym bardzo o pomoc w kodzie by zakres był 30:00 i nie dało się więcej i żeby poniżej 00:00 także nie dało się zejść
a tu kod:
- regfile = "m8def.dat"
- $crystal = 8000000
- $hwstack = 64
- $swstack = 64
- $framesize = 128
- Config Portd = Output
- Config Portb.0 = Output
- Config Portb.1 = Output
- Config Portb.2 = Output
- Config Portb.3 = Output
- Config Pinc.0 = Input
- Config Pinc.1 = Input
- Config Pinc.2 = Input
- Portc.0 = 1
- Portc.1 = 1
- Portc.2 = 1
- Portb.0 = 0
- Portb.1 = 0
- Portb.2 = 0
- Portb.3 = 0
- Portd = 255
- W1 Alias Portb.0
- W2 Alias Portb.1
- W3 Alias Portb.2
- W4 Alias Portb.3
- Prz1 Alias Pinc.0
- Prz2 Alias Pinc.1
- Enter Alias Pinc.2
- Segmenty Alias Portd
- Declare Sub Dec2bcd(byval Liczba As Byte , Byval Pozycja_wysw As Byte , Byref Tab() As Byte)
- Dim Sekundy As Byte
- Dim s1 as Byte
- Dim m1 as byte
- Dim Minuty as byte
- Dim Wyswietlacz As Byte
- Dim Tablica(4) As Byte
- Dim Kr1 as Bit
- Dim Kr2 as Bit
- Dim Kr3 as Bit
- Dim Kr4 as Bit
- Dim f_Odej as Bit
- Dim Startuj as bit
- dim 1_sek as Word
- Dim Menu as Byte
- Config Timer0 = Timer , Prescale = 256
- On Ovf0 Przerwanie
- Load Timer0 , 65
- Enable Ovf0
- Enable Interrupts
- s1 = 0
- m1 = 0
- Sekundy = 0
- Startuj = 0
- Menu = 1
- 'Set Kr1
- 'Set Kr2
- 'Set Kr3
- 'Set Kr4
- Do
- Select Case Menu
- Case 1:
- if Prz1 = 0 then
- waitms 15
- If Prz1 = 0 Then
- s1 = s1 + 1
- gosub Wyswietl
- waitms 30
- end if
- End if
- if f_Odej = 0 then
- if Prz2 = 0 then
- waitms 15
- If Prz2 = 0 Then
- s1 = s1 - 1
- gosub Wyswietl
- waitms 30
- If m1 > 0 Then
- If s1 < 1 Then
- m1 = m1 - 1
- end if
- end if
- end if
- End if
- end if
- if s1 = 60 Then
- m1 = m1 + 1
- s1 = 0
- gosub Wyswietl
- end if
- If m1 > 0 Then 'zapalanie kropki gdy min większe od 0
- Set Kr2
- else
- Reset Kr2
- End if
- Case 2:
- End Select
- Loop
- End 'end program
- '**************************************************************
- Wyswietl:
- If Sekundy = 60 then
- Sekundy = 60
- End if
- If Minuty = 30 Then
- Minuty = 30
- Sekundy = 0
- End if
- Sekundy = s1
- Dec2bcd Sekundy , 3 , Tablica(1)
- Minuty = m1
- Dec2bcd Minuty , 1 , Tablica(1)
- return
- Przerwanie:
- Load Timer0 , 65
- Incr Wyswietlacz
- incr 1_sek
- If Wyswietlacz = 5 Then
- Wyswietlacz = 1
- End If
- ' if Startuj = 1 then
- ' 1_sek = 0
- ' if 1_sek = 481 then
- ' s1 = s1 - 1
- ' toggle Kr3
- ' 1_sek = 0
- 'end if
- 'end if
- Select Case Wyswietlacz
- Case 1:
- W4 = 1
- Segmenty = Lookup(tablica(1) , Kody7seg)
- Portd.7 = Kr1
- W1 = 0
- Case 2:
- W1 = 1
- Segmenty = Lookup(tablica(2) , Kody7seg)
- Portd.7 = Kr2
- W2 = 0
- Case 3:
- W2 = 1
- Segmenty = Lookup(tablica(3) , Kody7seg)
- Portd.7 = Kr3
- W3 = 0
- Case 4:
- W3 = 1
- Segmenty = Lookup(tablica(4) , Kody7seg)
- Portd.7 = Kr4
- W4 = 0
- End Select
- Return
- '************************************************************
- Sub Dec2bcd(byval Liczba As Byte , Byval Pozycja_wysw As Byte , Byref Tab() As Byte)
- Local Pomocnicza1 As Byte
- Local Pomocnicza2 As Byte
- Pomocnicza1 = Makebcd(liczba)
- Pomocnicza2 = Pomocnicza1 And &B00001111
- Tablica(pozycja_wysw + 1) = Pomocnicza2
- Shift Pomocnicza1 , Right , 4
- Pomocnicza2 = Pomocnicza1 And &B00001111
- Tablica(pozycja_wysw) = Pomocnicza2
- End Sub
- Kody7seg:
- Data &B00111111 , &B00000110 , &B01011011 , &B01001111 , &B01100110,
- Data &B01101101 , &B01111101 , &B00000111 , &]
