www.pudn.com > GKC-DProteus.rar > GKC-D.c, change:2008-10-01,size:36325b


/********************************************** 
;*描述	 
  	        GKC-D开关动特性测试仪主程序 
 
;*硬件      MCU:89S54+,晶体频率:12MHZ 
            +HM6264(RAM:8KB,EPROM:16KB+) 
			LCD:TS12864-3(带汉字库)	 
			PRT:TPuP-40	微型点阵打印机					  
			KEY:1×5key( P1.0~P1.3+RST) 
;*端口      IOport^0~5:A1B1C1A2B2C2开关量输入 
            IOport^6:同步信号输入 
			IOport^7:速度脉冲输入,最大10KHZ 
			P1.5~P1.7:LCD--D/I,R/W,E控制 
			P3.4-合闸输出,P3.5分闸输出 
			P3.2:打印机STB,P3.3打印机BUSY 
			P3.0~P3.1:串口通讯-接上位机预留 
;*地址      SRAM:0X6000~7FFF,IOport:0XCFFF  
            //LCDCOM:0XA0FF;LCDDAT:0XA1FF 
;*其他		版本:1.0 
            作者:YHS402 
            日期:2006-9-29  
			修改:2007-11-8 
**********************************************/ 
#include <reg52.h> 
#include <stdio.h> 
#include <intrins.h> 
#include <string.h> 
#include <ctype.h> 
#include <absacc.h>  
#include "bitmap.h"		//开机画面头文件	   
#include "menu.h"		//菜单头文件 
#include "T6963.h"    //LCD驱动头文件 
#include "key.h"	  // 
#define uchar unsigned char 
#define uint  unsigned int 
//typedef unsigned char BYTE; 
#define ENTER  1    //确认键定义 
#define   UP   2    //光标向上键定义 
#define DOWN   3    //光标向下键定义 
//#define SCROLL 0x17  //卷屏键定义 
#define LEFT   4    //光标左右键定义  
sbit  swon_relay=P3^4;   //合闸出口定义 
sbit swoff_relay=P3^5;  //分闸出口定义 
sbit prtstb =P3^2;     //打印机STB定义 
sbit prtbusy =P3^3;    //打印机BUSY定义 
//#define ADC0809 XBYTE[9000]; //ADC外存地址 
#define IOport XBYTE[0XC000];//IO口地址 
/**************函数原形说明**************/ 
void prt_init(void); 
void prt_str(uchar *) ; 
void prt_char(uchar ) ; 
void prt_modeset(void); 
void showmenu(uchar*); 
void test_wave(void); 
uchar keyscan(void); 
void prt_datalist(void); 
void prt_datawave(void); 
void data_dispose1(bit); 
void data_dispose2(uint,uint ) ; 
/**************全局变量定义**************/ 
data uchar nkey,curline,curvalue; 
data uchar oldpin,npinval,swonoff; 
data uint  distlimit,sampletime,timelimit; 
data uint  Tsta,Tend; 
data bit mflag;         //打印点数标志改变 
data bit PRTMODE;       //打印方式:0自动,1手动 
static  data uint tcon; 
xdata struct  testdata	//测试数据结构 
{  
   uint time[6];		//时间2组6个 
   uint jump[6];		//弹跳2组6个 
   uint ttime[2];		//时间2组2个 
   uint ttq[2];			//同期2组2个 
   uint sd;				//速度 
   uint kj;				//开距 
 } closedata; 
xdata uchar dispbuff[18][18];//显示缓冲 
uchar xdata testbuff[2000];//测试断口外存缓冲 
//uchar xdata  adcbuff[1000];//ADC外存缓冲 
uint  xdata timebuff[2000];//测试时刻外存缓冲 
bdata uchar pinval,tmppin;	//断口状态位寻址变量 
sbit PINA1=pinval^0; 
sbit PINB1=pinval^1; 
sbit PINC1=pinval^2; 
sbit PINA2=pinval^3; 
sbit PINB2=pinval^4; 
sbit PINC2=pinval^5; 
sbit PINTB=pinval^6; 
sbit PINSD=pinval^7; 
sbit TMPA1=tmppin^0; 
sbit TMPB1=tmppin^1; 
sbit TMPC1=tmppin^2; 
sbit TMPA2=tmppin^3; 
sbit TMPB2=tmppin^4; 
sbit TMPC2=tmppin^5; 
sbit TMPTB=tmppin^6; 
sbit TMPSD=tmppin^7; 
 
extern char lcdInit(); // LCM 初始化 
extern void lcd_at(unsigned char ,unsigned char );/*设定文本x,y值*/ 
extern void lcd_clear();	 // 清屏 
extern void charout(unsigned char *str); //ASCII(8*8) 显示函数 
extern void lcdSetPos(unsigned char , unsigned char  );	// 设置当前地址 
extern uchar lcd_strdisp(uchar ,uchar ,char *);// ASCII(8*16) 及 汉字(16*16) 显示函数 
extern uchar lcdPR12(uchar ); // 写无参数的指令 
extern uchar lcdPR13(uchar ); // 写数据 
extern unsigned int Adc0832(unsigned char ); 
extern void  lcd_line( unsigned char ,unsigned char ,unsigned char ,unsigned char,bit); 
extern void Pixel(unsigned char ,unsigned char , bit ); 
extern  void showmenu(uchar *); // LCM 初始化 
extern  void lcd_bmpdisp(uchar,uchar,char *); // LCM 初始化 
extern  void lcdchardisp(uchar ,uchar ,char  )	; 
extern  void lcd_curset(uchar ); 
extern  void lcd_curclr(uchar ); 
extern  uchar lcd_curup(uchar ); 
extern  uchar lcd_curdown(uchar ); 
extern  void lcd_poson(uchar ); 
extern  void lcd_posoff(uchar ); 
extern  void lcd_chardisp(uchar,uchar,uchar); 
extern  uchar keyscan(); 
 
//unsigned char dsp[20]; 
//union AD{uint Dat;uchar HL[2];}	; 
 
 void delay_10us(uchar x)   
{   
  do 
  { 
  _nop_(); 
  _nop_(); 
  _nop_(); 
  _nop_(); 
  _nop_(); 
  _nop_(); 
  _nop_(); 
  }  while(--x);  
}   
void delay_ms(uint cnt)  
{  
  uchar i;  
  do  
  {  
     i = 4;  
     do  
	 {  
       delay_10us(25);  
      } while(--i);  
   } while(--cnt);  
}  
 
/*********字节BIT置位子程序*********/ 
void Bitset(uchar Pa,uchar n)    
{  
   Pa|=1<<n;  
} 
/*********字节BIT清0子程序*********/ 
void Bitclr(uchar Pa,uchar n)    
{  
   Pa&=~(1<<n);  
} 
/*********字节BIT测试子程序*********/ 
uchar Bittest(uchar Pa,uchar n)    
{  
  return Pa & (1<<n);  
}                
/*********BIT转0,1码子程序*********/ 
uchar Bit2val(bit nbit)    
{  
 if(!nbit) return 1; 
 else return 0; 
}           
/*********INT转ASCII码子程序*********/ 
void Int2str(uint num,uchar *p,uchar ndot)    
{   
 uchar pstr[5]; 
 uchar i; 
 pstr[0]=num/10000+0x30; 
 num=(num%10000); 
 pstr[1]=(num/1000+0x30);  
 num=(num%1000); 
 pstr[2]=num/100+0x30;  
  num=(num%100); 
 pstr[3]=num/10+0x30;   
   num=num%10; 
 pstr[4]=num+0x30; 
 for(i=0;i<5;i++) 
 { 
  if(i==(5-ndot)){*p=0x2e;p++; } 
  *p=pstr[i]; 
  p++; 
 } 
 *p=0x00; // return p-6;    
} 
 
/********通用子程序**********/  
 uint max(uint x,uint y,uint z) 
{ uint m,n; 
  m=(x>y?x:y); 
  n=(y>z?y:z); 
  return(m>n?m:n); 
} 
uint min(uint x,uint y,uint z) 
{ uint m,n; 
  m=(x<y?x:y); 
  n=(y<z?y:z); 
  return(m<n?m:n); 
} 
/*********打印列表子程序*********/     
void  test_list(void) 
{ 
  data_dispose1(swonoff); 
  lcd_clear(); 
  lcd_strdisp(0,0, "    数据列表    "); 
  lcd_strdisp(0,16,"  --正在打印--  "); 
  lcd_strdisp(0,32,"   **请稍后**  "); 
  //lcd_strdisp(0x98,okkeystr); 
  prt_datalist(); 
 } 
 /*********打印波形列表子程序*********/     
void  test_wavelist(void) 
{ 
  data_dispose1(swonoff); 
  lcd_clear(); 
  lcd_strdisp(0,0 ,"    波形列表    "); 
  lcd_strdisp(0,16,"  --正在打印--  "); 
  lcd_strdisp(0,32,"   **请稍后**  "); 
  //lcd_strdisp(0x98,okkeystr); 
  prt_datalist(); 
  prt_datawave(); 
 } 
/******nTEST DATA DISPLAY*********/ 
void test_datadisp(uchar n,char *str[2]) 
{	static uchar pp[7]; 
    char nc[]="1"; 
	*nc=0x30+n; 
	/* 
	sprintf(dispbuff[9*(n-1)+0],"%s %s %s %2.3f %s %s\n","A",nc,":",closedata.time[3*(n-1)+0],"ms",str[0]); 
	sprintf(dispbuff[9*(n-1)+1],"%s %s %s %2.3f %s %s\n","B",nc,":",closedata.time[3*(n-1)+1],"ms",str[0]); 
	sprintf(dispbuff[9*(n-1)+2],"%s %s %s %2.3f %s %s\n","C",nc,":",closedata.time[3*(n-1)+2],"ms",str[0]); 
	sprintf(dispbuff[9*(n-1)+3],"%s %s %s %2.3f %s %s\n","A",nc,":",closedata.jump[3*(n-1)+0],"ms"," JP"); 
	sprintf(dispbuff[9*(n-1)+4],"%s %s %s %2.3f %s %s\n","B",nc,":",closedata.jump[3*(n-1)+1],"ms"," JP"); 
	sprintf(dispbuff[9*(n-1)+5],"%s %s %s %2.3f %s %s\n","C",nc,":",closedata.jump[3*(n-1)+2],"ms"," JP"); 
	sprintf(dispbuff[9*(n-1)+6],"%s %s %s %2.3f %s %s\n","ABC",nc,": ",closedata.ttq[n-1],"ms"," TQ"); 
	sprintf(dispbuff[9*(n-1)+7],"%s %2.3f %s\n","DIST:  ",closedata.kj,"mm"); 
	sprintf(dispbuff[9*(n-1)+8],"%s %2.3f %s\n","SD:    ",closedata.sd,"m/s"); 
 
   	*/ 
    strcpy(dispbuff[9*(n-1)+0],"A");  
	strcat(dispbuff[9*(n-1)+0],nc);  
	strcat(dispbuff[9*(n-1)+0],": ");  
   	Int2str(closedata.time[3*(n-1)],pp,1); 
    strcat(dispbuff[9*(n-1)+0],pp);  
	strcat(dispbuff[9*(n-1)+0],"ms\0");  
	strcat(dispbuff[9*(n-1)+0]," ");  
	strcat(dispbuff[9*(n-1)+0],str[0]);  
	strcat(dispbuff[9*(n-1)+0],"\0");  
	strcpy(dispbuff[9*(n-1)+1],"B");  
	strcat(dispbuff[9*(n-1)+1],nc);  
	strcat(dispbuff[9*(n-1)+1],": ");  
   	Int2str(closedata.time[3*(n-1)+1],pp,1); 
    strcat(dispbuff[9*(n-1)+1],pp); 
	strcat(dispbuff[9*(n-1)+1],"ms");   
	strcat(dispbuff[9*(n-1)+1]," ");  
	strcat(dispbuff[9*(n-1)+1],str[0]); 
	strcat(dispbuff[9*(n-1)+1],"\0");   
    strcpy(dispbuff[9*(n-1)+2],"C");  
	strcat(dispbuff[9*(n-1)+2],nc);  
	strcat(dispbuff[9*(n-1)+2],": ");  
   	Int2str(closedata.time[3*(n-1)+2],pp,1); 
    strcat(dispbuff[9*(n-1)+2],pp);  
	strcat(dispbuff[9*(n-1)+2],"ms");  
	strcat(dispbuff[9*(n-1)+2]," ");  
	strcat(dispbuff[9*(n-1)+2],str[0]);  
	strcat(dispbuff[9*(n-1)+2],"\0");  
	strcpy(dispbuff[9*(n-1)+3],"A");  
	strcat(dispbuff[9*(n-1)+3],nc);  
	strcat(dispbuff[9*(n-1)+3],": ");  
   	Int2str(closedata.jump[3*(n-1)],pp,1); 
    strcat(dispbuff[9*(n-1)+3],pp);  
	strcat(dispbuff[9*(n-1)+3],"ms");  
	strcat(dispbuff[9*(n-1)+3]," ");  
	strcat(dispbuff[9*(n-1)+3]," JP\0");  
	strcpy(dispbuff[9*(n-1)+4],"B");  
	strcat(dispbuff[9*(n-1)+4],nc);  
	strcat(dispbuff[9*(n-1)+4],": ");  
   	Int2str(closedata.jump[3*(n-1)+1],pp,1); 
    strcat(dispbuff[9*(n-1)+4],pp); 
	strcat(dispbuff[9*(n-1)+4],"ms");   
	strcat(dispbuff[9*(n-1)+4]," ");  
	strcat(dispbuff[9*(n-1)+4]," JP\0");  
    strcpy(dispbuff[9*(n-1)+5],"C");  
	strcat(dispbuff[9*(n-1)+5],nc);  
	strcat(dispbuff[9*(n-1)+5],": ");  
   	Int2str(closedata.jump[3*(n-1)+2],pp,1); 
    strcat(dispbuff[9*(n-1)+5],pp);  
	strcat(dispbuff[9*(n-1)+5],"ms");  
	strcat(dispbuff[9*(n-1)+5]," ");  
	strcat(dispbuff[9*(n-1)+5]," JP\0");  
	strcpy(dispbuff[9*(n-1)+6],"ABC");  
	strcat(dispbuff[9*(n-1)+6],nc);  
	strcat(dispbuff[9*(n-1)+6],": ");  
   	Int2str(closedata.ttq[n-1],pp,1); 
    strcat(dispbuff[9*(n-1)+6],pp);  
	strcat(dispbuff[9*(n-1)+6],"ms\0");  
	strcat(dispbuff[9*(n-1)+6],str[1]);  
	strcpy(dispbuff[9*(n-1)+7],"DIST");  
	strcat(dispbuff[9*(n-1)+7],": ");  
   	Int2str(closedata.kj,pp,1); 
    strcat(dispbuff[9*(n-1)+7],pp);  
	strcat(dispbuff[9*(n-1)+7],"mm  \0");  
	//strcat(dispbuff[9*(n-1)+7],"\0");  
 	strcpy(dispbuff[9*(n-1)+8],"VELO");  
	strcat(dispbuff[9*(n-1)+8],": ");  
   	Int2str(closedata.sd,pp,4); 
    strcat(dispbuff[9*(n-1)+8],pp);  
	strcat(dispbuff[9*(n-1)+8]," m/s\0");  
	//strcat(dispbuff[9*(n-1)+8]," ");  
	  
	  
} 
 void databuff_init0() 
 { 
 uint i; 
 for(i=0;i<2000;i++) 
 { 
   testbuff[i]=0xff; 
  } 
   
 } 
