Code:
'****************************************************************
'* Name : Nacelle_Blinking_Lights_12F683_8Mhz_Int.pbp *
'* Author : Ross A. Waddell *
'* Notice : Copyright (c) 2014 *
'* : All Rights Reserved *
'* Date : 03/25/2014 *
'* Version : 2.0 *
'* Notes : Blinking nacelle engine lights (TOS Enterprise) *
'* : *
'****************************************************************
' 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). 12 by my guess.
' (c) Amber was steady (5 in a star pattern), all the rest blinked.
' For production version of this code, update config fuses to
' enable code protect (CP_ON)
' Basic blinky code provided by Darrel Taylor
' See forum posting here:
' http://www.picbasic.co.uk/forum/showthread.php?t=17299&p=116934#post116934
' ***************************************************************
' Pin Connections
' ***************************************************************
' GP5 -> pin 2 -> R4 -> BL4
' GP4 -> pin 3 -> R5 -> BL5
' GP3 -> pin 4 -> MCLR (input only, 'dummy' BL6)
' GP2 -> pin 5 -> R1 -> BL1
' GP1 -> pin 6 -> R2 -> BL2
' GP0 -> pin 7 -> R3 -> BL3
' ***************************************************************
' Initialization
' ***************************************************************
#CONFIG
__config _INTOSCIO & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOD_ON & _IESO_OFF & _FCMEN_OFF
#ENDCONFIG
DEFINE OSC 8
OSCCON = %01110000 ; 8MHz internal osc
ANSEL = 0 ; All Digital
CMCON0 = 7
TRISIO = 0 ; all OUTPUT
OPTION_REG = %00000110 ; Timer0 prescaler 1:128
TMR0IF VAR INTCON.2 ; Timer0 Overflow bit
;----[ MIBAM Setup ]--------------------------------------------------------
wsave var byte $70 SYSTEM ' Alternate save location for W
ssave VAR BYTE BANK0 SYSTEM ' location for STATUS register
psave VAR BYTE BANK0 SYSTEM ' location for PCLATH register
BAM_COUNT CON 5 ; How many BAM Pins are used?
;DEFINE BAM_INFO 1
INCLUDE "MIBAM.pbp" ; Mirror Image BAM module
Bright VAR BYTE[BAM_COUNT]
Br0 VAR Bright[0]
Br1 VAR Bright[1]
Br2 VAR Bright[2]
Br4 VAR Bright[3]
Br5 VAR Bright[4]
ASM
BAM_LIST macro ; Define PIN's to use for BAM
BAM_PIN (GPIO,0, Br0) ; and the associated Duty variables
BAM_PIN (GPIO,1, Br1)
BAM_PIN (GPIO,2, Br2)
BAM_PIN (GPIO,4, Br4)
BAM_PIN (GPIO,5, Br5)
endm
BAM_INIT BAM_LIST ; Initialize the Pins
ENDASM
;----[Setup Blinky parameters]-----------------------------------
DEFINE BLINKYFREQ 100 ; 10mS periods
LEDcount CON 5 ; Number of LEDs on the PORT
; BL3,BL2,BL1,BL5,BL4 ; PCB indicators
OnTimes DATA 50, 22, 38, 75, 5 ; default periods for each Output
OffTimes DATA 150, 45, 38, 95, 34
Brightness DATA 255,10,10, 10, 255
#DEFINE USE_RANDOM_SEQUENCE ; comment for contiuous Sequence
#IFDEF USE_RANDOM_SEQUENCE
RND VAR WORD : RND = 13864
MIN_ON CON 50 ; Minimum random ON time
MAX_ON CON 500 ; Maximum random ON time
MIN_OFF CON 50 ; Minimum random OFF time
MAX_OFF CON 500 ; Maximum random OFF time
RandPeriod VAR WORD[LEDcount]
RandPeriods DATA WORD 1000, WORD 1250, WORD 1500, WORD 1750, WORD 2000
#ENDIF
;----[Variables used only by Blinky]-----------------------------
LoopLED VAR WORD[LEDcount]
OnTime VAR WORD[LEDcount]
OffTime VAR WORD[LEDcount]
x VAR BYTE
;----[Initialize]------------------------------------------------
FOR x = 0 to LEDcount - 1 ; load the periods from EEPROM
READ OnTimes+x, OnTime(x)
READ OffTimes+x, OffTime(x)
#IFDEF USE_RANDOM_SEQUENCE
READ RandPeriods+(x<<1), WORD RandPeriod(x)
#ENDIF
NEXT X
;----[Main Program Loop]----------------------------------------
Main:
x = (x + 1) // LEDcount
IF LoopLED(x) < OnTime(x) THEN
READ Brightness + x, Bright(x)
ELSE
Bright(x) = 0
ENDIF
LoopLED(x) = (LoopLED(x) + 1) // (OnTime(x) + OffTime(x))
#IFDEF USE_RANDOM_SEQUENCE
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
IF x != (LEDcount - 1) THEN Main
Waiting: IF !TMR0IF THEN Waiting
TMR0 = 99
TMR0IF = 0
GOTO Main
Bookmarks