Code For temperature CPU

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Julien Morel.

I want to know the temperature of the processor of my mother card. I do not know if my mother card is compatible!
My result is of 255 C°:)

If you have another code, or if you can test this one and to tell me your temperature

Thank


The code is :





Procedure.s floatToString(number.f, nPlaces.l)
r=Pow(10,nPlaces)
vf.f=number*r
vs.s=Str(vf)
rs.s=Left(vs,Len(vs)-nPlaces)+"."+Right(vs,nPlaces)
ProcedureReturn rs
EndProcedure

#ADR_REG = $295
#DATA_REG = $296

If OpenLibrary(0, "WinIo.dll")

;Initialise
CallFunction(0, "InitializeWinIo")

;CPU Temperature
CallFunction(0, "SetPortVal", #ADR_REG, $4E, 1)
CallFunction(0, "GetPortVal", #DATA_REG, @bank, 1) ; read current value of bank switch register
bank | %00000001 ; set 1st bit for bank 1
CallFunction(0, "SetPortVal", #ADR_REG, $4E, 1)
CallFunction(0, "SetPortVal", #DATA_REG, bank, 1) ; and write it to select bank
CallFunction(0, "SetPortVal", #ADR_REG, $50, 1) ; get temp
CallFunction(0, "GetPortVal", #DATA_REG, @CpuTemp, 1)
Debug "CPU Temperature: "+StrU(CpuTemp, #Byte)+"ºC"

;System Temperature
CallFunction(0, "SetPortVal", #ADR_REG, $27, 1)
CallFunction(0, "GetPortVal", #DATA_REG, @systemTemp, 1)
Debug "System Temperature: "+StrU(systemTemp, #Byte)+"ºC"

;CPU Fan
CallFunction(0, "SetPortVal", #ADR_REG, $28, 1)
CallFunction(0, "GetPortVal", #DATA_REG, @cpuFan, 1)
fanDivisor = 4
cpuFan = 1350000 / fanDivisor / cpuFan
Debug "CPU Fan: "+Str(cpuFan)+"rpm"

;CPU Voltage
CallFunction(0, "SetPortVal", #ADR_REG, $20, 1)
CallFunction(0, "GetPortVal", #DATA_REG, @cpuVoltage, 1)
adjVoltage.s = floatToString((cpuVoltage*16)/1000, 2)
Debug "CPU Voltage: "+adjVoltage+"v"

;Clean up
CallFunction(0, "ShutdownWinIo")

MessageRequester("Température CPU","CPU Temperature: "+StrU(CpuTemp, #Byte)+"ºC",#PB_MessageRequester_Ok)
EndIf
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Kale.

you have to remember that with each make/model of the sensor chip the hardware ranges will be different. These:

#ADR_REG = $295
#DATA_REG = $296

are only for the 'Winbond W83697HF super I/O chip' present on my AbitKX7 Motherboard, yours may have a different chip on it. Check your motherboard manual.

--Kale

In love with PureBasic! :)
Post Reply