Code:
'****************************************************************
'* Name : Formation_Engine_Running_Lights_16F88_4Mhz_Int.pbp*
'* Author : Ross A. Waddell *
'* Notice : Copyright (c) 2012 *
'* : All Rights Reserved *
'* Date : 10/29/2012 *
'* Version : 1.0 *
'* Notes : Strobe lights, nacelle lights (steady-on and *
'* Christmas flashers) and running lights for the *
'* TOS Enterprise *
'* : *
'****************************************************************
' ***************************************************************
' Pin Connections
' ***************************************************************
' RA0 -> Flashing lights for nacelle engines 1 (x2)
' RA1 -> Flashing lights for nacelle engines 2 (x2)
' RA2 -> Flashing lights for nacelle engines 3 (x2)
' RA3 -> Flashing lights for nacelle engines 4 (x2)
' RA4 -> Flashing lights for nacelle engines 5 (x2)
' RA5 -> Dummy output (MCLR is input only)
' RA6 -> Secondary hull strobe/formation lights (x2)
' RA7 -> Primary hull running lights (x4)
' RB0 -> Button for toggling running light flash mode
' RB1 -> Steady-on lights for nacelle engines (x10)
' Secondary Hull Strobes Lights
' =============================
' The two strobe locastions are:
' - Port/starboard rear secondary hull (just forward of the "1837" marking),
' horizontally inline with the shuttlebay flight deck
' The strobe light flashed at the rate of twice per second,
' or every 12 film frames. Since it's a strobe, it stays on
' for much less time than a running light; approx. .020 sec
' Nacelle engine lights
' =====================
' (a) The colours used were: red, blue, green, amber and pink, all standard colours
' they had for common Christmas lights of the time.
' (b) They were all Christmas lights (C7, too big for a 1/350).
' (c) Amber was steady (5 in a star pattern), the other 5 blinked at various rates
' Running lights
' ==============
' The running light locations on the primary hull are (4):
' - Saucer Port [top] (red) - 1
' - Saucer Starboard [top] (green) - 1
' - Saucer Port/Starboard [bottom (white) - 2
' The TOS E running lights flash at a base timing of 1-1/2 sec (36 frames) on,
' 1/2 sec (12 frames) off (FlashMode = 0)
' Alternate is 1/2 sec on, 1.5 sec off (reverse of above). (FlashMode = 1)
' In "The Corbomite Maneuver", the lights were on for 18 frames and off for 20
' (FlashMode = 2)
' >> These modes are available via a momentary button
DEFINE OSC 4 ; Set oscillator 4Mhz
DEFINE BLINKYFREQ 100 ; 10mS periods
' ***************************************************************
' Device Fuses
' ***************************************************************
' PIC chip data sheets can be found here: C:\Program Files\Microchip\MPASM Suite
#CONFIG
__config _CONFIG1, _FOSC_INTOSCIO & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _LVP_OFF
#ENDCONFIG
' ***************************************************************
' Initialization
' ***************************************************************
OSCCON = %01100000 ; 4MHz internal osc
ANSEL = 0 ; PIC16F88 only
TRISA = 0 ; PORTA all output
TRISB = %00000001 ; Make PORTB pin 0 input for flash mode button
LEDcount CON 8 ; Number of blinking LEDs on PORTA
' BL1,BL2,BL3,BL4,BL5,MCLR,STB
OnTimes DATA 50 ,22 ,38 ,75 ,17 ,2 ,2 ; default "on" periods for each output
OffTimes DATA 150 ,45 ,38 ,95 ,117,2 ,48 ; default "off" periods for each output
; (Strobe flashes 2 times per second
; or every 500ms; subtract "on" time)
' Running lights will be handled slightly differently
' FlashMode Values
' ================
' 0 = 1-1/2 sec (36 frames) on, 1/2 sec (12 frames) off (Trek Ace, HobbyTalk)
' 1 = 1/2 sec (12 frames) on, 1-1/2 sec (36 frames) off (Master Replica model)
' 2 = 3/4 sec (18 frames) on, 5/6 sec (20 frames) off ("The Corbomite Maneuver")
FlashMode_Default CON 0
EE_FlashMode DATA FlashMode_Default
FlashMode VAR BYTE
READ EE_FlashMode, FlashMode
;----------------------------------------------------------------
#DEFINE USE_RANDOM_SEQUENCE ; comment for contiuous Sequence
#IFDEF USE_RANDOM_SEQUENCE ; randomization used for BL1-5 only
RND VAR WORD : RND = 13864
MIN_ON CON 15 ; Minimum random ON time
MAX_ON CON 115 ; Maximum random ON time
MIN_OFF CON 15 ; Minimum random OFF time
MAX_OFF CON 200 ; Maximum random OFF time
RandPeriod VAR WORD[LEDcount-3]
RandPeriods DATA WORD 1000, WORD 1250, WORD 1500, WORD 1750, WORD 2000
#ENDIF
CCPR1val CON EXT : @CCPR1val = (OSC*1000000/4)/ BLINKYFREQ
;CCPR1 VAR WORD EXT : @CCPR1 = CCPR1L
Timer1 VAR WORD EXT : @Timer1 = TMR1L
CCPIF VAR PIR1.2
LoopLED VAR BYTE[LEDcount]
OnTime VAR BYTE[LEDcount]
OffTime VAR BYTE[LEDcount]
x VAR BYTE
LED_STDY_ON VAR PORTB.1 ; Alias PORTB.1 as "LED_STDY_ON"
;Old_FlashMode VAR BYTE
PRI_HULL_LGHTS_ON_MS VAR BYTE
PRI_HULL_LGHTS_OFF_MS VAR BYTE
;----[Initialize on/off periods & random sequencing (if enabled)]---------------
; (only set up first 7 blinkies; the 8th [running lights] is separate)
FOR x = 0 to (LEDcount - 2) ; Load the periods from EEPROM
READ OnTimes+x, OnTime(x)
READ OffTimes+x, OffTime(x)
#IFDEF USE_RANDOM_SEQUENCE
IF x < 5 THEN
READ RandPeriods+(x<<1), WORD RandPeriod(x)
ENDIF
#ENDIF
NEXT X
GOSUB SetFlashRates ; Set up flash rates based on saved "FlashMode" val
;-- setup CCP1 and Start Timer1 --
CCPR1 = CCPR1val ; set compare value
CCP1CON = %00001011 ; compare mode, special event
Timer1 = 0 ; clear Timer1
T1CON.0 = 1 ; start Timer1
HIGH LED_STDY_ON ; Turn on steady-on LEDs
;----[Main Program Loop]----------------------------------------
Main:
x = (x + 1) // LEDcount
PORTA.0(x) = !!(LoopLED(x) < OnTime(x))
LoopLED(x) = (LoopLED(x) + 1) // (OnTime(x) + OffTime(x))
#IFDEF USE_RANDOM_SEQUENCE
IF x < 5 THEN
RandPeriod(x) = RandPeriod(x) - 1
IF RandPeriod(x) = 0 THEN
READ RandPeriods+(x<<1), WORD RandPeriod(x)
RANDOM RND
OnTime(x) = (MAX_ON - MIN_ON)* RND.HighByte / 255 + MIN_ON
OffTime(x)= (MAX_OFF - MIN_OFF)* RND.LowByte / 255 + MIN_OFF
ENDIF
ENDIF
#ENDIF
IF x != (LEDcount - 1) THEN Main
Waiting: IF !CCPIF THEN Waiting
CCPIF = 0
GOTO Main
SetFlashRates:
If FlashMode = 0 Then
PRI_HULL_LGHTS_ON_MS = 150
PRI_HULL_LGHTS_OFF_MS = 50
ElseIf FlashMode = 1 Then
PRI_HULL_LGHTS_ON_MS = 50
PRI_HULL_LGHTS_OFF_MS = 150
Else
PRI_HULL_LGHTS_ON_MS = 75
PRI_HULL_LGHTS_OFF_MS = 83
EndIf
OnTime(8) = PRI_HULL_LGHTS_ON_MS
OffTime(8) = PRI_HULL_LGHTS_OFF_MS
RETURN
END
What am I doing wrong? In case anyone is wondering, I only want to randomize RA0-4 flash rates. Also, RA5 (MCLR) is input only so I had to make that a dummy output pin.
Bookmarks