HOME

PRODUCTS

PROJECTS

TUTORIALS

C FUNCTIONS

PROGRAMS

VIDEOS

FORUM

COMPANY

SPANISH

                   

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:

# include P18F2550.inc

When installing the MPLAB IDE, this file is automatically stored in the installation folder.

 

SFR, name Address Function
PORTA F80H Digital input/output
PORTB F81H Digital input/output
PORTC F82H Digital input/output
TRISA F92H Configuration register I/O
TRISB F93H Configuration register I/O
TRISC F94H Configuration register I/O
STATUS FD8H Status register
FSR0H FEAH Indirect addressing register
FSR0L FE9H Indirect addressing register

 

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:

       0

0

0

1

1

1

1

0

 

ASSIGNMENT OF PORTS IN BOLT 18F2550 SYSTEM:

 

PORT A, PORT C

PORT B
RA0 ACTIVATE/DEACTIVATE RELAY RB0 ACTIVATE LED B0
RA4 MICROSWITCH SW1 RB1 ACTIVATE LED B1
RA5 MICROSWITCH SW2 RB2 ACTIVATE LED B2
RC1 MICROSWITCH SW3 RB3 ACTIVATE LED B3
RC2 MICROSWITCH SW4 RB4 ACTIVATE LED B4
  RB5 ACTIVATE LED B5
  RB6 ACTIVATE LED B6
  RB7 ACTIVATE LED B7

 

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 0, 1 and 2 are the CARRY, HALF CARRY AND ZERO, and are flags that are activated with a value equal to 1 when the result of an operation or instruction generates a carry, a half carry  or a value equal to zero respectively.

- 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 .

- - - N OV Z DC C

 

 

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.

 

BOLT-ASSEMBLER-TEMPLATE-2.asm Use this file as template, includes a delay subroutine.
KEYBOLT.inc Auxiliary file to be used with template. Store this file in same folder as your application program. Includes macros for inicialization and ports definitions.
KEYBOLT2.inc Version 2 of auxiliary file. Includes macro to read microswitches.
BOLT-BINARY-COUNTER-LEDS.asm Binary counter in leds of port B
BOLT-FLASH-LED.asm Flashes led B0 in periods of 1 second.
BOLT-READS-MICROSWITCHES-V-4.asm Reads microswitches and writes value in leds.
LOOK-UP-TABLES-MICROSWITCHES.asm Compares microswitches with values in table
LOOK-UP-TABLES-MICROSWITCHES.HEX  
MULTIPLICATION-MICROSWITCHES.asm Multiplies 2 values read from microswitches
MULTIPLICATION-MICROSWITCHES.HEX  
SHIFTING-LEDS-MICROSWITCHES.asm Shifting of leds according to values in microswitches
SHIFTING-LEDS-MICROSWITCHES.HEX  
BOLT-PING-PONG.asm If SW1=ON (0), shifts leds to right, if SW1=OFF (1), shifts leds to left
BOLT-PING-PONG.HEX  
BOLT-ASSEMBLER-TEST-PROGRAMS-FILE.zip Download all .asm and .hex files!

 

LEDS AND MICROSWITCHES BOLT 18F2550 ELECTRONIC DIAGRAM

 

 

RELAY ELECTRONIC DIAGRAM BOLT 18F2550