首页 > 代码库 > 温度传感器
温度传感器
1 unsigned const int tempvoltage[]={ 2 0xC42,0xC1C,0xBF5,0xBCE,0xBA5,0xB7D,0xB53,0xB29,0xAFE,0xAD3, 3 0xAA8,0xA7C,0xA4F,0xA23,0x9F5,0x9C8,0x99B,0x96D,0x93F,0x911, 4 0x8E4,0x8B6,0x888,0x85B,0x82D,0x800,0x7D3,0x7A7,0x77A,0x74E, 5 0x723,0x6F8,0x6CD,0x6A3,0x67A,0x651,0x629,0x601,0x5DA,0x5B3, 6 0x58D,0x568,0x544,0x520,0x4FD,0x4DB,0x4B9,0x498,0x478,0x459, 7 0x43A,0x41C,0x3FF,0x3E2,0x3C6,0x3AB,0x390,0x376,0x35D,0x345, 8 0x32D 9 }; 10 //这里是NTC表中的AD值0~60度 11 12 u16 Get_Adc_Average(u8 ch,u8 times) //采集ad值 13 { 14 u32 temp_val=0; 15 u8 t; 16 for(t=0;t<times;t++) 17 { 18 temp_val+=Get_Adc(ch); 19 delay_ms(5); 20 } 21 return temp_val/times; 22 } 23 24 25 26 u8 Compare_tempvol(u16 Vol) //vol来自于上面函数 27 { 28 u8 cmp_cnt; 29 cmp_cnt =0; 30 while(Vol<tempvoltage[cmp_cnt]) 31 { 32 cmp_cnt++; 33 if(cmp_cnt>59) 34 break; 35 } 36 return cmp_cnt; 37 }
1 if(temperature<0x32D || temperature>0xC42) //判断ad值得范围 3 4 printf("\r\nflagerror\r\n\r\n"); 5 6 } 7 8 else 9 { 10 adcx= Compare_tempvol(temperature); 11 12 printf("\r\nAD值=%d\r\n",adcy); 13 printf("\r\n温度=%d\r\n",adcx);
通过NTC表来的到温度值。
最后结果为:
温度传感器
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。