void databuff_init() 
 { 
  swonoff=1; 
  tcon=13; 
  testbuff[0]=0xff; 
  testbuff[1]=0xbf; 
  testbuff[2]=0x3f; 
  testbuff[3]=0xbf; 
  testbuff[4]=0x3f; 
  testbuff[5]=0xbf; 
  testbuff[6]=0xb9; 
  testbuff[7]=0xba; 
  testbuff[8]=0xbc; 
  testbuff[9]=0xb8; 
  testbuff[10]=0xbb; 
  testbuff[11]=0xbc; 
  testbuff[12]=0xb8; 
  testbuff[13]=0xff; 
  timebuff[0]=0; 
  timebuff[1]=50; 
  timebuff[2]=64; 
  timebuff[3]=100; 
  timebuff[4]=115; 
  timebuff[5]=122; 
  timebuff[6]=603; 
  timebuff[7]=614; 
  timebuff[8]=649; 
  timebuff[9]=652; 
  timebuff[10]=668; 
  timebuff[11]=673; 
  timebuff[12]=685; 
  timebuff[13]=2000; 
  data_dispose2(0,tcon); 
  //data_dispose1(swonoff); 
   
 } 
 /********数据处理子程序1**********/  
 void data_dispose1(uchar nsta) 
 { 
  bit nflag=1; 
  uchar j=1,*str[2]; 
  lcd_clear(); 
  if (nsta==0) {str[0]=" HZ"; str[1]="TQ";} 
  if (nsta==1) {str[0]=" FZ"; str[1]="TQ";} 
  if (nsta==2) {str[0]="HFZ"; str[1]="HF";} 
  if (nsta==3) {str[0]="FHZ"; str[1]="FH";} 
  if (nsta==5) {str[0]="N/A"; str[1]="NA";} 
  tmppin=testbuff[tcon-1]; 
  oldpin=testbuff[0]; 
 /*if ((oldpin&0x3f)==(tmppin&0x3f))  
  {  showmenu(errorstr); 
    while(1) 
    { nkey=keyscan(); 
      delay_ms(100);	 
      if(nkey==ENTER) break;  
	 }; 
   } 
  else 	*/ 
  { 
	test_datadisp(1,str); 
	test_datadisp(2,str); 
   while(nflag) 
  { 
     nkey=keyscan(); 
     delay_ms(100);	 
     switch(nkey) 
     { 
       case DOWN:{if (j>4)j=5;j++;break;} 
	   case UP:{if (j<2)j=2;j--;break;} 
	   case ENTER:{nflag=0;break;} 
      } 
     lcd_strdisp(0,0,dispbuff[3*(j-1)]); 
     lcd_strdisp(0,16,dispbuff[3*(j-1)+1]); 
     lcd_strdisp(0,32,dispbuff[3*(j-1)+2]); 
     lcd_strdisp(0,48,updownkeystr); 
   } 
  } 
 } 
/********数据处理子程序2**********/  
 void data_dispose2(uint nt1,uint nt2) 
 { 
 bit FLAGA1,FLAGB1,FLAGC1,FLAGA2,FLAGB2,FLAGC2,FLAGTB; 
 int i,sdcont=0; uint mintime,tbnt; 
 unsigned long sdval; 
 FLAGA1=FLAGB1=FLAGC1=FLAGA2=FLAGB2=FLAGC2=FLAGTB=1; 
 closedata.time[0]=closedata.time[1]=closedata.time[2]=0; 
 closedata.jump[0]=closedata.jump[1]=closedata.jump[2]=0; 
 closedata.time[3]=closedata.time[4]=closedata.time[5]=0; 
 closedata.jump[3]=closedata.jump[4]=closedata.jump[5]=0; 
 closedata.sd=closedata.kj=0; 
 closedata.ttq[0]=closedata.ttime[0]=0; 
 closedata.ttq[1]=closedata.ttime[1]=0; 
  
 for(i=0;i<nt2-1;i++)	   //查找同步时刻 
 { 
   pinval=testbuff[i]; 
   if(!PINTB) {tbnt=i;break;}  ; 
  }; 
  Tsta=tbnt;							 
 for (i=tbnt;i<nt2-1;i++)    //从同步时刻计算 
 { 
    //FCONT=1; 
	pinval=testbuff[i]; 
    tmppin=testbuff[i+1]; 
    if(tmppin!=pinval) 
   { 
	  if(TMPA1!=PINA1) 
	    { if(FLAGA1) 
	      {closedata.time[0]=timebuff[i+1]-timebuff[tbnt];FLAGA1=0; } 
	      closedata.jump[0]=timebuff[i+1]-closedata.time[0]-timebuff[tbnt]; 
		  Tend=i; 
		 }; 
	 if(TMPB1!=PINB1) 
	    { if(FLAGB1) 
	      {closedata.time[1]=timebuff[i+1]-timebuff[tbnt];FLAGB1=0; } 
	       closedata.jump[1]=timebuff[i+1]-closedata.time[1]-timebuff[tbnt]; 
		   Tend=i; 
	    }; 
     if(TMPC1!=PINC1) 
	   { if(FLAGC1) 
	      {closedata.time[2]=timebuff[i+1]-timebuff[tbnt];FLAGC1=0; } 
	      closedata.jump[2]=timebuff[i+1]-closedata.time[2]-timebuff[tbnt]; 
		  Tend=i; 
		}; 
	 if(TMPA2!=PINA2) 
	   { if(FLAGA2) 
	      {closedata.time[3]=timebuff[i+1]-timebuff[tbnt];FLAGA2=0; } 
	      closedata.jump[3]=timebuff[i+1]-closedata.time[3]-timebuff[tbnt]; 
		  Tend=i; 
		}; 
	 if(TMPB2!=PINB2) 
	   { if(FLAGB2) 
	      {closedata.time[4]=timebuff[i]-timebuff[tbnt];FLAGB2=0; } 
	       closedata.jump[4]=timebuff[i+1]-closedata.time[4]-timebuff[tbnt]; 
		   Tend=i; 
		}; 
     if(TMPC2!=PINC2) 
	   { if(FLAGC2) 
	      {closedata.time[5]=timebuff[i+1]-timebuff[tbnt];FLAGC2=0; } 
	      closedata.jump[5]=timebuff[i+1]-closedata.time[5]-timebuff[tbnt]; 
		  Tend=i; 
		}; 
	 if((tmppin&0x80)!=(pinval&0x80)) 
	  {  
	    if((pinval&0x80)==0) sdcont++; 
		// if(FCONT){Tend++; FCONT=0;}; 
	   }; 
   }; 
    
 } 
 Tend+=tbnt; 
 closedata.ttime[0]=max(closedata.time[0],closedata.time[1],closedata.time[2]); 
 mintime=min(closedata.time[0],closedata.time[1],closedata.time[2]); 
 closedata.ttq[0]=closedata.ttime[0]-mintime; 
 closedata.ttime[1]=max(closedata.time[3],closedata.time[4],closedata.time[5]); 
 mintime=min(closedata.time[3],closedata.time[4],closedata.time[5]); 
 closedata.ttq[1]=closedata.ttime[1]-mintime; 
 sdval=sdcont; 
 if (closedata.ttime[0]!=0) closedata.sd=sdval*10000/closedata.ttime[0] ; 
 closedata.kj=sdcont; 
 //TEND=closedata.ttime[0]+closedata.jump[0]; 
 } 
 /**********屏显曲线子程序*********/  
 void lcd_wave(uchar * databuff,uint TT,uchar Tend) 
{ 
  uchar m,n,i,x,y; 
  uint scale=0,t,r2,r1; 
  uchar *nstr; 
  //uchar ra1,ra2,ra3,ra4,ra5,ra6,ra7,ra8; 
  t=(timebuff[Tend]-timebuff[Tsta]); 
 //if(t<=100) scale=1; 
 /*while(t>100) 
  { 
    t=t/10; scale+=10	; 
	} 
 */ 
  scale=t/100;if(t<100) scale=1; 
  lcd_clear(); 
  lcd_bmpdisp(nasciimap[0],nasciimap[1],nasciimap); 
 /* lcd_strdisp(0,0,"A1"); 
  lcd_strdisp(0,8,"B1"); 
  lcd_strdisp(0,16,"C1"); 
  lcd_strdisp(0,24,"A2"); 
  lcd_strdisp(0,32,"B2"); 
  lcd_strdisp(0,40,"C2"); 
  lcd_strdisp(0,48,"TB"); 
  lcd_strdisp(0,56,"SD"); 
  */ 
  r1=18; 
  for( i=0;i<128;i++) 
  { 
	  //if(i>Tend+18) break; 
      x=databuff[i]; 
      y=databuff[i+1]; 
	  r2=r1+(timebuff[i+1]-timebuff[i])/scale; 
	  if(r2>128) r2=128; 
	 m=6;n=6; 
	 if((x&0x01)==0) m=2; 
	 if((y&0x01)==0) n=2; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
	  
	 m=14;n=14; 
	 if((x&0x02)==0) m=10; 
	 if((y&0x02)==0) n=10; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
 
	 m=22;n=22; 
	 if((x&0x04)==0) m=18; 
	 if((y&0x04)==0) n=18; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
 
	 m=30;n=30; 
	 if((x&0x08)==0) m=26; 
	 if((y&0x08)==0) n=26; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
 
	 m=38;n=38; 
	 if((x&0x10)==0) m=34; 
	 if((y&0x10)==0) n=34; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
 
	 m=46;n=46; 
	 if((x&0x20)==0) m=42; 
	 if((y&0x20)==0) n=42; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
 
	 m=54;n=54; 
	 if((x&0x40)==0) m=50; 
	 if((y&0x40)==0) n=50; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
     
	 m=62;n=62; 
	 if((x&0x80)==0) m=58; 
	 if((y&0x80)==0) n=58; 
	 lcd_line(r1,m,r2,m,1); 
	 lcd_line(r2,m,r2,n,1); 
	 
	 r1=r2; 
 
	 /* 
	 //-------------------------------------------------------- 
	 if((x&0x01)==0 &&(y&0x01)==0) lcd_line(i,2,i+1,2,1); 
	 if((x&0x01)==1 &&(y&0x01)==1) lcd_line(i,6,i+1,6,1); 
	 if((x&0x01)==0 &&(y&0x01)==1) lcd_line(i+1,2,i+1,6,1); 
	 if((x&0x01)==1 &&(y&0x01)==0) lcd_line(i+1,6,i+1,2,1); 
	 
	 if((x&0x02)==0 &&(y&0x02)==0) lcd_line(i,10,i+1,10,1); 
	 if((x&0x02)==2 &&(y&0x02)==2) lcd_line(i,14,i+1,14,1); 
	 if((x&0x02)==0 &&(y&0x02)==2) lcd_line(i+1,10,i+1,14,1); 
	 if((x&0x02)==2 &&(y&0x02)==0) lcd_line(i+1,14,i+1,10,1); 
 
	 if((x&0x04)==0 &&(y&0x04)==0) lcd_line(i,18,i+1,18,1); 
	 if((x&0x04)==4 &&(y&0x04)==4) lcd_line(i,22,i+1,22,1); 
	 if((x&0x04)==0 &&(y&0x04)==4) lcd_line(i+1,18,i+1,22,1); 
	 if((x&0x04)==4 &&(y&0x04)==0) lcd_line(i+1,22,i+1,18,1); 
	 //--------------------------------------------------- 
	 if((x&0x08)==0 &&(y&0x08)==0) lcd_line(i,26,i+1,26,1); 
	 if((x&0x08)==8 &&(y&0x08)==8) lcd_line(i,30,i+1,30,1); 
	 if((x&0x08)==0 &&(y&0x08)==8) lcd_line(i+1,26,i+1,30,1); 
	 if((x&0x08)==8 &&(y&0x08)==0) lcd_line(i+1,30,i+1,26,1); 
	   
	 if((x&0x10)==0 &&(y&0x10)==0) lcd_line(i,34,i+1,34,1); 
	 if((x&0x10)==16 &&(y&0x10)==16) lcd_line(i,38,i+1,38,1); 
	 if((x&0x10)==0 &&(y&0x10)==16) lcd_line(i+1,34,i+1,38,1); 
	 if((x&0x10)==16 &&(y&0x10)==0) lcd_line(i+1,38,i+1,34,1); 
 
	 if((x&0x20)==0 &&(y&0x20)==0) lcd_line(i,42,i+1,42,1); 
	 if((x&0x20)==32 &&(y&0x20)==32) lcd_line(i,46,i+1,46,1); 
	 if((x&0x20)==0 &&(y&0x20)==32) lcd_line(i+1,42,i+1,46,1); 
	 if((x&0x20)==32 &&(y&0x20)==0) lcd_line(i+1,46,i+1,42,1); 
	 //--------------------------------------------------- 
	 if((x&0x40)==0 &&(y&0x40)==0) lcd_line(i,50,i+1,50,1); 
	 if((x&0x40)==0x40 &&(y&0x40)==0x40) lcd_line(i,54,i+1,54,1); 
	 if((x&0x40)==0 &&(y&0x40)==0x40) lcd_line(i+1,50,i+1,54,1); 
	 if((x&0x40)==0x40 &&(y&0x40)==0) lcd_line(i+1,54,i+1,50,1); 
 
	 if((x&0x80)==0 &&(y&0x80)==0) lcd_line(i,58,i+1,58,1); 
	 if((x&0x80)==0x80 &&(y&0x80)==0x80) lcd_line(i,62,i+1,62,1); 
	 if((x&0x80)==0 &&(y&0x80)==0x80) lcd_line(i+1,58,i+1,62,1); 
	 if((x&0x80)==0x80 &&(y&0x80)==0) lcd_line(i+1,62,i+1,58,1); 
	 */ 
	// Int2str(scale,nstr); 
    // lcd_strdisp(100,40,"scl"); 
    // lcd_strdisp(100,52,nstr);	  
   } 
 while(1) 
 { 
  //m=keyscan(); 
  if(keyscan()==ENTER) break; 
  } 
 
 
} 
 
/********数据处理子程序3**********/  
 void data_dispose3(uint ntcon) 
{ 
  uint data maxtime[2],mintime[2],stime[2]; 
  uint data ntime[6]; 
  uint datatime[6],tmpend; 
  data_dispose2(0,ntcon); 
  tmpend=Tend; 
  ntime[0]=closedata.time[0]+closedata.jump[0]; 
  ntime[1]=closedata.time[1]+closedata.jump[1]; 
  ntime[2]=closedata.time[2]+closedata.jump[2]; 
  ntime[3]=closedata.time[3]+closedata.jump[3]; 
  ntime[4]=closedata.time[4]+closedata.jump[4]; 
  ntime[5]=closedata.time[5]+closedata.jump[5]; 
  maxtime[0]=max(ntime[0],ntime[1],ntime[2]); 
  mintime[0]=min(closedata.time[0],closedata.time[1],closedata.time[2]); 
  maxtime[1]=max(ntime[3],ntime[4],ntime[5]); 
  mintime[1]=min(closedata.time[3],closedata.time[4],closedata.time[5]); 
  datatime[0]=ntime[0]-mintime[0]; 
  datatime[1]=ntime[1]-mintime[0]; 
  datatime[2]=ntime[2]-mintime[0]; 
  datatime[3]=ntime[3]-mintime[1]; 
  datatime[4]=ntime[4]-mintime[1]; 
  datatime[5]=ntime[5]-mintime[1]; 
  stime[0]=maxtime[0]-mintime[0]; 
  stime[1]=maxtime[1]-mintime[1]; 
  data_dispose2(ntcon,tcon); 
  Tend=Tend+tmpend; 
  ntime[0]=closedata.time[0]+closedata.jump[0]; 
  ntime[1]=closedata.time[1]+closedata.jump[1]; 
  ntime[2]=closedata.time[2]+closedata.jump[2]; 
  ntime[3]=closedata.time[3]+closedata.jump[3]; 
  ntime[4]=closedata.time[4]+closedata.jump[4]; 
  ntime[5]=closedata.time[5]+closedata.jump[5]; 
  maxtime[0]=max(ntime[0],ntime[1],ntime[2]); 
  mintime[0]=min(closedata.time[0],closedata.time[1],closedata.time[2]); 
  maxtime[1]=max(ntime[3],ntime[4],ntime[5]); 
  mintime[1]=min(closedata.time[3],closedata.time[4],closedata.time[5]); 
  datatime[0]+=ntime[0]-mintime[0]; 
  datatime[1]+=ntime[1]-mintime[0]; 
  datatime[2]+=ntime[2]-mintime[0]; 
  datatime[3]+=ntime[3]-mintime[1]; 
  datatime[4]+=ntime[4]-mintime[1]; 
  datatime[5]+=ntime[5]-mintime[1]; 
  stime[0]+=maxtime[0]; 
  stime[1]+=maxtime[1]; 
  closedata.time[0]=datatime[0]; 
  closedata.time[1]=datatime[1]; 
  closedata.time[2]=datatime[2]; 
  closedata.time[3]=datatime[3]; 
  closedata.time[4]=datatime[4]; 
  closedata.time[5]=datatime[5]; 
  closedata.ttq[0]=stime[0]; 
  closedata.ttq[1]=stime[1]; 
} 
/**********打印波形子程序************/  
 void  test_wave(void) 
{ 
  lcd_wave(testbuff,Tsta,Tend); 
  lcd_clear(); 
  lcd_strdisp(0,0, "    数据波形    "); 
  lcd_strdisp(0,16,"  --正在打印--  "); 
  lcd_strdisp(0,32,"   **请稍后**  "); 
  //lcd_strdisp(0x98,okkeystr); 
  prt_datawave(); 
 } 
/************************************/ 
/*位变量不能正确传递,弃用!  C51?   */ 
/************************************/ 
 void switch_onoff(bit sw_relay) 
{ 
  sampletime=0; 
  TR0=1; 
  sw_relay=0; 
  while(TR0); 
  sw_relay=1; 
} 
/**********开关合分闸子程序************/  
 void switch_reon() 
 { 
  uint data tcon2; 
  lcd_clear(); 
   databuff_init0(); 
  lcd_strdisp(0,16,warningstr1); 
  lcd_strdisp(0,32,warningstr2); 
  //lcd_strdisp(0x98,okkeystr); 
  tcon=0; 
  //swonoff=2; 
  //oldpin=npinval=0xff; 
  oldpin=npinval=IOport; 
  sampletime=0; 
  testbuff[0]=oldpin; 
  timebuff[0]=0; 
  TR0=1; 
  swon_relay=0; 
  while(TR0); 
  sampletime=0; 
  swon_relay=1; 
  timebuff[0]=timebuff[1]-10; 
  testbuff[++tcon]=IOport;  
  tcon2=tcon; 
  TR0=1; 
  swoff_relay=0; 
  while(TR0); 
  swoff_relay=1; 
  timebuff[tcon2]=timebuff[tcon2+1]-10; 
  testbuff[++tcon]=IOport;  
  timebuff[tcon]=timebuff[tcon-1]+10; 
  data_dispose3(tcon2); 
  data_dispose1(swonoff); 
  lcd_wave(testbuff,Tsta,Tend); 
  if(!PRTMODE) prt_datalist(); 
 } 
 
 /**********开关分合闸子程序************/  
 void switch_reoff() 
 { 
  uint data tcon2; 
  lcd_clear(); 
  databuff_init0(); 
  lcd_strdisp(0,16,warningstr1); 
  lcd_strdisp(0,32,warningstr2); 
  //lcd_strdisp(0x98,okkeystr); 
  tcon=0; 
  swonoff=3; 
  //oldpin=npinval=0xff; 
  oldpin=npinval=IOport; 
  sampletime=0; 
  testbuff[0]=oldpin; 
  timebuff[0]=0; 
  TR0=1; 
  swoff_relay=0; 
  while(TR0); 
  sampletime=0; 
  tcon2=tcon; 
  swoff_relay=1; 
  testbuff[++tcon]=IOport;  
  timebuff[tcon]=timebuff[tcon-1]+10; 
  TR0=1; 
  swon_relay=0; 
  while(TR0); 
  swon_relay=1; 
  timebuff[tcon2]=timebuff[tcon2+1]-10; 
  testbuff[++tcon]=IOport;  
  timebuff[tcon]=timebuff[tcon-1]+10; 
  data_dispose3(tcon2); 
  data_dispose1(swonoff); 
  lcd_wave(testbuff,Tsta,Tend); 
  if(!PRTMODE) prt_datalist(); 
 } 
/************开关合闸子程序*********/  
void  test_close(void) 
{ 
  lcd_clear(); 
  databuff_init0(); 
  lcd_strdisp(0,16,warningstr1); 
  lcd_strdisp(0,32,warningstr2); 
  tcon=0; Tend=0; 
  swonoff=0; 
  oldpin=npinval=IOport; 
  //oldpin=npinval=0xff; 
  testbuff[0]=oldpin; 
  timebuff[0]=0; 
  sampletime=0; 
  TR0=1; 
  swon_relay=0; 
  while(TR0); 
  swon_relay=1; 
  delay_ms(20); 
  timebuff[0]=timebuff[1]-20; 
  testbuff[++tcon]=IOport;  
  //testbuff[++tcon]=0xff;  
  timebuff[tcon]=timebuff[tcon-1]+20; 
  //databuff_init();	//测试用检验数据处理程序 
  data_dispose2(0,tcon); 
  data_dispose1(swonoff); 
  lcd_wave(testbuff,Tsta,Tend); 
 
  if(!PRTMODE) prt_datalist(); 
  //lcd_wave(testbuff,Tsta,TEND); 
 } 
/**********开关分闸子程序************/  
 void test_open(void) 
{ 
  lcd_clear(); 
  databuff_init0(); 
  lcd_strdisp(0,16,warningstr1); 
  lcd_strdisp(0,32,warningstr2); 
  tcon=0; 
  swonoff=1; 
  //oldpin=npinval=0xFE; 
  oldpin=npinval=IOport; 
  testbuff[0]=oldpin; 
  timebuff[0]=0; 
  sampletime=0; 
  TR0=1; 
  swoff_relay=0; 
  while(TR0); 
  swoff_relay=1; 
  delay_ms(20); 
  timebuff[0]=timebuff[1]-10; 
  testbuff[++tcon]=IOport;  
  //testbuff[++tcon]=0xf0;  
  timebuff[tcon]=timebuff[tcon-1]+10; 
  data_dispose2(0,tcon); 
  data_dispose1(swonoff); 
  lcd_wave(testbuff,Tsta,Tend); 
 
  if(!PRTMODE) prt_datalist(); 
 } 
/***********开关重合闸子程序***********/  
 void test_openclose(void) 
{ 
 uchar flag=1; 
 lcd_clear(); 
 lcd_strdisp(0,0,"重合分闸"); 
 lcd_strdisp(24,16,"1:合分"); 
 lcd_strdisp(24,32,"2:分合"); 
 lcd_strdisp(0,48,okkeystr); 
 lcd_curset(2); 
 swonoff=3; 
 while(flag) 
 { 
  nkey=keyscan(); 
  delay_ms(100); 
  switch(nkey) 
    { 
	 case UP:	{lcd_curset(2);lcd_curclr(3);swonoff=2;break;} 
	 case DOWN:	{lcd_curset(3);lcd_curclr(2);swonoff=3;break;} 
	 case ENTER:{if(swonoff==2) switch_reon(); 
	             if(swonoff==3) switch_reoff();flag=0;break; } 
    } 
 } 
} 
/***********时限设置子程序******/  
void time_limitset(void) 
{ 
  bit flag; 
  uchar ntlimit; 
  ntlimit=timelimit/10000; 
  flag=1; 
  //lcd_clear(); 
  //lcd_poson(19); 
  showmenu(submenustr31); 
  lcd_chardisp(48,16,ntlimit+0x30); 
  lcd_poson(6); 
  while(flag) 
  { 
  nkey=keyscan(); 
  delay_ms(100); 
  switch(nkey) 
  { 
     case UP:  {  ntlimit++; if (ntlimit>6) ntlimit=6; 
                	//val=timelimit+0x30; 
                  lcd_chardisp(48,16,ntlimit+0x30); 
	              //lcd_poson(19);  
				  break;} 
	 case DOWN:	{ 
                  if (ntlimit<1) ntlimit=1; 
                  ntlimit--; 
	              //val=timelimit+0x30; 
                 lcd_chardisp(48,16,ntlimit+0x30); 
	             //lcd_poson(19); 
				 break;} 
	 case ENTER:{ timelimit=ntlimit*10000;flag=0;break; }	 
    } 
   } 
  lcd_posoff(); 
  curline=4; 
 } 
/**********触头开距设置子程序***********/  
void dist_limitset(void) 
{ 
  bit flag=1; 
  uchar val; 
  uchar col; 
  uchar distval[3]={0,5,0}; 
  flag=1; 
  showmenu(submenustr32); 
  lcd_chardisp(32,16,0x30); 
  lcd_chardisp(40,16,0x35); 
  lcd_chardisp(48,16,0x30); 
  col=0;val=0; 
  lcd_poson(4); 
  while(flag) 
  { 
  nkey=keyscan(); 
  delay_ms(100); 
  switch(nkey) 
    { 
     case UP:   { val++; if (val>9) val=9;distval[col]=val;break;} 
	 case DOWN:	 { if (val<1) val=1;val--; distval[col]=val;break;} 
	 case LEFT: { col++;if (col>2) col=0;val=distval[col];break; }	 
     case ENTER:{ distlimit=distval[0]*100+distval[1]*10+distval[2];  
	               flag=0;break; } 
     } 
     lcd_chardisp(32+8*col,16,val+0x30); 
     lcd_poson(4+col); 
  } 
 lcd_posoff(); 
  curline=4; 
} 
/***********定时器0初始化程序**********/  
void time0_init() 
{ 
  TMOD=0x02;//T0 mode 2 autoreload 
  IP=0x08;  // 
  IE=0x82;  //enable T0 interrupt 
  TH0=-97;	//T0 reroad value 
  TL0=-97; //中断调用响应2+1,计97+3=100us 
 } 
