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

📄 csy.c

📁 本程序能实现温度的实时采集与显示
💻 C
📖 第 1 页 / 共 3 页
字号:
_nop_();

_nop_();
_nop_();
_nop_();
_nop_();

_nop_();
_nop_();
_nop_();
_nop_();

_nop_();
_nop_();
_nop_();
_nop_();
TMDAT=dat&0x01;
Delay_Count(20);
_nop_();
_nop_();

Delay_Count(20);
_nop_();
_nop_();

Delay_Count(20);
_nop_();
_nop_();

Delay_Count(20);
_nop_();
_nop_();

TMDAT=1;
_nop_();
_nop_();

_nop_();
_nop_();

_nop_();
_nop_();

_nop_();
_nop_();
dat>>=1;
}
}
/*----------------------------------------------------
*    Main
*----------------------------------------------------*/
void temp()
{
unsigned char a,b,a2,b2,i,j,cha[6];
unsigned int w1;
unsigned int da1,da2;
//while(1)
//{
				tmreset();
				tmwbyte(0x0CC);
				tmwbyte(0x044);
		
				tmreset();
				tmwbyte(0x0CC);
				tmwbyte(0x0BE);
			
				a=tmrbyte(); //低8位
				b=tmrbyte(); //高8位

				a2=a&0x0F;
				w1=hextobcd1(a2); //小数(整型)

				a2=a&0x0F0;
				a2=a2>>4;
				b2=b&0x00F;
				b2=b2<<4;
				a2=a2|b2;

				da1=a2/10; //整数部分十位
				da2=a2%10; //整数部分个位

				cha[0]=' ';
				b2=b&0x0F0;
				if(b2)
					cha[1]='-';	
				else
					cha[1]='+';
				cha[2]=inttochar(da1);
				cha[3]=inttochar(da2);
				cha[4]='.';
				cha[5]=inttochar(w1);
				cha[6]='\0';				
printf("%s\n",cha);			
//fa2=atof(cha);

				for(j=1;j<=5;j++)
					{
					for(i=1;i<=200;i++)
						Delay_Count(255);
					}


//  s=1;
//   WRCommand(0x01);	//清除显示DDRAM
   ShowQQChar(0x9B,cha,3);
ShowQQChar(0x9E,chinese11,lengthCF11);
//   if (enter==0)
//   		break;
	}
//}
//温度显示结束

//pH值子程序开始
void phv()
{
 float volts,lr,ave;
 int i,k,decimation,samples;
 decimation=1728;
 CKCON=0;
// printf("MSC1210 ADC teperature test :\n");
 USEC=10;
 ACLK=9;
 ADMUX=0x08;
 PDCON&=0xF7;
 //ODAC=0x00;
 ADCON0=0x30;//pga=1
 ADCON2=decimation&0xff;
 ADCON3=(decimation>>8)&0x07;
 ADCON1=0x01;
 printf("Calibrating......\n");
 for (k=0;k<4;k++)
 {
  while (!(AIE&0x20));
  lr=bipolar();
 }
 //ODAC=0x7f;
 samples=10;
// while(1)
// {
  ave=0;
  for (i=0;i<samples;i++)
  {
   while(!(AIE&0x20));
   ave+=bipolar()*LSB;
  }
  volts=ave/samples;

  printf("volts=%f\r\n",volts);
// }
}
//pH值子程序结束


void firstscreen(void)

{
//一屏
  s=1;
   WRCommand(0x01);	//清除显示DDRAM
   ShowQQChar(0x80,chinese1,lengthCF1);
   ShowQQChar(0x90,chinese2,lengthCF2);
   ShowQQChar(0x88,chinese3,lengthCF3);
   ShowQQChar(0x98,chinese4,lengthCF4);
   temp();
   WaitNms(250);		//等待时间
   WaitNms(250);
 //等待时间

}

void pHsecondscreen(void)
{
//二屏
   s=2;
   LCDInit();
   RDBF();
   WRCommand(0x01);	//清除显示DDRAM
   ShowQQChar(0x80,chinese5,lengthCF5);
   ShowQQChar(0x87,chinese1,lengthCF1);
   ShowQQChar(0x90,chinese6,lengthCF6);
   ShowQQChar(0x88,chinese7,lengthCF7);
   ShowQQChar(0x98,chinese8,lengthCF8);
   WaitNms(250);		//等待时间
   WaitNms(250);		//等待时间

}

void DOsecondscreen(void)
{
//二屏
   s=3;
   LCDInit();
   RDBF();
   WRCommand(0x01);	//清除显示DDRAM
   //ShowQQChar(0x80,chinese5,lengthCF5);
   ShowQQChar(0x87,chinese2,lengthCF2);
   ShowQQChar(0x90,chinese5,lengthCF5);
   ShowQQChar(0x88,chinese9,lengthCF9);
   ShowQQChar(0x98,chinese8,lengthCF8);
   WaitNms(250);		//等待时间
   WaitNms(250);		//等待时间

}

void Fsecondscreen(void)
{
//二屏
   s=4;
   LCDInit();
   RDBF();
   WRCommand(0x01);	//清除显示DDRAM
   //ShowQQChar(0x80,chinese5,lengthCF5);
   ShowQQChar(0x87,chinese3,lengthCF3);
   ShowQQChar(0x90,chinese5,lengthCF5);
   ShowQQChar(0x88,chinese9,lengthCF9);
   ShowQQChar(0x98,chinese8,lengthCF8);
   WaitNms(250);		//等待时间
   WaitNms(250);		//等待时间

}

