📄 uart-adc-cbc.c
字号:
t = (6666.67*E + 956.33)/8.5297;
else if (E >= 1.1361 && E > 1.2642)
t = (6666.67*E + 1084.7)/8.6473;
else if (E >= 1.2642 && E > 1.39395)
t = (6666.67*E + 1193.5)/8.7338;
else if (E >= 1.39395 && E > 1.52505)
t = (6666.67*E + 1202.6)/8.7461;
else if (E >= 1.52505 && E > 1.6563)
t = (6666.67*E + 1077.9)/8.6576;
else if (E >= 1.6563 && E > 1.78605)
t = (6666.67*E + 804.11)/8.4752;
else if (E >= 1.78605 && E > 1.91295)
t = (6666.67*E + 365.2)/8.2;
else if (E >= 1.91295 && E > 2.03565)
t = (6666.67*E - 117.71)/7.9143;
else t=0;
result_temp=t*10;
return(result_temp);
}
//**************************************************
//**************************************************
//**************************************************
long metal(double EE,int channel)
{
float t;
long result;
float temp1, temp2, temp3;
t=high_temp()/10;
switch(channel)
{
case 1://meng
{
temp1 = -4642.78*EE/(273.2+t);
result = (long)(exp(temp1)*(10^4));
break;
}
case 4://yang
{
temp2 = (-1160.69*EE-27805.7+10.3873*t)/(273.2+t);
result = (long)(fabs(temp1)*(10^4));
break;
}
case 5://liu
{
temp3 = -(-4642*EE-2187.41+6.587*t)/(273.2+t);
result =(long)( exp(temp3)*(10^4));
break;
}
default:
break;
}
return(result);
}
void ADC0_Init (unsigned int ad_sel)
{
ADC0CN = 0x05; // ADC0 disabled; normal tracking
REF0CN = 0x03;
AMX0SL = ad_sel;
ADC0CF = 0x60;
ADC0CF |= 0x00;
EIE2 |= 0x02;
}
/*************************************************/
/*************************************************/
void ADC0_conversion (void) interrupt 14
{
time_ok=1;
}
/*************************************************/
/*************************************************/
void ADC0_temperature_Init (void)
{
ADC0CN = 0x05; // ADC0 disabled; normal tracking
REF0CN = 0x07;
AMX0SL = 0x0f;
ADC0CF = 0x60;
ADC0CF |= 0x01;
EIE2 |= 0x02; // enable ADC interrupts
}
/*************************************************/
/*************************************************/
void ADC0_voltage_conversion (void) interrupt 15
{
static unsigned char int_dec[9];
static unsigned long accumulator[9];
unsigned long temp;
EA=0;
ADCINT = 1; // clear ADC conversion complete
accumulator[channel] += ADC0;
int_dec[channel]+=1;
if(int_dec[channel] == INT_DEC)
{
temp=accumulator[channel];
int_dec[channel] =0 ;
result[channel] = temp >> 3;
accumulator[channel] = 0L;
ad_ok[channel]=1;
}
time_ok=1;
}
/***********************************************************************/
/***********************************************************************/
void ad_display(unsigned int turn)
{
long temp_int;
unsigned long temperature=0;
double temp;
//temperature
switch(turn)
{
case 9:
{
//voltage
Timer3_Init(1);
EA=1;
channel=8;
while(time_ok==0);
EA=0;
time_ok=0;
ADC0_temperature_Init();
ADCEN = 1;
if(ad_ok[channel]==1)
{
temperature = result[channel];
temperature = temperature - 41857;
temperature = (temperature * 100L) / 154;
temp_int = temperature/100 ;
ad[channel][0]=(temp_int%10);
ad[channel][1]=(unsigned int)((temp_int%100)/10);
ad[channel][2]=(temp_int-(temp_int%100))/100;
ad[channel][3]=(temp_int-(temp_int%100))/100;
ad[channel][4]=(temp_int-(temp_int%100))/100;
disp_16_8(&alphabet_big[19*16],1,13);
disp_16_8(&symbol[32],1,14);
if(ad[channel][4]!=0)
disp_16_8(&number[ad[channel][4]*16],1,15);
else disp_16_8(&symbol[64],1,15);
if((ad[channel][4]!=0)||(ad[channel][3]!=0))
disp_16_8(&number[ad[channel][3]*16],1,16);
else disp_16_8(&symbol[64],1,16);
if((ad[channel][4]!=0)||(ad[channel][3]!=0)||(ad[channel][2]!=0))
disp_16_8(&number[ad[channel][2]*16],1,17);
else disp_16_8(&symbol[64],1,17);
disp_16_8(&number[ad[channel][1]*16],1,18);
// disp_16_8(&symbol[0],1,19);
disp_16_8(&number[ad[channel][0]*16],1,19);
disp_16_16(&hanzi[3*32],1,20);//
}
break;
}
case 0:
{
//wendu
Timer3_Init(1);
EA=1;
channel=0;
while(time_ok==0);
EA=0;
time_ok=0;
ADC0_temperature_Init();
ADCEN = 1;
if(ad_ok[channel]==1)
{
temp_int=high_temp(); /////////////////////////////////
ad[channel][0]=(temp_int%10);
ad[channel][1]=(unsigned int)((temp_int%100)/10);
ad[channel][2]=(unsigned int)((temp_int%1000)/100);
ad[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_8(&alphabet_big[19*16],1,13);
disp_16_8(&symbol[32],1,14);
if(ad[channel][4]!=0)
disp_16_8(&number[ad[channel][4]*16],1,15);
else disp_16_8(&symbol[64],1,15);
if((ad[channel][4]!=0)||(ad[channel][3]!=0))
disp_16_8(&number[ad[channel][3]*16],1,16);
else disp_16_8(&symbol[64],1,16);
if((ad[channel][4]!=0)||(ad[channel][3]!=0)||(ad[channel][2]!=0))
disp_16_8(&number[ad[channel][2]*16],1,17);
else disp_16_8(&symbol[64],1,17);
disp_16_8(&number[ad[channel][1]*16],1,18);
disp_16_8(&symbol[0],1,19);
disp_16_8(&number[ad[channel][0]*16],1,20);
disp_16_16(&hanzi[3*32],1,21);//
}
break;
}
case 1:
{
//yang
Timer3_Init(1);
EA=1;
channel=1;
while(time_ok==0);
EA=0;
time_ok=0;
ADC0_Init(channel);
ADCEN = 1;
if(ad_ok[channel]==1)
{
temperature = result[channel];
temp_int = (unsigned int)(temperature*24380/65536); /////////////////////////////////
ad[channel][0]=(temp_int%10);
ad[channel][1]=(unsigned int)((temp_int%100)/10);
ad[channel][2]=(unsigned int)((temp_int%1000)/100);
ad[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_16(&hanzi[0],3,1);
disp_16_8(&alphabet_big[4*16],3,3);
disp_16_8(&symbol[32],3,4);
if(ad[channel][4]!=0)
disp_16_8(&number[ad[channel][4]*16],3,5);
else disp_16_8(&symbol[64],3,5);
if((ad[channel][4]!=0)||(ad[channel][3]!=0))
disp_16_8(&number[ad[channel][3]*16],3,6);
else disp_16_8(&symbol[64],3,6);
if((ad[channel][4]!=0)||(ad[channel][3]!=0)||(ad[channel][2]!=0))
disp_16_8(&number[ad[channel][2]*16],3,7);
else disp_16_8(&symbol[64],3,7);
disp_16_8(&number[ad[channel][1]*16],3,8);
disp_16_8(&symbol[0],3,9);
disp_16_8(&number[ad[channel][0]*16],3,10);
disp_16_8(&alphabet_small[16*12],3,11);
disp_16_8(&alphabet_big[16*21],3,12);
temp_int = (unsigned int)(temperature*24380/65536); /////////////////////////
temp_int=metal(temp_int,channel); //////////////////////////
ad_other[channel][0]=(temp_int%10);
ad_other[channel][1]=(unsigned int)((temp_int%100)/10);
ad_other[channel][2]=(unsigned int)((temp_int%1000)/100);
ad_other[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad_other[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_8(&alphabet_small[0],3,16);
disp_16_8(&symbol[32],3,17);
disp_16_8(&number[ad_other[channel][4]*16],3,18);
disp_16_8(&symbol[0],3,19);
disp_16_8(&number[ad_other[channel][3]*16],3,20);
disp_16_8(&number[ad_other[channel][2]*16],3,21);
disp_16_8(&number[ad_other[channel][1]*16],3,22);
disp_16_8(&number[ad_other[channel][0]*16],3,23);
}
break;
}
case 2:
{
//liu
Timer3_Init(1);
EA=1;
channel=4;
while(time_ok==0);
EA=0;
time_ok=0;
ADC0_Init(channel);
ADCEN = 1;
if(ad_ok[channel]==1)
{
temperature = result[channel];
temp_int = (unsigned int)(temperature*24380/65536); /////////////////////
ad[channel][0]=(temp_int%10);
ad[channel][1]=(unsigned int)((temp_int%100)/10);
ad[channel][2]=(unsigned int)((temp_int%1000)/100);
ad[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_16(&hanzi[32],5,1);
disp_16_8(&alphabet_big[4*16],5,3);
disp_16_8(&symbol[32],5,4);
if(ad[channel][4]!=0)
disp_16_8(&number[ad[channel][4]*16],5,5);
else disp_16_8(&symbol[64],5,5);
if((ad[channel][4]!=0)||(ad[channel][3]!=0))
disp_16_8(&number[ad[channel][3]*16],5,6);
else disp_16_8(&symbol[64],5,6);
if((ad[channel][4]!=0)||(ad[channel][3]!=0)||(ad[channel][2]!=0))
disp_16_8(&number[ad[channel][2]*16],5,7);
else disp_16_8(&symbol[64],5,7);
disp_16_8(&number[ad[channel][1]*16],5,8);
disp_16_8(&symbol[0],5,9);
disp_16_8(&number[ad[channel][0]*16],5,10);
disp_16_8(&alphabet_small[16*12],5,11);
disp_16_8(&alphabet_big[16*21],5,12);
temp_int = (unsigned int)(temperature*24380/65536); /////////////////
temp_int=metal(temp_int,channel); /////////////////
ad_other[channel][0]=(temp_int%10);
ad_other[channel][1]=(unsigned int)((temp_int%100)/10);
ad_other[channel][2]=(unsigned int)((temp_int%1000)/100);
ad_other[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad_other[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_8(&alphabet_small[0],5,16);
disp_16_8(&symbol[32],5,17);
disp_16_8(&number[ad_other[channel][4]*16],5,18);
disp_16_8(&symbol[0],5,19);
disp_16_8(&number[ad_other[channel][3]*16],5,20);
disp_16_8(&number[ad_other[channel][2]*16],5,21);
disp_16_8(&number[ad_other[channel][1]*16],5,22);
disp_16_8(&number[ad_other[channel][0]*16],5,23);
}
break;
}
case 3:
{
//meng
Timer3_Init(1);
EA=1;
channel=5;
while(time_ok==0);
EA=0;
time_ok=0;
ADC0_Init(channel);
ADCEN = 1;
if(ad_ok[channel]==1)
{
temperature = result[channel];
temp_int = (unsigned int)(temperature*24380/65536); /////////////////
ad[channel][0]=(temp_int%10);
ad[channel][1]=(unsigned int)((temp_int%100)/10);
ad[channel][2]=(unsigned int)((temp_int%1000)/100);
ad[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_16(&hanzi[64],7,1);
disp_16_8(&alphabet_big[4*16],7,3);
disp_16_8(&symbol[32],7,4);
if(ad[channel][4]!=0)
disp_16_8(&number[ad[channel][4]*16],7,5);
else disp_16_8(&symbol[64],7,5);
if((ad[channel][4]!=0)||(ad[channel][3]!=0))
disp_16_8(&number[ad[channel][3]*16],7,6);
else disp_16_8(&symbol[64],7,6);
if((ad[channel][4]!=0)||(ad[channel][3]!=0)||(ad[channel][2]!=0))
disp_16_8(&number[ad[channel][2]*16],7,7);
else disp_16_8(&symbol[64],7,7);
disp_16_8(&number[ad[channel][1]*16],7,8);
disp_16_8(&symbol[0],7,9);
disp_16_8(&number[ad[channel][0]*16],7,10);
disp_16_8(&alphabet_small[16*12],7,11);
disp_16_8(&alphabet_big[16*21],7,12);
temp_int = (unsigned int)(temperature*24380/65536); /////////////////
temp_int=metal(temp_int,channel); /////////////////
ad_other[channel][0]=(temp_int%10);
ad_other[channel][1]=(unsigned int)((temp_int%100)/10);
ad_other[channel][2]=(unsigned int)((temp_int%1000)/100);
ad_other[channel][3]=(unsigned int)((temp_int%10000)/1000);
ad_other[channel][4]=(unsigned int)((temp_int%100000)/10000);
disp_16_8(&alphabet_small[0],7,16);
disp_16_8(&symbol[32],7,17);
disp_16_8(&number[ad_other[channel][4]*16],7,18);
disp_16_8(&symbol[0],7,19);
disp_16_8(&number[ad_other[channel][3]*16],7,20);
disp_16_8(&number[ad_other[channel][2]*16],7,21);
disp_16_8(&number[ad_other[channel][1]*16],7,22);
disp_16_8(&number[ad_other[channel][0]*16],7,23);
}
break;
}
default: break;
}
}
/*************************************************/
/*************************************************/
void main (void)
{
int i,turn=0,tt;
WDTCN = 0xde;
WDTCN = 0xad;
EA=0;
LCD_RST=0;
delay();
LCD_RST=1;
SYSCLK_Init ();
PORT_Init();
LCM_initialize();
LCM_CLR();
i= clock_status_check();
if(i==1)
DS1302_initialize(&ds1302_origin[0]);
//Timer3_Init(SYSCLK/12/100);
//EA=1;
while(1)
{
i=key_detect();
if(i==1)
{
if(clock_set==0)
{
for(i=0;i<7;i++)
ds1302_clock_set[i]=ds1302_clock[i];
clock_set=1;
}
}
if(clock_set==0)
refresh_clock();
else
keypad();
if(tt==0)
{
ad_display(9);
ad_display(1);
tt=1;
}
else
{
ad_display(2);
ad_display(3);
tt=0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -