51单片机linux环境LED数码管开关循环判断演示

临文乍了了,彻卷兀若无。这篇文章主要讲述51单片机linux环境LED数码管开关循环判断演示相关的知识,希望能为你提供帮助。

【51单片机linux环境LED数码管开关循环判断演示】示例程序如下,有bug,能运行但效果可提升:

51单片机linux环境LED数码管开关循环判断演示

文章图片



#include < 8052.h>

#define LSA P1_5
#define LSB P1_6
#define LSC P1_7

char SEG[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

void init0(void)
{
LSA = 1;
LSB = 0;
LSC = 0;
}
void init1(void)
{
LSA = 1;
LSB = 0;
LSC = 0;
}
void init2(void)
{
LSA = 0;
LSB = 1;
LSC = 0;
}
void init3(void)
{
LSA = 1;
LSB = 1;
LSC = 0;
}
void init4(void)
{
LSA = 0;
LSB = 0;
LSC = 1;
}
void ledsplus(unsigned char leds,unsigned int delay)
{
P0=leds;
while(delay--);
delay=10000;
}
void seg1(unsigned char leds,unsigned int delay)
{
P0=SEG[leds];
//delay=50000;
while(delay--);
}
intmain(void)
{
init1();
unsigned char leds=0xff;
unsigned char cnt=0x00;
unsigned int delay=10000;
while(1)
{
if(P3_2==0)
{
for(leds=0xff; leds> 0x00; leds--)
{
ledsplus(leds,delay);
if(P3_4==0)
{
break;
}
}
}
if(P3_3==0)
{
for(leds=0x00; leds< 11; leds++)
{
seg1(leds,10000*cnt);
}
}
if(P3_4==0)
{
cnt++;
if(cnt> 7)
{
cnt=0x00;
}
}

P0=0xff;
delay=10000;
}
}




    推荐阅读