该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include"reg52.h"
#define uchar unsigned char
#define uint unsigned int
sbit U5_C = P3^6;
sbit U6_C = P3^7;
sbit beep = P3^4;
sbit K1 = P3^2;
sbit K2 = P3^3;
sbit JS = P3^5;
sbit sc = P3^5;
uchar shuju;
uchar ten;
uchar code duan[18] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff,0xbf};
uint code dshi[99]={50000,25000,16667,12500,10000,8333,7143,6250,5556,5000,4545,4167,3846,3571,3333,3125,2941,2778,2632,2500,2381,2273,2174,2083,2000,1923,1852,1786,1724,1667,1613,1563,1515,1471,1429,1389,1351,1316,1282,1250,1220,1190,1163,1136,1111,1087,1064,1042,1020,1000,980,961,943,926,909,893,877,862,848,834,820,806,794,782,769,758,747,736,725,715,704,695,685,676,667,658,650,641,633,625,618,610,603,595,};
uchar disp_sbuf[8];
void key1();
void key2();
void display();
void disp_drv();
void intion();
void delay(unsigned int i)
{
unsigned int m,n;
for (m = i;m > 0;m--)
for(n = 90;n > 0;n--);
}
void main()
{
intion();
while(1)
{
key1();
key2();
disp_drv();
display();
}
}
void key1()
{
if(K1==0)
{
delay(20);
if(K1==0)
{
while(!K1)
{
beep = 0;
disp_drv();
display();
}
beep = 1;
shuju++;
if (shuju > 99)
shuju = 1;
}
}
}
void key2()
{
if(K2==0)
{
delay(20);
if(K2==0)
{
while(!K2)
{
beep = 0;
disp_drv();
display();
}
beep = 1;
shuju--;
if(shuju < 1)
shuju = 99;
}
}
}
void disp_drv()
{
uchar i,wei = 0x80;
for(i = 0;i < 8;i++)
{
P0 = duan[disp_sbuf[i]];
U5_C = 1;
U5_C = 0;
P2 = wei;
U6_C = 1;
U6_C = 0;
delay(1);
wei = wei >> 1;
}
}
void display()
{
disp_sbuf[7] = shuju/10;
disp_sbuf[6] = shuju%10;
disp_sbuf[5] = 17;
disp_sbuf[4] = 17;
disp_sbuf[3] = 17;
disp_sbuf[2] = 17;
disp_sbuf[1] = shuju/10;
disp_sbuf[0] = shuju%10;
}
void intion()
{
TMOD = 0x01;
TH0 = (65536-10000) / 256;
TL0 = (65536-10000) % 256;
TR0 = 1;
ET0 = 1;
EA = 1;
}
void time0() interrupt 1
{
TH0 = (65536-dshi[shuju]) / 256;
TL0 = (65536-dshi[shuju]) % 256;
if(ten++>10)
{
ten=0;
sc=!sc;
}
}