Blink a LED with Assembly Language & a PIC




To state the blindingly obvious, there are many flavors of microcontroller in the world.  There are innumerable applications for them too.  This Instructable will cover the steps necessary to blink a LED using a PIC microcontroller and Microchip assembly language, showing you how to access and use some of the device’s hardware peripherals
Blink a LED with Assembly Language & a PIC
To do this I am going to show you how to blink a LED at approximately 1 Hz with a 50% duty cycle.

Step 1: Obtain Necessary Parts & Tools

What you will need

1. A PIC, preferably a 16F1936–but as long as you know your specific hardware, you could probably implement this on nearly any 8 bit PIC with an on-board 16 bit timer.  There are some slight programming differences between the 1936 and earlier uCs that you might be familiar with.  The 1936 is what I have at the moment, and it’s pretty spiffy

2. Some way to program the PIC. I am going to be using a PICkit III to do ICSP (In-circuit serial programming).  Can be gotten from Microchip for a small sum of money.  There are many programming options for PICs.  You can even roll your own programmer.

3.  MPlab.  This is available from Microchip for the low low cost of Free.

4.  Miscellaneous electronic parts/equipment
– A 3-6V power supply
– Breadboard
– Jumper wires
– 1 uF Capacitor
– 10K resistor
– LED of choice (around 20 ma current draw), and appropriately sized resistor.
-A small tactile switch

Step 2: Build the Circuit

A few quick notes on the circuit presented here.

-The header is meant to connect to the PICKIT III.  Pin 1 on the header corresponds to pin 1 on the PICKIT III.

-The LED goes on when a logic 0 is presented to RB0.  Usually chips like this can sink more current than they can source.

-Vcc needs to be 3-6V

-SW1 can be a simple tactile push button.  The purpose of the switch is to give you a way to drive MCLR low, and reset your chip.

-R1 is 10K or similar.  It pulls up the voltage on MCLR when C1 has charged up.

-You will probably need to view the original image to read the pin numbers

Step 3: About PICs

You probably know already that a computer executes code by loading the code from nonvolatile memory–such as a hard disk, and executing it in volatile memory which we call RAM.  Instructions + Data = Results

With PIC micro-controllers it is the same.  When a PIC starts up, the Arithmetic Logic Unit starts a special counter called a Program Counter at 0, and sequentially executes one instruction after the other, incrementing the Program Counter each time an instruction is executed.

The 8 bit mid-range pics have approximately 49 different instructions.  Depending on which PIC you use, these instructions may be of different width.  For the purposes of this tutorial I will be using a PIC 16F1936 which has instructions 14 bits wide.

Step 4: Understanding Data Memory and Paging

In the PIC 16F193x devices, there are three kinds of memory: data memory, program memory, and EEPROM memory.  This step will show you how to access  and use data memory.




To use program memory you must only know the hexadecimal location of that memory.  Being an 8-bit micro-controller, the PIC has to use a special trick called paging to expand it’s addressable memory range past 256 bytes.

The 16F193x devices have their data memory divided into approximately 32 banks of 128 bytes each.  Each bank is accessed by moving a number to a register called the bank-select register (BSR).  To access the contents of a particular register, except for special un-banked registers which can be accessed from any bank, you’ve got to be in that register’s bank.
Blink a LED with Assembly Language & a PIC
Attached to this step you’ll find part of the memory map for 16F1936 devices.  The unbanked registers have been highlighted/surrounded with a red rectangle.  A higher resolution image may be found on the data sheet.

 

For more detail: Blink a LED with Assembly Language & a PIC




Current Project / Post can also be found using:

  • blink led on tiva c with assembly
  • blinking a led using assembly language in pic
  • comment of assembly language programmes to flash led bulbs
  • which registor bank used in led programming blinking

Leave a Comment

*
= 4 + 1

Read previous post:
voltage meter
50 MHz frequency counter, voltage meter & SWR/PWR indicator using PIC16C71

Circuit schematic PCB HEX code, V1.11 (operates with 4,000 MHz quartz) Hex code, V1.12 (operates with 4,1943 MHz quartz) PIC...

Close
Scroll to top