/*************定时器0中断程序**************/  
/*中断服务必须在97us内可靠完成,看编译ASM码*/ 
/******************************************/ 
void time0_serve() interrupt 1 using 1 
{                   //push xx  10 us 
  pinval=IOport;               //6us 
  if(sampletime<timelimit)     // 7 us 
  { 
  if(npinval!=pinval)	         //4 us 
  { 
     testbuff[++tcon]=pinval; 		 //13 us 
     timebuff[tcon]=sampletime;     //20 us 
  //tcon++;  						 //2us 
  } 
  npinval=pinval;			// 2 us 
  sampletime++;				//5us 
  } 
 else                      //2us 
 { 
    TR0=0;   				   //1 us 
 }	                 //pop xx  12us 
}  			    	 // total MAX:91us 
/*********测试项目选择子程序 ********/  
void  test_itemsel(void)	   
{ // 
  uchar nflag=1; 
  showmenu(submenustr1); 
  curline=1; 
  lcd_curset(curline); 
  while(nflag) 
 { 
   nkey=keyscan(); 
   delay_ms(100);	 
   switch(nkey) 
   { 
     case UP:{  // 
	     curline=lcd_curup(curline);break; } 
	 case DOWN:{ // 
	     curline=lcd_curdown(curline);break; } 
	 case ENTER:// 
	 {  switch(curline) 
		{ 
		 case 1:	// 
		      {test_close();curline=1;break;} 
		 case 2:	// 
			  {test_open();curline=2;break;} 
		 case 3:	// 
		      {test_openclose();curline=3;break;} 
		 case 4:	// 
			  {nflag=0;break;} 
		 } ; 
		if(nflag) showmenu(submenustr1); 
		lcd_curset(curline); 
		break; 
	  } 
    } 
  } 
  curline=1; 
} 
/**********开关状态检查子程序*********/ 
void switch_stadisp(void) 
{ 
  uchar i; 
  data uchar pin1sta[6][4]={ 
                             {"分\0"},{"分\0"},{"分\0"}, 
							 {"分\0"},{"分\0"},{"分\0"} 
							 };    
   pinval=IOport; 
   for(i=0;i<6;i++) 
   { 
     if(!Bittest(pinval,i))  
	 { 
	    //pin1sta[i]="合\0"; 
		pin1sta[i][0]=0xba;  
		pin1sta[i][1]=0xcf; 
	  }; 
    } 
   showmenu(submenustr2); 
   lcd_strdisp(40,0,pin1sta[0]); 
   lcd_strdisp(40,16,pin1sta[1]); 
   lcd_strdisp(40,32,pin1sta[2]); 
   lcd_strdisp(104,0,pin1sta[3]); 
   lcd_strdisp(104,16,pin1sta[4]); 
   lcd_strdisp(104,32,pin1sta[5]); 
   while(1) 
   { 
	nkey=keyscan(); 
    delay_ms(100);	 
    if (nkey==ENTER) break; 
  	} 
    curline=2; 
} 
/*********测试初值设置子程序*********/ 
void test_initset(void) 
{ 
   uchar nflag; 
   showmenu(submenustr3); 
   curline=1; 
   lcd_curset(curline); 
   nflag=1; 
   while(nflag) 
   { 
	nkey=keyscan(); 
    delay_ms(100);	 
    switch(nkey) 
   { 
     case UP:{  // 
	     curline=lcd_curup(curline);break; } 
	 case DOWN:{  // 
	     curline=lcd_curdown(curline);break; } 
	 case ENTER:{  // 
	     switch(curline) 
		 { 
		  case 1:	// 
		      {time_limitset();curline=1;break;} 
		  case 2:	// 
		      {dist_limitset();curline=2;break;} 
		  case 3:	// 
		      {prt_modeset();curline=3;break;} 
		  case 4:	// 
		      {nflag=0;break;} 
		   }; 
		 if(nflag) showmenu(submenustr3); 
		 lcd_curset(curline); 
		 break; 
	  } 
    } 
	} 
   curline=3; 
} 
 
/*********测试打印报表子程序**********/ 
void test_reports(void) 
{ 
   uchar nflag=1; 
   showmenu(submenustr4); 
   curline=1; 
   lcd_curset(curline); 
   while(nflag) 
   { 
	nkey=keyscan(); 
    delay_ms(100);	 
    switch(nkey) 
   { 
     case UP:{  // 
	     curline=lcd_curup(curline);break; } 
	 case DOWN:{  // 
	     curline=lcd_curdown(curline);break; } 
	 case ENTER:{  // 
	     switch(curline) 
		{ 
	    case 1:	// 
	        {test_list();break;} 
		case 2:	// 
		    {test_wave();break;} 
		case 3:	// 
		    {test_wavelist();break;} 
		case 4:	// 
		    {nflag=0;break;} 
		 } ; 
		if(nflag) showmenu(submenustr4); 
		lcd_curset(curline); 
		break; 
	} 
    } 
	} 
  curline=4; 
} 
/***********打印点数计算子程序********/  
uchar prt_linenums() 
{ 
 uchar nums=9; 
 mflag=0; 
 if(PINSD!=TMPSD) nums+=9; 
 if(PINTB!=TMPTB) nums+=9; 
 if(PINA1!=TMPA1) nums+=9; 
 if(PINB1!=TMPB1) nums+=9; 
 if(PINC1!=TMPC1) nums+=9; 
 if(PINA2!=TMPA2) nums+=9; 
 if(PINB2!=TMPB2) nums+=9; 
 if(PINC2!=TMPC2) nums+=9; 
 if(nums!=9)	mflag=1; 
 return nums; 
} 
/***********打印机初始化子程序********/  
void prt_init() 
{ 
  prt_char(0x1b); //"ESC @" 
  prt_char(0x40); 
  prt_char(0x0d); 
} 
/**********打印一个字符子程序*********/  
 void prt_char(uchar d) 
{   
  while(prtbusy); 
  P0=d; 
  prtstb=0; 
  prtstb=1; 
} 
/**********打印字符串子程序********/  
void prt_str(uchar *p) 
{ 
 while( *p!='\0') 
 {   
   prt_char(*p); 
   p++; 
 } 
} 
/**********打印方式设置子程序********/  
void prt_modeset() 
{ 
 uchar flag=1; 
 lcd_clear(); 
 lcd_strdisp(16,0,"打印方式"); 
 lcd_strdisp(24,16,"0:自动"); 
 lcd_strdisp(24,32,"1:手动"); 
 lcd_curset(2); 
 lcd_strdisp(8,48,okkeystr); 
 PRTMODE=1;							  
 while(1) 
  { 
  nkey=keyscan(); 
  delay_ms(100); 
  if(nkey==UP)  {lcd_curset(2);lcd_curclr(3);PRTMODE=0;} 
  if(nkey==DOWN){lcd_curset(3);lcd_curclr(2);PRTMODE=1;} 
  if(nkey==ENTER){ flag=0;break; } 
   } 
  // curline=3;		 
} 
 
