本帖最后由 34af9uc 于 2021-1-19 15:37 编辑
/********************李想测温**********************/
/******************qq:774145445********************/
/*****************快手:共同学习stm8****************/
/******************20210118************************/
//Last use Code : 0x61C
// pms154c
// _______@______
// @1----|1 pb4 pb3 16|----@2
// 红----|2 pb5 pb2 15|----@3
// 绿----|3 pb6 pb1 14|----@4
// |4 pb7 pb0 13|----@5
// 3v|5 vdd gnd 12|---------------------|地
// |6 pa7 pa0 11|--jiance20r---| |
// |7 pa6 pa4 10|--dianzu100k--|--||--|
// |8_pa5___pa3__9|--ntc100k-----| 103
/**************************************************/
/******************************************************************************/
// 显示屏2353/188
// _2a_ ____
// 正转| 2e 2b | |
// | | | | |
// -2f- ----
// 反转| 2e 2c | |
// | |_2d_| |____|
// @1 @2 @3 @4 @5
// ____________________________
// | |led1|led2|led3|led4|led5|
// |_1_|_高_|_3A_|_3C_|_3E_|____|
// |_2_|_3B_|_高_|_2A_|_1B_|____|
// |_3_|_3D_|_2B_|_高_|_1A_|____|
// |_4_|_3F_|_2D_|_2C_|_高_|____|
// |_5_|_3G_|_2E_|_2F_|_2G_|_高_|
//共阳:0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90//0x88,0x83,0xc6,0xa1,0x86,0x8e
//共阴:0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f//0x77,0x7c,0x39,0x5e,0x79,0x71
/******************************************************************************/
#include "extern.h"
led1 bit pb.4;
led2 bit pb.3;
led3 bit pb.2;
led4 bit pb.1;
led5 bit pb.0;
xianshi_hong bit pb.5;
xianshi_lv bit pb.6;
void cewen(); //测温
void jisuan(); //计算温度
void xianshi(); //显示
void xianshi_js(); //显示计算
jiance bit pa.0; //检测脚
dianzu bit pa.4; //标准电阻100k
ntc bit pa.3; //ntc电阻100k
word cewen_a1,cewen_a2,cewen_a3;
byte temp; //温度
byte xianshi_a1;
//byte xianshi_b1,xianshi_b2,xianshi_b3; //百位十位个位
byte xianshi_c1,xianshi_c2,xianshi_c3; //百位十位个位机器码
/**************************************************/
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
byte a1;
while (1)
{
cewen(); //第一次舍弃
cewen();
jisuan();
xianshi_js();
a1 =70;
while(a1)
{
a1--;
xianshi();
}
}
}
/**************************************************/ //测温
void cewen()
{
cewen_a1 =0;
cewen_a2 =0;
/**************************************************/ //1放电
$ jiance out,low;
$ dianzu out,low;
$ ntc out,low;
.delay 1000;
/**************************************************/ //25℃//2计算标准电阻充电时间
$ jiance in;
$ dianzu out,high;
$ ntc in;
while(!jiance)
{
cewen_a1++; //这个就是100k等待的时间
}
/**************************************************/ //3放电
$ jiance out,low;
$ dianzu out,low;
$ ntc out,low;
.delay 1000;
/**************************************************/ //4计算ntc电阻充电时间
$ jiance in;
$ dianzu in;
$ ntc out,high;
while(!jiance)
{
cewen_a2++; //这个就是ntc等待的时间
}
}
/**************************************************/ //计算温度
void jisuan()
{
cewen_a3 =0;
if(cewen_a1 < cewen_a2) //低于25度(取较小数)
{
xianshi_hong =0; xianshi_lv =1; //绿灯亮
cewen_a3 =cewen_a2 - cewen_a1;
if (cewen_a3 < 27) {temp =25; return;} //25
if (cewen_a3 < 64) {temp =24; return;} //24
if (cewen_a3 < 110) {temp =23; return;} //23
if (cewen_a3 < 156) {temp =22; return;} //22
if (cewen_a3 < 219) {temp =21; return;} //21
if (cewen_a3 < 266) {temp =20; return;} //20
if (cewen_a3 < 329) {temp =19; return;} //19
if (cewen_a3 < 371) {temp =18; return;} //18
if (cewen_a3 < 443) {temp =17; return;} //17
if (cewen_a3 < 506) {temp =16; return;} //16
if (cewen_a3 < 574) {temp =15; return;} //15
if (cewen_a3 < 641) {temp =14; return;} //14
if (cewen_a3 < 709) {temp =13; return;} //13
if (cewen_a3 < 785) {temp =12; return;} //12
if (cewen_a3 < 883) {temp =11; return;} //11
if (cewen_a3 < 966) {temp =10; return;} //10
if (cewen_a3 < 1036) {temp =9; return;} //9
if (cewen_a3 < 1133) {temp =8; return;} //8
if (cewen_a3 < 1227) {temp =7; return;} //7
if (cewen_a3 < 1342) {temp =6; return;} //6
if (cewen_a3 < 1481) {temp =5; return;} //5
if (cewen_a3 < 1597) {temp =4; return;} //4
if (cewen_a3 < 1698) {temp =3; return;} //3
if (cewen_a3 < 1813) {temp =2; return;} //2
if (cewen_a3 < 2020) {temp =1; return;} //1
if (cewen_a3 < 2078) {temp =0; return;} //0
if (cewen_a3 < 2190) {temp =201; return;} //-1
if (cewen_a3 < 2314) {temp =202; return;} //-2
if (cewen_a3 < 2476) {temp =203; return;} //-3
if (cewen_a3 < 2665) {temp =204; return;} //-4
if (cewen_a3 < 2832) {temp =205; return;} //-5
if (cewen_a3 < 3028) {temp =206; return;} //-6
if (cewen_a3 < 3272) {temp =207; return;} //-7
if (cewen_a3 < 3451) {temp =208; return;} //-8
if (cewen_a3 < 3541) {temp =209; return;} //-9
}
else //高于25度(取较大数)
{
xianshi_hong =1; xianshi_lv =0; //红灯亮
cewen_a3 =cewen_a1 - cewen_a2;
if (cewen_a3 < 47) {temp =26; return;} //26
if (cewen_a3 < 76) {temp =27; return;} //27
if (cewen_a3 < 115) {temp =28; return;} //28
if (cewen_a3 < 146) {temp =29; return;} //29
if (cewen_a3 < 179) {temp =30; return;} //30
if (cewen_a3 < 209) {temp =31; return;} //31
if (cewen_a3 < 235) {temp =32; return;} //32
if (cewen_a3 < 262) {temp =33; return;} //33
if (cewen_a3 < 286) {temp =34; return;} //34
if (cewen_a3 < 311) {temp =35; return;} //35
if (cewen_a3 < 336) {temp =36; return;} //36
if (cewen_a3 < 359) {temp =37; return;} //37
if (cewen_a3 < 379) {temp =38; return;} //38
if (cewen_a3 < 395) {temp =39; return;} //39
if (cewen_a3 < 412) {temp =40; return;} //40
if (cewen_a3 < 432) {temp =41; return;} //41
if (cewen_a3 < 450) {temp =42; return;} //42
if (cewen_a3 < 467) {temp =43; return;} //43
if (cewen_a3 < 449) {temp =44; return;} //44
if (cewen_a3 < 482) {temp =45; return;} //45
if (cewen_a3 < 482) {temp =45; return;} //45
if (cewen_a3 < 510) {temp =46; return;} //46
if (cewen_a3 < 522) {temp =47; return;} //47
if (cewen_a3 < 449) {temp =48; return;} //48
if (cewen_a3 < 532) {temp =49; return;} //49
if (cewen_a3 < 554) {temp =50; return;} //50
if (cewen_a3 < 565) {temp =51; return;} //51
if (cewen_a3 < 576) {temp =52; return;} //52
if (cewen_a3 < 587) {temp =53; return;} //53
if (cewen_a3 < 595) {temp =54; return;} //54
if (cewen_a3 < 615) {temp =56; return;} //56
if (cewen_a3 < 622) {temp =57; return;} //57
if (cewen_a3 < 630) {temp =58; return;} //58
if (cewen_a3 < 640) {temp =59; return;} //59
if (cewen_a3 < 645) {temp =60; return;} //60
if (cewen_a3 < 655) {temp =61; return;} //61
if (cewen_a3 < 662) {temp =62; return;} //62
if (cewen_a3 < 669) {temp =63; return;} //63
if (cewen_a3 < 679) {temp =64; return;} //64
if (cewen_a3 < 684) {temp =65; return;} //65
if (cewen_a3 < 689) {temp =66; return;} //66
if (cewen_a3 < 697) {temp =67; return;} //67
if (cewen_a3 < 701) {temp =68; return;} //68
if (cewen_a3 < 707) {temp =69; return;} //69
if (cewen_a3 < 711) {temp =70; return;} //70
if (cewen_a3 < 716) {temp =71; return;} //71
if (cewen_a3 < 720) {temp =72; return;} //72
if (cewen_a3 < 726) {temp =73; return;} //73
if (cewen_a3 < 730) {temp =74; return;} //74
if (cewen_a3 < 735) {temp =75; return;} //75
if (cewen_a3 < 740) {temp =76; return;} //76
if (cewen_a3 < 743) {temp =77; return;} //77
if (cewen_a3 < 746) {temp =78; return;} //78
if (cewen_a3 < 750) {temp =79; return;} //79
if (cewen_a3 < 753) {temp =80; return;} //80
if (cewen_a3 < 757) {temp =81; return;} //81
if (cewen_a3 < 762) {temp =82; return;} //82
if (cewen_a3 < 766) {temp =83; return;} //83
if (cewen_a3 < 770) {temp =84; return;} //84
if (cewen_a3 < 773) {temp =85; return;} //85
if (cewen_a3 < 776) {temp =86; return;} //86
if (cewen_a3 < 779) {temp =87; return;} //87
if (cewen_a3 < 781) {temp =88; return;} //88
if (cewen_a3 < 783) {temp =89; return;} //89
if (cewen_a3 < 786) {temp =90; return;} //90
if (cewen_a3 < 788) {temp =91; return;} //91
if (cewen_a3 < 790) {temp =92; return;} //92
if (cewen_a3 < 792) {temp =93; return;} //93
if (cewen_a3 < 794) {temp =94; return;} //94
if (cewen_a3 < 795) {temp =95; return;} //95
if (cewen_a3 < 797) {temp =96; return;} //96
if (cewen_a3 < 799) {temp =97; return;} //97
if (cewen_a3 < 801) {temp =98; return;} //98
if (cewen_a3 < 803) {temp =99; return;} //99
if (cewen_a3 < 805) {temp =100; return;} //100
if (cewen_a3 < 813) {temp =105; return;} //105
if (cewen_a3 < 821) {temp =110; return;} //110
if (cewen_a3 < 832) {temp =115; return;} //115
if (cewen_a3 < 840) {temp =120; return;} //120
if (cewen_a3 < 845) {temp =125; return;} //125
if (cewen_a3 < 850) {temp =130; return;} //130
if (cewen_a3 < 852) {temp =140; return;} //140
if (cewen_a3 < 854) {temp =150; return;} //150
if (cewen_a3 < 856) {temp =160; return;} //160
if (cewen_a3 < 858) {temp =170; return;} //170
if (cewen_a3 < 859) {temp =180; return;} //180
if (cewen_a3 < 860) {temp =190; return;} //190
if (cewen_a3 < 861) {temp =199; return;} //199
}
}
/**************************************************/
void xianshi_js() //显示计算
{
//byte xianshi_a1;
byte xianshi_b1,xianshi_b2,xianshi_b3; //计算百位十位个位十进制
xianshi_b1 =0;
xianshi_b2 =0;
xianshi_b3 =0;
xianshi_a1 =temp;
if(xianshi_a1>200)
{
xianshi_b1 =0; //百位
xianshi_b2 =10; //十位显示负号
}
if(xianshi_a1>100)
{
xianshi_b1 =1; //百位
xianshi_a1 -=100; //减一百
}
while(xianshi_a1>9) //计算十位代替除法
{
xianshi_a1 -=10;
xianshi_b2 +=1; //十位
}
xianshi_b3 =xianshi_a1;//个位
/**************************************************/
//共阳:0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90//0x88,0x83,0xc6,0xa1,0x86,0x8e
//共阴:0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f//0x77,0x7c,0x39,0x5e,0x79,0x71//用这个-0x20;
/**************************************************/ //百位机器码
xianshi_c1 =xianshi_b1;
/**************************************************/ //十位机器码
if(xianshi_b2 ==0) {xianshi_c2 =0x3f;} //十位
if(xianshi_b2 ==1) {xianshi_c2 =0x06;}
if(xianshi_b2 ==2) {xianshi_c2 =0x5b;}
if(xianshi_b2 ==3) {xianshi_c2 =0x4f;}
if(xianshi_b2 ==4) {xianshi_c2 =0x66;}
if(xianshi_b2 ==5) {xianshi_c2 =0x6d;}
if(xianshi_b2 ==6) {xianshi_c2 =0x7d;}
if(xianshi_b2 ==7) {xianshi_c2 =0x07;}
if(xianshi_b2 ==8) {xianshi_c2 =0x7f;}
if(xianshi_b2 ==9) {xianshi_c2 =0x6f;}
if(xianshi_b2 ==10) {xianshi_c1 =0x20;} //负号
/**************************************************/ //个位机器码
if(xianshi_b3 ==0) {xianshi_c3 =0x3f;} //个位
if(xianshi_b3 ==1) {xianshi_c3 =0x06;}
if(xianshi_b3 ==2) {xianshi_c3 =0x5b;}
if(xianshi_b3 ==3) {xianshi_c3 =0x4f;}
if(xianshi_b3 ==4) {xianshi_c3 =0x66;}
if(xianshi_b3 ==5) {xianshi_c3 =0x6d;}
if(xianshi_b3 ==6) {xianshi_c3 =0x7d;}
if(xianshi_b3 ==7) {xianshi_c3 =0x07;}
if(xianshi_b3 ==8) {xianshi_c3 =0x7f;}
if(xianshi_b3 ==9) {xianshi_c3 =0x6f;}
}
/**************************************************/ //五种状态
void xianshi() //显示
{
/**************************************************/ //第一种
$ led1 out,high
$ led2 in;
$ led3 in;
$ led4 in;
$ led5 in;
//if(){} //高
if(xianshi_c3.0) {$ led2 out,low;} //3a
if(xianshi_c3.2) {$ led3 out,low;} //3c
if(xianshi_c3.4) {$ led4 out,low;} //3e
//if(){} //空
.delay 1000;
/**************************************************/ //第二种
$ led1 in;
$ led2 out,high
$ led3 in;
$ led4 in;
$ led5 in;
if(xianshi_c3.1) {$ led1 out,low;} //3b
//if(){} //高
if(xianshi_c2.0) {$ led3 out,low;} //2a
if(xianshi_c1==1) {$ led4 out,low;} //1b
//if(){} //空
.delay 1000;
/**************************************************/ //第三种
$ led1 in;
$ led2 in;
$ led3 out,high
$ led4 in;
$ led5 in;
if(xianshi_c3.3){$ led1 out,low;} //3d
if(xianshi_c2.1){$ led2 out,low;} //2b
//if(){} //高
if(xianshi_c1==1){$ led4 out,low;} //1a
//if(){} //空
.delay 1000;
/**************************************************/ //第四种
$ led1 in;
$ led2 in;
$ led3 in;
$ led4 out,high
$ led5 in;
if(xianshi_c3.5){$ led1 out,low;} //3f
if(xianshi_c2.3){$ led2 out,low;} //2d
if(xianshi_c2.2){$ led3 out,low;} //2c
//if(){} //高
//if(){} //空
.delay 1000;
/**************************************************/ //第五种
$ led1 in;
$ led2 in;
$ led3 in;
$ led4 in;
$ led5 out,high
if(xianshi_c3.6){$ led1 out,low;} //3g
if(xianshi_c2.4){$ led2 out,low;} //2e
if(xianshi_c2.5){$ led3 out,low;} //2f
if(xianshi_c2.6){$ led4 out,low;} //2g
//if(){} //高
.delay 1000;
}
/**************************************************/
/**************************************************/
|
|