#include<reg51.h>
#include "uart.c"
#define uchar unsigned char
#define uint unsigned int
//定义管脚
sbit key_1=P1^0; //计数
sbit key_2=P1^2;//页面上翻
sbit key_3=P1^1;//页面下翻
sbit key_4=P1^3;//清零
sbit key_5=P1^4;//回到计数模式
//--定义全局变量--//
unsigned char code wei[4] = {
0xfe,0xfd,0xfb,0xf7};//位选控制 查表的方法控制
unsigned char code duan[18] = {
0x5f,0x44,0x9d,0xd5,0xc6,0xd3,0xdb,0x47,0xdf,0xd7,0xcf,0xda,0x1b,0xdc,0x9b,0x8b,0x80};
//0、1、2、3、4、5、6、7、8、9、A、b、C、d、E、F的显示码
uchar count,yemian,number;//分别用来记录当前数值,显示的页面 以及将记录写到数组的哪个位置
uchar record[15]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void display(uchar a,uchar b,uchar c); //动态显示函数
void delay(unsigned int ms)//延时1毫秒(不够精确的)
{
unsigned int i,j;
for(i=0;i<ms;i++)
for(j=0;j<110;j++);
}
void key()
{
if(key_1==0)
{
delay(5);
if(key_1==0)
{
count++;
if(count>98)
count=99;
while(key_1==0)
display(yemian,count,record[yemian-1]);
}
}
if(key_2==0)
{
delay(5);
if(key_2==0)
{
if(yemian>1)
yemian--;
else
yemian=15;
while(key_2==0)
display(yemian,count,record[yemian-1]);
}
}
if(key_3==0)
{
delay(5);
if(key_3==0)
{
if(yemian<15)
yemian++;
else
yemian=1;
while(key_3==0)
display(yemian,count,record[yemian-1]);
}
}
if(key_4==0)
{
delay(5);
if(key_4==0)
{
if(count!=0&&number<15)
{
record[number++]=count;
}
count=0;
while(key_4==0)
display(yemian,count,record[yemian-1]);
}
}
if(key_5==0)
{
delay(5);
if(key_5==0)
{
yemian=0;
while(key_5==0)
display(yemian,count,record[yemian-1]);
}
}
}
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main(void)
{
uchar i;
Uart_init();
while(1)
{
for(i=0;i<15;i++)
{
display(yemian,count,record[yemian-1]);
key();
if(i==0)
SendASC('$');
display(yemian,count,record[yemian-1]);
SendASC(record[i]/10+0x30);
display(yemian,count,record[yemian-1]);
SendASC(record[i]%10+0x30);
}
display(yemian,count,record[yemian-1]);
SendASC(count/10+0x30);
display(yemian,count,record[yemian-1]);
SendASC(count%10+0x30);
display(yemian,count,record[yemian-1]);
SendASC('!');
display(yemian,count,record[yemian-1]);
}
}
/*******************************************************************************
* 函 数 名 : DigDisplay
* 函数功能 : 使用数码管显示
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void display(unsigned char a,unsigned char b,uchar c)
{
P2=0x7f;
if(a!=0)
P0=~duan[a];
else
P0=~0x00;
delay(5);
P0=~0x00;
P2=0xbf;
if(a!=0)
P0=~duan[16];
else
P0=~0x00;
delay(5);
P0=~0x00;
P2=0xdf;
if(a!=0)
P0=~duan[c/10];
else
P0=~duan[b/10];
delay(5);
P0=~0x00;
P2=0xef;
if(a!=0)
P0=~duan[c%10];
else
P0=~duan[b%10];
delay(5);
P0=~0x00;
}
|