/**********打印单点子程序*********/  
 void prt_dot(uchar pos,bit n1,bit n2) 
{ 
  if(mflag&&(n1!=n2)) 
  { 
    prt_char(pos); 
	prt_char(pos+1); 
	prt_char(pos+2); 
	prt_char(pos+3); 
	prt_char(pos+4); 
	prt_char(pos+5); 
	prt_char(pos+6); 
	prt_char(pos+7); 
	prt_char(pos+8); 
	prt_char(pos+9); 
  } 
  else 
  prt_char(pos+9*Bit2val(n1)); 
} 
/**********打印数据波形子程序*********/  
void prt_datawave() 
{  
  uchar num,tlen,tlen2,flen,i,j,k,l; 
  bit ftb=1; 
  prt_init(); 
  prt_char(0x0a); 
  prt_str("---------------------------------------"); 
  prt_char(0x0a); 
  prt_str("              [TEST  WAVES]"); 
  prt_char(0x0a); 
  prt_str("    T   SD  TB   A1  B1  C1  A2  B2  C2"); 
  prt_char(0x0a); 
  pinval=testbuff[0]; 
  k=0; 
  for(i=0;i<tcon;i++) 
  { pinval=testbuff[i]; 
	tmppin=testbuff[i+1]; 
	tlen=timebuff[i+1]-timebuff[i]; 
	flen=0;tlen2=0; 
	//if(tlen>100) {tlen2=tlen%100;tlen/=100; flen=2;} 
	//if((tlen>=100)) {tlen2=tlen%10;tlen/=10; flen=2;ftb=0;} 
	//else  
	flen=1; 
	//if(i==0) flen=0; 
   	num=9;mflag=0; 
	for(j=0;j<(tlen+tlen2);j++) 
	{ 
	  prt_char(0x1b); 
	  prt_char(0x27); 
	  if(j==(tlen+tlen2-1)) 
	  { mflag=1; 
	    num=prt_linenums(); 
		//k=0;//flen=1; 
	  } 
	  if(j>tlen) flen=0; 
	  if((k==10)||(k==0)) 
	  {  
	    //flen++; 
		prt_char(num+5*(flen) ); 
		for(l=0;l<5*(flen);l++) 
		{ 
	      prt_char(25+l); 
		} 
	    //prt_char(0x0d); 
	    k=0; 
	   }else   prt_char(num);  
	prt_char(30); 
	prt_dot(55,PINSD,TMPSD); 
	prt_dot(80,PINTB,TMPTB); 
	prt_dot(105,PINA1,TMPA1); 
	prt_dot(130,PINB1,TMPB1); 
	prt_dot(155,PINC1,TMPC1); 
	prt_dot(180,PINA2,TMPA2); 
	prt_dot(205,PINB2,TMPB2); 
	prt_dot(230,PINC2,TMPC2); 
	prt_char(0x0d); 
	k++; num=9;mflag=0; 
	} 
  } 
  prt_char(0x0a); 
  prt_char(0x0a); 
  prt_str("  SCALE:  "); 
  //prt_char(0xe4); 
  prt_char(0xC3); 
  prt_str("--[1 MS] "); 
  prt_str("   "); 
  prt_char(0xC1); 
  prt_char(0xC0); 
  prt_str("--[10 MS] "); 
  prt_char(0x0a); 
  prt_str("  DATE:   "); 
  prt_str("2008-00-00"); 
  prt_char(0x0a); 
} 
/**********打印数据列表子程序*********/  
 void prt_datalist() 
{ //uchar i,j;  
  prt_char(0x0a); 
  prt_str("---------------------------------------"); 
  prt_char(0x0a); 
  prt_str("TEST DATE:   "); 
  prt_str("2008-00-00"); 
  prt_char(0x0a); 
  prt_str("TAG NO1:             TAG NO2: "); 
  prt_char(0x0a); 
  prt_str(dispbuff[8]); 
  prt_char(0x0a); 
  prt_str(dispbuff[7]); 
  prt_char(0x0a); 
  prt_str(dispbuff[6]); 
  prt_str("     "); 
  prt_str(dispbuff[15]); 
  prt_char(0x0a); 
  prt_str(dispbuff[5]); 
  prt_str("     "); 
  prt_str(dispbuff[14]); 
  prt_char(0x0a); 
  prt_str(dispbuff[4]); 
  prt_str("     "); 
  prt_str(dispbuff[13]); 
  prt_char(0x0a); 
  prt_str(dispbuff[3]); 
  prt_str("     "); 
  prt_str(dispbuff[12]); 
  prt_char(0x0a); 
  prt_str(dispbuff[2]); 
  prt_str("     "); 
  prt_str(dispbuff[11]); 
  prt_char(0x0a); 
  prt_str(dispbuff[1]); 
  prt_str("     "); 
  prt_str(dispbuff[10]); 
  prt_char(0x0a); 
  prt_str(dispbuff[0]); 
  prt_str("     "); 
  prt_str(dispbuff[9]); 
  prt_char(0x0a); 
  prt_str("ITEM--VALUE--ACT     ITEM--VALUE--ACT"); 
  prt_char(0x0a); 
  prt_str("            [TEST LISTS]"); 
  prt_char(0x0a); 
 } 
/**************主程序**************/ 
main() 
{ 
    uchar nline=0x40; 
	//databuff_init0(); 
	lcd_init();	            //LCD初始化								 
    lcd_clear();            //LCD清屏 
	lcd_bmpdisp(128,64,nBitmapDot);//显示开机画面 
	delay_ms(3000); 
	lcd_clear();			//LCD清屏 
	//dispbuffclear();      //显示缓存初始化 
	curline=1;  	        //光标初值设置 
	timelimit=10000;        //测试时限30000*0.1ms 
	distlimit=50;	        //触头开距50mm 
   	PRTMODE=1; 				//手动打印方式 
   	swon_relay=1;           //合闸继电器初值 
	swoff_relay=1;          //分闸继电器初值 
	swonoff=5;				//分合闸初值N/A 
	time0_init();           //定时器0初始化 
	databuff_init();	//测试用检验数据处理程序 
	showmenu(mainmenustr);  //显示主菜单 
	lcd_curset(curline);	//设置当前行光标 
	while(1)				//循环检查键盘 
  	{ 
     uchar nkey; 
	 nkey=keyscan();	    //扫描键盘 
	 delay_ms(200);			 
	 switch(nkey) 
     { 
       case UP:				//上移光标 
	   { // 
         curline=lcd_curup(curline); 
	     break;  
	   } 
      case DOWN:		 	//下移光标 
	  { // 
        curline=lcd_curdown(curline); 
	    break;  
	  } 
	  case ENTER:		   	//确认处理 
	  {  // 
	    switch(curline) 
		{ 
	      case 1:	// 进入测试项目选择 
	      {test_itemsel();break;} 
	      case 2:	// 进入开关状态显示 
		  {switch_stadisp();break;} 
	      case 3:	// 进入初值设置程序 
		  {test_initset();break;} 
	      case 4:	// 进入打印报表程序 
		  {test_reports();break;} 
	    } ; 
		showmenu(mainmenustr); //显示主菜单 
        //curline=4; 
        lcd_curset(curline);  //显示当前光标 
		break; 
	   } 
	  } 
    } 
}