(Reviving an old thread)
I now need to simplify this a bit and put this on a 8-pin PIC. I need 5 blinkies so I'd like to use a 12F629 (knowing GP3/MCLR is input only, I'll use GP0-GP5 and if nothing happens on GP3 then that's fine).
The code won't compile because of this part:
Code:
;-- 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
These registers exist on a 16F690 (and others) but not 12F629. I had earlier tried a 12F683 (my go-to PIC) but the .inc file for it already has a define for CCPR1 so I'd have to comment out that line in the .inc file but that makes me a wee bit uncomfortable.
Is there a way to make this work on a 12F690 or 12F683? If not, is there another 8-pin PIC I could use? I need to be able to find SMT packages as the space where the PCB is going is extremely tight (I've never soldered SMTs before so that should be fun).
Here's the whole code:
Code:
'****************************************************************
'* Name : Nacelle_Blinking_Lights_5_12F629_4Mhz_Int.pbp *
'* Author : Ross A. Waddell *
'****************************************************************
' For production version of this code, update config fuses to
' enable code protect 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
' ***************************************************************
DEFINE OSC 4 ' Set oscillator 4Mhz
DEFINE BLINKYFREQ 100 ' 10mS periods
CMCON = %0000111 'Turn off comparators
TRISIO = %00000000 'Make all GPIO pins output
' ***************************************************************
' Device Fuses
' ***************************************************************
' PIC chip data sheets can be found here: C:\Program Files\Microchip\MPASM Suite
#CONFIG
__config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON & _CP_OFF & _CPD_OFF
#ENDCONFIG
LEDcount CON 6 ; Number of blinking LEDs
; (includes 'fummy' LED on GP3/MCLR pin,
; rates defined separately below)
' BL3,BL2,BL1,BL6,BL5,BL4
' --- --- --- --- --- ---
' default "on" periods for each output
OnTimes DATA 50 ,82 ,50 ,33 ,133, 2
' default "off" periods for each output
OffTimes DATA 150 ,45 ,50 ,33 ,22 ,48
;----------------------------------------------------------------
#DEFINE USE_RANDOM_SEQUENCE ; comment for contiuous Sequence
#IFDEF USE_RANDOM_SEQUENCE
RND VAR WORD : RND = 13864
MIN_ON CON 33 ; Minimum random ON time
MAX_ON CON 100 ; Maximum random ON time
MIN_OFF CON 33 ; Minimum random OFF time
MAX_OFF CON 100 ; Maximum random OFF time
RandPeriod VAR WORD[LEDcount]
RandPeriods DATA WORD 1000, WORD 1250, WORD 1500, WORD 500, WORD 2000, 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
' ***************************************************************
;----[Initialize on/off periods & random sequencing (if enabled)]---------------
FOR x = 0 to (LEDcount) ; 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
;-- 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
Main:
x = (x + 1) // LEDcount
GPIO.0(x) = !!(LoopLED(x) < OnTime(x))
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 !CCPIF THEN Waiting
CCPIF = 0
GOTO Main
Bookmarks