**蓝桥杯stc15f2k60s2芯片编程(数码管)**
**
**
**
**
#include
unsigned char shuzu[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF};
unsigned char i,j;
void main()
{
P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
while(1){
i++;
if(i==8)i=0;
P0=0XFF;
P2=(P2&0X1F)|0XE0;
P2&=0X1F;
// P0=1<
P2=(P2&0X1F)|0XC0;
P0=1<<i;
P2=P2&0X1F;
// P0=shuzu[i];
P2=(P2&0X1F)|0XE0;
P0=shuzu[i];
P2&=0X1F;
j=1000;while(j--);
}
}
**
**
**
**
#include
#include
void shumaguan();
void Timer0Init();
void Delay100us();
unsigned char abile[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF};
unsigned char saomiao[]={0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF};
void main()
{
while(1){
P2=0XC0;P0=0X01;P2=0XFF;P0=0XFF;
Timer0Init();
shumaguan();
Delay100us();
}
}
void shumaguan()
{
saomiao[0]=abile[0];
saomiao[1]=abile[5];
saomiao[2]=abile[2];
saomiao[3]=abile[1];
saomiao[4]=abile[1];
saomiao[5]=abile[3];
saomiao[6]=abile[1];
saomiao[7]=abile[4];
}
void weixuan() interrupt 1
{
unsigned char i;
P2=P2&0x1f|0xe0;
P0=0xff;
P2=0x1f;
P2=P2&0x1f|0xc0;
P0=1<<i;
P2=0x1f;
P2=P2&0x1f|0xe0;
P0=saomiao[i];
P2=0x1f;
i++;
if(i==8) i=0;
}
void Timer0Init() //[email protected]
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xAE;
TH0 = 0xFB;
TF0 = 0;
TR0 = 1;
EA=1;
ET0=1;
}
void Delay100us() //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 2;
j = 15;
do
{
while (--j);
} while (--i);
}
**
**
#include
#include
unsigned char shuzu[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF};
unsigned char i,j,miao;
sbit K1=P3^0;
void anjian();
void Delay10ms(); //@11.0592MHz
void main()
{
P2=0XC0;P0=0X01;P2=0XFF;P0=0XFF; //????????,???
while(1){
anjian();
P2=(P2&0X1F)|0XC0; //´ò¿ªÎ»Ñ¡
P0=0x80; //0000 0001
P2&=0X1F;
P2=(P2&0X1F)|0XE0; //´ò¿ª¶ÎÑ¡
P0=shuzu[miao%10];
P2&=0X1F;
j=1000;while(j--);
P2=(P2&0X1F)|0Xc0; //´ò¿ªÎ»Ñ¡
P0=0x40; //0000 0001
P2&=0X1F;
P2=(P2&0X1F)|0XE0;
P0=shuzu[miao/10];
P2&=0X1F;
j=1000;while(j--);
}
}
void anjian()
{
if(K1==0)
{
Delay10ms();
if(K1==0)
{
miao++;
}
while(!K1);
}
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
**
**
#include
#include
unsigned char shuzu[]={0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90,0XBF,0XFF};
unsigned char i,j,miao;
sbit K1=P3^0;
void anjian();
void Delay10ms(); //@11.0592MHz
void main()
{
P2=0XC0;P0=0X01;P2=0XFF;P0=0XFF; //????????,???
while(1){
anjian();
P2=(P2&0X1F)|0XC0; //´ò¿ªÎ»Ñ¡
P0=0x80; //0000 0001
P2&=0X1F;
P2=(P2&0X1F)|0XE0; //´ò¿ª¶ÎÑ¡
P0=shuzu[miao%10];
P2&=0X1F;
j=1000;while(j--);
P2=(P2&0X1F)|0Xc0; //´ò¿ªÎ»Ñ¡
P0=0x40; //0000 0001
P2&=0X1F;
P2=(P2&0X1F)|0XE0;
P0=shuzu[miao/10];
P2&=0X1F;
j=1000;while(j--);
}
}
void anjian()
{
if(K1==0)
{
Delay10ms();
if(K1==0)
{
miao++;
}
while(!K1);
}
}
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}