[Hardware] Software Engineers make the LED flashes up

Many people especially those just getting started with hardware engineers more tangled choose what mcu chip, for example, be a flashing LED, with at89c51 or pic16f887, and some even thought to use stm32 or esp8266 and so on. In fact there is no need for that, or if only interest is to learn knowledge, which mcu play are the same, and you will learn java and c #, as are the language, you can not say more cattle x java than c #, java can do a, c # is almost able to do, so that hardware is unnecessary tangled, if this tangled, but delays. But if it is to do the project or product, it is not the same thing, although the same chip may be able to achieve a certain function, but it comes to cost, performance, packaging, among other factors, we need to look good discretion, which is like c # can learn a play, but the real time to the project, the project was to look at the actual requirements, and some java project had previously been developed, but also a linux server, and the boss is not willing to pay more than, what to open source, java that still use it.
Long-winded a few words, that is entered, the last time we did a first hardware program, to light a led lighting led essence is to a pin microcontroller (strictly speaking, is a bit of a port )Position. at89c51 has P0, P1, P2, P3 four ports, each port has eight pins, other types of microcontrollers almost.
But the last years led program has been lit, that if it flashes, is turn on and off, like a lantern like that. Is actually quite simple, say the last time, is set to 0 on, and if that set it? Yes, that exterminate. It's that simple.
But there is a problem, because the single-chip program runs very fast, runtime instructions are microsecond, one second equals 1000 milliseconds, 1 millisecond equal to 1000 microseconds, you can imagine if a turn on and off two sequential instructions are executed What would be the result? We do not feel flicker, feel that has been lit. So, ah we have to find ways to separate the two instructions for some time, is on for a while, such as a light for two seconds, then let off a second or two, so that our eyes can clearly feel the light and went out. It says so, you need to add a delay procedure is to our software program inside of sleep, but in this hardware can not sleep, we have to write myself a delay program.
Well, according to the above ideas, we give the complete procedure is as follows, I do not understand there are some comments have been added:

#include <reg51.h>
#include <stdio.h>
sbit P10 = P1 ^ 0; // defined P10

void main (void)

the while (. 1) 
{
unsigned int I; 
for (I = 0; I <30000; I ++) 
P10 = 0; // Note: is the low lighting LED
for (I = 0; I <30000; I ++) 
P10 =. 1;
}
}

Guess you like

Origin blog.csdn.net/wwwmagic/article/details/91792569