|
电路原理图如下:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define led P0
#define haha P2
sbit s1 = P1^0;
sbit s2 = P1^1;
sbit s3 = P3^0;
sbit s4 = P3^1;
sbit s5 = P3^2;
sbit wei3 = P2^3;sbit wei2 = P2^2;sbit wei1 = P2^1;sbit wei0 = P2^0;
sbit a = P2^7;sbit b = P2^6;sbit c = P2^5;sbit d = P2^4;
uchar code tab[11]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
uchar code time_counter[10][2]={{0xda,0x1c},{0xde,0xe4},{0xe1,0xec},{0xe5,0xd4},{0xe9,0xbc},
{0xed,0xa4},{0xf1,0x8c},{0xf5,0x74},{0xf9,0x5c},{0xfc,0x18}};
uchar num1 = 0;
uchar num2 = 8;
char k=0;
char pause=1;
bit flag1 = 0;
uchar buf[4]={0,10,0,0};
//================================?¨ê±?÷0/13?ê??ˉoˉêy==============================
void T0_T1_init()
{
TMOD = 0x11;
TH1 = time_counter[k-1][0];
TL1 = time_counter[k-1][1];
TR1 = 0;
ET1= 1;
EA = 1;
}
//================================ms???óê±oˉêy=====================================
void delay1m(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<120;j++);
}
void display()
{
wei3=1;wei2=1;wei1=1;wei0=0;led = tab[buf[3]];delay1m(1);led=0xff;
wei3=1;wei2=1;wei1=0;wei0=1;led = tab[buf[2]];delay1m(1);led=0xff;
wei3=1;wei2=0;wei1=1;wei0=1;led = tab[buf[1]];delay1m(1);led=0xff;
wei3=0;wei2=1;wei1=1;wei0=1;led = tab[buf[0]];delay1m(1);led=0xff;
}
//================================?÷oˉêy===========================================
void main()
{
T0_T1_init();
buf[1] = 10;
a=b=c=d=0;
while(1)
{
display();
if(s1 == 0)
{
delay1m(3);
if(s1 == 0)
{
flag1 = 0;
buf[0] = 0;
}
while(!s1) display();
}
if(s2 == 0 )
{
delay1m(3);
if(s2 == 0)
{
flag1 = 1;
buf[0] = 1;
}
while(!s2) display();
}
if(s3 == 0)
{
delay1m(3);
if(s3 == 0)
{
k++;
TR1=1;
if(k > 10 )
{
k = 1;
}
buf[2]= k/10;
buf[3]= k%10;
}
while(!s3) display();
}
if(s4 == 0)
{
delay1m(3);
if(s4 == 0)
{
k--;
TR1=1;
if(k <= 0)
{
k = 10;
}
buf[2]= k/10;
buf[3]= k%10;
}
while(!s4) display();
}
if(s5==0)
{
delay1m(3);
if(s5==0)
{
if(TR1==1)
{
pause=k;
k=0;
TR1=0;
a=b=c=d=0;
}
else if(TR1==0)
{
k=pause;
TR1=1;
}
buf[2]= k/10;
buf[3]= k%10;
while(!s5) display();
}
}
}
}
//==================================?¨ê±?÷1?D??oˉêy£?ó?óú??3??μ?ê????===================================
void time1_interrupt()interrupt 3
{
static num1 = 0;
static num2 = 0;
TH1 = time_counter[k-1][0];
TL1 = time_counter[k-1][1];
if(flag1 == 0)
{
switch(num1)
{
case 0:a = 1;b = 0;c = 0;d = 0;break;
case 1:a = 1;b = 1;c = 0;d = 0;break;
case 2:a = 0;b = 1;c = 0;d = 0;break;
case 3:a = 0;b = 1;c = 1;d = 0;break;
case 4:a = 0;b = 0;c = 1;d = 0;break;
case 5:a = 0;b = 0;c = 1;d = 1;break;
case 6:a = 0;b = 0;c = 0;d = 1;break;
case 7:a = 1;b = 0;c = 0;d = 1;break;
}
num1++;
if(num1 == 8)num1 = 0;
}
else
{
switch(num2)
{
case 0:a = 1;b = 0;c = 0;d = 1;break;
case 1:a = 0;b = 0;c = 0;d = 1;break;
case 2:a = 0;b = 0;c = 1;d = 1;break;
case 3:a = 0;b = 0;c = 1;d = 0;break;
case 4:a = 0;b = 1;c = 1;d = 0;break;
case 5:a = 0;b = 1;c = 0;d = 0;break;
case 6:a = 1;b = 1;c = 0;d = 0;break;
case 7:a = 1;b = 0;c = 0;d = 0;break;
}
num2++;
if(num2 == 8)num2 = 0;
}
}
|
-
-
原理图.doc
56 KB, 下载次数: 15, 下载积分: 黑币 -5
评分
-
查看全部评分
|