Solo disponible en BuenasTareas
  • Páginas : 44 (10873 palabras )
  • Descarga(s) : 0
  • Publicado : 27 de noviembre de 2011
Leer documento completo
Vista previa del texto

Microcontroller Basics Course
part 1: the TASM assembler
By B. Kainka

This course is for everyone who always wanted to how microcontrollers work and how to use them, but was always afraid to ask. It is intended to explain the fundamentals, starting from scratch. The Elektor Electronics 89S8252 Flash Microcontroller Board (presented in last month’s issue) is used as thehardware platform.
Nowadays, we all take working with computers for granted, and not only that, we often work with quite powerful equipment. The heart of a computer is its processor, such as a Pentium III. Relatively speaking, a microcontroller is both much less and much more than the processor of a typical PC. It is less because it processes smaller programs, uses less memory and is usually muchslower. However, it is also more because it already has many elements on a single chip that are spread out over the complete motherboard of a PC, namely working memory, timers, interfaces and port connections. What makes microcontrollers attractive is that is in the limiting case, a complex problem can be solved using only a single IC. Using programming alone, anyone can produce a special IC thatdoes exactly what he or she wants — and at a relatively low cost. A microcontroller is thus some-

Figure 1. The 89S8252 Flash Board, which is used in this course, is a generalpurpose microcontroller system.


Elektor Electronics


thing like a logical circuit with many possible inputs and outputs. What this circuit does is determined by a program. Perhapsyou want to build a digital counter, or would you rather have a stopwatch? Do you want to create a special logical gate, or perhaps a universal clock generator? Do you need to decode a complicated digital signal or control a digital circuit? In all of these cases, a microcontroller can help you. There are many examples of problems whose solutions previously required an enormous board full of ICsand now can be solved quite elegantly by a single IC, namely a microcontroller. Consequently, some knowledge of programming is worth having. There are many different approaches that can be taken to achieve this goal. The hardware basis for this course is the 89S8252 Flash Microcontroller Board described in last month’s issue of Elektor Electronics (see Figure 1). As already announced, forprogramming software we will use the following three programming languages: assembler, Basic and C. Our first experiments will be carried out in assembler. Why should we use assembler in particular? Isn’t it rather difficult, perhaps too difficult for beginners? The answer is no, since the initial examples will be very small and easy to understand. The advantage or using assembler is that it allows us towork very close to the hardware, so we can see exactly what is happening. High-level languages (such as BASIC), by contrast, hide much of what actually takes place. In our first experiment, all we

Figure 3. The first sample program in TASMedit.exe.

want to do is to switch the levels on one of the microcontroller’s output ports. After all, operating a switch is the first step in automation.Also, the results can be observed using a voltmeter connected to lead P1.4 via connector K4 (see Figure 2). In order to change the level on this lead, we will use a small assembler program. Put briefly, assembler is a notation used to write instructions for a processor or microcontroller. Every microcontroller has an instruction set, which ultimately consists of numerical values and associatedfunctions. The following series of six numbers represents a small, complete program for an 89S8252 microcontroller — in fact, it is what is called a machine-language program: 116,15,245,144,128,254 It is generally customary to write computer programs using hexadecimal numbers instead of decimal numbers, since the former are easier to read. In hexadecimal notation, the above program looks like this:...