C51 MCU LED Example Program Set

Publisher:京玩儿Latest update time:2017-02-04 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1、

The program implements the function: Let 8 LEDs light up in a row 1—》...——》8 1《——...《——8 The arrows represent the direction of the LED flow, first from 1-8 and then from 8 to 1. The program has been tested and runs normally // If you use this code to test, pay attention to which port your LED is connected to the microcontroller. This code uses port P2

#include

#define uint unsigned int

#define uchar unsigned char

fly a,b;

uchar code led_array[]={

0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f

}; //LED display code array, from 0xfe to 0x7f, from the first LED tube to the eighth LED tube, one at a time, the format is 0fff ffff\f0ff ffff\ff0f ffff...ffff fff0\ LED starts to light up from 1, and when it reaches the eighth LED, it starts to light up in the reverse direction ffff fff0\ffff ff0f\ffff f0ff...0fff ffff (Note: 0 represents light; 1 represents no light) I don't know if you understand what I mean....

void delay(uint x)

{

uint z,y;

for(z=x;z>0;z--)

for(y=110;y>0;y--);

}//Delay function

 

void sumup_ini()

{

P2=0xfe;//

}//Total initialization function, I like to write programs in modular form, but this module is too small... cough cough cough!!!

void main()

{

 

sumup_ini(); //Call the total initialization function

while(1) This goes without saying!

{

                

for(a=0;a<8;a++)

    {

P2=led_array[a];

if(P2!=led_array[7]) //Here we use if to determine whether the last LED is on. If it is the last one, the delay function will not be executed. Otherwise, the following delay function will be executed every time the LED moves one position.

 

 

/*(Here is the explanation of why we need to judge whether the last LED is lit. If the delay is executed after the last LED is lit, it will be the same as the initial value of the reverse flow function. led_array[7] is the first LED that is lit in the reverse flow and the last LED that is lit in the reverse flow. So if we don’t use if to judge, it is equivalent to delaying the time of other LEDs in led_array[7] by 2 times... In order to make the time of each LED being lit equal, I use if to judge the following)*/

delay(500);

 

 

    } //LED forward flow lights up

for(b=7;b>0;b--)

                    {

                        P2=led_array[b];

                        delay(500);

                    } //LED direction flow light

 

}

}


Keywords:C51 Reference address:C51 MCU LED Example Program Set

Previous article:4x4 matrix keyboard scanner
Next article:MCU 4*4 matrix keyboard

Recommended ReadingLatest update time:2024-11-16 14:34

C51 serial port interrupt processing subroutine
This serial port processing program is written based on the following protocol: Frame content FRAME = frame header FA + frame length len (excluding frame header and frame trailer) + data stream data + frame trailer FB. The entire data stream is processed in the serial port interrupt subroutine, rather than processing
[Microcontroller]
74ls164 made of C51 program
c51 74hc164--165--595c51 The 51 single-chip microcomputer drives the 74ls164 marquee. The advantage is that only two ports are used to achieve it. The circuit is shown in the figure below: #include reg51.h #include intrins.h #define uint unsigned int #define uchar unsigned char sbit dat=P2^
[Microcontroller]
74ls164 made of C51 program
51 single chip microcomputer C51 program
C51 Program Before learning C51 programming, you need to have a certain understanding and learning of C language; here we only introduce the differences from C language; The specific differences are as follows: 1. Several unique data types for MSC-51 microcontrollers have been added to C51 a. sfr and sfr16: used t
[Microcontroller]
51 single chip microcomputer C51 program
C51 Compiler - Advanced Programming Skills (5) - Data Storage Format
Data Storage Formats This section describes the storage formats of the available data types. The Cx51 provides several data storage formats as follows: Data Type         Bits   Bytes Value Range bit                  1       —      0 to 1 signed char          8       1       -128 to +127 unsigned char          
[Microcontroller]
Detailed explanation of data idata xdata code in keil c51
51 single-chip microcomputer adopts Harvard structure. The memory space addressing has overlap. Different variables can be defined on different buses (referred to as bus domains in this article, or domains for short). Several domain modifiers such as data, idata, xdata, and code are defined in keilc51. These modifiers
[Microcontroller]
Detailed explanation of data idata xdata code in keil c51
KeilC51 data type conversion
1. /*06-03-31 found during debugging in KEIL*/    Example 1:  ......  unsigned long int b;  unsigned int x;  x=968;  b=100*x;  b=96800-65536;    Example 2:  ......  unsigned long int b,x;  x=968;  b=100*x;  b=96800;    Example 3:  ......  unsigned long int b;  unsigned int x;  x= 968;  b=(unsigned lo
[Microcontroller]
How to use a microcontroller to drive a standard PC keyboard? C51 program detailed description
  Function: connect the PC keyboard (P/S2 interface) to the 8-bit microcontroller   Principle: The keyboard clock is connected to port p3.2, which is the external interrupt int0 of 8051, and the keyboard data is connected to p1.0   Each time a key is pressed, the keyboard will send a pulse to the microcontroller,
[Microcontroller]
How to use a microcontroller to drive a standard PC keyboard? C51 program detailed description
Write a simple C51 program
Introduction: For embedded systems, if RTOS is not running, the main function (main()) in program development needs to use some mechanism to make it run happily forever. It has no end. If you want to exit from the main function, what you do depends on the C language compiler used. 01 Question raised Today I saw an i
[Microcontroller]
Write a simple C51 program
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号