Reprogram the chips. Programming microcontrollers for beginners: easy and accessible

The topic of electronic design is becoming increasingly popular. We bring to your attention an article that will tell you about microcontrollers for beginners.

What microcontrollers are there?

First of all, it is necessary to outline the situation with microcontrollers. The fact is that they are produced not by one company, but by several, so there are quite a lot of different microcontrollers that have different parameters, different features when using and various possibilities. They differ in speed, additional interfaces and number of pins. The most popular throughout the former USSR are representatives of RIS and AVR. Programming AVR and PIC microcontrollers is not difficult, which has ensured their popularity.

How are microcontrollers programmed?

Programming of microcontrollers is carried out, as a rule, using special devices called programmers. Programmers can be either purchased or homemade. But when flashing a microcontroller using a homemade programmer, the chance that it will turn into a “brick” is quite high. There is another option that can be considered using the Arduino board as an example. The board runs on an Atmel microcontroller and is used for programming AVR microcontrollers. The board already has a pre-flashed bootloader and a USB port, which allow you to safely flash the microcontroller in use, without giving the user access to data that could damage this same microcontroller. Programming microcontrollers for beginners is not as difficult as it might seem, and with some skill and intelligence it will save you from the need to go for a new mechanism.

Hardware differences between different microcontrollers

When choosing microcontrollers, you should pay attention to some hardware differences, not even from different companies, but also in the same model range. First, you should pay attention to the possibility of rewriting information to the microcontroller. This function will allow you to experiment with one MK for a long time. Also pay attention to the number of pins with their purpose. Do not neglect the operating frequency of the crystal on which the circuit operates: the number of operations per second that the microcontroller can perform depends on it. When examining these characteristics, as well as the memory of the MK, at first it may seem that nothing meaningful can be done on microcontrollers, but this is a mistaken opinion. Remember that programming microcontrollers for beginners does not require the most the best technology at first, but you can take something more powerful in reserve.

Microcontroller programming languages

Two languages ​​are used for programming microcontrollers: C/C++ and assembler. Each of them has its own advantages and disadvantages. So, if we talk about assembler, then it makes it possible to do everything very subtly and efficiently, this is especially important when there is not enough random access memory or operational capacity (which, however, happens quite rarely). But studying it and writing programs on it requires quite a lot of effort, punctuality and time. Therefore, for development based on microcontrollers, the programming languages ​​C and C++ are often used. They are more understandable; in their appearance and structure they are close to human speech, although they do not represent it in a full understanding. They also have very well-developed functionality that can easily interact with the hardware, imagining that it is just a program element. For all their obvious advantages, more voluminous programs are created in C and C++ than in assembler.

Also, in some cases, when the operational space used is critical, these languages ​​can be combined. Almost all development environments for C and C++ have the ability to install assembler inserts into the program. Therefore, if a problem arises in a critical area, you can write an assembly insert and integrate it into the firmware for the microcontroller, and the firmware itself, or rather, most of it, can be written in C or C++. Programming microcontrollers in SI is easier, which is why many people choose these languages. But those who are not afraid of difficulties and want to understand the peculiarities of how the equipment works can try their hand at assembly language.

Parting words

If you want to experiment with great. We can only advise you to be patient and persistent, and then any goals set for the inventor will turn out to be feasible. Programming microcontrollers for beginners and for experienced people looks different: what is difficult for beginners, is routine for experienced people. The main thing is to remember that everything that does not contradict the laws of physics is feasible and solvable.



Soldering another chip onto another board or cutting a track on the board for the tenth time to make the next (but not the last) changes to a new device, you begin to think: “Shouldn’t I quit this tedious task?!” Your new device does not turn out the way you would like, but you are already tired of changing the circuit and redoing everything on the board.
Flipping through electronics magazines, you increasingly come across the words: processor, microcontroller, firmware, programming. But these words have no specific meaning for you. You've heard somewhere, and maybe even held in your hands something that you even think about with awe... microcontrollers! Something that reduces the size of devices, giving them capabilities unattainable to you... No, you, as an electronics engineer, understand the general ideas of how these devices work, but their practical use in your products is out of the question! You have already tried several times to master microcontrollers, you even purchased a couple of books from the “... for dummies” series and downloaded several popular tutorials from the Internet. Some time passed, and everything stopped at the most interesting point: the diagrams shown in the books were clear to you, but the methods for creating a program remained a mystery to you. Typing a few characters in English (or some other language) in the program specified in the book is not a problem for you. But the ESSENCE and METHODS of using these mysterious symbols, the sequence of which in the book was called a program, are not clear. You blamed yourself for being stupid and put the idea of ​​mastering microcontrollers aside. And why? You already do a great job: you have many, many chips on which you develop your devices... Devices on large boards that you debug and rework for a long, long time...
But meet the guy from next door: he writes programs, loads them into the microcontroller, and what you have to debug for months, he does in a few days. You panic, start looking for abandoned books, and remember everything you’ve read before... He can, but you can’t. You get to know this guy better, and under the guise of a side conversation, you begin to ask him about microcontrollers and their capabilities. And he calmly says that controllers are a hobby for him. You ask him to tell you about their device. His answers are simple and unpretentious.

Microcontrollers. What is a microcontroller?
A microcontroller is a small specialized computer, in Russian micro-computer. Moreover, this microcomputer is made in one chip, on one crystal. Hence the full name: “single-chip microcomputer.” Like a computer, a microcontroller is an electronic device whose operation is controlled by a program - a sequence of commands pre-loaded into memory. These commands are executed by the processor: a sort of “mega-brain” that includes an ALU - an arithmetic-logical unit. That is, the processor “can” perform mathematical operations and perform logical operations on data.

Processor capacity. Methods of presenting information.
Both the processor and memory are digital devices that “understand” signals of only two levels: there is voltage/current, and there is no voltage/current on the line. These two states are usually written as follows: logical one - “1”, and logical zero - “0”. Commands and data are a collection of ones and zeros. One line (called a discharge) in its two states can convey only two values. But as the number of digits increases, the number of values ​​also increases: two digits are already four, and eight digits are already 256 values. A digit is usually called a bit: one digit is one bit. And a set of eight bits is a byte: eight bits is one byte. But one byte has only 256 values. To transmit more information, several bytes are used sequentially located in memory. Two bytes already convey 65536 values. Three bytes - 16777216 values! And so on. The most common processors are those that can process eight bits in one operation, which is why such processors are called eight-bit.

Processor command system.
When a processor is developed, it is built into the ability to execute certain commands. The instructions that a given processor is able to execute are called the instruction set. What are these commands? The most common arithmetic and logical commands, as well as commands for working with ports - communication lines between the processor and the outside world. The processor, having read a value from a memory cell or the state of a port into its own memory - a register, can perform mathematical or logical operations on it. Mathematically, the operations are clear to us: addition, subtraction and others. Logical actions mean the following actions: comparison - more, less, equal; working on the bits of a memory cell or register: zeroing or setting it, as well as operations of shifting bits to the left or right.

Memory and its types.
Data can be read from memory. Memory is a place where a program and/or data can be stored for some time. They can be stored for a short time - until the power is turned off, or for a long time - regardless of the presence of supply voltage. The first type of memory is used to store intermediate data used during execution various operations. That’s why it’s called “random access memory”. The second type of memory is more often used to store programs. There are several types of long-term memory: once programmable memory, electrically erasable memory, and ultraviolet or x-ray erasable memory. The physical structure and operating principle of memory may be different, but the essence is the same: to store data. The concept of “cell” is used to describe a data storage. Therefore, the more cells, the more data can be stored. Each cell has an individual address. The processor accesses the value of a memory cell exactly by its address.

Ports. Port operating modes.
Data can also be received from external devices through communication lines - microcontroller pins. These communication lines are called ports, or scientifically: data input and output devices. The port pins can be inputs, using which the processor receives information from the outside from various sensors, or be outputs, sending signals to which can be controlled external devices. In modern microcontrollers, the pins of almost all ports are bidirectional, i.e., they can be both inputs and outputs. Universal ports need to be configured - set the operating mode to input or output. For this purpose, there is a special memory cell - a register for controlling port operating modes. For example, in order to make the required output (bit) of the port an input, 1 or 0 is written to the control register bit, depending on the microcontroller model.

Peripherals.
But the microcontroller contains not only a processor and memory. The main role is played by the so-called peripheral devices: timers, counters, analog comparators, digital-to-analog and analog-to-digital converters, serial communication devices (often called a serial port). Often the microcontroller also has a number of non-volatile memory cells (most often Flash), in which various data can be stored.

Microcontroller families.
The presence of all of the listed devices in the microcontroller is not necessary. Most often, a manufacturer produces several product models containing various peripheral devices. Microcontrollers with one type of processor (and a set of executable machine codes), but different peripheral devices, belong to the same family. That's what they say: microcontrollers of the ATtiny family.

Multifunctionality of microcontroller pins.
The question may arise: how do all these devices “communicate” with the outside world, if most chips in a DIP package have no more than 40 pins? To solve the problem of pin shortage, a method is used to combine the functions of several devices using a single pin. For example, the pins of one of the ports (8 bits - 8 pins) are also used to operate an analog-to-digital converter, and the pins of another port are used as inputs of analog comparators, a serial port, or for connecting other built-in nodes. To control the operating modes of the pins, a special port operating mode control register is used (it was discussed earlier when explaining the principles of port operation). In most microcontrollers, the pins have multiple functions. If you refer to the technical documentation for the controller, when describing the output function, a note will be made about the main and alternative functions this conclusion. For example: PD0/RX - the zero bit of port D is also the input of the serial port, PB1/Ain0 - the first bit of port B is also the input of the analog comparator.

Algorithms. Programs.
Commands to the processor are given in a certain order, in accordance with a previously developed algorithm. An algorithm is a sequence of execution by a processor. Moreover, the commands must be understandable to the processor, and at the same time have an unambiguous interpretation, without any independence in its execution. The algorithm can be written down verbally. For example: start of the program; make the zero bit of the port an input; make the seventh bit of the port an output; read the value of the zero bit of the port; if it is equal to a logical one, then perform the following actions: load a logical one into the seventh bit of the port; return to the beginning of the program. This is how we described the algorithm of operation of a circuit consisting of a switch, a light bulb (or other load) and a power source. The result of the execution will be as follows: when you press the button, voltage is supplied to the input of the port, the processor executes the program - it supplies voltage to the output of the port. And while the contacts are closed, there will be voltage at the port output.
But such writing is very difficult to perceive. Therefore, methods for graphically describing the algorithm were developed. Here is an example of a graphical recording of the above algorithm.
Rice. Algorithm-1. Graphical method algorithm descriptions

Branch commands: conditional and unconditional branches.
Special processor instructions include conditional and unconditional jump instructions. In order to understand this, it is necessary to explain the concept of “the address pointer of the command being executed.” The processor has a special register that stores the address of the currently executing instruction. When power is applied, this register is reset and a zero is written to it. Next, the processor begins to execute commands stored in memory, starting from address zero - after all, the address pointer register of the executed command contains zero. After executing the command, this pointer is incriminated, i.e., its value is increased. The processor reads the next instruction from memory at the address specified in the pointer. That is, commands are executed sequentially. You can break the sequence of program execution using conditional and unconditional jump commands. To do this, a command is stored in one of the memory cells, instructing the processor to change the value of the address pointer register of the instruction being executed. An unconditional jump instruction instructs the processor to change the sequential order of program execution and begin executing instructions stored in memory starting from the previously specified address.
The conditional jump command is more complex: when executed, it checks whether some condition is met. For example, you need to compare the value of two memory cells. If the value of the first cell is greater, then continue executing the program at address A, otherwise (i.e., the value of the first cell is less) - go to address C.

Interrupts and their types. Interrupt priorities.
There is another way to “force” the processor to stop sequential execution of the program and start executing the program at a specific address - call an “interrupt”. The concept of interruption appeared along with the first processors. The thing is that the processor controls devices that are slower than it. For example, the processor must process data until a certain signal appears. Let's give a simple example: the processor runs a program to count the number of pulses received at one of its ports. When you press the button, the processor must interrupt the execution of this program and execute another program: turn on some device (i.e., apply a logical one to one of the bits of the port - “1”). How to solve this problem? In the program itself, you can constantly poll the required digit of the port to which the button is connected. But at the same time, part of the processor resources (speed) will be practically wasted on polling the port. The second way is to use interrupts. The processor (and therefore the microcontroller) has a special pin. It is usually referred to as “Int” (English: “Interrupt”). When a signal is applied to the “Int” pin, the following actions occur:
- stopping the execution of the main program,
- the value of the address pointer register of the executed command is stored in RAM (the place where program execution is interrupted),
- after which a new address is loaded into the same register (depending on the wishes of the processor manufacturer),
- in the memory cell with the specified address there is an unconditional jump command: “go to address xx”,
- in memory, starting from the cell with address xx, there is another program, let's call it a utility program.

In our case, the utility program must issue a logical unit to the port, thereby turning on the required device. And here is where the fun begins: the last command of the utility program is the “exit interrupt” command. Upon receiving this command, the processor reads the previously stored value of the instruction address pointer register from memory and loads it into this register. Consequently, the processor continues executing the main program from where it was interrupted.
But an interruption can be caused not only by external signals, but also by internal devices of the microcontroller itself: timers, counters, serial ports and even non-volatile memory. Again, this is done mainly to reduce the number of commands executed to analyze the state of these peripheral devices. Let's give an example: the process of writing data into non-volatile memory is very long, during which time the processor can execute a very large number of commands. Therefore, the processor executes the main program, issues a command to erase non-volatile memory, and then continues executing the main program. As soon as clearing of non-volatile memory is completed, the control circuits generate an interrupt signal from this memory. The processor interrupts the execution of the main program and the process of writing data to memory begins. This method of performing an action outside the main program is called background mode. It is also often said: “this part of the program runs in the background.”
When working with interrupts, you must be careful: a situation is possible in which the execution of the program and the operation of the entire device may be disrupted. The fact is that the microcontroller has several interrupts. To control interrupt operating modes, there is an interrupt control register. When setting up interrupt operating modes, you allowed several interrupts to operate - this is a normal situation. But, having received an external or internal interrupt signal to the main program and proceeded to execute the interrupt service program, you did not disable interrupts. The processor is executing a utility program and at this moment it receives another interrupt signal. The processor interrupts the execution of the service program and proceeds to execute the program for processing a new interrupt. It's easy to imagine what this might lead to.
To solve this problem, a method was developed to assign each interrupt a degree of severity, or “interrupt priority.” Depending on the microcontroller model, the interrupt priority can be set rigidly (and the programmer only allows or disables the processing of a particular interrupt), or can be implemented programmatically by programmers (i.e., the interrupt priority depends on the preferences of the programmer and the algorithm for implementing a specific task).

We control the processor. Programming languages. Translators.
Machine codes. Assembler.
Commands for the processor are sequences of ones and zeros. Often processor commands are called machine codes, emphasizing that these commands were originally designed for a specific performer - a machine, but not a person. Remembering commands from numbers (machine codes) is very difficult. Therefore, to simplify the work, a way was invented to replace digital sequences with symbolic abbreviations that are more understandable to humans. For example, for the command “load data” they came up with a clear abbreviation “ld” (English “load” - load), for the command “compare” - “cp” (English “compare” - comparison), and so on. This method of symbolically recording processor commands is called “assembler”. If, when working with machine codes, the programmer directly enters processor control commands into the device’s memory, then when working with assembler, there is a kind of intermediary between the program and the processor that converts symbolic notations into machine codes. The program that acts as an intermediary is called a translator, i.e., a translator. But there is a small nuance: assembler refers not only to the method of symbolic designation of digital instructions (machine codes), but also to a translator program that helps the programmer translate symbolic designations of commands directly into machine commands. Therefore, the following technique is often used: when they talk about a language, they write Assembler, when they talk about a program, they write simply assembler.
Assembler has a huge advantage: programs written in Assembly are executed very quickly by the processor. The fact is that assembler is practically a machine command. But assembler also has disadvantages: the main disadvantage is the difficulty of writing programs, the second is that even relatively simple programs have a large amount of source text, which makes it difficult to analyze the program.

Modularity of programs. Frequently repeated tasks.
Each programmer accumulated a certain number of programs during his work. But many programs contain the same actions. For example, many programs poll the keyboard and analyze the pressed button. This means that this part of the program code can be transferred from one program to another. Program libraries were gradually formed from such pieces (modules). Programmers began to “sculpt” a program from modules: that is, they inserted the required module into the required place in the program. This approach accelerated the process of writing a program and increased the reliability of the program as a whole due to the use of already debugged modules. But from the first days, the problem of sharing modules arose: after all, each programmer wrote modules according to his own “standard” - as it was more convenient for him at one time or another. Therefore, a standard (more precisely, several starts) for writing these modules was gradually developed. They described the structure of the modules for more convenient “gluing” into one program.

