(C51 Learning 1) How to light up the LED lamp

Publisher:CreativeDreamerLatest update time:2019-02-15 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Find the minimum system schematic diagram of C51


The development board you bought online must have a CD with a schematic diagram. First find the minimum system schematic diagram. This schematic diagram shows what the CPU I/O interface is connected to. And the I/O ports are numbered.



2. Find the LED module schematic


As can be seen from the figure below, each of the 8 interfaces of the P1 group I/O port is connected to an LED light, and when a port on P1 is at a low level, the LED will light up.



3. Programming


#include

sbit LED0=P1^0; // Use your own logo LED0 to represent I/O port P1^0

sbit LED1=P1^1;

 

void main()

{

LED0 = 0; //P1^0 port gives low level

LED1 = 0; //P1^1 port gives low level

while(1); //Do not let the program end to prevent it from running away or freezing.

}




4 Flowing Water Lights


#include

sbit LED0=P1^0;

sbit LED1=P1^1;

sbit LED2=P1^2;

sbit LED3=P1^3;

sbit LED4=P1^4;

sbit LED5=P1^5;

sbit LED6=P1^6;

sbit LED7=P1^7;

 

void delay(unsigned int i) //ÑÓ³Ùº¯Êý

{

while(--i);

}

 

void main()

{

 

while(1)

{

LED0=0;

delay(2000);

LED0=1;

delay(2000);


LED1=0;

delay(2000);

LED1=1;

delay(1000);


LED2=0;

delay(2000);

LED2=1;

delay(2000);


LED3=0;

delay(2000);

LED3=1;

delay(2000);


LED4=0;

delay(2000);

LED4=1;

delay(2000);


LED5=0;

delay(2000);

LED5=1;

delay(2000);


LED6=0;

delay(2000);

LED6=1;

delay(2000);


LED7=0;

delay(2000);

LED7=1;

delay(2000);

}

}



Keywords:C51 Reference address:(C51 Learning 1) How to light up the LED lamp

Previous article:(C51 Learning 2) Light up the digital tube
Next article:[MCU Notes] Solution to the problem that the Keil C51 compilation environment cannot jump to a function

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号