📄 max6675.c
字号:
#include <reg51.h>
#include <stdlib.h>
#include <stdio.h>
#include "SVM12864_lcd.h"
#define uchar unsigned char
#define uint unsigned int
//--------------热电偶数字转换器MAX6675
sbit SO=P1^0;
sbit CS=P1^1;
sbit SCK=P1^2;
sbit P1_7=P1^7;
sbit P1_6=P1^6;
sbit P2_0=P2^0;
sbit P2_1=P2^1;
/*******************************************************
FUNCTION:delay_ms(uchar ntimes)
parameter: nTimes--延迟的毫秒数
cai 2006.05.20
*******************************************************/
void delay_ms(uchar ntimes)
{
uchar i;
for (i = 0; i<ntimes;i++)
{
TH0 = 256 - (1000/256);
TL0 = 1000%256;
TR0 = 1;
while (!TF0);
TF0 = 0;
}
TR0 = 0;
}
/**************************************************************
//FUNCTION:delay_ms(uchar ntimes)
//parameter: nTimes--延迟的微秒数
//sample:delay_ms(10);
//cai 2006.05.20
//*************************************************************/
void delay_us(uchar ntimes)
{
TH0 = 0xFF;
TL0 = 256 - ntimes;
TR0 = 1;
while (!TF0);
TR0 = 0;
TF0 = 0;
}
/********************************
//读取MAX6675
*********************************/
int Read_6675()
{ uchar i;
uint dat_temp;
uint dat_6675;
i=0;
dat_temp=0;
dat_6675=0;
//ready
CS=0;
//delay_us(10);
SCK=0;
//delay_us(10);
//get D15-D0 from 6675
for(i=0;i<16;i++)
{
SCK=1;
dat_temp=dat_temp<<1;
if(SO==1)
dat_temp=dat_temp|0x01;
SCK=0;
//delay_us(10);
}
CS=1;
dat_temp=dat_temp<<1;
dat_temp=dat_temp>>4;
dat_temp=dat_temp/4;
dat_6675 = dat_temp;
return dat_6675;
}
/* *******************************
//转换读取MAX6675的数据dat
*********************************/
void dat_cov(uint dat)
{
}
main()
{
uint j;
uint dat;
uint margin;
uchar i;
char a[16];
char smargin[16];
margin=0;
dat=0;
j=0;
margin=25;
//LCDRST=0;
for(i=0;i<5;i++) delay_ms(200);
//LCDRST=1;
LCD_Ini();
LCD_At(1);
LCD_Printf("Test clear CMD ..");
LCD_At(2);
LCD_Printf("Foracb!");
LCD_At(3);
LCD_Printf("The MRGN is 25`C");
while(1)
{
LCD_At(4);
//读取MAX6675的温度值
dat=Read_6675();
if(dat>=0)
{
sprintf(a,"T is %d`C",dat);
LCD_Printf(a);
}
//低于MRGN/margin 警报!
if(dat<=margin) P1_6=0;
else P1_6=1;
//键盘扫描 调整参数MRGN/margin
P2_0=1; // 用于调整参数MRGN/margin
P2_1=1; // 用于调整参数MRGN/margin
while(P2_0&&P2_1&&j<60000){j++;};
if(P2_0==0)
{
margin=margin-1;
}
else if(P2_1==0)
{
margin=margin+1;
};
if(j<60000)
{
LCD_At(3);
sprintf(smargin,"The MRGN is %d`C",margin);
LCD_Printf(smargin);
for(i=0;i<80;i++) delay_ms(200);
}
j=0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -