Author Topic: Error While Trying To Compile Code  (Read 5453 times)

0 Members and 1 Guest are viewing this topic.

Offline Lance

  • Frequent Contributor
  • **
  • Posts: 312
  • Resistance if futile if R<1Ohm
Error While Trying To Compile Code
« on: February 12, 2011, 06:54:16 am »
I'm trying to write a program for a PIC16F917. Everything was going good, until I got this error message:

Code: [Select]
Error   [285] C:\Program Files\HI-TECH Software\PICC\9.81\include\pic16f917.h; 111.14 no identifier in declaration
Error   [314] C:\Program Files\HI-TECH Software\PICC\9.81\include\pic16f917.h; 111.14 ";" expected

********** Build failed! **********

I looked at the header in question and couldn't find any errors in it.

Code: [Select]
// Register: STATUS
volatile unsigned char           STATUS              @ 0x003;
// bit and bitfield definitions
volatile bit CARRY               @ ((unsigned)&STATUS*8)+0;
volatile bit DC                  @ ((unsigned)&STATUS*8)+1;
volatile bit ZERO                @ ((unsigned)&STATUS*8)+2; <---This is the line the error occurs on.
volatile bit nPD                 @ ((unsigned)&STATUS*8)+3;
volatile bit nTO                 @ ((unsigned)&STATUS*8)+4;
volatile bit IRP                 @ ((unsigned)&STATUS*8)+7;
volatile bit RP0                 @ ((unsigned)&STATUS*8)+5;
volatile bit RP1                 @ ((unsigned)&STATUS*8)+6;

Does anyone know where this is coming from?
« Last Edit: February 12, 2011, 07:09:20 am by Lance »
#include "main.h"
#include <pic.h>
//#include <killallhumans.h>
 

Offline adam1213

  • Regular Contributor
  • *
  • Posts: 120
  • Country: au
Re: Error While Trying To Compile Code
« Reply #1 on: February 12, 2011, 07:15:04 am »
try commenting out where you include that file and check if any of the errors that you get are not related to that file.
edit after original post modified: Maybe "ZERO" is being used for something else
« Last Edit: February 12, 2011, 07:17:01 am by adam1213 »
 

Offline Lance

  • Frequent Contributor
  • **
  • Posts: 312
  • Resistance if futile if R<1Ohm
Re: Error While Trying To Compile Code
« Reply #2 on: February 12, 2011, 07:26:49 am »
That did it. This is a section from main.h

Code: [Select]
/* Numbers */
//#define ZERO   0x00
#define ONE    0x01
#define TWO    0x02
#define THREE  0x03
#define FOUR   0x04
#define FIVE   0x05
#define SIX    0x06
#define SEVEN  0x07
#define EIGHT  0x08
#define NINE   0x09
So I guess zero was already being used. Looks like I need to find something else to use for that definition.

Now to figure out why the device refuses to do anything. This is the first program I've compiled using the Hi-Tech C compiler. The one I used at school vastly simplifies things, which makes it somewhat useless.
« Last Edit: February 12, 2011, 07:29:09 am by Lance »
#include "main.h"
#include <pic.h>
//#include <killallhumans.h>
 

Offline adam1213

  • Regular Contributor
  • *
  • Posts: 120
  • Country: au
Re: Error While Trying To Compile Code
« Reply #3 on: February 12, 2011, 09:59:16 am »
is there a reason that you are using defines for numbers?
 - normally defines are used instead of a number to make the code easier to read and maintain eg "#define BLINK_FREQUENCY 1" However something like "#define ONE 0x01" doesn't achieve this.

Also I am curious about why you are using "0x" before the numbers - try defining 10 then using it and check if you get the result you expect.
 

Offline jinuq

  • Contributor
  • Posts: 18
Re: Error While Trying To Compile Code
« Reply #4 on: February 12, 2011, 07:24:42 pm »
0x is used for hexadecimal notation in C.

In his use it would be unnecessary. 0x10 and 10 are different numbers.
 

Alex

  • Guest
Re: Error While Trying To Compile Code
« Reply #5 on: February 12, 2011, 08:09:03 pm »
In MPLAB PIC assembly, you can use the radix directive to set the default number format. Eg radix decimal will tell MPLAB that MOVLW 10 means move the number 10 to W reg. You can make hex numbers default, radix hexadecimal or radix hex, just try to see which one is accepted.
 

Offline Lance

  • Frequent Contributor
  • **
  • Posts: 312
  • Resistance if futile if R<1Ohm
Re: Error While Trying To Compile Code
« Reply #6 on: February 13, 2011, 12:06:15 am »
I can't get this thing to do anything useful. I tried having some LEDs toggle with the following code.
I'm using a PIC16F917
Code: [Select]
void main(void)

