Pytania, kody i porady dotyczące nie tylko Bascom.
-
elektrofil
- Posty: 14
- Rejestracja: 21 maja 2021, 15:13
Post
autor: elektrofil » 11 sty 2025, 10:48
Witam,mój problem polega na tym, iż nie potrafię odczytać źródła resetu w mikrokontrolerze atmega88
oto wycinek kodu który miałby to robić:
Mcureg = Peek(mcusr)' (&h34) ' Adres rejestru MCU Status Register (MCUSR)
print "mcureg=";mcureg
' Sprawdź źródło resetu
If Mcureg.wdrf = 1 Then ' Czy reset nastąpił przez Watchdog?
Watchdog_flag = 1
Print "Reset przez Watchdog"
End If
If Mcureg.porf = 1 Then ' Czy reset nastąpił przez Power-On Reset?
Poweron_flag = 1
Print "Reset przez Power-On"
End If
If Mcureg.extrf = 1 Then ' Czy reset nastąpił przez zewnętrzny sygnał RESET?
External_reset = 1
Print "Reset przez zewnętrzny sygnał"
End If
' Wyczyść rejestr MCUSR po odczytaniu
Poke 0h34 , 0
niestety niezależnie od źródła resetu wskazuje 0 czyli brak źródła resetu.
-
niveasoft
- Posty: 1266
- Rejestracja: 17 sie 2015, 12:13
-
Kontakt:
Post
autor: niveasoft » 12 sty 2025, 5:10
W samplach jest przykład dla Watchdoga własnie dla M88
$regfile = "m88def.dat" ' specify the used micro
$crystal = 8000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 32 ' default use 32 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim B As Byte
Dim Wdbit As Bit
B = R0 ' read the wd flag
Print "Watchdog test"
If B.wdrf = 1 Then ' there was a WD overflow
Wdbit = 1 ' store the flag
End If
Trzeba to odczytac na poczatku bo potem ginie a dodatkowo Bascom czyści RAM wiec Bascom to chyba przepisuje do R0
For chips that have an enhanced WD timer, the WD timer is cleared as part of the chip initialize procedure. This because otherwise the WD timer will only work once. If it is important to know the cause of the reset, you can read the register R0 before you run other code.
When the chip resets, the status registers with the reset cause bits is saved into register R0.
This is done because the compiler need to reset these flags since otherwise they can not occur again. And before clearing the bits, the status is saved into register R0.
-
elektrofil
- Posty: 14
- Rejestracja: 21 maja 2021, 15:13
Post
autor: elektrofil » 12 sty 2025, 12:27
bardzo ważne jest aby
było pierwszym rozkazie w kodzie.