jak w Bascom odczytać zródłó resetu dla m88

Pytania, kody i porady dotyczące nie tylko Bascom.
ODPOWIEDZ
Awatar użytkownika
elektrofil
Posty: 14
Rejestracja: 21 maja 2021, 15:13

jak w Bascom odczytać zródłó resetu dla m88

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ć:
  1. Mcureg = Peek(mcusr)' (&h34)        ' Adres rejestru MCU Status Register (MCUSR)
  2.         print "mcureg=";mcureg
  3. ' Sprawdź źródło resetu
  4. If Mcureg.wdrf = 1 Then     ' Czy reset nastąpił przez Watchdog?
  5.     Watchdog_flag = 1
  6.     Print "Reset przez Watchdog"
  7. End If
  8.  
  9. If Mcureg.porf = 1 Then     ' Czy reset nastąpił przez Power-On Reset?
  10.     Poweron_flag = 1
  11.     Print "Reset przez Power-On"
  12. End If
  13.  
  14. If Mcureg.extrf = 1 Then    ' Czy reset nastąpił przez zewnętrzny sygnał RESET?
  15.     External_reset = 1
  16.     Print "Reset przez zewnętrzny sygnał"
  17. End If
  18.  
  19. ' Wyczyść rejestr MCUSR po odczytaniu
  20. Poke 0h34 , 0
niestety niezależnie od źródła resetu wskazuje 0 czyli brak źródła resetu.
Awatar użytkownika
niveasoft
Posty: 1266
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: jak w Bascom odczytać zródłó resetu dla m88

Post autor: niveasoft » 12 sty 2025, 5:10

W samplach jest przykład dla Watchdoga własnie dla M88
  1. $regfile = "m88def.dat"                                     ' specify the used micro
  2. $crystal = 8000000                                          ' used crystal frequency
  3. $baud = 19200                                               ' use baud rate
  4. $hwstack = 32                                               ' default use 32 for the hardware stack
  5. $swstack = 32                                               ' default use 32 for the SW stack
  6. $framesize = 40                                             ' default use 40 for the frame space
  7. Dim B As Byte
  8. Dim Wdbit As Bit
  9.  
  10. B = R0                                                      ' read the wd flag
  11.  
  12. Print "Watchdog test"
  13. If B.wdrf = 1 Then                                          ' there was a WD overflow
  14.    Wdbit = 1                                                ' store the flag
  15. 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.
Awatar użytkownika
elektrofil
Posty: 14
Rejestracja: 21 maja 2021, 15:13

Re: jak w Bascom odczytać zródłó resetu dla m88

Post autor: elektrofil » 12 sty 2025, 12:27

bardzo ważne jest aby było pierwszym rozkazie w kodzie.
ODPOWIEDZ