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

📄 measure.c

📁 本人开发的测量水的浊度的仪器
💻 C
字号:
#include "iic.h"
#include "ads1100.h"
#include "lcd.h"
#include "measure.h"
#include "math.h"
#include "system.h"

idata ushort value[7];
extern code ushort degree[7];

void displayvalue(float fvalue)
{
	uchar i,buf[20];

	for(i=0;i<18;i++)
		buf[i] = ' ';
	buf[i] = 0;
	printstring16x(0,8,12,buf);

	sprintf(buf,"%4.2fNTU",fvalue);
	printstring16x(0,8,12,buf);
}

float calculate(ushort x)
{
	float f;
	uchar i;

	for(i=0;i<7;i++)
	{
		if(x < value[i])
			break;
	}
	if(i)
	{
		if(i>6)
			f = 1000.0;
		else 
			f = degree[i-1]+(float)(x-value[i-1])/(float)(value[i]-value[i-1])*(float)(degree[i]-degree[i-1]);
	}
	else
		f = 0.0;

	if(f > 1000.0)
		f = 1000.0;

    return f;
}

float calculates(ushort x)
{
	float f;

	f = x*1000.0/0x7fff;

	return f;
}

void sendtoprinter(float fvalue)
{
	uchar second,minute,hour,date,month,year;

	second 	= readsecond();
	minute 	= readminute();
	hour 	= readhour();
	date 	= readdate();
	month 	= readmonth();
	year 	= readyear();

	printf("\n===============\n");
	printf("Measuring time:\n");
	delay(10);
	printf("20%02bx-%02bx-%02bx\n",year,month,date);
	delay(10);
	printf("%02bx:%02bx:%02bx\n",hour,minute,second);
	delay(10);
	printf("Water quality:\n");
	delay(10);
	printf("  %4.2fNTU\n",fvalue);
	printf("===============\n\n");
}

void measure()
{
	ushort adsvalue=0;
	ushort oldvalue=0;
	uchar i,tmp1,tmp2;
	uchar flag;
	float fvalue;

	clear(0x0000);
	clear(0x4000);
	printstring16(0,0,0,"现已进入测量程序");
	printstring16(0,28,26,"按1打印");
	printstring16(0,28,28,"按2退出");

	readiic(0x20,&flag);

	for(i=0;i<7;i++)
	{
		readiic(i*2,&tmp1);
		delay(1);
		readiic(i*2+1,&tmp2);
		delay(1);
		value[i] = tmp2*256+tmp1;
	}

	while(1)
	{
		readads1100(&adsvalue);
		if(adsvalue != oldvalue)
		{
			if(flag == 0x55)
				fvalue = calculate(adsvalue);
			else
				fvalue = calculates(adsvalue);
			oldvalue = adsvalue;

			displayvalue(fvalue);
		}

		printtime();

		i = readkey();
		if(i == KEY_1)
			sendtoprinter(fvalue);
		if(i == KEY_2)
			break;
		delay(500);
	}
}


⌨️ 快捷键说明

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