1.2. First experiment--light LED

Source: Internet
Author: User

1.2. First experiment--light LED


(1) Bits, bytes, io ports, io port


(2) binary and hexadecimal conversions
A hexadecimal bit equals four bits, for example, 0xFF corresponds to a binary is 1111 1111

Experimental Purpose: Eight LED lights are lit

Analysis of the experimental process:

(1) Eight LEDs are controlled by eight-bit bits, bits is 1 o'clock LED light, bits is 0 o'clock LED lights out
(2) Eight LEDs are lit separately, with no effect on each other
(3) Because 1 control LED is bright, so want eight LED lights full light, the corresponding binary number is 1111 1111, converted to 16 is 0xFF
(4) If you want to let eight led interval light, the corresponding binary number is 1010 1010, converted to 16 binary is 0xAA
(5) An IO port control eight bits, each one to control one led, in this microcontroller reference P0 port

Experimental phenomena:

When P0=0xff, eight led all bright, when p0=0x0, eight led all out, when P0=0XAA, eight led interval light off.

Experiment Code:

#include<reg51.h>void main(void)    {        //通过P0这个IO端口控制八颗LED灯        P0=0xff;//点亮八颗LED        P0=0x0f;//点亮四颗LED        P0=0xAA;//隔一颗亮一颗 二进制数为10101010    }

Experiment Summary:
(1) 1 corresponds to High level, the P0 port output high power, generate a voltage difference, so that led bright. The opposite 0 corresponds to the low level.
(2) binary and hexadecimal conversions need to be enhanced.

1.2. First experiment--light LED

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.