Home     Contact     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS     Terms of services     Privacy policy  
 Home      Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science   

PIC Tutorials - An LED Sequencer
Before reading this tutorial, make sure you have read the How to use our PIC Tutorials page!

The circuit on a breadboard.

This tutorial will demonstrate an LED sequencer. The LEDs will turn on one after another from right to left. With this tutorial you will become familiar with the bit rotate function.

In Action

The Circuit

One remark needs to be done for the above circuit. There is only one limiting resistor for all 8 LEDs. Normally this would be wrong. A limiting resistor should be added to each LED separately to ensure the same brightness for all the LEDs no matter how many are turned on. But because only one LED is turned on each time, there is no need for separated resistors.

The Code

Let's take a look at the code

; Main Program ------------------------------------------------------------
				bank1					;Go to bank 1
				movlw b'11111111'		        ;
				movwf TRISA				;Set the port pin types of the RA

				movlw b'00000000'		        ;
				movwf TRISB				;Set the port pin types of the RB
				bank0					;Go to bank 0
				bcf Carry
				call Wait500mSec
				clrf PORTB
				bsf PORTB,0				;Set RB0 output
				call Wait500mSec
				rlf PORTB,f
				call Wait500mSec
				rlf PORTB,f
				call Wait500mSec
				rlf PORTB,f
				call Wait500mSec
				rlf PORTB,f
				call Wait500mSec
				rlf PORTB,f
				call Wait500mSec
				rlf PORTB,f
				call Wait500mSec
				rlf PORTB,f
				goto MainLoop

This is a rather simple code. First, we set all the RB pins as outputs. Then the MainLoop is continuously looped. 9 steps are within this loop:

  • Step 1: The PORTB is cleared and all LEDs are turned off
  • Step 2: PORTB bit 0 is set. The first LED (RED) is turned on
  • Step 3-9: The PORTB register is rotated left (rlf) and the LEDs are turned on in sequense

When all steps are done, the loop will run again from the beginning.

Notice the 'call Wait500mSec' instruction between each step. This instruction will create a 500 mSec delay. The subroutine 'Wait500mSec' is located inside the header file 'mSecDelays4MHz.inc' that is included in the project. As always, all files needed for this project can be found at the bottom of the page.

The project Files

Following are the files for this project:

 PIC Tutorials - An LED Sequencer

Previous page ---- Next page

Go back to the book contents

Go to the discussion forum of this book




  Email (shall not be published)


Notify me of new posts via email

Write your comments below:
BEFORE you post a comment:You are welcome to comment for corrections and suggestions on this page. But if you have questions please use the forum instead to post it. Thank you.


  • At 26 October 2011, 20:14:18 user nodoubtman wrote:   [reply @ nodoubtman]
    • There full bunch of errors in the codes, i corrected the code, and compiled it, if you want the code, contact me thanks!

    No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise without the prior written permission of the author.

    Read the Disclaimer

    All trademarks used are properties of their respective owners.
    Copyright © 2007-2009 Lazaridis Giorgos.
    All rights reserved.

     HOT in heaven!

  • Disclaimer
  • Book Contents
  • Discussion forum

  • Basics
  • What will you need
  • Choosing the right PIC
  • The MPLAB
  • Getting familiar with the MPLAB environment
  • Creating a new project
  • Open and close projects
  • Creating new files and including them in the project
  • Your very first assembly program
  • Compile a program and transfer to the PIC
  • Section 1: Beginner's theory
  • Memory Organization
  • The Data Memory Organization
  • The Program Memory Organization
  • The instructions
  • General knowledge about instructions
  • Value Loading Instructions
  • Program Flow Instructions
  • Mathematic Instructions
  • Logic Function Instructions
  • Bit Orientated Instructions
  • Byte Orientated Instructions
  • Miscellaneous Instructions
  • The Basic Special Function Registers
  • The Status Register
  • The Option_Reg Register
  • The TRIS and PORT registers
  • Beginner's PIC Tutorials
  • How to use our PIC Tutorials
  • A Pushbutton turning an LED on and off
  • A Simple LED Flasher
  • Interfacing Multiple Switches - The internal Pull-Up resistors
  • An LED Sequencer
  • Interface a Single 7seg Digit
  • Interface Multiple 7seg Digits
  • A 3-digits Decimal Counter
  • A Clever Button
  • Section 2: Intermediate theory
  • Instruction Cycle Duration and Calculated Delays
  • The Timer Modules - Timer0
  • The Timer Modules - Timer1
  • The Timer Modules-Timer2

  • NEW in heaven!

    New Theory: AC electric motor working principle

     Contact     Forum     Projects     Experiments     Circuits     Theory     BLOG     PIC Tutorials     Time for Science     RSS   

    Site design: Giorgos Lazaridis
    © Copyright 2008
    Please read the Terms of services and the Privacy policy