Dell emulator zasilacza attiny 13 prośba o opis kodu

Pytania, kody i porady dotyczące nie tylko Bascom.
ODPOWIEDZ
grafii1
Posty: 58
Rejestracja: 23 wrz 2018, 11:28

Dell emulator zasilacza attiny 13 prośba o opis kodu

Post autor: grafii1 » 13 maja 2019, 9:34

Witam , czy mógłbym prosić o prosty opis kodu do emulatora zasilacza , kod z sieci i działa . Te modele mają identyfikacje na 3 przewodzie . Układ działa , większa część kodu jest dla mnie zrozumiała lecz przy " mnemoniki procesorów AVR " trochę się gubię ...
  1. '1mulation eines DS2501 aus Dell Notebook netzteilen
  2.  
  3.  
  4. ' Entwicklung basiert auf folgenden Quellen :
  5.  
  6. ' Dallas DS 2501/02 Datasheet
  7. ' Webseite Wolfgang Pöllinger -> www.wpö.de
  8. ' Webseite http://www.howtofixcomputers.com/forums/dell/dell-pa-10-ac-adapter-center-pin-108608.html
  9. ' Webseite http://www.laptop-junction.com/toast/content/inside-dell-ac-power-adapter-mystery-revealed
  10. ' Webseite http://www.ringwelt.de/computer/pc/dell-d600-mit-12v-netzteil.html
  11. ' Webseite http://bascom.at.ua/publ/1-1-0-1
  12.  
  13.  
  14. '  Attiny 13 V  ---   UB = 3,6 Volt  -- 78L05 + 2x 1n4148 an dessen Ausgang --  gespeist aus 19 Volt von Dell
  15. '  1Wire an Pin2 = PB3
  16.  
  17. '
  18. '
  19. '
  20. '
  21. '               + VCC +3,6
  22. '                  +
  23. '                  |
  24. '                 .-.
  25. '                 | | 4k7
  26. '                 | |
  27. '                 '-'
  28. '                  | ___
  29. '  Dell 1 Wire  o--o|___|---------> PB3
  30.  
  31. '                    220R
  32. '
  33. '
  34. '
  35.  
  36. ' (created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)
  37.  
  38.  
  39.  
  40.  
  41. $crystal = 9600000
  42. $regfile = "attiny13.dat"
  43.  
  44.  
  45. $hwstack = 32
  46. $swstack = 8
  47. $framesize = 16
  48.  
  49. Wait 1
  50.  
  51. Dim Incommand(2) As Byte
  52. Dim Bytedat As Byte
  53. Dim Bytedatbuffer As Byte
  54.  
  55. Dim I As Byte
  56. Dim B As Byte
  57. Dim Crc As Byte
  58. Dim Bufstart As Byte
  59.  
  60.  
  61.  
  62. ' Commands
  63.  
  64. Const Skip_rom = &HCC
  65. Const Read_rom = &H33
  66. Const Read_mem = &HF0
  67.  
  68. ' we use port b .3
  69. Const Dqpin = 3
  70. Const Ipin = 0                                              ' value in DDRB for input
  71. Const Opin = 1                                              ' value in DDRB for output
  72. Dq Alias Pinb.dqpin
  73.  
  74.  
  75.  
  76. ' Timings
  77.  
  78. Const Owpresent = 150
  79. Const Owpause = 50
  80. Const Owstrobe = 15
  81. Const Owdata = 25
  82.  
  83. ' Timer Delays
  84.  
  85. Const T1reset = 60
  86. Const Timeout = 120
  87.  
  88. ' ***********************  TIMER and ISR
  89. Config Timer0 = Timer , Prescale = 64
  90. Stop Timer0
  91. Enable Timer0
  92. On Timer0 Isr Nosave
  93. Timer_t0 Alias Tcnt0
  94. '***************************************
  95.  
  96.  
  97.  
  98.  
  99. Mainloop:
  100. Waitreset:
  101.  
  102.     Disable Interrupts
  103.     Timer_t0 = 0
  104.  
  105. Waitfall:
  106.  
  107. L1:
  108.     sbis pinb, DqPin
  109.     rjmp L1
  110. L2:
  111.     sbic pinb, DqPin
  112.     rjmp L2
  113.  
  114.     Start Timer0
  115.  
  116. Rwaitrise:
  117.  
  118. L01:
  119.     sbic pinb, DqPin
  120.     rjmp L01
  121. L02:
  122.     sbis pinb, DqPin
  123.     rjmp L02
  124.  
  125.     Stop Timer0
  126.  
  127.     If Timer_t0 < T1reset Then Goto Waitreset
  128.     If Timer_t0 > Timeout Then Goto Waitreset
  129.  
  130.  
  131. Sendpresense:
  132.     Waitus Owpause
  133.  
  134.     Ddrb.dqpin = Opin
  135.  
  136.     Waitus Owpresent
  137.     Ddrb.dqpin = Ipin
  138.     Timer_t0 = 0
  139.     Enable Interrupts
  140.  
  141. Readb:
  142.  
  143.     Gosub Readbyte
  144.  
  145. Readb1:
  146.  
  147.     If Bytedat = Read_rom Then Goto Readrom
  148.  
  149.  
  150.     If Bytedat = Skip_rom Then
  151.      Crc = 0
  152.      For B = 1 To 2
  153.      Gosub Readbyte
  154.      Incommand(b) = Bytedat
  155.      Bytedatbuffer = Crc Xor Incommand(b)
  156.  
  157.       Crc = Crc8(bytedatbuffer , 1)
  158.      Next B
  159.  
  160.  
  161.      Gosub Readbyte                                         ' empty read for high adress
  162.      'Bytedatbuffer = Crc Xor 00
  163.      Bytedat = Crc8(crc , 1)
  164.      Gosub Sendbyte
  165.  
  166.  
  167.  
  168.      If Incommand(1) = Read_mem Then Goto Readmem
  169.  
  170.  
  171.  
  172.     End If
  173.     Goto Waitreset
  174. End
  175.  
  176. Readrom:
  177.        For B = 0 To 7
  178.        Bytedat = Lookup(b , Rom)
  179.        Gosub Sendbyte
  180.        Next B
  181. Goto Waitreset
  182. '----------------------------------
  183. '================================
  184. Readbyte:
  185.          For I = 0 To 7
  186.  
  187. L11:
  188.     sbis pinb, DqPin
  189.     rjmp L11
  190. L12:
  191.     sbic pinb, DqPin
  192.     rjmp L12
  193.          Timer_t0 = 256 - T1reset
  194.          Start Timer0
  195.  
  196.          Rotate Bytedat , Right
  197.          Waitus Owstrobe
  198.  
  199.  
  200.          Bytedat.7 = Dq
  201.  
  202.          Next I
  203.          Stop Timer0
  204. Return
  205. '----------------------------------
  206. Sendbyte:
  207.        Bytedatbuffer = Bytedat
  208.         For I = 0 To 7
  209.  
  210. L21:
  211.     sbis pinb, DqPin
  212.     rjmp L21
  213. L22:
  214.     sbic pinb, DqPin
  215.     rjmp L22
  216.            Timer_t0 = 256 - T1reset
  217.            Start Timer0
  218.  
  219.            If Bytedat.0 = 0 Then Ddrb.dqpin = Opin
  220.            Waitus Owdata
  221.            Ddrb.dqpin = Ipin
  222.  
  223.            Rotate Bytedat , Right
  224.  
  225.         Next I
  226.         Bytedat = Bytedatbuffer
  227.         Stop Timer0
  228. Return
  229. '-----------------------------------
  230.  
  231. Readmem:
  232. Crc = 0
  233. Bufstart = Incommand(2)
  234.  
  235.      For B = Bufstart To 63
  236.      Bytedat = Lookup(b , Mem1)
  237.      'Print Hex(bytedat)
  238.     Bytedatbuffer = Crc Xor Bytedat
  239.  
  240.  Crc = Crc8(bytedatbuffer , 1)
  241.      Gosub Sendbyte
  242.      Next B
  243.  
  244.  Bytedat = Crc
  245.  
  246.  Gosub Sendbyte
  247.  
  248.  Goto Waitreset
  249.  
  250.  
  251. ' ***********************  isr
  252. Isr:
  253.  
  254.     If Dq = 0 Then                                          ' Das ist Strange mit den Goto aus der Isr rauszugehen.
  255.                                                             'aber es läuft
  256.     Timer_t0 = T1reset
  257.  
  258.     Goto Rwaitrise
  259.     Else
  260.     Goto Waitreset
  261.     End If
  262.  
  263. Return
  264.  
  265. '******************************
  266.  
  267.  
  268.  
  269.  
  270.  
  271. '*************** ROM **************************
  272. Rom:
  273. Data &H11 , &HB4 , &H91 , &H2F , &H05 , &H00 , &H00 , &HB8
  274.  
  275.  
  276.  
  277. '*************** mem 1 **************************
  278. ' Settings für 90 Watt Netzteil
  279.  
  280. Mem1:
  281.                                                            '90
  282. Data &H44 , &H45 , &H4C , &H4C , &H30 , &H30 , &H41 , &H43
  283. Data &H31 , &H35 , &H30 , &H31 , &H39 , &H35 , &H30 , &H37
  284. Data &H37 , &H43 , &H4E , &H30 , &H43 , &H38 , &H30 , &H32
  285. Data &H33 , &H34 , &H38 , &H36 , &H36 , &H31 , &H36 , &H31
  286. Data &H52 , &H32 , &H33 , &H48 , &H38 , &H41 , &H30 , &H33
  287. Data &H4D , &H7C , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
  288. Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
  289. Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Dell emulator zasilacza attiny 13 prośba o opis kodu

