Home > other >  Single chip microcomputer
Single chip microcomputer

Time:11-03

How do you write MCU make LED lights flashing program

CodePudding user response:

Set a timer, and change the state of LED lights in interrupt handlers,

CodePudding user response:

If you hand in your homework, then according to the textbook, the two methods, one is to use a loop to delay, time to let the LED turn port, then back to a time delay; 2 is to use interrupts, first set the timer interrupt, time is a "light" "out" of the time, to the LED in the interrupt service port, in fact you can also define "bright" and "destroy" time,

If it is in the practical application as a working status lamp (commonly known as "breathing lamp"), that's a little bit clever, because the breath of the lamp flicker is said machine (program) on the right (or predicted) within the scope of operation, is to find an available source of timing cycle (no separate timers, save resources), hung on the interrupt, place a marker in the interrupt service (don't flip directly output), the main program of the query on the sign and detected after (a count to make longer) can be attached to flip port, if the program are the benefits of such mistakenly blocked interrupts, breathing light will stop flashing (by this time the main program is running), and if the main program into an infinite loop (break), breathing lamp will stop, so more can run calibration procedures of the state,

CodePudding user response:

CodePudding user response:

refer to the second floor SupermanTm response:
if you hand in your homework, then according to the textbook, the two methods, one is to use a loop to delay, time to let the LED turn port, then back to a time delay; 2 is to use interrupts, first set the timer interrupt, time is a "light" "out" of the time, to the LED in the interrupt service port, in fact you can also define "bright" and "destroy" time,

If it is in the practical application as a working status lamp (commonly known as "breathing lamp"), that's a little bit clever, because the breath of the lamp flicker is said machine (program) on the right (or predicted) within the scope of operation, is to find an available source of timing cycle (no separate timers, save resources), hung on the interrupt, place a marker in the interrupt service (don't flip directly output), the main program of the query on the sign and detected after (a count to make longer) can be attached to flip port, if the program are the benefits of such mistakenly blocked interrupts, breathing light will stop flashing (by this time the main program is running), and if the main program into an infinite loop (break), also will stop breathing lamp, so it could be more calibration program running state,

To study the

CodePudding user response:

Write a while () plus time delay or use the timer

CodePudding user response:


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
LED flashing simple test * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
The include & lt; Reg51. H>//this file defines the special function of 51 register
/* * * * * * * delay function * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//define a demonstration function, periodic time is about a ms,

Void delay (unsigned int I)
{
Unsigned char j;
For (I; I & gt; 0; I -)
For (j=100; J & gt; 0; J -);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
The main ()
{
While (1)
{
The P2=0 x00;//set point P2 mouth for the low level of led lights
delay(1000);//call delay routine led out continuously, keeping
The P2=0 XFF;//set the P2 mouth for high level led light bright
delay(1000);//call delay routine led light continuously, keeping
//repeat the above statement, lit led lights, light condition, go out, to keep out//out state circulation process of the four,
}

CodePudding user response:

This is the process of the 51, other single-chip microcomputer logic is similar,

CodePudding user response:

Studied the

CodePudding user response:

Online routines you can see a lot

CodePudding user response:

Praise a, very practical
  • Related