As each token is interpreted the machine code is executed. For each instruction e. These are read from memory and interpreted sequentially. The key points here are : controlling program.

Author:Brar Dokree
Language:English (Spanish)
Genre:Personal Growth
Published (Last):20 August 2019
PDF File Size:20.96 Mb
ePub File Size:5.88 Mb
Price:Free* [*Free Regsitration Required]

Various pin functions cannot be used simultaneously, but can be changed at any point during operation. Anyway, it is important to point out that the CPU is manufactured in RISC technology as this fact may be crucial when deciding which microcontroller to use.

By the way, to program other microcontrollers in assembly language it is necessary to know more than instructions by heart. The execution time is the same for almost all instructions, and lasts 4 clock cycles. The clock frequency is stabilized by a quartz crystal. The exceptions to the rule are jump and branch instructions the execution time of which is 2 clock cycles. Each deserves to be separately discussed here due to their specific functions, features and organization.

No further explanations are required as the whole process is performed automatically by means of a special program installed on the PC and a simple electronic device called the programmer. This is why this memory containing locations is perfect as a permanent storage for some of the results created and used during the operation.

It consists of two parts: general-purpose registers and special-function registers SFRs. All of them are divided in four memory banks to be explained later in the chapter. Although both groups of registers are cleared when power goes off and both are manufactured in the same and act in a similar manner, they do not have many things in common when it comes to their functions.

Since the microcontroller is not creative at all, it is necessary to specify the exact address of some general purpose register and assign it that function. Make sure that the value of this register is incremented by 1 after each product passes through a sensor. This is how a simple program is created. The microcontroller is able to execute this program as it knows what the sum to be incremented is and where it is stored. Similarly, each program variable must be preassigned some of the general-purpose registers.

By changing its bits it is determined which port pin is to be configured as a converter input, the start time and speed of conversion. Furthermore, each SFR register has its own name both registers and their bits , which considerably simplifies the process of program writing.

Since high-level programming languages contains a list of all SFR registers with their exact addresses, it is sufficient to specify the name of a register in order to read or change its contents. Another feature of these memory locations is that they have their names both registers and their bits , which considerably simplifies the process of writing a program. Since high-level programming languages can use the list of all registers with their exact addresses, it is enough to specify the name of a register in order to read or change its contents.

Prior to accessing any register during program write whether to read or change its contents , it is necessary to select the bank containing it. To make dealing with SFRs as simple as possible, the most commonly used registers have the same address in all banks and therefore can be easily accessed. On the contrary, when you write a program in higher programming languages, such as Basic, and use compilers such as mikroBasic PRO for PIC, it is sufficient to specify the name of a re gister you need.

Having this information, the compiler is capable of selecting the appropriate bank as well as to include appropriate instructions into the code during the process of compiling. This must be a wonderful news then. Before the microcontroller starts to execute a subroutine GOSUB instruction or when an interrupt occurs, the address of the instruction to be executed next is pushed onto the stack, i. As a result, the microcontroller knows from where to continue regular program execution when a subroutine or an interrupt execution is complete.

The address is cleared after the return to the program and one stack location is thus automatically available for further use. Note that data is always circularly pushed onto the stack. It means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored with the first push.

The tenth push overwrites the second push and so on. Data overwritten in this way is not recoverable. Since the programmer cannot access these registers for write or read and there is no bit to indicate stack overflow or underflow condition, it is necessary to pay special attention to it during program writing.

The saveBank auxiliary variable saves the state of these two bits. The current program memory address is automatically pushed onto the stack and the default address predefined by the manufacturer is written to the program counter. The location from where the program proceeds with execution is called an interrupt vector.

For the PIC16F microcontroller, the address is h. As seen in figure below, the interrupt vector should be skipped during regular program execution. A part of the program to be executed when an interrupt request arrives is called an interrupt routine it is a subroutine in fact. The first instruction of the interrupt routine is located at the interrupt vector. How long will it take to execute the subroutine and what it will be like, depends on the skills of the programmer as well as on the interrupt source itself.

This is why the first part of every interrupt routine should be interrupt source detection. When the interrupt source is known and interrupt routine is executed, the microcontroller reaches the RETFIE instruction, pops the address from the stack and proceeds with program execution from where it left off. The interrupt routine should be written by the user. Each of them controls some process within the microcontroller.

It really looks like a big control table with a lot of instruments and switches. Now you are concerned about whether you will be able to learn how to use them all? Powerful devices such as microcontrollers are similar to supermarkets: they offer many things at low prices and it is up to you to choose what you need.

Therefore, choose the area you are most interested in and learn only what you have to. When you get a full understanding of hardware operation, study SFRs which are in control of it there are usually a few of them. The performance of all devices is controlled by an appropriate control system and the microcontroller is no exception to the rule.

One has to be familiar with such systems in order to be able to use devices properly. Of course, we are talking about SFRs where the whole story about programming starts and ends. Their bits control different modules within the chip and therefore are described along with processes they are in control of. IRP — Bit is used for selecting register bank at indirect addressing.

RP1,RP0 — Bits are used for selecting register bank at direct addressing.


Programming the PIC Microcontroller with MBASIC



PIC Microcontrollers – Programming in BASIC


JBL 3635 PDF




Related Articles