MIBAM2

Here's another quick example that simulates a Cylon or Kitt car scanner.

It's running on a 16F887 with 8Mhz internal OSC. The PCB is the Microchip 44-pin Demo Board that comes with the PICkit2 Debug Express package.

It's not too bad with 8 LEDs, but 16 would be better. The sequence will automatically use however many LEDs you define.

By adjusting the constants, you can make it look like most of the different seasons of the shows. (Excluding the New "Knight Rider" 2009). 2009 can be done too, but it'll take a little modification.

Youtube Video

The main difference is in the way the Duytcycle variables are declared. By grouping them in an Array, they can be used with FOR loops to control all the LEDs, instead of having to access each one individually like the RGB's.

;----[ MIBAM Setup ]--------------------------------------------------------
BAM_COUNT CON 8                     ; How many BAM Pins are used?
INCLUDE "MIBAM.pbp"                 ; Mirror Image BAM module


BAM_DUTY  VAR BYTE[BAM_COUNT]
  LED1    VAR BAM_DUTY[0]           ; group them in an array for easy access
  LED2    VAR BAM_DUTY[1]           ; with FOR loops etc.
  LED3    VAR BAM_DUTY[2] 
  LED4    VAR BAM_DUTY[3] 
  LED5    VAR BAM_DUTY[4] 
  LED6    VAR BAM_DUTY[5] 
  LED7    VAR BAM_DUTY[6] 
  LED8    VAR BAM_DUTY[7] 


ASM
BAM_LIST  macro                     ; Define PIN's to use for BAM
     BAM_PIN (PORTD,0, LED1)        ;   and the associated Duty variables
     BAM_PIN (PORTD,1, LED2)
     BAM_PIN (PORTD,2, LED3)
     BAM_PIN (PORTD,3, LED4)
     BAM_PIN (PORTD,4, LED5)
     BAM_PIN (PORTD,5, LED6)
     BAM_PIN (PORTD,6, LED7)
     BAM_PIN (PORTD,7, LED8)
  endm
  BAM_INIT  BAM_LIST                ; Initialize the Pins
ENDASM

Then with all the dutycycles in the array, you can do something like this.

Speed       CON 6         ; Smaller=Faster
TracerSpeed CON 15        ; Smaller=Faster Left/Right
Brightness  CON 200       ; Tracers DutyCycle
DrainSpeed  CON 30        ; Smaller=Shorter Trail


Idx         VAR BYTE
LoopCount   VAR BYTE
NextLED     VAR BYTE
TraceDIR    VAR BIT


  TraceDIR  = 0
  LoopCount = 0
  NextLED   = 0

Main:
    if LoopCount = TracerSpeed then             ; __[ Cylon/Kitt Scanner ]__
      LoopCount = 0
      BAM_DUTY(NextLED)=Brightness
      if TraceDIR then                          ; if scanning left
        NextLED = NextLED - 1
        if NextLED = 0 then TraceDIR = 0
      else                                      ; else scanning right
        NextLED = NextLED + 1
        if NextLED = BAM_COUNT-1 then TraceDIR = 1
      endif
    endif

    FOR Idx = 0 to BAM_COUNT - 1                ; Drain all dutycycles
       IF BAM_DUTY(Idx) > 0 then
           BAM_DUTY(Idx)=BAM_DUTY(Idx)*DrainSpeed/(DrainSpeed+1)
       ENDIF
    NEXT Idx
    pause Speed
    LoopCount = LoopCount + 1
GOTO Main

Attached is the full code and HEX file for the 887 on the Demo Board.

MIBAM_Cyclon.zip

Page last modified on March 03, 2018, at 12:53 AM