程序
#include <REGX52.H>
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
sbit SO = P1^7;
sbit SCK = P1^6;
sbit CS = P1^5;
sbit wx = P2^7;
sbit dx = P2^6;
#define uchar unsigned char
#define uint unsigned int
const uchar DevID = 1;
uchar buffer;
uchar rcv_buffer[20];
uchar send_buffer[20];
uchar flag_ok = 0;
uint MAX6675_Temp;
uchar Flag_connect;
uchar CRCH,CRCL;
uchar wd[2];
uchar flag_dis;
uchar dis[4] = {
0x00, 0x00, 0x00,0x00 };
uchar code SMG[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint MAX6675_ReadReg(void)
{
uchar i;
uint dat;
i = 0;
dat = 0;
CS = 0;
SCK = 0;
for(i=0; i<16; i++)
{
SCK = 1;
dat = dat<<1;
if( SO==1 )
dat = dat|0x01;
SCK = 0;
}
CS = 1;
return dat;
}
void DelayMs(uint i)
{
uint j,k;
for(j=i; j>0; j--)
for(k=118; k>0; k--);
}
void SMG_DisChar(uchar place, uchar num)
{
P0=0X00;
dx = 1;
P0 = SMG[num];
dx = 0;
P0=0XFF;
wx = 1;
P0 = place;
wx = 0;
DelayMs(1);
}
void Display(uint temp)
{
if(Flag_connect==0)
{
if(temp > 999)
{
SMG_DisChar(0XFE,temp/1000);
}
if(temp > 99)
{
SMG_DisChar(0XFD,(temp%1000)/100);
}
if(temp > 9)
{
SMG_DisChar(0XFB,(temp/10)%10);
}
SMG_DisChar(0XF7,temp%10);
}
else
{
SMG_DisChar(3, 0x0F);
SMG_DisChar(2, 0x0F);
SMG_DisChar(1, 0x0F);
SMG_DisChar(0, 0x0F);
}
}
void main(void)
{
uchar cnt = 11;
uint t;
while(1)
{
t=MAX6675_ReadReg();
Flag_connect=t&0x04;
Flag_connect=Flag_connect>>2;
t = t<<1;
t = t>>4;
MAX6675_Temp = t/4;
for(t=0; t<200; t++)
{
Display(MAX6675_Temp);
}
}
}