#include <STC15F2K60S2.H>
sbit HC138_A=P2^5;
sbit HC138_B=P2^6;
sbit HC138_C=P2^7;
sbit buzz_1= P0^6;
sbit jdq_2= P0^4;
unsigned char code SMG_duanma[18]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,0xbf,0x7f};//有第零个位置
unsigned char yu=1;
void DelaySMG(unsigned int num)
{
unsigned int i;
while(num--)
for(i=0; i<628; i++);
}
void Init_HC138(unsigned char n)
{
switch (n)
{
case 4:
HC138_A=0;
HC138_B=0;
HC138_C=1;
break;
case 5:
HC138_A=1;
HC138_B=0;
HC138_C=1;
break;
case 6:
HC138_A=0;
HC138_B=1;
HC138_C=1;
break;
case 7:
HC138_A=1;
HC138_B=1;
HC138_C=1;
break;
}
}
void led_disp()
{
Init_HC138(4);
P0=0xfe;
}
void close_buzz()
{
Init_HC138(5);
buzz_1=0;//0是关闭
jdq_2=0;//0是关闭
}
void smg_show_bit(unsigned char dat,unsigned char pos)
{
Init_HC138(6);//数码管的位置
P0=0x01<<pos;
Init_HC138(7);//数码管的内容
P0=dat;
}
void smg_dynamic()
{
// unsigned char i;
// for(i=0;i<8;i++)
// {
//
// smg_show_bit(SMG_duanma[i],i);
// Delay(1) ;
//
// }
//
smg_show_bit(SMG_duanma[2],0);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[0],1);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[2],2);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[2],3);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[16],4);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[16],5);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[yu/10],6);
DelaySMG(1) ;
smg_show_bit(SMG_duanma[yu%10],7);
DelaySMG(1) ;
}
void delay(unsigned char t)//注意这有两个延时函数,一个延时数码管,一个整体延时
{
while(t--)
{
smg_dynamic();
}
}
void main()
{
close_buzz();
while(1)
{
smg_dynamic();
yu++;
if(yu>12)
{
yu=1;
}
delay(80);
}
}