Post autor: niveasoft » 13 maja 2019, 9:45

To jest bardzo proste.
Te wstawki to jest oczekiwanie na to aż pin zmieni swój stan na przeciwny i z powrotem.
Kiedy pisałem swój emulator DS18B20 to przeanalizowałem te wstawki i sprawdziłem jak ma się to do komend Bascoma typu Bitwait.
Otóż nie różni się niczym więc w swoim kodzie użyłem Bitwait.
  1. L1:
  2.     !sbis pinb, DqPin   'DqPin=3  wiec to oznacza "sprawdź czy PINB.3 "is set" czyli czy równa się jeden
  3.     !rjmp L1               'jeśli wynik sprawdzenia to false to skocz pod adres L1 czyli wróć
  4.                'sprowadza się do tego że będzie tu czekał aż na pinie PINB.3 pojawi się stan wysoki
  5. L2:
  6.     !sbic pinb, DqPin   'DqPin=3  wiec to oznacza "sprawdź czy PINB.3 "is clear" czyli czy równa się zero
  7.     !rjmp L2               'jeśli wynik sprawdzenia to false to skocz pod adres L2 czyli wróć
  8.                'sprowadza się do tego że będzie tu czekał aż na pinie PINB.3 pojawi się stan niski
Prościej jest napisać:
  1. Bitwait PINB.3, Set
  2. Bitwait PINB.3, Reset
