#include<f:\Keil\C51\INC\STC\STC12c5a60S2.H>
#define uchar unsigned char
#define uint unsigned int
sbit COM4=P2^3;
sbit COM3=P2^2;
sbit COM2=P2^1;
sbit COM1=P2^0;
sbit COMG=P3^2;
sbit SEGG=P3^1;
sbit key1=P2^6;
sbit key2=P2^7;
unsigned char i=0,j=9;
unsigned char C1[10]={0x01,0x00,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01};
unsigned char C2[10]={0x03,0x02,0x02,0x02,0x03,0x01,0x01,0x02,0x03,0x03};
unsigned char C3[10]={0x01,0x00,0x03,0x02,0x02,0x02,0x03,0x00,0x03,0x02};
unsigned char C4[10]={0x03,0x02,0x01,0x03,0x02,0x03,0x03,0x02,0x03,0x03};
/****************延时程序******************/
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
/************开关控制程序********************/
key()
{
if(key1==0)
{
delay(10);
if(key1==0)
{
i++;
if(i>9)
i=0;
while(key1==0);
}
}
}
keyz()
{
if(key2==0)
{
delay(10);
if(key2==0)
{
i--;
if(j<0)
i=9;
while(key2==0);
}
}
}/************主函数********************/
void main(void)
{
P1=i;
while(1)
{
key(); //调用开关程序
keyz();
/******************完成一次扫描******************/
P2=0x0e; //COM口给数据
P1= C1; //seg给数据
COMG=0; //com公共端
SEGG=1; //seg公共段
delay(3);
P2=~0x0e;
P1=~ C1;
COMG=1;
SEGG=0;
delay(3);
P2=0x0D;
P1= C2;
COMG=0;
SEGG=1;
delay(3);
P2=~0x0D;
P1=~ C1;
COMG=1;
SEGG=0;
delay(3);
P2=0x0B;
P1= C3;
COMG=0;
SEGG=1;
delay(3);
P2=~0x0B;
P1=~ C3;
COMG=1;
SEGG=0;
delay(3);
P2=0x07;
P1= C4;
COMG=0;
SEGG=1;
delay(3);
P2=~0x07;
P1=~C4;
COMG=1;
SEGG=0;
delay(3);
}
}
|