Programming languages ​​and their functional division.
Gradually, these disparate standards for the use of modules formed what would later be called “programming languages.” Like human languages, a programming language has several sublevels that determine both the writing of individual words (modules) and the methods for writing them, as well as the rules for their use. Over time, programming languages ​​have evolved and changed. Gradually, all programming languages ​​were divided into several groups, depending on their “professional orientation”:
- applied programming languages ​​(FORTRAN for mathematicians, FoxPro for financial workers);
- universal (Pascal and Basic);
- system (Assembler and C).

System words began to be called low-level languages, i.e., the programmer works at the lower level, closest to the processor. And languages, when working with which the programmer does not have to directly control the operation of the processor, began to be called High Level Languages ​​(often referred to as Java languages). Do not confuse this abbreviation with the name of the Java language - "Java".

Broadcast of the program. Methods for broadcasting a program.
As with assembler, a program written in any language high level, must be converted into commands understandable to the processor. At first, this was done manually: a command in assembler was found in a table and written down in machine code. To speed up the process of converting (translating) a program, special programs were written - translators. There are two methods for translating a program: interpretation and compilation. Consequently, a translator is called either an interpreter or a compiler. When using an interpreter, the source text of the program is analyzed and sequentially, command by command, executed by the interpreter. The interpreter contains modules for all usable actions. This per-instruction conversion is very slow. But this method has a big advantage: you can stop the program, change its code and continue its execution. This is convenient when debugging a program. Also in this case, we have the source text of the program and can edit it many times.
When using a compiler, the program text is analyzed and a file containing machine instructions, called an executable file, is created. This ensures a very high execution speed of the compiled program - after all, the conversion of program text into machine codes occurs only once during its compilation. But you won’t be able to change the program on the fly: you need to change the program text and compile it again. If the source code is missing for some reason, then it is impossible to recompile the program, and changing the executable file is extremely difficult.

The process of creating a program. Program development environments.
With the advent of translators, the process of creating a program began to look like this:
- an algorithm for the future program is being developed,
- the algorithm is encoded (i.e., described in the form of programming language commands),
- the resulting code is written in some text editor,
- the file with the program text is transferred to the translator,
- the translator converts symbolic commands into commands understandable to the processor and saves them to a file,
- this file is loaded into memory.
As you can see, the programmer had to work in several programs. Most often, all these programs were written by different manufacturers, so the compatibility of these programs with each other was not guaranteed. Their compatibility had to be determined by trial and error.

Integrated software development environment.
IN Lately a new approach has appeared: “Integrated Development Environment” (English “IDE”). Integration refers to the execution in one program of the entire process of creating a program: having written the program text, the programmer with a mouse click starts the translation of the program text into machine codes, after which the resulting executable file is automatically loaded into the memory of the processor device. That is, everything is done in one program. This approach speeds up the programmer's work.

First difficulties.
All previous chapters were an introductory course, preparing you to perceive new information. We have several problems along the way.
1. A large amount of varied information: electronics, microcontroller design, algorithms, syntax of programming languages, descriptions of working with software tools. And how to write? One reader is a good electronics engineer, but has never written a program, another is a programmer, but electronics is at the level of a radio circle, the third is something in between...

2. Selection of MK: if all microcontrollers are good, then on the basis of which product and which manufacturer should we base the process of further training and practical application of microcontrollers?
In order to select a microcontroller for TRAINING, we need to fulfill the following conditions:
A) the microcontroller chosen for training must be accessible and inexpensive.
B) it must be a modern product, but not the newest.

Now in more detail about each point.
With point A, everything is clear: what’s the point of studying a product that is difficult to purchase or its price is exorbitant for a beginner.
Point B requires clarification. The fact is that new products always have some flaws. They are discovered only after some time, until someone accidentally stumbles upon this problem while working with this product. But new products do not immediately find their way into new designs: it takes time to write programs for new models. There is a human factor here: developers already have ready-made solutions for previous models of microcontrollers, and switching to new ones is difficult.
Also, all new microcontrollers have only a proprietary description. And it is written in English and using numerous professional terms: after all, it is intended for professionals! And we are students... After some time, examples of designs appear, more detailed descriptions with numerous comments and advice. Then someone will start translating the documentation into Russian (not everything, but at least the most complex or most frequently used).
There may be no tools for a new microcontroller: compilers, debuggers and programmers “do not understand” this product. Again, waiting until the authors of these programs update their creations...

3. You must select a programming language, on which we plan to write programs for MK.
Choosing a programming language is a very sensitive task. To teach microcontroller programming, I would like to use a programming language with a simple syntax: the programmer must deal with the program, but not its design!
Here it is necessary to make an explanation in advance: currently, three “families” of languages ​​are popular among developers of programs and devices on microcontrollers: C (written as “C”), Pascal (Pascal) and BASIC (BASIC). Pascal was originally developed as a tool for learning programming. BASIC itself is similar in structure to Pascal, but the writing of commands is simplified and the requirements for program design are much less. C is considered to be a language for professionals. Xi is like Chinese philosophy: not only the symbol (command) is important, but also its style and color. Jokes aside, but my opinion is this: C is a nightmare. Its use is justified only in some very narrowly specialized tasks. But our task is to try our strengths and spend them as little as possible on tasks that do not have a direct connection with the main goal.

4. We need a program development environment for microcontrollers. Its choice directly depends on the type of MK used and programming language.
The program development environment is very important for successfully mastering microcontroller programming. It is possible to write programs in a text editor like Notepad, but it is inconvenient (tested!). And calling the compiler on the command line is a thankless task in our graphical window-based age.
The choice of development environment directly depends on the microcontroller on which we will build the practical part of the training. On top of everything else, we need to have free tools. But, as testing of such programs has shown, free software most often has mediocre quality both from the point of view of both use and from the point of view of learning MK programming: the presence of errors or flaws in the translators themselves create additional difficulties and deprive one of self-confidence.
A demo version would also do, if it had a minimum of restrictions and worked for at least half a year - this is exactly the period needed to gain skills in working with microcontrollers at home.

5. A programmer that will be used to load written programs into the MK’s memory. The choice of programmer also depends on the type of MK used. There are, of course, “universal” programmers that allow you to work with different microcontrollers and memory chips, but they are expensive. Yes, and not needed in most cases. Therefore, it is easier to produce something highly specialized for this family of MKs.
But the point is not so much the complexity of the programmer circuits, but the method of connecting this programmer to the PC. Here it is necessary to clarify: a programmer is an electronic adapter that converts signals from computer interfaces (COM, LPT and USB ports) into signals supplied to the outputs of the MK to load the program into its memory. The electronic adapter is controlled by a PC program, which “forces” the adapter to issue the necessary sequences of signals to the MK pins.
If a programmer adapter connected to a PC via COM and LPT ports can be made at home - “on the knee”, then making such an adapter, but connected to USB port, is already somewhat problematic: the heart of such an adapter is often... a microcontroller. A paradox arises here: in order to program the MK we need to program the MK.
A logical question arises: why make a complex adapter that connects to USB, when you can make a simple one and connect it to an LPT or COM port. The thing is that many (almost all) modern PCs do not have these ports. Therefore, you will have to make a more complex adapter for programming the MK.

March 2010

I asked myself these questions in March, and now it’s already the end of November. But this time was not in vain: I found a way out of the situations described above and found answers to all the questions that tormented me. And now first things first.

Answer to question number 1
If the materials of the previous chapters could somehow be logically systematized and presented step by step, then the materials in the subsequent chapters are given in parallel: one implies the other. Perhaps my method of presenting new materials will seem somewhat chaotic to you, but I could not come up with something more beautiful in design.

Answer to question number 2
Microcontroller manufactured by ATMEL ATMEGA48. Well described, has been in production for several years, is not planned to be discontinued for at least another 3 years, has optimal technical specifications.

Answers to questions 3 and 4
The programming environment is BASCOM (manufactured by MCS Electronics, author Mark Alberts). The programming language is similar in style and requirements for the design of program text to Pascal, but the command syntax is taken from BASIC.
Reasons for choosing:
- a fully functional demo version of the compiler (the only limitation: the code generated by the compiler is limited to 4 KB in size)
- the desire of the program author to cooperate (I translated the interface messages and help system into Russian, he added Russian to this program)
- presence of a Russian-language forum for users of this compiler

Answer to question number 5
It was not possible to combine the simplicity of the circuit and USB. It was decided to describe two models of programmers: one connects to the LPT port of the computer, the second to the COM port. If these ports are missing, the second version of the programmer can be connected to a computer using a USB-COM converter. This is how we get a USB-COM-programmer-microcontroller combination.
The first model of the programmer is known as STK-200/300, contains a third-state buffer chip and several resistors. The second model is the well-known USBasp programmer.

The cartridge chip is a small flash card into which all information about the operation of this cartridge is recorded.

For example, the chip contains information about the type of cartridge, its production date and serial number. During operation of the printer or MFP, the Additional Information about the date of its installation in the device, the current counter of prints made by the cartridge, and other technical data. When the cartridge's fingerprint counter reaches a certain value, the cartridge chip receives information that the cartridge is empty. Then the device warns the user that the cartridge is empty and needs to be replaced. Depending on the brand of printer or MFP, the equipment either continues to work with such a warning or stops.

In this case, there are several options:

1. Do not change the cartridge chip

If you have Canon or HP equipment, the chip in your empty cartridge does not block the operation of the printer or MFP, but only constantly signals that the cartridge is empty. In this case, when refilling the cartridge, you can not change it, and ignore warnings about an empty cartridge.

2. Reprogram the chip.

In Samsung and Xerox printers, the cartridge chip often blocks the operation of the printer after the cartridge becomes empty. In order for the refilled cartridge to start working, the chip is reprogrammed. This can be done in our workshops. You can also find out about the possibility of reprogramming (zeroing) the chip of your cartridge .

3. Replace the chip

If the chip cannot be reprogrammed, then it is either changed every time it is refilled, or the printer/MFP is reflashed once. You can find out about the need change the chip when refueling in our in the notes column.

4. Reflash the printer

This change to the printer software will allow it to function with cartridges that do not have a chip. This is a one-time operation. You can find out more about reflashing the printer and its cost .

Failure of a key is a very rare phenomenon if we consider the so-called tablets, and very likely if we are talking about a contactless RFID system built on cards triggered from a long distance.

If for some reason the entrance door, the gate of a private house or the lock at work no longer unlocks, the question often arises: how to reprogram the key to the intercom? For the average user, this process does not mean complex intervention and participation in programming a personal identification device.

Features of programming intercom keys

To understand why programming individual intercom keys only involves recording a new identifier and linking it to the subscriber on the device installed in the door, it is worth paying special attention to the mechanics of operation and the internal structure of the usual tablets and cards.

All keys are built on a one-time device circuit. If a failure or physical violation of the internal structure occurs, the personal identifier is simply thrown away or destroyed. Neither repair nor reprogramming without the use of special industrial devices is provided.

RFID

Small keychains and cards are already familiar to many people. For such a key to operate, it does not need to be leaned against the reading pad. You just need to bring it a certain distance.

The keys are ranked according to their operating range:

  1. with an identification zone of 100-150 mm, common format, Proximity type;
  2. with a detection range of up to 1 m, Vicinity type.

Despite such differences in range, all identifiers work according to a simple scheme.

An intercom using keys of this class has a low-intensity electromagnetic field radiation unit in the contact area. Inside the RFID card or key fob is located simple circuit, it includes an inductive oscillating circuit, a miniature transmitting antenna and a signal-forming chip.

When the key is brought into the radiation zone, energy is generated and the internal electrical circuit is activated. The card or key fob transmits a radio frequency signal, the intercom recognizes the identifier and unlocks the door if it is registered in its memory.

There is simply no simple way to reprogram an RFID-class intercom key for most types of products. The identifier is formed by a factory-sprayed chip, the number of unique combinations (cards and key fobs) is huge, changes to the code are not provided.

The key can deteriorate either due to mechanical kinks or breaks (as a result, damage to the chip or transmitting antenna grid occurs), or due to exposure to strong electromagnetic radiation, comparable in strength to a microwave oven.

Touch-Memory

Touch-Memory is the contact tablet most people are familiar with. There is also a microchip inside this key.

However, the identifier is transmitted via a single-channel electrical circuit. When the key is applied to the contact pad, the data reading circuit is closed in the intercom.

A unique code stitched into the tablet is transmitted and checked against one of those stored in the device’s memory. If identification is successful, the door will unlock.

A Touch-Memory tablet can be damaged by exposure to strong static voltage by applying the tablet to electrified clothing. This is quite difficult to do, since the pulse must pass between certain points of the contact pad, but this is the most common cause of breakdowns.

The tablet with the chip is very durable, it is difficult to damage it mechanically, the key is that, in addition to exposure to static, it can be burned in the microwave. Touch-Memory tolerates any other influences, including the most powerful neodymium magnets, without consequences.

The way to program access keys for an intercom of this class is to use a special programmer. It is used to make clones of tablets, as well as universal master keys for a series of intercoms.

Touch-Memory is divided into classes. They depend not on the internal structure and principles of operation, but on the manufacturers, each of whom creates an internal circuit with certain characteristics and a methodology for generating a unique code.

The following types of Touch-Memory are widely used:

  • with markings starting with DS (Dallas), used in a huge number of models Vizit, Eltis, C2000 and others;
  • marked DC, as well as Cifral KP-1 - Touch-Memory data is intended only for Cifral intercoms;
  • K series, widely used in Metacom access control systems and other intercoms.

Similarly, there are classes and RFID formats, for example, the oldest HID, the popular EM-Marin, and also used in Mifare cards triggered from a long distance. Therefore, before figuring out how to program a personal key for an intercom from an entrance door, you first need to purchase a Touch-Memory or RFID compatible format.

Do-it-yourself intercom key programming

The method for encoding a personal key for an intercom from work, home or friends' entrance consists only of recording the data of the corresponding personal identifier into the memory of the device controlling the door. To do this yourself, you need to access the service functions from the front panel keypad.

The technicians who install the intercom are required to reprogram and change the factory master codes and other service information of the device.

If this is done, the methods for registering your key in the intercom using standard access combinations will not work. However, a huge number of devices on the door respond to factory codes and allow you to activate service functions.

Algorithm of actions

The easiest way is to find out how to encode the key for the intercom from the entrance door from a service company. Some of them provide such data.

But there is a set of standard actions for intercoms of common brands.

  1. Rainmann, Raikman - press call, enter 987654, then sound signal— 123456. If the invitation P appears on the display, press 2, apply a tablet, press #,<номер квартиры>, #. Recording into memory is done with the * button;
  2. — dial #-999, after the invitation sound, dial code 1234 (for some series - 6767, 0000, 12345, 9999, 3535). After this, press 3, after a pause - the apartment number, apply the key, press #, *. If the factory code (1234 and others) is not accepted, the intercom will emit a two-tone signal;
  3. , - hold the call button until there is a reaction (sound, invitation on the display), enter 1234, then the apartment number, call. In response to the invitation to place the key, exit the menu by pressing the * button.

The most modern versions of the Cifral intercom use fairly complex code sets. The method for encoding the key to the intercom from the entrance door looks like this: call, 41, call, 14102, 70543.

Then you should wait for the invitation to appear on the screen, press 5, enter the apartment number, after the inscription on the Touch display, attach the key. A sound signal indicates recording into memory.

Conclusion

You can record any of the purchased keys, which are mistakenly called blanks, into the intercom memory. In reality, it is a working mechanism with its own unique code. It only needs to be registered at the entrance device.

A variety of key application techniques are available. The same one can be used on several intercoms of the same brand, provided that registration has been made on each one. The main thing is that the Touch-Memory tablet or RFID card or key fob must have a format compatible with the device on the door.

Video: How to duplicate an intercom key

I am categorically against this approach. Usually it all ends - either with nothing, or with forums clogged with pleas for help. Even if someone is helped, 90% of the time it will never appear on electronics sites again. In the remaining 10%, he continues to flood the forums with pleas; they will first kick him, then throw mud at him. Of these 10%, another 9% are eliminated. Then there are two options: either it comes to a stupid head and still goes to the beginning, or in particularly neglected variants, it is his lot to copy other people’s designs, without a single thought about how it works. Arduinists are often born from the latter.

The way from scratch, in my opinion, is to study the peripherals and features, if it is a microcontroller. It’s better to first figure out how to kick your legs, then timers, then interfaces. And only then try to raise your FAT. Yes, this is not fast, and it will require time and effort, but practice shows that no matter how you try to shorten this path, problems will still emerge that will have to be solved and you will spend much more time without this base.

Just don’t confuse warm and soft. First, there are exceptions to all rules, I personally saw people who had never held microcontrollers in their hands before, but in an extremely short period of time they were able to outpace experienced experienced radio amateurs, we don’t take them into account. Secondly, I came across individuals who started by copying diagrams and figured it out right away, but this is most likely an exception to the rule. Thirdly, there are also experienced programmers among the Arduino developers; this is just a platform, but this is rather an exception.

If we talk about the general mass, then things are exactly as I described at the beginning: reluctance to deal with the basics, at best, delays the moment when you have to return to these issues. In the worst case, you will quickly hit the ceiling of your knowledge and always blame someone else for your problems.

2. Before solving a problem, break it down to the point of absurdity, down to “soldering a resistor”, this helps, it’s been tested. Small problems are much easier to solve. When a large task is broken down into a bunch of small actions, all that remains is to complete them. I can give you one more piece of good advice, even though it may seem crazy to you - get a notebook and write in it everything you are going to do. You think I’ll remember that, but no. Let's say today I'm in a good mood and I'm thinking about how to collect the board. Write down an action plan: go buy a resistor, prepare the wires, mount the display. Then you’ll forget everything, open your notebook and look - yeah, today I’m in the mood to saw and plan, I’ll do the fastening. Or you are assembling a board and the last component remains to be soldered, but that’s not the case, the resistors have run out, so I should have written it down before soldering, then I remembered.

3. Do not use code generators, non-standard features and other simplifications, at least in the first stages. I can give you my personal example. When I was actively using AVR, I used the CAVR codogen. I was completely satisfied with him, although everyone said he was crap. The bells were constantly ringing, there were problems with libraries, with syntax, with porting, but it was hard to give up on it. I didn’t understand how it worked, I just knew where and how to check the boxes.

The stake was driven into my coffin with the advent of STM32, it was necessary to crawl onto them, and that’s when the problems appeared. Problems are putting it mildly; in fact, I had to master microcontrollers and the C language from scratch. I didn't repeat past mistakes again. I must say this has already come in handy more than once. Since then, I’ve had the opportunity to work with other platforms and I don’t experience any difficulties; the approach justifies itself.

Regarding all the improvements and simplifications, there was one very good comparison that they are like wheelchairs that ride on rails, you can ride and enjoy, but you can’t get up, where they take you, you will arrive there.

4. Learn C language. Oh, how often do I hear novice radio amateurs boast that they know the radio well. This became food for me; I always like to consult with such interlocutors. It usually becomes clear right away that they don’t know the language at all. I can say that despite the apparent simplicity, I haven’t met many people who really knew him well. Basically, everyone knows him as much as is required to solve problems.

However, the problem in my opinion is that without knowing the possibilities, you severely limit yourself. On the one hand, not optimal solutions that will require more powerful hardware, on the other hand, unreadable code that is difficult to maintain. In my opinion, readability and maintainability of code is one of the most important places and it is difficult for me to imagine how this can be achieved without using all the capabilities of the C language.

Many beginners are disdainful of learning the language, so if you are not like everyone else, you will immediately become two steps above other beginners. It also makes no difference where to study the language. In my opinion, a microcontroller is not very suitable for this. It is much easier to install some kind of Visual studio or Qt Creator and solve problems on the command line.

It will also be a good help to study any language tests that are given during interviews. If you dig around, you can learn a lot of new things.

5. Learning assembler? There is no need to be afraid of him, nor to idolize him. You shouldn’t think that if you know how to write a program in assembly language, you will immediately become a microcontroller guru, for some reason this is a common misconception. First of all, it is a tool. Even if you don't plan to use it, I would still strongly recommend writing at least a couple of programs. This will greatly simplify your understanding of the operation of the microcontroller and the internal structure of programs.

6. Read the datasheet. Many developers neglect this. By studying the datasheet you will be two steps higher than those developers. Doing this is extremely useful, firstly, this is the primary source, no matter what sites you read, in most cases they repeat information from the datasheet, often with errors and omissions. There may also be information there that you don't think about now, but that may be useful in the future. It may happen that some kind of error pops up and you remember that yes, it was said about this in the datasheet. If your goal is to become a good developer, then this stage cannot be avoided; you will have to read datasheets; the sooner you start doing this, the faster your growth will go.

7. People often ask to send datasheets in Russian. A datasheet is something that should be perceived as the truth, the most accurate information. Even there, mistakes are possible. If the translator’s mistakes are added to this, he is also a human being, maybe not even on purpose, just misspelled. Or he has his own vision, he may miss something that, in his opinion, is not important, but perhaps extremely important for you. The situation becomes especially funny when you need to find documentation for not very popular components.

In my opinion, it is much easier to exclude the entire layer of these problems in advance than to catch them later. Therefore, I am categorically against translations, the only true advice is to study English in order to read datasheets and manuals in the original. You can understand the meaning of a phrase with the help of translator programs, even if your language level is completely zero.

I conducted an experiment: I had a student, a datasheet and Google translator. Experiment No. 1: the student was given a datasheet and given the task to independently find the required values, the result is “how can I”, “I don’t know English”, “I didn’t find anything/I didn’t understand” are typical phrases indicating that he didn't even try. Experiment No. 2: the same student was given the same datasheet and the same task, with the difference that I sat next to him. The result is that after 5 minutes he found all the necessary values ​​himself, absolutely without my participation, without knowing English.

8. Reinvent the wheel. For example, if you are studying some new thing, say a transistor, Uncle Horowitz authoritatively declares from the pages of his book that the transistor amplifies, always say - I DON’T BELIEVE. We take the transistor in our hands, plug it into the circuit and make sure that this is really the case. There is a whole layer of problems and subtleties that are not described in books. You can only feel them when you pick them up and try to assemble them. At the same time, we get a bunch of related knowledge and learn the subtleties. In addition, any theory without practice will be forgotten much faster.

At the initial stage, one method helped me a lot - first you assemble a circuit and see how it works, and then try to find a rationale in a book. The same is with the software part, when there is a ready-made program, it is easier to understand it and correlate the pieces of code which is responsible for what.

It is also important to go beyond what is permitted, apply more/less voltage, make larger/smaller resistors and monitor changes in the operation of the circuit. All this remains in the brain and will be useful in the future. Yes, this is fraught with consumption of components, but I consider this inevitable. At first, I sat and fired everything, but now, before betting this or that denomination, I always remember those fun times and the consequences of putting the wrong denomination.

9. How would I do this if I were the developers? Can I do better? Ask yourself these questions every time, it really helps you progress in your learning. For example, study the 1wire, i2c, spi, uart interfaces, and then think about how they differ, whether it could have been done better, this will help you understand why everything is this way and not otherwise. You will also be aware of when and which one is better to use.

10. Don't be limited by technology. It is important that this advice has a very fine line. There was a stage in life when from every doorway you could hear “you should know FPGAs”, “but you can do something with FPGAs”. Formally, I had no goals to study PLISins, but there was no way I could ignore it. A little time was allocated for familiarization with this issue. Time was not wasted, I had a number of questions regarding the internal structure of microcontrollers, and it was after communicating with the Plisins that I received answers to them. There are many similar examples; all the knowledge that I acquired in one form or another came in handy sooner or later. I don't have a single useless example.

But as has been said, the issue of technology has a fine line. There is no need to grab everything. There are many areas in electronics. Maybe you like analog, maybe digital, maybe you’re a power supply specialist. If it’s not clear, then try yourself everywhere, but practice shows that at first it’s better to concentrate on something specific. Even if you need to press in several directions, it is better to do it in steps, first pushing through one thing.

11. If you ask a novice radio amateur what he likes more: programming or circuit design, then with a 99% probability the answer will be programming.

At the same time, these programmers spend most of their time on making boards with LUT/photoresist. The reasons are generally clear, but quite often this turns into a kind of insanity, which consists of making boards for the sake of making boards.

On the Internet, almost the only real way to programming is to become a Jedi of printed circuit board manufacturing. I also went through this path, but every time I ask myself the question why? Ever since I bought myself a couple of boards, for all occasions, every time I think that I could easily live all this time without homemade boards. My advice is, if there is even a drop of doubt, it is better not to bother and take a ready-made debugging board, and it would be better to spend time and money on programming. 12. The next piece of advice is especially painful; I really don’t want to discuss it, but I have to.

They often write to me, saying that xxx rubles are too expensive, where can I get them cheaper. It seems like a common question, but usually I immediately get tensed by it, since it often turns into endless complaints about the lack of money. I always have a question: why not tear off the butt and go to work? Even at the same time, even for construction, you have to wait a month, but then you can buy a couple of boards that will last for the next year. Yes, I know that it is difficult to find work in small towns and villages, move to a big city. Work remotely, in general you need to spin. There is simply no point in complaining, there is a way out of the situation, whoever looks for it finds it. The tool should allow you to develop devices as quickly as possible. For some reason, many developers do not value their time. A typical example is a cheap crimp for terminals, which many employers like to save on. The problem is that it doesn't even crimp correctly, causing the wires to fall out. You have to perform a bunch of additional manipulations, wasting time accordingly. But as you know, a fool pays three times, so low price the crimper will increase many times due to the time spent and poor quality of crimping.

I'm not saying that cheap = bad, no - it all depends on the situation. Let me return to the example of the crimper; there was a time when I crimped it with anything, so problems often arose. It’s especially unpleasant when you start a board and it doesn’t work, after a long search for an error you realize that it’s because of a poorly crimped wire, it’s a shame. Since normal crimping appeared, there have been no such problems. Yes, the inner toad was croaking and choked by its cost, but I never regretted this decision. All I want to say is that after working with a normal tool, you don’t want to go back to the bad one, you don’t even want to discuss it. As practice shows, it is better not to skimp on tools; if in doubt, test it from someone, read reviews, reviews.

14. Start a website, you can write whatever you want on it, just like notes. Practice shows that employers still don’t read it, but the fact itself has a great effect.

15. Tricky question: profile higher education, is it necessary? I know of more than one case where people worked with absolutely no education and, based on their experience and knowledge, they could give a light to any certified specialist. Actually, I don’t have a specialized education, do I feel discomfort from this? To a certain extent, yes.

At the very beginning, when microcontrollers were a hobby for me, I helped a lot with coursework and diplomas from different universities, just to assess my level. I can say with confidence that the level is generally low, regardless of the name of the university. It is not necessary to study for several years in order to write such a diploma. You can achieve this yourself in a very short period of time. And yet, there were often times when students knew some subject that they took in the 2-3rd year, but I did not know it. Although all this knowledge was compensated by self-education, it would still be better not to waste time on this.

University for the sake of a piece of paper. I can say that there were also situations when they were offered a job that required a mandatory education and it was a shame that at that moment there was no piece of paper. But in general, history shows that most employers don't care about your paperwork.

The next point is quite often not taken into account, this is the environment. Don’t forget that the people you study with are your generation, and it is possible that you will work with them. The number of firms operating in one industry is very limited. Practice shows that even in big cities, everyone knows about each other, down to intimate details.

Another point is opportunities. Often, universities have their own capabilities - equipment, maybe some sections, maybe some programs for working abroad, this should be used if there is even the slightest opportunity. If you don’t see any prospects at a university, go to another, the world doesn’t end at just one.

To summarize, the advice is this: if there is even the slightest opportunity, you need to go study, definitely according to your profile; if there is at least some chance, then climb everywhere, and not sit in the back seat. Make acquaintances, at the same time practice and develop yourself at home.

16. Is it too late to start programming at 20, 30, 40, 50 years old? The practice of other people shows that age is not a hindrance at all. For some reason, many do not take into account the fact that there is a whole layer of work that young people, due to their ambitions, do not want to do. Therefore, employers prefer to hire those who will carry it. This is your chance to get hooked, and then everything depends only on you.

And one last piece of advice. Many radio amateurs are uncommunicative, angry and irritable - consider this a job specificity. Radiate kindness and positivity, be a good person.

If you find an error, please select a piece of text and press Ctrl+Enter.