#include"stc12c5a.h"
#define uchar unsigned char
sbit dula=P4^2;
sbit wela=P4^3;
sbit jia_key=P2^4;
sbit jian_key=P2^5;
sbit zf_key=P2^6;
sbit aa=P2^0;//矩阵键盘第一行
bit flag=0;
uchar num=0,show_num=2,maichong=4,table_begin=0;
uchar code table1[]={0x01,0x02,0x04,0x08,0x08,0x04,0x02,0x01};
//电机正反转IO口高低电平对应表
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//数码显示管IO对应表
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void display()
{
dula=0;
P0=table[show_num];
dula=1;
dula=0;
wela=0;
P0=0xfe;
wela=1;
wela=0;
delay(5);
P0=table[0];
dula=1;
dula=0;
P0=0xfd;
wela=1;
wela=0;
delay(5);
}
void key()
{
if(jia_key==0)
{
delay(200);
if(jia_key==0)
{
num++;
if(num==4)
num=3;
while(jia_key==0);
}
}
if(jian_key==0)
{
delay(200);
if(jian_key==0)
{
if(num!=0)
num--;
while(jian_key==0);
}
}
if(zf_key==0)
{
delay(200);
if(zf_key==0)
{
flag=~flag;
while(zf_key==0);
}
}
}
void dispose()
{
switch(num)
{
case 0:
show_num=2;
maichong=5;
break;
case 1:
show_num=4;
maichong=4;
break;
case 2:
show_num=6;
maichong=3;
break;
case 3:
show_num=8;
maichong=2;
break;
}
if(flag==0)
{
table_begin=0;
}
else
table_begin=4;
}
void qudong()
{
uchar i,j;
for(j=0+table_begin;j<4+table_begin;j++)
{
P1=table1[j];
for(i=0;i<maichong;i++)
{
display();
}
}
}
void main()
{
while(1)
{
aa=0;
key();
dispose();
qudong();
}
}
|