' *************************** Mod Jamy 28.03.2017 **********************************
' Emulation eines DS2501 aus Dell Notebook netzteilen
' Entwicklung basiert auf folgenden Quellen :
' Dallas DS 2501/02 Datasheet
' Webseite Wolfgang Pöllinger ->
www.wpö.de
' Webseite
http://www.howtofixcomputers.com/for...in-108608.html
' Webseite
http://www.laptop-junction.com/toast...stery-revealed
' Webseite
http://www.ringwelt.de/computer/pc/d...-netzteil.html
' Webseite
http://bascom.at.ua/publ/1-1-0-1
' Arduino
' 1Wire an Pin2 = PB3
'
'
'
'
' + VCC +5v
' +
' |
' .-.
' | | 4k7
' | |
' '-'
' | ___
' Dell 1 Wire o--o|___|---------> PB3 (arduino pin 11')
' 220R
'
'
'
' (created by AACircuit v1.28.6 beta 04/19/05
www.tech-chat.de)
$crystal = 16000000
$regfile = "m328Pdef.dat"
$hwstack = 32
$swstack = 8
$framesize = 16
Dim Incommand(2) As Byte
Dim Bytedat As Byte
Dim Bytedatbuffer As Byte
Dim I As Byte
Dim B As Byte
Dim Crc As Byte
Dim Bufstart As Byte
' Commands
Const Skip_rom = &HCC
Const Read_rom = &H33
Const Read_mem = &HF0
' we use port b .3
Const Dqpin = 3
Const Ipin = 0 ' value in DDRB for input
Const Opin = 1 ' value in DDRB for output
Dq Alias Pinb.dqpin
' Timings
Const Owpresent = 280 ' 150
Const Owpause = 90 '50
Const Owstrobe = 28 '15
Const Owdata = 45 '25
' Timer Delays
Const T1reset = 110 '60
Const Timeout = 225 '120
' *********************** TIMER and ISR
Config Timer0 = Timer , Prescale = 64
Stop Timer0
Enable Timer0
On Timer0 Isr Nosave
Timer_t0 Alias Tcnt0
'***************************************
Mainloop:
Waitreset:
Disable Interrupts
Timer_t0 = 0
Waitfall:
L1:
sbis pinb, DqPin
rjmp L1
L2:
sbic pinb, DqPin
rjmp L2
Start Timer0
Rwaitrise:
L01:
sbic pinb, DqPin
rjmp L01
L02:
sbis pinb, DqPin
rjmp L02
Stop Timer0
If Timer_t0 < T1reset Then Goto Waitreset
If Timer_t0 > Timeout Then Goto Waitreset
Sendpresense:
Waitus Owpause
Ddrb.dqpin = Opin
Waitus Owpresent
Ddrb.dqpin = Ipin
Timer_t0 = 0
Enable Interrupts
Readb:
Gosub Readbyte
Readb1:
If Bytedat = Read_rom Then Goto Readrom
If Bytedat = Skip_rom Then
Crc = 0
For B = 1 To 2
Gosub Readbyte
Incommand(b) = Bytedat
Bytedatbuffer = Crc Xor Incommand(b)
Crc = Crc8(bytedatbuffer , 1)
Next B
Gosub Readbyte ' empty read for high adress
'Bytedatbuffer = Crc Xor 00
Bytedat = Crc8(crc , 1)
Gosub Sendbyte
If Incommand(1) = Read_mem Then Goto Readmem
End If
Goto Waitreset
End
Readrom:
For B = 0 To 7
Bytedat = Lookup(b , Rom)
Gosub Sendbyte
Next B
Goto Waitreset
'----------------------------------
'================================
Readbyte:
For I = 0 To 7
L11:
sbis pinb, DqPin
rjmp L11
L12:
sbic pinb, DqPin
rjmp L12
Timer_t0 = 256 - T1reset
Start Timer0
Rotate Bytedat , Right
Waitus Owstrobe
Bytedat.7 = Dq
Next I
Stop Timer0
Return
'----------------------------------
Sendbyte:
Bytedatbuffer = Bytedat
For I = 0 To 7
L21:
sbis pinb, DqPin
rjmp L21
L22:
sbic pinb, DqPin
rjmp L22
Timer_t0 = 256 - T1reset
Start Timer0
If Bytedat.0 = 0 Then Ddrb.dqpin = Opin
Waitus Owdata
Ddrb.dqpin = Ipin
Rotate Bytedat , Right
Next I
Bytedat = Bytedatbuffer
Stop Timer0
Return
'-----------------------------------
Readmem:
Crc = 0
Bufstart = Incommand(2)
For B = Bufstart To 63
Bytedat = Lookup(b , Mem1)
'Print Hex(bytedat)
Bytedatbuffer = Crc Xor Bytedat
Crc = Crc8(bytedatbuffer , 1)
Gosub Sendbyte
Next B
Bytedat = Crc
Gosub Sendbyte
Goto Waitreset
' *********************** isr
Isr:
If Dq = 0 Then ' Das ist Strange mit den Goto aus der Isr rauszugehen.
'aber es läuft
Timer_t0 = T1reset
Goto Rwaitrise
Else
Goto Waitreset
End If
Return
'******************************
'*************** ROM **************************
Rom:
Data &H11 , &HB4 , &H91 , &H2F , &H05 , &H00 , &H00 , &HB8
'*************** mem 1 **************************
' Settings für 90 Watt Netzteil
Mem1:
Data &H44 , &H45 , &H4C , &H4C , &H30 , &H30 , &H41 , &H43
Data &H30 , &H39 , &H30 , &H31 , &H39 , &H35 , &H30 , &H34
Data &H36 , &H43 , &H4E , &H30 , &H43 , &H38 , &H30 , &H32
Data &H33 , &H34 , &H38 , &H36 , &H36 , &H31 , &H36 , &H31
Data &H52 , &H32 , &H33 , &H48 , &H38 , &H41 , &H30 , &H33
Data &H4D , &H7C , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
Data &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF , &HFF
[свернуть]