📄 070707.c
字号:
/*******************************************************
* Productor name:OXYGEN
* Write by:kenny_zhou
* Mail address:zhou_vip_1980@163.com
* Write date:2006.09.22
* Modify date:2007.07.07
* Version:V0.1
* MCU:EM78P447S
* Crystal:4MHz 2 cycle Mode
*******************************************************
* T(sensor) = sensor_time * T(tcc) + (tcc_value-50)/2
* T(standard) = stand_time * T(tcc) + (tcc_value-50)/2
* R(sensor) = [T(sensor) * R(stand)] / T(stand)
* R(sensor) =100K(25 C)
* R(standard) = 220R
* T(tcc)=100us
*******************************************************/
#include "em78x447xx.h"
#include "temp_table.h"
#define DISI() _asm{DISI}
#define ENI() _asm{ENI}
#define WDTC() _asm{WDTC}
#define uchar unsigned char
#define ushort unsigned short
#define ulong unsigned long
/*
static uchar flag1@0x36;
static bit key_valid@0x36@0;
static bit heat_begin@0x36@3;
static bit over_heat@0x36@4;
static bit half_heat@0x36@5;
static bit quarter_heat@0x36@6;
static bit eighth_heat@0x36@7;
static uchar flag2@0x37;
static bit sensor@0x37@0;
static bit one_time_charge@0x37@1;
static bit one_team_finish@0x37@2;
static bit sample_error@0x37@3;
static bit display_set_actual@0x37@4;
static bit rc_charging_now@0x37@5;
static bit lcd_data_ok@0x37@7;
*/
static uchar flag1@0x36;
static bit key_valid@0x36@0;
static bit heat_begin@0x36@3;
static bit over_heat@0x36@4;
static bit half_heat@0x36@5;
static bit quarter_heat@0x36@6;
static bit eighth_heat@0x36@7;
static uchar flag2@0x37;
static bit sensor@0x37@0;
static bit one_time_charge@0x37@1;
static bit one_team_finish@0x37@2;
static bit sample_error@0x37@3;
static bit display_set_actual@0x37@4;
static bit rc_charging_now@0x37@5;
static bit lcd_data_ok@0x37@7;
static uchar sample_times@0x22;//the sample times
static uchar key_time@0x23;
static uchar tcc_present_value@0x24;
static uchar display_time@0x25;
static uchar status_temp@0x26;
static uchar a_temp@0x27;
//******************************************
//the 0X10~0X1F are the C reserve registers
//******************************************
static uchar p7_status@0x28:bank 0;
static uchar key_value_last@0x29:bank 0;
static uchar key1_time@0x2A:bank 0; //count the time of the same key be pressed
static uchar key_same@0x2B:bank 0; //same_key flag
static uchar key_value@0x2C:bank 0;
static uchar rc_times@0x2D:bank 0; //count the RC sample times ,the maxiume time is 6
static uchar NUM1@0x2E:bank 0;
static uchar NUM2@0x2F:bank 0;
static uchar NUM3@0x30:bank 0;
static uchar NUM4@0x31:bank 0;
static uchar heat_key@0x32:bank 0; //heat_key is valid flag
static uchar delay@0x33:bank 0;
static ushort sensor_value@0x34:bank 0;
static ushort difference@0x20:bank 1;
static ushort tcc_times@0x22:bank 1;
static ushort set_f@0x24:bank 1;//the set F temprature
static ushort actual_f@0x26:bank 1;//the present F temprature
static uchar heat_time@0x28:bank 1;//
static ushort stop_time@0x2A:bank 1;//count the time of 20 minutes
static ulong rc_accumulate_sensor@0x2C:bank 1;//the accumulate value of sensor resister
static ulong rc_accumulate_stand@0x30:bank 1;//the accumulate value of standard resister
static uchar sample_error_times@0x34:bank 1;
static uchar data_error_times@0x35:bank 1;
static ushort rc_temp[6]@0x20:bank 2;
static ushort r_min_t@0x2E:bank 2;
static ushort r_max_t@0x30:bank 2;
static uchar r_min_p@0x20:bank 3;
static uchar r_max_p@0x21:bank 3;
static uchar tcc_time_1@0x22:bank 3;
static uchar tcc_time_2@0x23:bank 3;
static uchar r4_temp@0x24:bank 3;
static uchar temp@0x25:bank 3;
static ushort check_table_value@0x26:bank 3;//the value is the C temprature
const uchar char_seg[10]=
{//0,1,2,3,4,5,6,7,8,9
0x50,0xD7,0x64,0x45,0xC3,0x49,0x48,0xD5,0x40,0x41
};
void disp_seg_com(void);
void delay_2ms(void);
void rc_charge(void);
void accumulate(void);
void stop_time_count(void);
void heat_control(void);
void check_temp_table(void);
void division(void);
void rc_data_manage(void);
void key_detect(void);
void add_dec(void);
void main()
{//disable the all INT
DISI();
WDTC();
_asm
{
MOV A,@0x8F
CONTW //set the CONT register
}
WDTCR=0x31;//enable the WDT
//WDTCR=0x9F;
P7CR=0x06;//set the P7.1,P7.2 are INPORT ; the P7.0,P7.3~P7.7 are OUTPORT
P6CR=0x00;//set the P6 are OUTPORT
P7=0x06;//initial P7
P6=0x00;//initial P6
P5CR=0xFF;//set the P5.0~P5.3 are input(high dependent)
set_f=250;//set the "initial" F temprature
flag1=flag2=rc_times=0;
tcc_time_1=tcc_time_2=0;
actual_f=heat_time=stop_time=0;
heat_key=difference=0;
while(1)
{
WDTC();
division();
disp_seg_com();
key_detect();//check the key status
while(heat_begin==1)
{
heat_control();//heater control
if(key_same==1)
{//set the temprature during in the heating
display_set_actual=1;//set the "display_set_actual" flag
division();
}
else
{
if(lcd_data_ok==1)
{//the value of check_table was ready
division();
lcd_data_ok=0;//cleat the "lcd_data_ok" flag
}
else
{//the check_table value was not ready
rc_charge();
}
}
disp_seg_com();
display_time++;
if(display_set_actual==0)
{
if(display_time==200)
{
display_set_actual=1;//set the "display_set_actual" flag
display_time=0;
}
}
if(display_set_actual==1)
{
if(display_time==140)
{
display_set_actual=0;//clear the "display_set_actual" flag
display_time=0;
}
}
stop_time_count();//the 20 minutes counter
if(rc_charging_now==0)
{
key_detect();//check the key status
}
}
}
}
//delay 4ms
void delay_2ms(void)
{
for(delay=0;delay<200;delay++)
{
WDTC();
}
}
//display the temprature mumber
void disp_seg_com()
{//get the segment and common signal ,and send to P5 and P6
uchar temp1,temp2,temp3,temp4;//the temprate value of "bai" "shi" "ge" "set_actual_f_c"
WDTC();
//T1 first 4ms
temp1=((NUM4<<6)&0xC0)|((NUM3<<4)&0x30)|((NUM2<<2)&0x0C)|(NUM1&0x03);
P5CR=0x0E;//set P5_0 is output
P5_0=1;//then set P5_0 is 1
P6=temp1;//set segment and common
delay_2ms();
//T1 second 4ms
temp2=((NUM4<<4)&0xC0)|((NUM3<<2)&0x30)|(NUM2&0x0C)|((NUM1>>2)&0x03);
P5CR=0x0D;//set P5_1 is output
P5_1=1;//then set P5_1 is 1
P6=temp2;//set segment and common
delay_2ms();
//T1 third 4ms
temp3=((NUM4<<2)&0xC0)|(NUM3&0x30)|((NUM2>>2)&0x0C)|((NUM1>>4)&0x03);
P5CR=0x0B;//set P5_2 is output
P5_2=1;//then set P5_2 is 1
P6=temp3;//set segment and common
delay_2ms();
//T1 fouth 4ms
temp4=(NUM4&0xC0)|((NUM3>>2)&0x30)|((NUM2>>4)&0x0C)|((NUM1>>6)&0x03);
P5CR=0x07;//set P5_3 is output
P5_3=1;//then set P5_3 is 1
P6=temp4;//set segment and common
delay_2ms();
//T2 first 4ms
P5CR=0x0E;//set P5_0 is output
P5_0=0;//then set P5_0 is
P6=~temp1;//set segment and common
delay_2ms();
//T2 second 4ms
P5CR=0x0D;//set P5_1 is output
P5_1=0;//then set P5_1 is
P6=~temp2;
delay_2ms();
//T2 third 4ms
P5CR=0x0B;//set P5_2 is output
P5_2=0;//then set P5_2 is 1
P6=~temp3;
delay_2ms();
//T2 fouth 4ms
P5CR=0x07;//set P5_3 is output
P5_3=0;//then set P5_3 is 1
P6=~temp4;
delay_2ms();
}
//count the 20 minutes stop time
void stop_time_count(void)
{
WDTC();
stop_time++;
if(stop_time>11142)//20 minute
{
stop_time=0;//initial the register
heat_time++;
if(heat_time>3)
{
heat_begin=0;//clear the "heat_begin" flag
P7_5=0;//turn off heater
P7_3=0;
P7_4=0;//turn off led
heat_time=0;//clear the register
actual_f=0;//clear the actual temp value
}
}
}
//heat control
void heat_control(void)
{
WDTC();
if(heat_begin==1)
{
difference=set_f-actual_f;
if(difference<401)
{//"set > actual" temprature
//the lowest actual temprature is 76F
if(difference>10)
{//10<difference<325
P7_5=1;//full heating
half_heat=0;//clear "half_heat" flag
P7_3=1;
P7_4=0;//red led on
}
else
{//difference<10
P7_5=!P7_5;//half heat
half_heat=1;//set "half_heat" flag
P7_3=0;
P7_4=1;//green led on
}
}
else
{//"actual > set" temprature
P7_5=0;//stop heat
P7_3=0;
P7_4=1;//green led on
}
}
}
//RC charge detect
void rc_charge(void)
{
WDTC();
if(one_team_finish==0)
{//one team sample is not finished
if(one_time_charge==1)
{//one time RC(sensor/standard) is finished
//judge the sample value is valid or not
p7_status=P7;//save the present status of P7
P7CR=0x06;//set P7.7,P7.6 and P7.0 are output
P7=p7_status;//restore the status of P7
P7_6=0;
P7_7=0;
P7_0=0;//release the charge of C1
tcc_times=(tcc_time_2*256+tcc_time_1)*100+(tcc_present_value-55);//get the charge time
tcc_time_1=0;
tcc_time_2=0;//initial the register
if(sensor==1)
{//sensor==1, then sensor charge time value saving
rc_temp[rc_times]=tcc_times;
tcc_times=0;//initial the charging time register
rc_times++;
if(rc_times>5)
{//sensor sample 6 times is finished
accumulate();
rc_times=0;//initial the register
sensor=0;//sensor resister charge finished,set "sensor=0",prepare to stand resister charge
one_team_finish=1;//set "one_team_finish" flag,prepare the next RC charge team
//"one team finish" = "6 sensor charge" + "6 standard charge"
}
one_time_charge=0;
}
else
{//sensor==0,then standard charge time value saving
rc_temp[rc_times]=tcc_times;
tcc_times=0;//initial the charging time register
rc_times++;
if(rc_times>5)
{
accumulate();
rc_times=0;//initial the register
sensor=1;//stand charge finished,set "sensor=1",prepare to sensor resister charge
}
one_time_charge=0;//clear "one_time_charge"falg,prapare the net charge
}
}
else
{//one team RC(sensor/standard) is not finished,FIRST->standard,SECOND->sensor
if(sensor==1)
{//sensor==1,then sensor resister charge
if(rc_charging_now==0)
{//the rc is not runing ,so could to do this things
p7_status=P7;//save the present status of P7
P7CR=0x47;//set P7.6 and P7.0 are high resistand
P7=p7_status;//restore the status of P7
rc_charging_now=1;//set the "rc_charging_now" flag
TCC=0x37;//initial the TCC,T=100us
IMR=0x09;//initial the INT
P7_7=1;//start sensor resister charge
ENI();
}
}
else
{//sensor==0,then standard resister charge
if(rc_charging_now==0)
{//the rc is not runing ,so could to do this things
p7_status=P7;//save the present status of P7
P7CR=0x87;//set P7.7 and p7.0 are high resistand
P7=p7_status;//restore the status of P7
rc_charging_now=1;//set the "rc_charging_now" flag
TCC=0x37;//initial the TCC,T=100us
IMR=0x09;//initial the INT
P7_6=1;//start standard resister charge
ENI();
}
}
}
}
else
{//one team(6 sensor charge + 6 standard charge) RC are finished
check_temp_table();
actual_f=check_table_value*9/5+32;
//intial the "one team finish" flag
one_team_finish=0;//clear the "one_team_finish" flag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -