⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6675._c

📁 基于AVR单片机的热电偶测量系统源码
💻 _C
字号:
/************************************************************
  FileName: 6675.c
  Description: 温度函数,读取并且显示温度                      
  Function List:  
1. read_max6675()  读取6675的转换结果
2. max6675_display()  显示6675的转换结果
3. wendu6675()  读取并显示6675的转换结果
4. Delay10ms()  延时函数 
***********************************************************/
#include <iom16v.h>
#include <macros.h>
#include "6675.h"

unsigned int read_max6675(void)
{
     unsigned char i;
     unsigned int  x=0; 
	 clr_sck;
     wait;
     clr_cs6675;
     wait; 
     set_sck; 
     wait;
for(i=0;i<16;i++)   //读取转换结果的12位
      {
        wait;
	    clr_sck;
        if(PINB&0x08)
        x|=(1<<(15-i));
        wait;
	    set_sck;
      }
	
	x=(x&0x7fff)>>3; 
	set_cs6675;  
       return x; 
}

void max6675_display(unsigned int x)
{      
       unsigned int temp[5]={0,0,0,0,0};
       unsigned int n=0,m=0;
       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;
       Draw_NtoArab(0x02,0x10,temp[0]);
       Draw_NtoArab(0x02,0x18,temp[1]);
       Draw_NtoArab(0x02,0x20,temp[2]);
       Draw_NtoArab(0x02,0x28,temp[3]);
       Draw_NtoArab(0x02,0x38,temp[4]);
}

void wendu6675(void)
{     unsigned int t;
      Delay10ms(100);
 	  while(1)
      {
	  t=read_max6675();
          max6675_display(t);
	  Delay10ms(100);
	  }
}

void Delay10ms(unsigned char count)
{
     unsigned char TimeCount;
	 unsigned int j;
     TimeCount = count;
	 while(TimeCount > 0)
	 {
	     for(j=0;j<200;j++)
		 {;;}
		 TimeCount--;
	 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -