📄 main.c
字号:
else {t_buf[(i*8+j)*2-1]=i*8+j; t_buf[(i*8+j)*2]=temp&0xff; }
}
/************* display temperature *********************************/
void display_temp_6(unsigned i,unsigned char j,short int temp)
{
unsigned char y,z,h,w0,w1;
signed char down,up;
bit err,qq;
err=0;
qq=0;
w0=28;w1=31;
z=0;
if(j==1|j==4){y=2;}
if(j==2|j==5){y=4;}
if(j==3|j==6){y=6;}
// if(j==4|j==8){y=6;}
if(temp<-880|temp>2000|temp==-1)
{if(j<=3){write_word(0,y,28,&chinese[51]);
write_word(0,y,44,&chinese[52]);}
else{write_word(1,y,28,&chinese[51]);
write_word(1,y,44,&chinese[52]);}
err=1; // err control r ,l
}
if(temp<0){temp*=(-1);qq=1;} // qq control z ,f
temp*=0.0625;
if(~err)
{
read_iic_data(1,&iic_read,0,8); //继电器
if(iic_read[3]==1){down=iic_read[1]*(-1);}
else down=iic_read[1];
if(iic_read[4]==1){up=iic_read[2]*(-1);}
else {up=iic_read[2];}
if(temp<=down|temp>=up)
{
call=0;
}
}
h=temp/100;
if(j<=3){ if(h==0){w0-=7;} //w0
write_byte(0,y,7,&number[25]);
write_byte(0,y,18,&number[22]);
if(~err){if(qq){write_byte(0,y,23,&number[25]);} //负号!
write_byte(0,y,w0+18,&number[26]);
write_byte(0,y,w0+26,&number[12]);}
write_byte(0,y,0,&number[i+10]);
write_byte(0,y,12,&number[j]);
if(~err){
if(h==1)
{
write_byte(0,y,w0,&number[h]);}
z=(temp-(h*100))/10;
write_byte(0,y,w0+7,&number[z]);
z=temp%10;
write_byte(0,y,w0+14,&number[z]);
}}
else
{
if(h==0){w1-=7;}
write_byte(1,y,10,&number[25]);
write_byte(1,y,21,&number[22]); //:
if(~err){if(qq){write_byte(1,y,26,&number[25]);} //负号!
write_byte(1,y,w1+26,&number[12]);
write_byte(1,y,w1+18,&number[26]);
}
write_byte(1,y,3,&number[i+10]);
write_byte(1,y,15,&number[j]);
if(~err)
{
if(h==1){
write_byte(1,y,w1,&number[h]);}
z=(temp-(h*100))/10;
write_byte(1,y,w1+7,&number[z]);
z=temp%10;
write_byte(1,y,w1+14,&number[z]);
}}
// SEND RS485
if(err){t_buf[(i*6+j)*2-1]=i*6+j; t_buf[(i*6+j)*2]=0xfe;}
else {t_buf[(i*6+j)*2-1]=i*6+j; t_buf[(i*6+j)*2]=temp&0xff; }
}
/******************** display single temp *********************************************/
void display_temp_single(unsigned i,unsigned char j,short int temp)
{
unsigned char y,z,h,w0,w1;
signed char down,up;
bit err,qq;
err=0;
qq=0;
w0=28;w1=31;
z=0;
if(j==1|j==4){y=2;}
if(j==2|j==5){y=4;}
if(j==3|j==6){y=6;}
// if(j==4|j==8){y=6;}
if(j<=3){
// write_byte(0,y,23,&number[19]);
// write_byte(0,y,31,&number[19]);
// write_byte(0,y,39,&number[19]);
// write_byte(0,y,47,&number[19]);
write_byte(0,y,55,&number[19]); }
if(j>3){ write_byte(1,y,23,&number[19]);
// write_byte(1,y,31,&number[19]);
// write_byte(1,y,39,&number[19]);
// write_byte(1,y,47,&number[19]);
write_byte(1,y,55,&number[19]); }
if(temp<-880|temp>2000|temp==-1)
{if(j<=3){write_word(0,y,28,&chinese[51]);
write_word(0,y,44,&chinese[52]);}
else{write_word(1,y,28,&chinese[51]);
write_word(1,y,44,&chinese[52]);}
err=1; // err control r ,l
}
if(temp<0){temp*=(-1);qq=1;} // qq control z ,f
temp*=0.0625;
if(~err)
{
read_iic_data(1,&iic_read,0,8); //继电器
if(iic_read[3]==1){down=iic_read[1]*(-1);}
else down=iic_read[1];
if(iic_read[4]==1){up=iic_read[2]*(-1);}
else {up=iic_read[2];}
if(temp<=down|temp>=up)
{
call=0;
}
}
// SEND RS485
if(err){t_buf[(i*6+j)*2-1]=i*6+j; t_buf[(i*6+j)*2]=0xfe;}
else {t_buf[(i*6+j)*2-1]=i*6+j; t_buf[(i*6+j)*2]=temp&0xff; }
h=temp/100;
if(j<=3){ if(h==0){w0-=7;} //w0
write_byte(0,y,7,&number[25]); //-
write_byte(0,y,18,&number[22]); //:
if(~err){if(qq){write_byte(0,y,23,&number[25]);} //负号!
write_byte(0,y,w0+18,&number[26]);
write_byte(0,y,w0+26,&number[12]);}
write_byte(0,y,0,&number[j+10-1]);
write_byte(0,y,12,&number[1]);
if(~err){
if(h==1)
{
write_byte(0,y,w0,&number[h]);}
z=(temp-(h*100))/10;
write_byte(0,y,w0+7,&number[z]);
z=temp%10;
write_byte(0,y,w0+14,&number[z]);
}}
else
{
if(j>3){j-=3;}
if(h==0){w1-=7;}
write_byte(1,y,10,&number[25]);
write_byte(1,y,21,&number[22]); //:
if(~err){if(qq){write_byte(1,y,26,&number[25]);} //负号!
write_byte(1,y,w1+26,&number[12]);
write_byte(1,y,w1+18,&number[26]);
}
write_byte(1,y,3,&number[j+10-1]);
write_byte(1,y,15,&number[2]);
if(~err)
{
if(h==1){
write_byte(1,y,w1,&number[h]);}
z=(temp-(h*100))/10;
write_byte(1,y,w1+7,&number[z]);
z=temp%10;
write_byte(1,y,w1+14,&number[z]);
}}
}
/************** timer interrupt 0 *********************************/
void time_0(void)interrupt 1 using 3
{
ch451_clk=0;
ch451_clk=1;
base_time=!base_time;
TH0=0x00;
TL0=0x00;
// if(flag_s){ok_es++;if(ok_es>500){ok_es=0;ES=1;}}
if(flag_exit){ok_n_times++;}
if(ok_n_times>100){flag_exit_ok=1;ok_n_times=0;}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
/********* ch451 init *************************/
void ch451_init(void)
{
ch451_din=0;
ch451_din=1;
ch451_load=1;
ch451_clk=1;
_nop_();
}
/************ write 12 bit to ch451 *************/
void ch451_write(unsigned short int command)
{
unsigned char i;
EX1=0;
ch451_load=0;
for(i=0;i<12;i++)
{
ch451_din=command&1;
ch451_clk=0;
command>>=1;
ch451_clk=1;
}
ch451_load=1;
EX1=1;
}
/********** CH451 interrupt **************************/
void ch451_inter() interrupt 2 using 1
{
key_flag=1;
}
/********** bring a key code ************************/
unsigned char key_code()
{
unsigned char i;
unsigned char command,keycode;
command=0x07;
EX1=0;
ch451_load=0;
for(i=0;i<4;i++)
{
ch451_din=command&1;
ch451_clk=0;
command>>=1;
ch451_clk=1;
}
ch451_load=1;
keycode=0;
for(i=0;i<7;i++)
{
keycode<<=1;
keycode|=ch451_dout;
ch451_clk=0;
ch451_clk=1;
}
EX1=1; // open outinterrupt
IE1=0; // interrupt flag bit ;
return(keycode);
}
/*************** initialization all function ********************/
void initialization()
{
TMOD=0x01; /*工作模式,定时器0*/
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1; /*启动定时器器*/
EX1=0; // out interrupt
PX1=0; // 优先级
IT1=1; // 边沿触发(下降沿有效)
/************************/
TMOD|= 0x20;
SCON = 0x50;
TH1 = 0xf4;
TL1 = 0xf4;
PCON = 0x00; // SMOD=0
TR1 = 1; /* 定时器1启动计数*/
ES = 0; /* 串口开中断 */
PS = 0; /* 串口低优先级 */
REN = 1; /* 串口接收允许 */
EA = 1; /* 开CPU中断 */
DE=0;
/*************************/
initialization_led_screen();
// There have lcd_scrren error!
// ds18b20_start();
key_flag=0;
delay_iic();
read_iic_data(1,&iic_read,0,1);
if(iic_read[0]==-1|iic_read[0]>64|iic_read[0]<0){memery_error();} //存储器故障!
start();
if(iic_read[0]==0) // read two times
{ lcd_screen_blank();
found_new();
display_set();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -