PDA

View Full Version : How to Figure Out Compile Errors?



RossWaddell
- 24th February 2013, 22:18
I'm trying to port over code from a 12F683 to a 16F687 from this (http://www.picbasic.co.uk/forum/showthread.php?t=17299) thread but I get the dreaded 'syntax error' and it highlights the 'CCP1CON = %00001011' line. How do I figure out what's really going on? I know this chip has the CCP1CON register and the '1011' is supposed to set the compare mode, special event trigger.



DEFINE OSC 20 ; Set oscillator 20Mhz

#CONFIG
__config _FOSC_HS & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF
#ENDCONFIG

' ************************************************** *************
' Initialization
' ************************************************** *************

ANSEL = 0
TRISA = %00000100 ; Make PORTA all output except for INT pin
TRISB = 0 ; Make all PORTB pins output
TRISC = 0 ; Make all PORTC pins output

CCPR1val CON EXT : @CCPR1val = (OSC*1000000/4)/ BLINKYFREQ
CCPR1 VAR WORD EXT : @CCPR1 = CCPR1L
Timer1 VAR WORD EXT : @Timer1 = TMR1L
CCPIF VAR PIR1.2

;-- 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:
HIGH PORTB.0
pause 1000
LOW PORTB.0
pause 1000

goto Main

Darrel Taylor
- 25th February 2013, 03:22
... I know this chip has the CCP1CON register ...

The 16F687 doesn't have a CCP module.
Therefore, no CCP1CON.

RossWaddell
- 25th February 2013, 03:29
I downloaded the datasheet before ordering it, and it mentions the CCP1CON register - does that only apply to one of the other chips in the shared PIC16F631/677/685/687/689/690 data sheet?

Can anyone think of another chip that has a CCP module, USART and 8 output pins on a PORTA/B/C which doesn't have the CCP/Rx pin?

HenrikOlsson
- 25th February 2013, 06:19
Hi,
If you look at page 2 of the datasheet you'll find the following table:
6853
There you'll see that the 16F687 doesn't have the ECCP module. I'm not sure exactly what you're trying to do but if you want 8 outputs can't you split them across two ports? Say PortB.0-3 and PortC.0-3 of the 16F690 (same datasheet), RX is on PortB.4 and the CCP1 on PortC.5 so both of those are avoided.

Finally, in the code in your first post I don't see BLINKYFREQ being defined anywhere.

/Henrik.

RossWaddell
- 25th February 2013, 13:30
Datasheet's with combined PICs drive me nuts, but in most cases I've seen so far it's usually just 2 PICs; this is the first time I've run across one which has 6 and only some have ECCP modules (I think the 16F690 has it, which may be why a search through the datasheet comes up with 'CCP1CON'.

I trimmed the code to test and left out the definition of BLINKYFREQ - even with it back in, though, it still doesn't compile (same reason).

For the 8 pins together, its because of this cool code from Darrel:



;----[Main Program Loop]----------------------------------------
Main:
' Check if flash mode has changed
IF FlashMode <> Old_FlashMode Then
Old_FlashMode = FlashMode
GOSUB SetNavLtsFlashRates
EndIF

x = (x + 1) // LEDcount
PORTB.1(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


In this example, it's offset by 1 since PORTB.0 is the INT pin which is being used to detect a button push.

HenrikOlsson
- 25th February 2013, 17:42
Hi,
Yes, the table shows the 16F690 having both an ECCP module and an USART. Unfortunately they won't leave you with unrestriced access to PortB.

If, instead of doing the indexed bit operation ( PortB.1(x) etc ) on the PortB or any other Port, you do them on a BYTE variable (like myLEDS or whatever) you can then, as a final task in the loop take the value of that BYTE variable and split it across two ports. Write the four low bits to PortB.0-3 and the four high bits to PortC.0-3. Not saying that I'm sure it will work, Darrel may be using one of his tricks, but I think it might. Perhaps its worth a try.

/Henrik.

RossWaddell
- 25th February 2013, 18:01
I was going to use PORTC on the 16F690.

HenrikOlsson
- 25th February 2013, 18:31
Hmm, then I'm not following, which doesn't really matter as long as you get what you need but in a previous post you wrote

Can anyone think of another chip that has a CCP module, USART and 8 output pins on a PORTA/B/C which doesn't have the CCP/Rx pin?
On the 16F690 the RX-pin is on PortB.5 and the CCP1 pin on PortC.5. I thought you were using those pins for their peripheral functions therfore not allowing 8 consecutive bits on either of those two ports - but I've must have misunderstood.

/Henrik.

RossWaddell
- 25th February 2013, 18:54
Sorry for not being clear, Henrik. For the current iteration of the code on a PIC16F88 I'm using PORTB.1-7 (since PORTB.0 is the INT pin which I have hooked up to a button switch) where the CCP1 pin is PORTB.3 but it doesn't matter as I'm only using the compare module, not the capture or PWM.