Zobacz jak wygląda kod tworzony przez Bascom odczytany moim programem NosaveTool
  1. 2:        $regfile = "attiny13.dat"
  2. 3:        $hwstack = 32
  3. 4:        $swstack = 8
  4. 5:        $framesize = 16
  5. 6:        
  6. 7:        Bitwait Pinb.3 , Set
  7. 00000046: 9BB3     SBIS      $16, 3              
  8. 00000048: CFFE     RJMP      $-0002 (0046)      
  9. 8:        Bitwait Pinb.3 , Reset
  10. 0000004A: 99B3     SBIC      $16, 3              
  11. 0000004C: CFFE     RJMP      $-0002 (004A)      
  12. 9:        
  13. 10:       End
grafii1
Posty: 58
Rejestracja: 23 wrz 2018, 11:28

Re: Dell emulator zasilacza attiny 13 prośba o opis kodu

Post autor: grafii1 » 13 maja 2019, 13:10

Dzięki za szybką odpowiedź , troszkę muszę się jeszcze podszkolić i w zasadzie też bazowałem na bitwait to rzeczywiście jest dużo prostsze ale czy spełnia tę same funkcję . Czy mógłbyś coś jeszcze krótko napisać o rejestrach R00...R31 , z czym tosie je .
Ps. NosaveTool , czy można go pobrać i gdzie go znajdę .
ODPOWIEDZ