背景图片
基于合泰HT66F018的双路TDS读取源码 - 啊和的博客

基于合泰HT66F018的双路TDS读取源码 - 啊和的博客 基于合泰HT66F018的双路TDS读取源码 - 啊和的博客

基于合泰HT66F018的双路TDS读取源码

本程序来源于合泰官方

官方已将TDS值算法打包成lib文件,如需使用,请直接在代码上调用即可。

QQ截图20180908085041

部分程序预览

if(j !=0xaa)
    {
        g_u16TDSjData=TDSyuan_Data;
        wr_eeprom(0x01,    g_u16TDSjData);
        wr_eeprom(0x00,    g_u16TDSjData>>8);
        
        g_u16TDSjData=TDSjing_Data;
        wr_eeprom(0x03,    g_u16TDSjData);
        wr_eeprom(0x02,    g_u16TDSjData>>8);
        wr_eeprom(0x04,    0xaa);
    }
    
    g_u16TDS1jData = rd_eeprom(0x00);
    g_u16TDS1jData = (g_u16TDS1jData<<8) | rd_eeprom(0x01);

    g_u16TDS2jData = rd_eeprom(0x02);
    g_u16TDS2jData = (g_u16TDS2jData<<8) | rd_eeprom(0x03);   

 

//PB.4-->DS18B20
//PB.5-->LED SELECT
//PA-->LED/SEG
//PD0~3-->SEG1 SELECT
//PB0~2-->SEG2 SELECT
//PC0~2-->SEG3 SELECT
//PC3~5-->SEG4 SELECT
//------------------------------------------
#include "HT66F0185.h"
#include "define.h"
#include "IIC.h"
#include "DS18B20.h"

volatile unsigned int IIC_Count;
volatile unsigned int TDS1_Seg[3],TDS2_Seg[3];
volatile unsigned int NTC1_Seg[3],NTC2_Seg[3];
volatile unsigned char MODE;

//#############################################################################
//========================Start Of Program=====================================
void main()
{	
	init();
	TDS1 = TDS2 = 0;
	NTC1 = NTC2 = 0;
	while(1)
	{	
		if(IIC_Count>=10000)		//delay 10000*0.1mS = 1S
		{
			IIC_Count = 0;
			IIC();					//讀取IIC
				
//			returnDS18B20();		//讀取DS18B20
//			startDS18B20();			//開啟DS18B20
		}			
//		KeyScan();		
		GCC_CLRWDT();
	}	
}					

//############################################################################

void init()
{ 
	_wdtc = 0xa8;
	_cpc = 0x08;
	_acerl = 0x00;	
	GCC_CLRWDT();
		
	KeyFlag1 = 0;
	KeyFlag2 = 0;
	KeyFlag3 = 0;
	KeyCount = 0;	
	SegPortc = 0;
	SegPort  = 0;
	SegIndex = 0;
	IIC_Count = 0;
	Temperature = 0;
	MODE = 0;
	
	//計時器0中斷設置,0.5mS進一次中斷
	_tm0c0 = 0b00100000;		//8000000/16 = 500000
	_tm0c1 = 0b11000001;
	_tm0al = 0x32;				//50d = 0032h  ,delay 0.1mS
	_tm0ah = 0; 
	_t0ae = 1;
	_mf0e = 1;
	_emi = 1;
	
	_t0on = 1;
}
/*
void KeyScan()
{	
	//----------------_pa5 scan-----------------
	_papu5 = 1;
	_pa5 = 1;
	_pac5 = 1;	
	GCC_NOP();
	if(KeyFlag1 == 0 && _pa5 == 0)
	{
		KeyCount++;
		if(KeyCount >= 10)
		{
			KeyCount = 0;
			KeyFlag1 = 1;
		}
	}
	else
	{
		if(KeyFlag1 == 1 && _pa5 == 1)
		{
			KeyFlag1 = 0;
			LEDValue = 0b00011111;
			//8888888888888888888888888888888888
			SegValue = 555;
		}
	}
	//----------------_pa6 scan-----------------
	_papu6 = 1;
	_pa6 = 1;
	_pac6 = 1;
	GCC_NOP();
	if(KeyFlag2 == 0 && _pa6 == 0)
	{
		KeyCount++;
		if(KeyCount >= 10)
		{
			KeyCount = 0;
			KeyFlag2 = 1;
		}
	}
	else
	{
		if(KeyFlag2 == 1 && _pa6 == 1)
		{
			KeyFlag2 = 0;
			LEDValue = 0b00111111;
			//8888888888888888888888888888888888
			SegValue =666;
		}
	}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
	//----------------_pa7 scan-----------------
	_papu7 = 1;
	_pa7 = 1;
	_pac7 = 1;
	GCC_NOP();
	if(KeyFlag3 == 0 && _pa7 == 0)
	{
		KeyCount++;
		if(KeyCount >= 10)
		{
			KeyCount = 0;
			KeyFlag3 = 1;
		}
	}
	else
	{
		if(KeyFlag3 == 1 && _pa7 == 1)
		{
			KeyFlag3 = 0;
			LEDValue = 0b01111111;
			//8888888888888888888888888888888888
			SegValue = 777;
		}
	}	
}
*/		


