/***********STC8H8K64U两位数码管显示***************/
/*****************QQ:74145445**********************/
/*****************快手:共同学习stm8****************/
/*****************20221221*************************/
/****************可控硅触发时间********************/
#include<STC8H.H>
sbit led_1_a =P2^4;
sbit led_1_b =P2^3;
sbit led_1_c =P4^6;
sbit led_1_d =P7^7;
sbit led_1_e =P7^6;
sbit led_1_f =P2^6;
sbit led_1_g =P2^7;
sbit led_1_dp =P0^0;
sbit led_1_3 =P4^5;
sbit led_1_5 =P2^5;
sbit led_2_a =P4^1;
sbit led_2_b =P7^3;
sbit led_2_c =P0^5;
sbit led_2_d =P5^2;
sbit led_2_e =P0^4;
sbit led_2_f =P4^3;
sbit led_2_g =P4^4;
sbit led_2_dp =P0^6;
sbit led_2_3 =P5^3;
sbit led_2_5 =P4^2;
sbit key_1 =P3^4;
sbit key_2 =P3^5;
sbit key_3 =P3^2;
sbit key_4 =P3^3;
sbit out_1 =P1^3;
/**************************************************/
unsigned char code led[]={
0x3F,0x06,0x5B,0x4F,0x66,0x6D,
0x7D,0x07,0x7F,0x6F}; // 0~9
/**************************************************/
void xianshi();
void yanshi();
void anjian();
void chufa();
unsigned char xianshi_a1;
unsigned char xianshi_shi,xianshi_ge;
/**************************************************/
void main()
{
/**************************************************/
P0M0 |=(1<<0)+(1<<5)+(1<<4)+(1<<6);
P0M1 &=~((1<<0)+(1<<5)+(1<<4)+(1<<6));
P1M0 |=1<<3;
P1M1 &=~(1<<3);
P2M0 |=(1<<5)+(1<<4)+(1<<3)+(1<<6)+(1<<7);
P2M1 &=~((1<<5)+(1<<4)+(1<<3)+(1<<6)+(1<<7));
P3M0 &=~((1<<4)+(1<<5)+(1<<2)+(1<<3)); //输入
P3M1 |=(1<<4)+(1<<5)+(1<<2)+(1<<3); //输入
P4M0 |=(1<<6)+(1<<5)+(1<<1)+(1<<3)+(1<<4)+(1<<2);
P4M1 &=~((1<<6)+(1<<5)+(1<<1)+(1<<3)+(1<<4)+(1<<2));
P5M0 |=(1<<2)+(1<<3);
P5M1 &=~((1<<2)+(1<<3));
P7M0 |=(1<<7)+(1<<6)+(1<<3);
P7M1 &=~((1<<7)+(1<<6)+(1<<3));
/**************************************************/
out_1=0;
while(1)
{
xianshi();
anjian();
yanshi();
chufa();
}
}
/**************************************************/
void yanshi()
{
unsigned int y;
unsigned char z;
for(y=1000;y>0;y--)
for(z=200;z>0;z--);
}
/**************************************************/
void xianshi()
{
xianshi_shi =xianshi_a1/10;
xianshi_ge =xianshi_a1%10;
xianshi_shi =led[xianshi_shi]; //取回十位的模
xianshi_ge =led[xianshi_ge]; //取回个位的模
led_1_3=1;
led_1_5=1;
if(xianshi_shi&(1<<0)){led_1_a=0;}else{led_1_a=1;}
if(xianshi_shi&(1<<1)){led_1_b=0;}else{led_1_b=1;}
if(xianshi_shi&(1<<2)){led_1_c=0;}else{led_1_c=1;}
if(xianshi_shi&(1<<3)){led_1_d=0;}else{led_1_d=1;}
if(xianshi_shi&(1<<4)){led_1_e=0;}else{led_1_e=1;}
if(xianshi_shi&(1<<5)){led_1_f=0;}else{led_1_f=1;}
if(xianshi_shi&(1<<6)){led_1_g=0;}else{led_1_g=1;}
if(xianshi_shi&(1<<7)){led_1_dp=0;}else{led_1_dp=1;}
led_2_3=1;
led_2_5=1;
if(xianshi_ge&(1<<0)){led_2_a=0;}else{led_2_a=1;}
if(xianshi_ge&(1<<1)){led_2_b=0;}else{led_2_b=1;}
if(xianshi_ge&(1<<2)){led_2_c=0;}else{led_2_c=1;}
if(xianshi_ge&(1<<3)){led_2_d=0;}else{led_2_d=1;}
if(xianshi_ge&(1<<4)){led_2_e=0;}else{led_2_e=1;}
if(xianshi_ge&(1<<5)){led_2_f=0;}else{led_2_f=1;}
if(xianshi_ge&(1<<6)){led_2_g=0;}else{led_2_g=1;}
if(xianshi_ge&(1<<7)){led_2_dp=0;}else{led_2_dp=1;}
}
/**************************************************/
void anjian()
{
if(key_1==0) //加1
{
xianshi_a1++;if(xianshi_a1>99){xianshi_a1=0;}
while(key_1==0);
}
if(key_2==0){xianshi_a1--; if(xianshi_a1>99){xianshi_a1=99;}} //减1
if(key_4==0) //加10
{
xianshi_a1 +=10;if(xianshi_a1>99){xianshi_a1=0;}
while(key_1==0);
}
}
/**************************************************/
void chufa()
{
unsigned char a1;
unsigned int b1;
unsigned char i, j;
if(key_3==0)
{
for(a1=100;a1>0;a1--)
if(key_3==0)
{
while(key_3==0); //等待松手
out_1=1;
for(b1=xianshi_a1;b1>0;b1--)
{
for(i=65;i>0;i--)
for(j=15;j>0;j--);
}
out_1=0;
}
}
}
/**************************************************/
/**************************************************/
/**************************************************/
|