|
#include "reg52.h"
#include "absacc.h"
#include "math.h"
#define uchar unsigned char
#define uint unsigned int
#define dm XBYTE[0x8000]
#define wm XBYTE[0x8100]
sbit S0=P3^1;
sbit CS=P3^2;
sbit SCK=P3^3;
sbit Work_Stop=P1^4;
uint Re_Convert (void); //redianou convert
void Disp_temp(void);
void Delay_50us (uint t);
uchar click=0,Time_h=0,Time_m=0,Time_l=0;
uint disp;
uint total,P_Temp1,P_Temp;
float S_Temp;
const uchar code tab1[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
const uchar code tab2[]={0x01,0x80,0x10,0x04,0x08}; //tab1为数码管的段码,tab2为数码管的位码
/******************************************************************************************************/
void main(void) /*主程序*/
{
Delay_50us (100);
Work_Stop =0;
S0 =0;
while(1)
{
P_Temp =Re_Convert();
P_Temp1 =0.25*P_Temp; //P_Temp =(1024*P_Temp)/4096/10
Disp_temp();
disp=0;
P_Temp=0;
P_Temp1=0;
}
}
/******************************************************************************************************/
void Delay_50us(uint t) /*延时50us程序*/
{
uchar j;
for(;t>0;t--)
for(j=19;j>0;j--);
}
/********************************************热电偶转换程序***********************************************/
uint Re_Convert (void)
{
uchar i;
uint P_Temp2 =0;
SCK =0;
S0 =0;
CS =0;
for(i=0;i<16;i++)
{
SCK =1;
if(S0==1)
{
P_Temp2 =P_Temp2 | 0x01;
}
Delay_50us(1);
SCK =0;
Delay_50us(1);
P_Temp2 <<=1;
}
CS =1;
if(P_Temp2 & 0x0004)
{
Work_Stop =1;
}
P_Temp2 =(P_Temp2 & 0x7fff) >>3;
return(P_Temp2);
P_Temp2 =0;
Delay_50us(1000);
}
/********************************************显示程序***********************************************/
void Disp_temp(void)
{
Time_h=P_Temp1/100;
Time_m=P_Temp1/10%10;
Time_l=P_Temp1%10;
dm=tab1[Time_h];
wm=tab2[2];
Delay_50us(50);
dm=tab1[Time_m];
wm=tab2[3];
Delay_50us(50);
dm=tab1[Time_l];
wm=tab2[4];
Delay_50us(50);
}
/********************************************** END ***************************************************/ |
|