/****************pms152+max6675读取温度************/
/****************qq:774145445**********************/
/****************快手:共同学习stm8*****************/
/****************20210323**************************/
#include "extern.h"
// pms152
// __________@_________
// |1 pb4 pb3 16|
// so-|2 pb5 pb2 15|-led1
// cs-|3 pb6 pb1 14|-led2
// sck-|4 pb7 pb0 13|-led3
// |5 vdd gnd 12|
// 加k1-|6 pa7 pa0 11|-led4
// 减k2-|7 pa6 pa4 10|-led5
// |8_pa5_________pa3__9|-led6
/**************************************************/
// max6675
// __________@_________
// |1 gnd nc 8|
// |2 t- so 7|-pb5
// |3 t+ cs 6|-pb6
// |4_vcc__________sck_5|-pb7
/**************************************************/
// 显示屏CS3631AW-4-D/888
// @1 @2 @3 @3 @4 @5 @6
// _1a_ _2a_ _3a_
// 1f 1b | | | |
// | | | | | |
// -1g- ---- ----
// 1e 1c | | | |
// |_1d_|.1h |____|. |____|.
// _________________________________
// | |led1|led2|led3|led4|led5|led6|
// |___|_@1_|_@2_|_@3_|_@4_|_@5_|_@6_|
// |_1_|_高_|_1f_|_1g_|_1c_|_1d_|_3d_|
// |_2_|_1a_|_高_|_2f_|_2g_|_2c_|____|
// |_3_|_1b_|_2a_|_高_|_3f_|_3g_|_3e_|
// |_4_|_1e_|_2b_|____|_高_|_3a_|____|
// |_5_|____|_2e_|_3b_|_3c_|_高_|____|
// |_6_|_1h_|_2d_|_2h_|_3h_|____|_高_|
/**************************************************/
bit so :pb.5;
bit cs :pb.6;
bit sck :pb.7;
bit led1 :pb.2;
bit led2 :pb.1;
bit led3 :pb.0;
bit led4 :pa.0;
bit led5 :pa.4;
bit led6 :pa.3;
bit k1 :pa.7;
bit k2 :pa.6;
word temp;
byte xianshi_a1,xianshi_a2,xianshi_a3; //百位十位个位机器码
byte chabiao_a1; //查表用
//word anjian_a1; //按键用
/**************************************************/
void yanshi(); //延时
void wendu(); //温度
void xianshi(); //显示
void jisuan(); //计算
void chabiao(); //查表
void anjian(); //按键
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/4 // SYSCLK=IHRC/4
$ cs out,high;
$ so in;
$ sck out,low;
$ k1 in,pull;
$ k2 in,pull;
//anjian_a1 =150;
byte a1;
while (1)
{
wendu();
jisuan();
a1 =75; //75hz
while(a1--)
{
xianshi();
}
}
}
/*
void Interrupt (void)
{
pushaf;
if (Intrq.T16)
{ // T16 Trig
// User can add code
Intrq.T16 = 0;
//...
}
popaf;
}
*/
/**************************************************/
void wendu() //温度
{
word wendu_a1;
byte wendu_b1;
//$ cs out,high;
//$ so in;
//$ sck out,low;
//.delay 2000;
cs =0; //片选
nop;
wendu_b1 =16;
while(wendu_b1--) //循环16次
{
sck =1;
//nop;
wendu_a1 <<=1; //左移一次
if(so){wendu_a1 |=1;}
sck =0;
//nop;
}
cs =1; //片选
sck =0;
nop;
wendu_a1 >>=5; //低三位没用,/4=实际温度
nop;
temp =wendu_a1;
}
/**************************************************/
void xianshi() //显示//六线数码管六种状态
{
/**************************************************/ //第一种状态
$ led1 out,high; //高
$ led2 in; //高阻
$ led3 in;
$ led4 in;
$ led5 in;
$ led6 in;
//if() {$ led1 out,low;} //高
if(xianshi_a1.5){$ led2 out,low;} //1f
if(xianshi_a1.6){$ led3 out,low;} //1g
if(xianshi_a1.2){$ led4 out,low;} //1c
if(xianshi_a1.3){$ led5 out,low;} //1d
if(xianshi_a3.3){$ led6 out,low;} //3d
yanshi();
/**************************************************/ //第二种状态
$ led1 in;
$ led2 out,high; //高
$ led3 in;
$ led4 in;
$ led5 in;
$ led6 in;
if(xianshi_a1.0){$ led1 out,low;} //
//if() {$ led2 out,low;} //高
if(xianshi_a2.5){$ led3 out,low;} //
if(xianshi_a2.6){$ led4 out,low;} //
if(xianshi_a2.2){$ led5 out,low;} //
//if(){$ led6 out,low;} //
yanshi();
/**************************************************/ //第三种状态
$ led1 in;
$ led2 in;
$ led3 out,high; //高
$ led4 in;
$ led5 in;
$ led6 in;
if(xianshi_a1.1){$ led1 out,low;} //
if(xianshi_a2.0){$ led2 out,low;} //
//if() {$ led3 out,low;} //高
if(xianshi_a3.5){$ led4 out,low;} //
if(xianshi_a3.6){$ led5 out,low;} //
if(xianshi_a3.4){$ led6 out,low;} //
yanshi();
/**************************************************/ //第四种状态
$ led1 in;
$ led2 in;
$ led3 in;
$ led4 out,high; //高
$ led5 in;
$ led6 in;
if(xianshi_a1.4){$ led1 out,low;}
if(xianshi_a2.1){$ led2 out,low;}
//if() {$ led3 out,low;}
//if() {$ led4 out,low;} //高
if(xianshi_a3.0){$ led5 out,low;}
//if() {$ led6 out,low;}
yanshi();
/**************************************************/ //第五种状态
$ led1 in;
$ led2 in;
$ led3 in;
$ led4 in;
$ led5 out,high; //高
$ led6 in;
//if() {$ led1 out,low;}
if(xianshi_a2.4){$ led2 out,low;}
if(xianshi_a3.1){$ led3 out,low;}
if(xianshi_a3.2){$ led4 out,low;}
//if() {$ led5 out,low;} //高
//if() {$ led6 out,low;}
yanshi();
/**************************************************/ //第六种状态
$ led1 in;
$ led2 in;
$ led3 in;
$ led4 in;
$ led5 in;
$ led6 out,high; //高
//if() {$ led1 out,low;}
if(xianshi_a2.3){$ led2 out,low;}
//if() {$ led3 out,low;}
//if() {$ led4 out,low;}
//if() {$ led5 out,low;}
//if() {$ led6 out,low;} //高
yanshi();
}
/**************************************************/
void jisuan() //计算
{
word jisuan_a1;
byte jisuan_b1,jisuan_b2,jisuan_b3;
jisuan_a1 =temp;
jisuan_b1 =0;
jisuan_b2 =0;
jisuan_b3 =0;
while(jisuan_a1>99) //计算百位
{
jisuan_b1 ++;
jisuan_a1 -=100;
}
while(jisuan_a1>9) //计算十位
{
jisuan_b2 ++;
jisuan_a1 -=10;
}
jisuan_b3 =jisuan_a1; //计算个位
chabiao_a1 =jisuan_b1;
chabiao();
xianshi_a1 =chabiao_a1; //百位机器码
chabiao_a1 =jisuan_b2;
chabiao();
xianshi_a2 =chabiao_a1; //十位机器码
chabiao_a1 =jisuan_b3;
chabiao();
xianshi_a3 =chabiao_a1; //个位机器码
}
/**************************************************/
void chabiao() //查表
{
//共阴:0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f//0x77,0x7c,0x39,0x5e,0x79,0x71
if(chabiao_a1 ==0){chabiao_a1 =0x3f; return;} //0
if(chabiao_a1 ==1){chabiao_a1 =0x06; return;}
if(chabiao_a1 ==2){chabiao_a1 =0x5b; return;}
if(chabiao_a1 ==3){chabiao_a1 =0x4f; return;}
if(chabiao_a1 ==4){chabiao_a1 =0x66; return;}
if(chabiao_a1 ==5){chabiao_a1 =0x6d; return;}
if(chabiao_a1 ==6){chabiao_a1 =0x7d; return;}
if(chabiao_a1 ==7){chabiao_a1 =0x07; return;}
if(chabiao_a1 ==8){chabiao_a1 =0x7f; return;}
if(chabiao_a1 ==9){chabiao_a1 =0x6f; return;}
//if(chabiao_a1 ==10){chabiao_a1=0x; return;} //不显
}
/**************************************************/
void yanshi() //延时
{
.delay 9000;
}
/**************************************************
void anjian() //按键
{
byte anjian_b1;
if(!k1) //加
{
}
if(!k2) //减
{
}
}
/**************************************************/
|
|