Assembly language programming. Bolt 18F2550 system, with 8 leds, 4 dip switches and 1 relay.
This tutorial provides basic assembly language programming information for the Bolt 18F2550 system, and simple examples to control devices, such as LEDs, microswitches and relays. The examples are accompanied by electronic diagrams and test programs written in assembly language. The exercises are developed for Bolt 18F2550 system or the Bolt v.Lite version, which have 8 LEDs, 4 microswitches and a relay controlled by the microcontroller, but can be easily modified to suit any other Microchip's microcontroller. The figure shows a general diagram of the control devices listed.
To facilitate user programming, a template file is provided on which you can develop your application, as well as an auxiliary file. Once assembled the project from MPLAB IDE, the .hex generated file can be loaded directly into the Bolt system using software Bolt v.1.0.1. IMPORTANT NOTE: for microswitches SW1 ... SW4: the "ON" (contacts closed) position generate a low voltage, ie a logic 0, and the "OFF" position (contacts open) generate a high voltage, ie a logical 1. See diagrams of electronic microswitches later in this tutorial.
|
Pin assignment on the microcontroller 18F2550 The 18F2550 microcontroller have the following pin assignment in their circuits. Because it is a multifunction microcontroller, pins can be configured to perform various tasks. For example, the RA0 pin can be used as a digital input/output as well as an analog input for the A/D 10-bit. Similarly, the RC6 pin can be used as digital input/output or transmit signal of serial port.
The RAM and SFRs: The 18F2550 has 2048 locations in RAM. However, part of this memory area is already assigned to the microcontroller functions: in locations 000H-05FH are the so called access logs to RAM (Access RAM), which are used during the execution of the program for addressing the special registers and RAM. Additionally, the buffer memory to the USB port of the circuit is in 400H to 7FFH locations. From address 060H, to address 3FF, is the area of RAM available for user programs. Finally, in the directions FFFH-F60H, are the so called SFR or special function registers, which aims to enable the user to configure the various functions, circuits and interfaces available in the microcontroller, such as I/O ports, timers, asynchronous serial port, USB port, the A/D, etc..
Special functions registers, SFR: The 18F2550 is a microcontroller with numerous functions and settings. There are 83 special registers (Special Function Registers, SFRs) and 14 configuration registers. To see the full details of these registers, please see the 18F2550 data sheet. To learn basic programming and management of the input/output, we will use test programs, with only nine special registers shown in the table below which are used in simple applications. In all programs it is essential to declare the file P18F2550.inc where establishing equivalence between the names of the registers and bits and their addresses, using the directive: When installing the MPLAB IDE, this file is automatically stored in the installation folder.
|
DIGITAL
PORTS:
Digital Ports: The 18F2550 has 3 digital ports, Port A, with 6 bits available (RA0. .. RA5), port B with 8 bits available (RB0. .. RB7) and port C with 7 bits available. A total of 21 bits. All bits are bidirectional, that is, can be programmed as inputs or outputs, according to a data address registers, called "TRISA" for the port A, "TRISB" for port B and TRISC for port C. To configure a bit as input, write a "1" and to program as output, a "0" in the corresponding bits in these registers. PROGRAMMING EXAMPLE FOR TRISA REGISTER: In this example, bit RA0 of PORT A is programmed as an output, and bits RA4...RA1 are programmed as inputs:
ASSIGNMENT OF PORTS IN BOLT 18F2550 SYSTEM:
STATUS REGISTER
The register
named STATUS,
contains several flags
of importance
in the 18F2550.
When programming in assembly
language, the proper use of
these flags is essential. - Bits 3 and 4 are the OVERFLOW and NEGATIVE, and are flags that are activated with a value equal to 1 when the result of an operation or instruction generates an overflow or a negative two's complement arithmetic .
|
TEMPLATES AND TEST PROGRAMS List of templates and test programs in assembly language for Bolt 18F2550 system. Use this template to develop your own programs. Remember that you must use software Bolt v.1.0.1 to load the .hex file in module.
LEDS AND MICROSWITCHES BOLT 18F2550 ELECTRONIC DIAGRAM
RELAY ELECTRONIC DIAGRAM BOLT 18F2550
|