Welcome to hificat.com ---- HANGZHOU KinCony ELECTRONICS CO.,LTD.
About Us Contact Us          Our Patents Our Articles        Forum      SiteMap    Chinese Version

Chapter 1. Overview Chapter 2. Emulation Guide Chapter 3. Build Your First Project Chapter 4. In System Programming
Chapter 5. USB Interface Installation Chapter 6. LED Display Application Chapter 9. FAQ Chapter 10. System Configuration and Service
 
Chapter 7. Basic Experiments
7.1. Experiment with LED 7.2. Experiment with Flowing LEDs 7.3. Experiment with Keys 7.4. Experiment with Beeper
7.5. Experiment with Relay 7.6. Experiment with LED Display 7.7. Experiment with Serial Port  
 
8.1. Experiment with Matrix Key 8.2. Experiment with Stepping Motor 8.3. Experiment with 1-Wire Digital Thermometer DS18B20
8.4. Experiment with 24C01 EEPROM 8.5. Experiment with 93C46 Serial EEPROM 8.6. Experiment with DS1302 Real-time Clock
8.7. Experiment with 8-bit Serial AD Converter ADC0832 8.8. Experiment with 1602 Character LCD Module 8.9. Experiment with 12864 Graphic LCD
8.10. Experiment with Infra-red Remote Controller 8.11. Experiment with Wireless Encoding Module Chapter 11. User Feedback

Chapter 7. Basic Experiments

7.1. Experiment with Flashing LED

LED, short for light emitting diode, is commonly seen in daily life. We start up this chapter with the simplest experiment on LED flashing.

The Fundamentals of LED

There are many types of LED. Φ3mm normal luminance LEDs are shown in the below picture.

See LED’s symbol. When certain voltage is given between A (anode) and K (cathode), LED will light up. Different LED works on different voltage, ranging from 1.6V to 2.8V. Forward current ranges from 4 to 10mA.

Circuit Design

With LED’s voltage and current parameters, it’s easy to calculate a suitable resistor used to limit the current. For example, if system power is 5V, resistor used is 1kΩ, and LED V(on) is 2.0V, then the current on LED is ( 5V - 2V ) / 1000 Ω = 3mA. To increase the luminance, increase the current to 10mA is a good practice. Because ( 5V - 2V ) / 1000Ω = 3mA, we use 330Ω.

See below schematic diagram. The LED’s anode is connected via a resistor to VCC, and its cathode is connected to MCU’s I/O pin. When MCU’s I/O pin becomes low level, the LED will light up. In this experiment, setting P0.0 to be low will light the LED D up.

Software Design

Likewise, to turn off the LED, what we need to do is just to set P0.0 to high level. It’s also easy to make the LED flashing (lighting on and off in turn). Insert a delay around 300ms between LED on and off will make the LED flashing.

01 #include <reg51.h>

02

03 sbit LED = P0^0;

04

05 void Delay()

06 {

07   unsigned char i,j;

08     for(i=0;i<255;i++)

09         for(j=0;j<255;j++);

10 }

11

12 void main()

13 {

14   while(1)

15   {

16      LED = 0;

17      Delay();

18      LED = 1;

19      Delay();

20    }  

21  }

Program Notes

Line 1: include the 8051 register definition header file

Line 3: bit define the I/O pin connecting with LED

Line 5-10 delay function, the delay time depends on the MCU clock

Line 7: define 2 unsigned char variable i and j

Line 8-9: delay certain time by the for loop self-increment

Line 12-21: main function

Line 14: the while loop

Line 16: light the LED up

Line 17: invoke the delay function

Line 18: light the LED off

Line 19: invoke the delay function



COPYRIGHT2003--2008 HANGZHOU KinCony ELECTRONICS CO.,LTD. All Rights Reserved

Add:Rm 11-3-702, Pujing Jiayuan, Gongshu District, Hangzhou, Zhejiang, China.
Tel:+86-0571-85956028,Fax:+86-0571-88230070 E-mail: hificat@163.com  ICQ:164806453  Webmaster:Hificat