Professional Documents
Culture Documents
1 PDF
1 PDF
Microcontroller
BootCamp (1)
Arduino and Bascom
By Burkhard Kainka
(Germany)
You might ask why you should use a microcon- For comparison: the NE555 timer IC
troller when it’s possible to do so much with First of all there’s the output. When you look
ordinary analog electronics. At first glance, this at the internal block diagram of the NE555 on
looks like a good question. New microcontrollers the data sheet (Figure 1), you can see that it
with more features, higher performance, higher has a push-pull output stage that can actively
clock rates and even more memory are appear- switch high and low. Microcontrollers have exactly
ing all the time, but the first demo program for the same kind of outputs. They are called ports,
every one of them invariably makes a LED blink. where the name “port” can stand for a set of
This leads to the justified criticism that you could outputs or for pins that can be configured either
get the same result by simply taking an NE555 as inputs or as outputs. The circuitry connected
timer IC and adding a couple of resistors and a to the output for a LED blinker application is also
capacitor. That’s absolutely right, and the com- the same: a LED with a series resistor, connected
parison is better than you might think because either to ground (GND) or to the supply voltage
a lot of the elements of an NE555 timer IC can (Vcc). The NE555 also has a second output driven
also be found in a microcontroller. by an open-collector transistor, which can only
switch something to ground. Many microcontrol- the other hand, an analog electronics solution is
lers can also emulate this function. Actually the a better and more economical choice for quite a
only difference is that microcontrollers usually few simple tasks.
have several outputs but the NE555 has only one,
since the push-pull output and the open-collector Anyone with a bit of experience in microcon-
output are not independent. troller development can also mention another
advantage of microcontrollers: once the circuit
Next we have the inputs of the NE555, which is complete, you don’t need to touch the solder-
consist two inputs to a comparator that controls ing iron again. From that point on, all you do is
an internal flip-flop. A typical application for this write and test code. Changes to device functions
is an astable multivibrator, which hobbyists often can be implemented and tested very quickly.
call a blinker circuit. You can put all this together Microcontrollers are general-purpose and versatile
in almost no time. You just plug the numbers computation workhorses. The learning curve is
into a couple of formulas to determine the right worth the effort, since you ultimately save time.
component values, and then the NE555 does Your first exposure to a microcontroller data
exactly what you want. Determining the compo- sheet may put you off, since it can easily amount
nent values for an NE555 circuit and program- to 300 pages or more. Fortunately, there are
ming a microcontroller are actually comparable
tasks. There’s another thing that’s very similar:
both devices (NE555 and microcontroller) have
VCC
a Reset input that you can use to set everything
RESET
back to the starting point. And with both devices 4 8
VCC
the Reset input is usually high in the quiescent
state and must be actively pulled to ground.
5k
DIS-
THRESHOLD 6 INHIBIT/ 7
Figure 2 shows a simple square-wave genera- R
RESET CHARGE
CONTROL 5
tor in the form typically used as an LED blinker. VOLTAGE
DIS
controller are summarized in Table 1. You could
3
OUT
formulate the result of a fair comparison as fol- 9V 6 NE555
THR
lows: The microcontroller has a bit more of 2 TR
1k
CV GND
everything and is therefore generally the better
5 1
choice for complex tasks. For example, a single LED
1k
4 11
D2 D5
on a display, and much more. However, perhaps 5
D3 D4
6
for them will be a frequent topic in this series on doesn’t work in practice, and likewise a micro-
microcontroller programming. controller with nothing in its program memory
cannot program itself. However, this is possible if
You can type in the program in Listing 1 yourself a boot loader is already present in memory, and
or download it from the Elektor page. The file the Arduino comes with a built-in boot loader.
UNO_LED1.bas is located in the zip folder [3]. The development environment on the PC also has
Compiling the program is very easy: simply click to be able to download program code using the
Program/Compile, click the corresponding icon Arduino boot loader. Fortunately, Bascom devel-
on the toolbar (a black IC), or press the F7 key. oper Mark Alberts already guessed that some-
If there is any sort of error in the source text, one would want to program an Arduino board in
an error message will be displayed. If there are Bascom at some point in time, so this capabil-
no problems, a pop-up window shows what per- ity is already incorporated. After you configure
centage of the memory is occupied. In this case the right settings, everything is quite easy. Here
it is less than 1%, which is rounded down to 0%. we describe how this works with the demo ver-
What matters is the resulting hex file UNO_LED1. sion, since there is a small difference with the
hex or the binary file UNO_LED1.bin, which are full version.
two different file formats with the same con-
tent. They contain the executable code for the
microcontroller. Now you have to load this code
into the microcontroller’s flash memory. There
are many ways to do this, and for now we only
describe the simplest way. Other options will be
described in subsequent instalments.