void Tsecondscreen(void)
{
//二屏
   s=5;
   LCDInit();
   RDBF();
   WRCommand(0x01);	//清除显示DDRAM
   //ShowQQChar(0x80,chinese5,lengthCF5);
   ShowQQChar(0x87,chinese4,lengthCF4);
   ShowQQChar(0x88,chinese10,lengthCF10);
   temp();  
   //ShowQQChar(0x88,chinese9,lengthCF9);
   ShowQQChar(0x98,chinese8,lengthCF8);
   WaitNms(250);		//等待时间
   WaitNms(250);		//等待时间

}


//主函数
void main(void)
{

//读写flash变量
FTCON=0x64;
USEC=11-1;
MSEC=11059-1;
//上为读写flash变量
//ph=12.45;
//sprintf(sph,"%5.2f",ph);
 autobaud();
//printf("OK");
   //printf("%s",sph);
  LCDInit();
RDBF();
 // printf("已调用完判忙函数\r\n");


WRCommand(0x01);	//清除显示DDRAM
  // ShowQQChar(0x80,sph,3);
 printf("已调用完判忙函数\r\n");
 
 b=4;
firstscreen();
while(1)
	{
		if(s==1)
		{
			temp();
			phv();
		
		}

//		dat=flash_read(0,0);
//		printf("dat=%d\n",dat);
//		flash_write(0,0,0x0B);
//		dat=flash_read(0,0);
//		printf("dat=%d\n",dat);
//		while(RI=0);
//		RI=0;

//b为行标志,s为屏标志
	if(up==0 && b==4)  
	    { WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
		WRCommand(0x88);
	       b=3;
	     }
	if(down==0&& b==4)
	       {WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
		   WRCommand(0x80);
	        b=1;
	     }
	   
	if(up==0 && b==3)
	   {WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
	   WRCommand(0x90);
	       b=2;
	      }
	if(down==0 && b==3)
	       {WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
		   WRCommand(0x98);
	        b=4;
	    }
	if(up==0 && b==2)
	   {WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
	    WRCommand(0x80);
	
	       b=1;
	     }
	if(down==0 && b==2)
	       {WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
		   WRCommand(0x88);
	        b=3;
	    }
	if(up==0 && b==1)
	   {WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	
	    WRCommand(0x98);
	
	       b=4;
	      }
	if(down==0 && b==1)
	    { WaitNms(250);
	WaitNms(250);
	WaitNms(250);
	      WRCommand(0x90);
	        b=2;
	    }
	
	if(enter==0 && b==1 && s==1)
	   { WaitNms(250);
	   pHsecondscreen();
	      b=4;}
	if(enter==0 && b==2 && s==1)
	   { WaitNms(250);
	   DOsecondscreen();
	      b=4;}
	
	if(enter==0 && b==3 && s==1)
	   { WaitNms(250);
	   Fsecondscreen();
	      b=4;}
	

	if(enter==0 && b==4 && s<6 && s>1)
	   { WaitNms(250);
	    firstscreen();
		   b=4;}
//	if(enter==0 && b==2 && s==5)//开始温度测量
	 //  { WaitNms(250);
	 //  LCDInit();
	      //  } 
	}

}


     
	  
	 //P1=0;
    /* if(start==0)
       {
    	loop2:     secondscreen();
        if(run==0)
	          {
	        	loop3: thirdscreen();
                if(display==0)
    	            {
		             loop4:	fourthscreen();
                      WaitNms(250);		//等待时间
                      WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间

		              fifthscreen();
					  WaitNms(250);		//等待时间
                      WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
		                  if(close==0)
		                	{
							 sixthscreen();
					  WaitNms(250);		//等待时间
                      WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
                      WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
					  WaitNms(250);		//等待时间
		                	 goto loop1;
 		                    }
                     goto loop4;
		        	}
               goto loop3;
	           }
	    	goto loop2;
          }
     goto loop1;  */ 
  
    // } 


/*
///////////////////////////////////////////////////////////////////////////////////////////
//深圳瑞特RT12864带M系列(控制器ST7920A),单片机:89S52,晶振:12M,
//并行连接方式,P2.7-RS,P2.1-RW,P2.2-E
//设计:TIMEN HUANG
#include<reg1210.h>
#include <intrins.h>
#include<stdio.h>
#include<stdlib.h> 
extern void autobaud(void);
sbit RS=P2^7;//串口时为CS
sbit RW=P2^1; //串口为SID
sbit E=P2^2;  //串口为时钟SCLK





#define BF    0x80 //用于检测LCM状态字中的Busy标识
typedef unsigned int Uint;
typedef unsigned char Uchar;


//汉字,直接可以写入字形
//第一屏
unsigned char code chinese1[] = {"欢迎进入数字全天"};
const Uchar lengthCF1=8;
unsigned char code chinese2[] = {"星座示教仪系统"};
const Uchar lengthCF2=7;
unsigned char code chinese3[] = {"请长按 (启动) 键"};
const Uchar lengthCF3=8;
unsigned char code chinese4[] = {"进入系统...."};
const Uchar lengthCF4=6;
//第二屏
unsigned char code chinese5[] = {"系统启动中,"};
const Uchar lengthCF5=6;
unsigned char code chinese6[] = {"请稍后...."};

⌨️ 快捷键说明

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