main.c
#include
#include
#include "juzhen.h"
extern unsigned char cun[7];
unsigned char display[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
unsigned char shuzu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
extern unsigned char key;
void xianshi();
void Timer0Init();
void main()
{
Timer0Init();EA=1;ET0=1;
P2=0XA0;P0=0X00;
while(1)
{
anjian();
xianshi();
}
}
void xianshi()
{
display[0]=shuzu[cun[7]];
display[1]=shuzu[cun[6]];
display[2]=shuzu[cun[5]];
display[3]=shuzu[cun[4]];
display[4]=shuzu[cun[3]];
display[5]=shuzu[cun[2]];
display[6]=shuzu[cun[1]];
display[7]=shuzu[cun[0]];
}
void Timer0Init(void) //2毫秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x9A; //设置定时初值
TH0 = 0xA9; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void shuma()interrupt 1
{
unsigned char i;
P2=0XE0;
P0=0XFF;
P2=0X1F;
P2=0XC0;
P0=1<=8)i=0;
}
juzhen.c
#include
#include
#include "juzhen.h"
unsigned char key;
unsigned char cun[7];
unsigned char a;
sbit l1=P4^4;
sbit l2=P4^2;
sbit l3=P3^5;
sbit l4=P3^4;
sbit h1=P3^0;
sbit h2=P3^1;
sbit h3=P3^2;
sbit h4=P3^3;
void anjian()
{
l1=0;
l2=l3=l4=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{cun[a]=7;a++;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{cun[a]=4;a++;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{cun[a]=1;a++;}
while(!h3);
}
// if(h4==0)
// {
// Delay10ms();
// if(h4==0)
// {key=4;}
// while(!h4);
// }
l2=0;
l1=l3=l4=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{cun[a]=8;a++;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{cun[a]=5;a++;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{cun[a]=2;a++;}
while(!h3);
}
if(h4==0)
{
Delay10ms();
if(h4==0)
{cun[a]=0;a++;}
while(!h4);
}
l3=0;
l1=l2=l4=1;
h1=h2=h3=h4=1;
if(h1==0)
{
Delay10ms();
if(h1==0)
{cun[a]=9;a++;}
while(!h1);
}
if(h2==0)
{
Delay10ms();
if(h2==0)
{cun[a]=6;a++;}
while(!h2);
}
if(h3==0)
{
Delay10ms();
if(h3==0)
{cun[a]=3;a++;}
while(!h3);
}
// if(h4==0)
// {
// Delay10ms();
// if(h4==0)
// {key=12;}
// while(!h4);
// }
// l4=0;
// l1=l2=l3=1;
// h1=h2=h3=h4=1;
// if(h1==0)
// {
// Delay10ms();
// if(h1==0)
// {key=13;}
// while(!h1);
// }
// if(h2==0)
// {
// Delay10ms();
// if(h2==0)
// {key=14;}
// while(!h2);
// }
//
// if(h3==0)
// {
// Delay10ms();
// if(h3==0)
// {key=15;}
// while(!h3);
// }
//
// if(h4==0)
// {
// Delay10ms();
// if(h4==0)
// {key=16;}
// while(!h4);
// }
//
if(a>=8)a=0;
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
juzhen.h
#ifndef __JUZHEN_H__
#define __JUZHEN_H__
void Delay10ms();
void anjian();
#endif