C语言CPU测试温度程序
// Target : M8
// Crystal: 80000Mhz
/
不可在RESET时做LCD显示,因为DS18B20的复位回应时间只有80us,显示一个字符的时间
远大于这个值
/
#include <iom8vh>
#include <macrosh>
#include "1602Driverh"
#define Set_DQ1 DDRC |= 0x08; PORTC |= 0x08; //总线拉高
#define Set_DQ0 DDRC |= 0x08; PORTC &= 0xf7; //总线置低
#define Read_DQ PINC&0x08 //读总线
#define MatchROM 0xcc //匹配ROM
#define WriteMode 0x4e //写模式
#define TH 0x64 //设置温度上限100
#define TL 0x8a //设置温度下限-10
#define MatchTemp 0x7f //写温度匹配寄存器,12bit
#define ConverTem 0x44 //DS18B20温度转换命令
#define Get_Value 0xbe //读取温度寄存器值
char DelayMs = 0;
void port_init(void)
{
DDRD = 0xff;
PORTD = 0xff;
DDRB = 0xff;
PORTB = 0xff;
DDRC = 0xff;
PORTC = 0xff;
}
//TIMER1 initialize - prescale:1
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 15uSec
// actual value: 14875uSec (08%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x89;
OCR1AH = 0x00;
OCR1AL = 0x77;
OCR1BH = 0x00;
OCR1BL = 0x77;
ICR1H = 0x00;
ICR1L = 0x77;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xFF; //reload counter high value
TCNT1L = 0x89; //reload counter low value
if (DelayMs > 0)
{
DelayMs --;
}
}
void Delay_15us(unsigned int n)
/---Ms延时函数---/
{
DelayMs=n;
while(DelayMs > 0);
}
/
功能:主机向总线写0
/
void Writr0(void)
{
Set_DQ1;
Set_DQ0;
Delay_15us(5);
Set_DQ1;
Delay_15us(1);
}
/
功能:主机向总线写1
/
void Writr1(void)
{
Set_DQ1;
Set_DQ0;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
Set_DQ1;
Delay_15us(2);
}
/
功能:向总线写一个字节
输入:需要写的字
/
void WriteBits(char Byte)
{
char i = 0;
for (i=0;i<8;i++)
{
if (Byte & 0x01)
{
Writr1();
}
else
{
Writr0();
}
Byte>>=1;
}
}
/
功能:DS18B20复位程序
返回:总线复位成功,返回1
/
char Reset1820(void)
{
static char CheckTimes = 0;
static char CheckValue = 1;
Delay_nms(1);
Set_DQ1;
Set_DQ0; //拉低总线480us
Delay_15us(34);
Set_DQ1;
DDRC &= 0xf7; //设置端口为输入状态,读取数据
PORTC |= 0x08;
while(PINC&0x08); //等待,直至确认复位成功
CheckValue = Read_DQ;
Delay_15us(32);
return CheckValue;
}
void Init1820(void)
{
if (Reset1820() == 0x08)
{
LCD_Write_String(0,0,"1820 Not Detect!");
LCD_Write_String(0,1," ");
}
else
{
LCD_Write_String(0,0,"Init DS18B20 OK!");
LCD_Write_String(0,1," ");
}
WriteBits(MatchROM);
WriteBits(WriteMode);
WriteBits(TH);
WriteBits(TL);
WriteBits(MatchTemp);
}
/
功能:从总线中读取数据位
返回:读取值
/
char ReadBit(void)
{
char i = 0;
char Read_Value = 0;
Set_DQ1;
Set_DQ0;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
Set_DQ1;
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
DDRC &= 0xf7; //设置端口为输入状态,读取数据
PORTC |= 0x08;
asm("nop");
Read_Value = Read_DQ;
Delay_15us(3);
return Read_Value;
}
/
功能:从总线读取一个字节
返回:读取到的字符
/
char ReadBits(void)
{
char i = 0;
char b = 0;
char ReadBits_Value = 0;
for (i=8;i>0;i--)
{
ReadBits_Value = ReadBits_Value>>1;
b = ReadBit();
if(b)
{
ReadBits_Value = ReadBits_Value|0x80;
}
}
//DEC_Num_Disp(0,1,ReadBits_Value,5);
return ReadBits_Value;
}
/
功能:获得温度值
返回:温度值--摄氏温度
/
char Get_Temperature(void)
{
static int TempLow = 0;
static int TempHi = 0;
static char Temp2 = 0;
static long final = 0;
static Sign = 0; //温度的符号位
Reset1820();
WriteBits(MatchROM);
WriteBits(ConverTem);
//Delay_15us(6);
Reset1820();
WriteBits(MatchROM);
WriteBits(Get_Value);
Delay_15us(5);
TempLow = ReadBits(); //温度低位
Delay_15us(5);
Temp2 = ReadBits();
Sign = Temp2&0xf8; //符号位取高5位
TempHi = Temp2&0x07; //温度高位
if (Sign == 0) //正温的数据处理
{
final = (((TempHi)<<8)|TempLow)625;
LCD_Write_String(0,1," ");
}
else
{
final = (~(((TempHi)<<8)|TempLow)+1)625;
LCD_Write_String(0,1,"-");
}
if (final >= 37400)
{
LCD_Write_String(10,1,"Fever!");
}
if ((final < 37400)&(final>36000))
{
LCD_Write_String(10,1,"Normal");
}
if (final<=36000)
{
LCD_Write_String(10,1,"Low! ");
}
Point_Disp(1,1,final,6,3);
return final;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
timer1_init();
LCD_Init();
LCD_Write_Char(0x01,0); //清屏
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x04; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void main(void)
{
init_devices();
Delay_nms(5);
LCD_Write_String(0,0,"1820 Not Detect!");
LCD_Write_String(0,1,"Reset after sure");
Init1820();
Delay_nms(100);
LCD_Write_String(0,0,"Body Temp Test:");
LCD_Write_String(0,1," C ");
while(1)
{
Get_Temperature();
}
}
>>> import psutil
>>> psutilcpu_times()
scputimes(user=396146, nice=169729, system=2150659, idle=16900540, iowait=62959, irq=00, softirq=1942, steal=00, guest=0, nice=00)
>>>
>>> for x in range(3):
psutilcpu_percent(interval=1)
40
59
38
>>>
>>> for x in range(3):
psutilcpu_percent(interval=1, percpu=True)
[40, 69, 37, 92]
[70, 85, 24, 21]
[12, 90, 99, 72]
>>>
>>>
>>> for x in range(3):
psutilcpu_times_percent(interval=1, percpu=False)
scputimes(user=15, nice=00, system=05, idle=965, iowait=15, irq=00, softirq=00, steal=00, guest=00, guest_nice=00)
scputimes(user=10, nice=00, system=00, idle=990, iowait=00, irq=00, softirq=00, steal=00, guest=00, guest_nice=00)
scputimes(user=20, nice=00, system=00, idle=980, iowait=00, irq=00, softirq=00, steal=00, guest=00, guest_nice=00)
>>>
>>> psutilcpu_count()
4
>>> psutilcpu_count(logical=False)
2
>>>
如果您的1660ti显卡配备了风扇控制功能,您可以通过NVIDIA控制面板来调整风扇转速。
以下是具体步骤:
1 打开NVIDIA控制面板。在桌面上右键单击,选择"NVIDIA控制面板"。
2 点击"设备"选项卡,然后选择您想要调节风扇速度的显卡。
3 在左侧导航栏中选择"风扇"选项。
4 在右侧的"手动控制"下拉菜单中选择您想要使用的风扇控制模式:"手动"或"自动"。
5 如果您选择手动控制,可以通过拖动滑块来调整风扇转速。如果您选择自动控制,则显卡将自动调整风扇转速以保持显卡温度在安全范围内。
6 调整完毕后,点击"应用"按钮保存设置。
请注意,过高或过低的风扇转速都会对显卡产生影响,因此请谨慎调整风扇转速。同时,不同型号的显卡风扇控制方式可能有所差异,请参考您的显卡说明书或联系厂家获取更多信息。
以上就是关于C#如何获取电脑CPU温度,硬盘温度,主板温度,CPU转速全部的内容,包括:C#如何获取电脑CPU温度,硬盘温度,主板温度,CPU转速、python如何获取服务器硬件状态信息,包括CPU温度、硬盘温度、主板电池电压、主机电源电压、CPU风扇转速、1660ti风扇转速调整等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)