{

unsigned int i = 0;



Initialize(); //Initialize Processor



while(1)

{

RD7=!RD7;

RD6=!RD7;

RD5=!RD6;

RD4=!RD5;

for(i=0;i<255;i++)

{

}

for(i=0;i<255;i++)

{

}



}

}

Just messing around with the port settings I can control whether or not a LED is on, but I can't actually make the controller actively do anything.

Here is a section from my header that sets the registers, I haven't gotten around to setting all of them yet.
Code: [Select]
/******************************************************************************

Register Definitions

******************************************************************************/

/*******************************

System Registers

*******************************/

/* STATUS Register */

#define STATUS_Init (0b00011000)



/* OPTION_REG Register */

#define OPTION_REG_Init (0b1100000)



/* INTCON Register */

//INTERRUPT CONTROL

#define INTCON_Init (0b10100000)



/* PIE1 Register */

//PERIPHERAL INTERRUPT ENABLE

#define PIE1_Init (0b00000000)



/* PIE2 Register */

//PERIPHERAL INTERRUPT ENABLE

#define PIE2_Init (0b00000000)



/* PIR1 Register */

//PERIPHERAL INTERRUPT REQUEST

#define PIR1_Init (0b00000000)



/* PIR2 Register */

//PERIPHERAL INTERRUPT REQUEST

#define PIR2_Init (0b00000000)



/* PCON Register */

//POWER CONTROL

#define PCON_Init (0b00000011)





/*******************************

Port Registers

*******************************/

//PORTS DEFINED IN pic16f91x.h or pic16F917.h

//FOR THE LOVE OF KHALESS! DON'T MESS WITH THAT FILE!

//IT WILL BREAK EVERYTHING!!!!!!!!!!

/* PORTA */

#define PORTA_Init 0x00 //Initializes ports to 0

#define TRISA_Init (0b00000000) //Input=1 Output=0


/* PORTB */

#define PORTB_Init 0x00 //Initializes ports to 0

#define TRISB_Init (0b00000000) //Input=1 Output=0


/* PORTC */

#define PORTC_Init 0x00 //Initializes ports to 0

#define TRISC_Init (0b00000000) //Input=1 Output=0


/* PORTD */

#define PORTD_Init 0x00 //Initializes ports to 0

#define TRISD_Init (0b00000000) //Input=1 Output=0


/* PORTE */

#define PORTE_Init 0x00 //Initializes ports to 0

#define TRISE_Init (0b00000000) //Input=1 Output=0


/* ANSEL Register */

//Defines Digital/Analog I/O

//If enabled digital inputs from port will read zero

//If TRIS for port clear will function as digital output

#define ANSEL_Init (0b00000000) //Sets Input Mode Analog/Digital

//1=Analog I/O 0=Digital I/O



/*******************************

Oscillator Module Registers

*******************************/

/* OSCCON Register */

#define OSCCON_Init (0b01110111)



/* OSCTUNE Register */

#define OSCTUNE_Init (0b00011111)



/*******************************

Timer0 Module Registers

*******************************/

/* TMR0 Register */

#define TMR0_Init (0b00000000)



/*******************************

Timer1 Module Registers

*******************************/

/* T1CON Register */

#define T1CON_Init (0b10000000)



/*******************************

Timer2 Module Registers

*******************************/

/* T2CON Register */

#define T2CON_Init (0b00000000)



/*******************************

Comparitor Module Registers

*******************************/

/* CMCON0 Register */



/* CMCON1 Register */



/* VRCON Register */



/*******************************

AUSART Module Registers

*******************************/

//ADDRESSABLE UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER



/*******************************

LCD Driver Module Registers

*******************************/





/*******************************

PLVD Module Registers

*******************************/

//PROGRAMMABLE LOW-VOLTAGE DETECT



/*******************************

ADC Module Registers

*******************************/



/* Analog Input Channels */

/*

#define ADC0

#define ADC1

#define ADC2

#define ADC3

#define ADC4

#define ADC5

#define ADC6

#define ADC7

*/



/* A/D Convertor Input Channels */

/* Shift Channel numbers by 3 for addition to ADCON0 Register */

/*

#define ADC_0 (0 << 3)

#define ADC_1 (1 << 3)

#define ADC_2 (2 << 3)

#define ADC_3 (3 << 3)

#define ADC_4 (4 << 3)

#define ADC_5 (5 << 3)

#define ADC_6 (6 << 3)

#define ADC_7 (7 << 3)

*/





/* ADCON0 Register */

#define ADCON0_Init (0b00000000)





/* ADCON1 Register */

#define ADCON1_Init (0b00000000)



/*******************************

Data EEPROM and Flash Program Memory Control Module Registers

*******************************/

//Electrically Erasable Programmable Read-Only Memory



/*******************************

SSP Module Registers

*******************************/

