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,