#include "io430.h"
#include "in430.h"
unsigned int byte,bytee,t;
void Delay(unsigned int n)
{
unsigned int j;
for(j=0;j<n;j++)
{
;
}
}
void max6675_display(unsigned int x)
{
unsigned int temp[5]={0,0,0,0,0};
unsigned int n,m,t;
m=10237.5*x/4095;
temp[0]=m/10000;
n=m-temp[0]*10000;
temp[1]=n/1000;
n=n-temp[1]*1000;
temp[2]=n/100;
n=n-temp[2]*100;
temp[3]=n/10;
n=n-temp[3]*10;
temp[4]=n/1;
t=temp[4];
}
unsigned int read_max6675(void)
{
byte=0;
unsigned int i=0;
P2OUT &=~BIT6; //CS=0,P2.6输出低电平
P1OUT &=~BIT1; //SCK=0
//Delay(10);
for(i=0;i<16;i++)
{
Delay(10);
P1OUT |=BIT1; //SCK=1
Delay(10);
if(P1IN&BIT0)
//byte+=1;
// byte<<=1;
byte|=(1<<(15-i));
P1OUT &=~BIT1; //SCK=0
}
P2OUT |=BIT6; //CS=1
P1OUT &=~BIT1;//SCK=0
bytee=byte;
if(bytee&0x8000)byte=0xfe;
else if(bytee&0x4)byte=0xff;
else
{
byte=byte&0x7ff8;
byte=byte>>3;
//byte=byte>>2;
}
return byte;
}
int main( void )
{ P1DIR &=~BIT0; // P1.0为输入
P1DIR |=BIT1; //P1.1作输出
P1SEL=0;
P2DIR |=BIT6; //P2.6作输出
P2SEL=0;
while(1)
{
Delay(1000); //延时
t=read_max6675(); //读取温度
max6675_display(t); //显示温度值
Delay(1000);
}
}
|