//Synchronous Serial Port



/*******************************

CCP Module Registers

*******************************/

//CAPTURE/COMPARE/PWM

There's some stuff in there that's commented out.
« Last Edit: February 13, 2011, 12:11:37 am by Lance »
#include "main.h"
#include <pic.h>
//#include <killallhumans.h>
 

Offline adam1213

  • Regular Contributor
  • *
  • Posts: 120
  • Country: au
Re: Error While Trying To Compile Code
« Reply #7 on: February 13, 2011, 01:45:16 am »
I am guessing that you are trying to make the leds blink but they might not be blinking.

the microcontroller might be running too quickly for you to see the leds blink.
- also the compiler might optimise out your loop. You can normally prevent this by either not optimising the code / having something like "volatile unsigned int i"

try to measure the time between blinks (with an oscilloscope / frequency counter / simulator) then try to increase it to a point where you can see the led blink.
 

Alex

  • Guest
Re: Error While Trying To Compile Code
« Reply #8 on: February 13, 2011, 01:53:21 am »
Is your MCU even running? Lets take a step back. Can you put your MCU on a breadboard, connect an LED anywhere on port D  (anode to pin) with a 180 Ohm resistor, hook up a 4-10MHz crystal with the appropriate capacitors, connect your 5V.

Over to MPLAB. Go over to Configure>select device and select your pic. Then Configure>Config bits and make sure your oscillator is set to XT, the watchdog timer disabled, power up timer On, MCLR pin internal, code protect off, data protect off, BOD all disabled, last two disabled.

Now try this:

#include   <p16f917.h>

void main(void)

{

LATD = 0xFF;
TRISD = 0x00;

while(1){;}

}

This will just turn on the LED but it will mean you MCU is working and executes instructions. I have to say that this is an example for C18, I have not used HI-TECH C for way too long. If it does not compile, try to get it to compile and check for functionality.

If you reach a dead-end ping us back. I will setup HT C here, I think I have the DOS version  :D
« Last Edit: February 13, 2011, 01:58:14 am by Alex »
 

Offline adam1213

  • Regular Contributor
  • *
  • Posts: 120
  • Country: au
Re: Error While Trying To Compile Code
« Reply #9 on: February 13, 2011, 02:25:40 am »
assuming that the program is able to set the led to appear always on / always off the microcontroller is likely running... - also the PIC16F917 has an internal oscillator

assuming OSCCON_Init is used with the value 0b01110111 then the mcu is likely its internal oscillator and running at 8 Mhz
 

Offline Lance

  • Frequent Contributor
  • **
  • Posts: 312
  • Resistance if futile if R<1Ohm
Re: Error While Trying To Compile Code
« Reply #10 on: February 13, 2011, 02:50:10 am »
assuming that the program is able to set the led to appear always on / always off the microcontroller is likely running... - also the PIC16F917 has an internal oscillator

assuming OSCCON_Init is used with the value 0b01110111 then the mcu is likely its internal oscillator and running at 8 Mhz
That's what I was trying to use. According to the documentation it should be running at 32Mhz
« Last Edit: February 13, 2011, 02:52:45 am by Lance »
#include "main.h"
#include <pic.h>
//#include <killallhumans.h>
 

Offline adam1213

  • Regular Contributor
  • *
  • Posts: 120
  • Country: au
Re: Error While Trying To Compile Code
« Reply #11 on: February 13, 2011, 03:44:03 am »
assuming that the program is able to set the led to appear always on / always off the microcontroller is likely running... - also the PIC16F917 has an internal oscillator

assuming OSCCON_Init is used with the value 0b01110111 then the mcu is likely its internal oscillator and running at 8 Mhz
That's what I was trying to use. According to the documentation it should be running at 32Mhz


according to the datasheet the fastest oscillator frequency is 20Mhz for the PIC16F917.

Without seeing the code I can't tell if you are actually setting the oscillator settings.
- I suggest you change "#define INTCON_Init (0b10100000)" to "#define INTCON_Init (0b00000000)" to avoid interrupts being enabled (specifically INTCON.GIE) at least until you actually want to use interrupts. Interrupts can cause unexpected behaviour unless implemented correctly.


Currently I assume that your program is probably making the leds flash but at a speed too fast for you to see.
- try making the LEDs continually display the state of a pin. set the pin to be an input then try connect the pin to low (ground) / high (vdd).
 

Offline Lance

  • Frequent Contributor
  • **
  • Posts: 312
  • Resistance if futile if R<1Ohm
Re: Error While Trying To Compile Code
« Reply #12 on: February 13, 2011, 05:34:44 am »
That was it. I made the delay much longer and it's working fine. Now to figure out the other modules. Thanks for the help everyone.
#include "main.h"
#include <pic.h>
//#include <killallhumans.h>
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf