📄 max6675.c
字号:
/**************************************
Max6675 驱动程序
*************************************/
#include <reg52.h>
#include "stdafx.h"
/*以下定义为Muc与Max6675 SPI口软件模拟端口定义 */
sbit SO =P3^7; // 7pin DAT to s52 P3^7
sbit CS =P3^6; // 6pin chip seclect to s52 P3^6
sbit SCK =P3^5; //5pin Clock from s52 P3^5
uchar almflag;
uint max6675(uchar degree);
/**********************************************************************
This procedure performs serial communication with IC12 (max6675),
Input: degree is accurate selection , byte to send to IC12
Ouput:
modify: 关键点,要得到AD结果需定时硬件中断CPU
************************************************************************/
uint max6675(uchar degree)
{
uchar i;
int adout;
//uchar degree=1;
adout = 0; // reset conversion read
SCK=0;
CS = 0; // activate CS
for(i=0; i<16; i++) // Cycle 16 times
{
SCK = 1; // Set Clock signal to 1
if(SO) // Test if data from so is 1
{
adout = adout | 1; // addtional one approach
}
if(i!=16) // not equ 16th cycle
{
if(adout==0xfffc) // hot open alarm
{
almflag=1;
//return 0;
}
adout<<=1; // shift left 1 position
}
SCK = 0;
} // end cycle
// set Clock to 0
CS = 1; // diable CS
adout = (adout & 0x7fff) >>3; // Drop dummy sign bit D15
//TR1=1;
if (degree == 0 )
{
adout=adout;
}
else {
adout*=10;}
return adout; // 注:adout 的数值类型,如为有符号,则要保留原
// 符号位.
}
/*-----------------------------------------------------------------------------------------------------------
;中位值平均滤波程序
函数说明: 相当于“中位值滤波法”+“算术平均滤波法”连续采样N个数据,
去掉一个最大值和一个最小值然后计算N-2个
数据的算术平均值
因消耗内存,且影响速度,暂停用
-----------------------------------------------------------------------------------------------------------*/
/*
uint filter(void)
{
char count,i,j,k;
uint value_buf[N];
uint temp;
uint sum=0;
for (count=0;count<N;count++)
{
value_buf[count]=max6675(1);
//delayxus(1);
}
for (i=0;i<N-1;i++) // 外循环N次
{
k = i;
for (j=i+1;j<N;j++)
if (value_buf[j]<value_buf[k]) k=j; // 后小前的比较,小的前移
temp = value_buf[k];
value_buf[k] = value_buf[i]; // 下个前移一个,继续下一轮的比较
value_buf[i] = temp; // 按小到大的排序,结果10个有序数字.
}
for(count=1;count<N-1;count++) // 从1开始 去最小值,N-1 最后个大值
sum += value_buf[count];
return sum/(N-2);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -