Java教程

肺活量,源码51

本文主要是介绍肺活量,源码51,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
晶振频率  22.1184MHz
#include"reg52.h"


#define open 0x3f
#define close 0x3e
#define row 0xc0
#define page 0xb8
#define line  0x40

#define OUT  P1

sbit RESET=P3^4;
sbit CS1=P3^2;
sbit CS2=P3^3;
sbit E=P3^7;
sbit R_W=P3^5;
sbit D_I=P3^6;

sbit AD_CS=P2^3;
sbit AD_CLK=P2^1;
sbit AD_IO=P2^2;

/// 智(0) 能(1) 肺(2) 活(3) 量(4) 测(5) 仪(6) 毫(7) 升(8)
static code unsigned char word[][2][16]={

0x10,0x14,0x13,0x92,0x7E,0x32,0x52,0x92,0x00,0x7C,0x44,0x44,0x44,0x7C,0x00,0x00,
0x00,0x01,0x01,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x00,0x00,/*"智",0*/

0x10,0xB8,0x97,0x92,0x90,0x94,0xB8,0x10,0x00,0x7F,0x48,0x48,0x44,0x74,0x20,0x00,
0x00,0xFF,0x0A,0x0A,0x4A,0x8A,0x7F,0x00,0x00,0x3F,0x44,0x44,0x42,0x72,0x20,0x00,/*"能",1*/

0x00,0x00,0xFE,0x12,0x12,0xFE,0x04,0xE4,0x24,0x24,0xFF,0x24,0x24,0xE4,0x04,0x00,
0x40,0x30,0x0F,0x21,0x41,0x3F,0x00,0x1F,0x00,0x00,0xFF,0x08,0x10,0x0F,0x00,0x00,/*"肺",2*/

0x10,0x60,0x01,0xC6,0x30,0x20,0x24,0x24,0x24,0xFC,0x22,0x22,0x22,0x22,0x20,0x00,
0x04,0x04,0xFF,0x00,0x00,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,0x00,/*"活",3*/

0x40,0x40,0x40,0xDF,0x55,0x55,0x55,0xD5,0x55,0x55,0x55,0xDF,0x40,0x40,0x40,0x00,
0x40,0x40,0x40,0x57,0x55,0x55,0x55,0x7F,0x55,0x55,0x55,0x57,0x50,0x40,0x40,0x00,/*"量",4*/

0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,
0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,/*"测",5*/

0x40,0x20,0xF0,0x0C,0x03,0x00,0x38,0xC0,0x01,0x0E,0x04,0xE0,0x1C,0x00,0x00,0x00,
0x00,0x00,0xFF,0x00,0x40,0x40,0x20,0x10,0x0B,0x04,0x0B,0x10,0x20,0x60,0x20,0x00,/*"仪",6*/

0x00,0x82,0x82,0x82,0xBA,0xAA,0xAA,0xAB,0xAA,0xAA,0xAA,0xBA,0x82,0x82,0x82,0x00,
0x00,0x01,0x20,0x28,0x2A,0x2A,0x2A,0x7E,0xAA,0xAA,0xAA,0xA8,0xA0,0x81,0xE0,0x00,/*"毫",7*/

0x00,0x40,0x44,0x44,0x44,0xFE,0x42,0x42,0x40,0x40,0xFE,0x40,0x40,0x60,0x40,0x00,
0x00,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,/*"升",8*/

};


///
static code unsigned char 
letter[][2][8]={	
/字符为8*16格式
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,/*"0",0*/

0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,/*"1",1*/

0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,/*"2",2*/

0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,/*"3",3*/

0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,/*"4",4*/

0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,/*"5",5*/

0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,/*"6",6*/

0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,/*"7",7*/

0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,/*"8",8*/

0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,/*"9",9*/

0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,/*":",10*/
};
///


unsigned char writepage=0,writeline=0;
unsigned char circlemax=3,circle=0;
unsigned char temp;
union thetime{unsigned long total;
			  struct{unsigned char timeH1,timeH0,timeL1,timeL0;}time;
             }sum;
union thenum {unsigned int total;
			  struct{unsigned char numH,numL;}numHL;
             }num;

void initUart(void);
void delay(unsigned char);
void wtitedata(unsigned char);
void writeorder(unsigned char);
void clear(void);
void sendpc(unsigned int carnum,unsigned long time,unsigned char circle,unsigned char circlemax);
void sendlcm(unsigned int carnum,unsigned long time,unsigned char circle,unsigned char circlemax);

void delay(unsigned char ms)
  {unsigned char i;
  for(;ms>0;ms--)
   for(i=100;i>0;i--)
    ;
  }


void writedata(unsigned char _data)
  {
   delay(0);
   E=0;
   R_W=0;
   D_I=1;   
   E=1;
   OUT=_data;
   E=0;
   //delay(1);
  }

void writeorder(unsigned char _order)
  {
  delay(0);
  E=0;
  R_W=0;
  D_I=0; 
  E=1;
  OUT=_order;
  E=0;
  //delay(1);
  }
//清屏
void clear(void)
{
  unsigned char t,i,j,pg,l;
  t=1;
  CS1=0;
  CS2=1;
  do
  {
  for(i=0;i<8;i++)
    {
    pg=page|i;
	writeorder(pg);
    l=line|0x00;
    writeorder(l);
	for(j=0;j<128;j++)
	  {
	   writedata(0x00);
	   }
    }
  CS1=1;
  CS2=0;
  }while(t--);
}

///******************************///
void out_word(unsigned char _page,unsigned char _line,unsigned char word_num,unsigned char back)
 {
  unsigned char i,j,k,wordbyte,order;
  char m;
  m=_line;
  if(m>127)
     m=127;
  k=0;
//
  if(m<64)
  {
  CS1=1;
  CS2=0;
  for(j=0;j<2;j++)
    {
	 order=_page+j;
	 if(order>7)
        break;
     order=page|order;
	 writeorder(order);
	 order=line|m;
	 writeorder(order);

	 for(i=0;i<16&&((m+i)<64);i++)
	    {wordbyte=word[word_num][j][i];
		 if(back>0)
		    wordbyte=~wordbyte;
	     writedata(wordbyte);
		}
	 k=i;
	}
  }
  if((m+k)>=64)
  {
  m=(m+k)-64;
  CS1=0;
  CS2=1;
  for(j=0;j<2;j++)
    {	 
	 writepage=_page+j;
	 if(writepage>7)
        break;
     order=page|writepage;
	 writeorder(order);
	 writeline=m;
	 order=line|writeline;
	 writeorder(order);
	for(i=k;i<16&&((m+i)<64);i++)
	    {wordbyte=word[word_num][j][i];
		 if(back>0)
		    wordbyte=~wordbyte;
		 writedata(wordbyte);
		}
	}
  }
}
/
/
void out_letter(unsigned char _page,unsigned char _line,unsigned char letter_num,unsigned char back)
 {
  unsigned char i,j,k,letterbyte,order;
  char m;
  m=_line;
  if(m>127)
     m=127;
  k=0;
  if(m<64)
  {
  CS1=1;
  CS2=0;
  for(j=0;j<2;j++)
    {
	 order=_page+j;
	 if(order>7)
        break;
     order=page|order;
	 writeorder(order);
	 order=line|m;
	 writeorder(order);

	 for(i=0;i<8&&((m+i)<64);i++)
	    {letterbyte=letter[letter_num][j][i];
		 if(back>0)
		    letterbyte=~letterbyte;
	     writedata(letterbyte);
		}
	 k=i;
	}
  }
  if((m+k)>=64)
  {
  m=(m+k)-64;
  CS1=0;
  CS2=1;
  for(j=0;j<2;j++)
    {	 
	 writepage=_page+j;
	 if(writepage>7)
        break;
     order=page|writepage;
	 writeorder(order);
	 writeline=m;
	 order=line|writeline;
	 writeorder(order);
	for(i=k;i<8&&((m+i)<64);i++)
	    {letterbyte=letter[letter_num][j][i];
		 if(back>0)
		    letterbyte=~letterbyte;
		 writedata(letterbyte);
		}
	}
  }
}

//
void initUart(void)
{
 TMOD|=0x20;
 SCON=0x50;
 TH1=0xfa;
 TL1=0xfa;
 TR1=1;
 ET1=1;
}

void uart(void) interrupt 4   //串口中断
{ 
  if(RI)
    {
	  RI=0;
	  temp=SBUF;

	}
  else if(TI)
       TI=0;

}
/
发数据到上位机
void sendpc(unsigned int carnum,unsigned long time,unsigned char circle,unsigned char circlemax)
{
 num.total=carnum;
 sum.total=time;
 SBUF=0x00; 表示开始
 delay(10);
 SBUF=num.numHL.numH;
 delay(10);
 SBUF=num.numHL.numL;
 delay(10);
 SBUF=sum.time.timeH1;
 delay(10);
 SBUF=sum.time.timeH0;
 delay(10);
 SBUF=sum.time.timeL1;
 delay(10);
 SBUF=sum.time.timeL0;
 delay(10);
 SBUF=circle;
 delay(10);
 SBUF=circlemax;
 delay(10);
 SBUF=0xFF;表示结束
 delay(10);
}
/
void sendlcm(unsigned int carnum,unsigned long time,unsigned char circle,unsigned char circlemax)
{
  unsigned char temp,temp2;

  carnum=carnum%10000;
  temp=carnum/1000;
  out_letter(2,50,temp,0);
  carnum=carnum%1000;
  temp=carnum/100;
  out_letter(2,60,temp,0);
  carnum=carnum%100;
  temp=carnum/10;
  out_letter(2,70,temp,0);
  temp=carnum%10;
  out_letter(2,80,temp,0);

  time=time%1000000;
  temp=time/100000;
  out_letter(4,40,temp,0);
  time=time%100000;
  temp=time/10000;
  out_letter(4,48,temp,0);
  time=time%10000;
  temp=time/1000;
  out_letter(4,56,temp,0);
  time=time%1000;
  temp=time/100;
  out_letter(4,68,temp,0);
  time=time%100;
  temp=time/10;
  out_letter(4,76,temp,0);
  temp=time%10;
  out_letter(4,84,temp,0);

  temp2=circle%100;
  temp=temp2/10;
  out_letter(6,20,temp,0);
  temp=temp2%10;
  out_letter(6,28,temp,0);

  temp2=circlemax%100;
  temp=temp2/10;
  out_letter(6,92,temp,0);
  temp=temp2%10;
  out_letter(6,100,temp,0);
}
//
unsigned char TLC549(void)
{
 unsigned char x,i,temp;
 temp=0;
 x=0;
 AD_CLK=0;
 AD_CS=1;
 delay(100);
 AD_CS=0;
 for(i=0;i<8;i++)
   {
	x=x<<1;
 	AD_CLK=1;
 	AD_CLK=0;
 	temp=AD_IO;
 	temp=temp&0x01;
	x=x+temp;

   }
 return x;
}


void main(void)
{  
  unsigned char order,i,temp;
  unsigned char adsum;
  unsigned int  sum;
  unsigned long v;
  initUart();
  //开显示
  delay(1);
  delay(250);
  writeorder(close);
  delay(250);
  CS1=0;
  CS2=1;
  writeorder(open);
  CS1=1;
  CS2=0;
  writeorder(open);
  clear();
  order=row|0x00;
  writeorder(order);
  order=page|0x00;
  writeorder(order);
  delay(1);
/****************/

智能肺活量测量仪
  out_word(1,0,0,0);
  out_word(1,16,1,0);
  out_word(1,32,2,0);
  out_word(1,48,3,0);
  out_word(1,64,4,0);
  out_word(1,80,5,0);
  out_word(1,96,4,0);
  out_word(1,112,6,0);

肺活量:    毫升
  out_word(5,0,2,0);
  out_word(5,16,3,0);
  out_word(5,32,4,0);

  out_letter(5,48,10,0);

  out_word(5,96,7,0);
  out_word(5,112,8,0);
/
/

//  sum.total=0x4f3f2f1f;
//  num.total=359;
//  sendlcm(num.total,sum.total,circle,circlemax);
//  sendpc(num.total,sum.total,circle,circlemax); 
   


  while(1)
  
  {
  sum=0;
  v=0;
  for(i=0;i<20;i++)
    {
	  delay(1);
	  adsum=TLC549();
	  sum=sum+adsum;
	}
  delay(200);
  sum=sum/20;
  if(sum>0x60)
     sum=sum-0x66;
	 else
	     sum=0;
  SBUF=sum;
  delay(20);
  sum=sum%10000;

  temp=sum/1000;
  out_letter(5,64,temp,0);
  sum=sum%1000;
  temp=sum/100;
  out_letter(5,72,temp,0);
  sum=sum%100;
  temp=sum/10;
  out_letter(5,80,temp,0);
  sum=sum%10;
  temp=sum;
  out_letter(5,88,temp,0);
 
  }

  while(1);
}

 

这篇关于肺活量,源码51的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!