|
附件:
#include
#include "LCD1602.h"
#include "Key2.h"
#include "CeLiang.h"
void Delay1ms(unsigned int count)
{
unsigned int i,j;
for(i=0;i
for(j=0;j<120;j++);
}
void IntToStr(uint t, uchar *str, uchar n)
{ uchar a[5]; uchar i2, j;
a[0]=(t/10000)%10; //取得整数值到数组
a[1]=(t/1000)%10;
a[2]=(t/100)%10;
a[3]=(t/10)%10;
a[4]=(t/1)%10;
for(i2=0; i2<5; i2++) //转成ASCII码
a[i2]=a[i2]+'0';
for(i2=0; a[i2]=='0' && i2<=3; i2++);
for(j=5-n; j
{ *str=' '; str++; }
for(; i2<5; i2++)
{ *str=a[i2]; str++; } //加入有效的数字
*str='\0';
}
main()
{ uchar i,key;
uchar TempBuffer[10]; //LCD字符显示缓存
max=0;
LCD_Initial(); //LCD初始化
/*延时2s*/
for(i=100;i>0;i--)
Delay1ms(20);
/*提示输入脉冲的测量次数*/
GotoXY(0,0);
Print(" INPUT Measure ");
GotoXY(0,1);
Print(" Number(10-64): ");
/*此while循环为测量次数输入模块*/
while(1)
{ key=keyScan();
switch(key)
{ case(11):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+1;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(12):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+2;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(13):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+3;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(21):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+4;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(22):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+5;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(23):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+6;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(31):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+7;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(32):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+8;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(33):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+9;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
case(42):
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
max=max*10+0;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
break;
}//switch
if(max>64)
{ max=64;
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
}
if(max>9)break;
}//while
/*输入测量次数模块结束*/
/*显示输入的数2s*/
for(i=100;i>0;i--)
Delay1ms(20);
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
for(i=100;i>0;i--)
Delay1ms(20);
//这里加了初始化
for(i=0;i<=(max+1);i++)
{ time.second=0;
time.m_second=0;
time.mm_second_1=0;
time.mm_second_2=0;
time.mm_second=0;
}
//在PROTEUS仿真中发现,当输入值MAX>27,就进入了死循环,不知为什么???????
GotoXY(0,0);
Print(" PLEASE PRESS 1 ");
GotoXY(0,1);
Print(" TO START ");
key=0;
/*下面为测量脉冲过程*/
while(keyScan()!=11);
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
GotoXY(0,0);
Print(" LOADING..... ");
int0_initial();
while(puls_num
/*测量脉冲结束,下面为结果计算和显示*/
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
/*显示输入的数5s*/
for(i=100;i>0;i--)
Delay1ms(50);
//数据处理
data_processing();
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
IntToStr(max,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
/*显示输入的数5s*/
for(i=100;i>0;i--)
Delay1ms(50);
LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
GotoXY(0,1);
Print(" Measrue End! ");
/*显示输入的数2s*/
for(i=100;i>0;i--)
Delay1ms(20);
GotoXY(0,0);
Print(" PLEASE PRESS 2 ");
GotoXY(0,1);
Print(" TO SHOW ");
while(keyScan()!=12);
for(i=max;i>1;i--)
{ LCD_Write(LCD_COMMAND,LCD_CLEAR_SCREEN); //清屏
IntToStr(i,&TempBuffer[0],3);
GotoXY(0,0);
Print(&TempBuffer[0]);
GotoXY(0,1);
Print("DATA:");
GotoXY(8,1);
Print(".");
IntToStr(time.second,&TempBuffer[0],3);
GotoXY(5,1);
Print(&TempBuffer[0]);
IntToStr(time.m_second,&TempBuffer[0],3);
GotoXY(9,1);
Print(&TempBuffer[0]);
IntToStr(time.mm_second,&TempBuffer[0],3);
GotoXY(12,1);
Print(&TempBuffer[0]);
while(keyScan()!=43);
}
while(1);
}
|
|