led

科普:LED的开启电压是2V,反向击穿电压是5v,工作电压约为3v,通常正向电流为10~20mA,当电流在3~10mA时,led亮度与电压成反比。电流超过30mA的时候,led会烧毁,一般串联300欧姆左右的电阻。

windows下仿真程序(proteus+keilc)

点亮一个灯

proteus的仿真图:


led_第1张图片
点亮一个灯

keilc的代码如下:

#include 
void main()
{
    P1 = 0;
    while(1);
}

led闪烁

led_第2张图片
led闪烁
#include 

#define uint unsigned int
#define uchar unsigned char

sbit led P1^0

void delay(uint timer)
{
    uchar j = 124;
    while(timer--)
    {
        while(j--);
    }
}

void main()
{
    while(1)
    {
        led = ~led;
        delay(100);
    }
}

心形流水灯

led_第3张图片
心形流水灯
//version 1
#include 

#define uint unsigned int
#define uchar unsigned char

uchar code led[] = {
                    0xfe, 0xfd,0xfb,0xf7,
                    0xef, 0xdf,0xbf,0x7f};

void delay(uint timer)
{
    uchar j = 124;
    while(timer--)
    {
        while(j--);
    }
}



void main()
{
    uchar i=0 ;
    while(1)
    {
    P1 = led[i];
    i = (i+1)%8;
    delay(50);
    }   
}
//version 2
#include 

#define uint unsigned int
#define uchar unsigned char

uchar code led[] = {
                    0xfe, 0xfd,0xfb,0xf7,
                    0xef, 0xdf,0xbf,0x7f};

void delay(uint timer)
{
    uchar j = 124;
    while(timer--)
    {
        while(j--);
    }
}



void main()
{
    uchar i=0 ;
    while(1)
    {
        for(i = 0; i<8;i++)
        {
            P1 = led[i];
            delay(70);
        }
    }   
}
    
//version 3
#include 

#define uint unsigned int
#define uchar unsigned char

void delay(uint timer)
{
    uchar j = 124;
    while(timer--)
    {
        while(j--);
    }
}

void main()
{
    uchar i;
    while(1)
    {
        for(i = 0;i<8;i++)
        {
            P1 = ~(1<
led_第4张图片

你可能感兴趣的:(led)