void __attribute((interrupt(0x0c))) ISR_TM0(void)
{
 	_t0af = 0;
	GCC_CLRWDT();
	IIC_Count++;
	
	//掃描數碼管之前,先熄滅
	SegPortc = 0;				
	_pbc = (_pbc & 0b01011000);   //使其不影響到PB3、PB4、PB6管腳
	_pcc = 0;
	_pdc = 0;
	_pb = (_pb | 0b10100111);
	_pc = 0xff;
	_pd = 0xff;
	
	//依次逐位掃描數碼管
	switch(SegIndex)			
	{
		//---------------Display 原水TDS----------------
		case 0:	
				_pc5 = 1;
				SegPort = SegTab[MODE];
				_pd0 = 0;
				SegIndex++;
				break;
		case 1:	
				_pd0 = 1;
				SegPort = SegTab[TDS2_Seg[0]];
				_pd1 = 0;
				SegIndex++;
				break;
		case 2:	
				_pd1 = 1;
				SegPort = SegTab[TDS2_Seg[1]];
				_pd2 = 0;
				SegIndex++;
				break;
		case 3:	
				_pd2 = 1;
				SegPort = SegTab[TDS2_Seg[2]];
				_pd3 = 0 ;
				SegIndex++;
				break;
		//---------------Display 原水溫度----------------
//		case 4:	
//				_pd3 = 1;
//				SegPort = SegTab[NTC2_Seg[0]];
//				_pb0 = 0;
//				SegIndex++;
//				break;
//		case 5:	
//				_pb0 = 1;
//				SegPort = SegTab[NTC2_Seg[1]] | 0x80;
//				_pb1 = 0;
//				SegIndex++;
//				break;
//		case 6:	
//				_pb1 = 1;
//				SegPort = SegTab[NTC2_Seg[2]];
//				_pb2 = 0;
//				SegIndex++;
//				break;
		case 4:	
				_pd3 = 1;
				SegPort = SegTab[NTC1_Seg[0]];
				_pb0 = 0;
				SegIndex++;
				break;
		case 5:	
				_pb0 = 1;
				SegPort = SegTab[NTC1_Seg[1]] | 0x80;
				_pb1 = 0;
				SegIndex++;
				break;
		case 6:	
				_pb1 = 1;
				SegPort = SegTab[NTC1_Seg[2]];
				_pb2 = 0;
				SegIndex++;
				break;
				
				
		//---------------Display 淨水溫度----------------  改對了
//		case 7:	
//				_pb2 = 1;
//				SegPort = SegTab[TDS1_Seg[0]];
//				_pc0 = 0;
//				SegIndex++;
//				break;
//		case 8:	
//				_pc0 = 1;
//				SegPort = SegTab[TDS1_Seg[1]];
//				_pc1 = 0;
//				SegIndex++;
//				break;
//		case 9:	
//				_pc1 = 1;
//				SegPort = SegTab[TDS1_Seg[2]];
//				_pc2 = 0;
//				SegIndex++;
//				break;
		case 7:	
				_pb2 = 1;
				SegPort = SegTab[NTC2_Seg[0]];
				_pc0 = 0;
				SegIndex++;
				break;
		case 8:	
				_pc0 = 1;
				SegPort = SegTab[NTC2_Seg[1]] | 0x80;
				_pc1 = 0;
				SegIndex++;
				break;
		case 9:	
				_pc1 = 1;
				SegPort = SegTab[NTC2_Seg[2]];
				_pc2 = 0;
				SegIndex++;
				break;
		//---------------Display 淨水TDS----------------
//		case 10:	
//				_pc2 = 1;
//				SegPort = SegTab[NTC1_Seg[0]];
//				_pc3 = 0;
//				SegIndex++;
//				break;
//		case 11:	
//				_pc3 = 1;
//				SegPort = SegTab[NTC1_Seg[1]] | 0x80;
//				_pc4 = 0;
//				SegIndex++;
//				break;
//		case 12:	
//				_pc4 = 1;
//				SegPort = SegTab[NTC1_Seg[2]];
//				_pc5 = 0;
//				SegIndex = 0;
//				break;
		case 10:	
				_pc2 = 1;
				SegPort = SegTab[MODE];
				_pc3 = 0;
				SegIndex++;
				break;
		case 11:	
				_pc3 = 1;
				SegPort = SegTab[TDS1_Seg[0]];
				_pc4 = 0;
				SegIndex++;
				break;
		case 12:	
				_pc4 = 1;
				SegPort = SegTab[TDS1_Seg[1]];
				_pc5 = 0;
				SegIndex++;
				break;
		case 13:	
				_pc5 = 1;
				SegPort = SegTab[TDS1_Seg[2]];
				_pc6 = 0 ;
				SegIndex++;
				break;
		default:
				SegIndex = 0;
				break;
	}
	GCC_CLRWDT();
}


 

项目下载地址:TDS资料.rar

评论 0

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论