Hi
I am going wrong somewhere with something that i feel should be quite simple.
I have a header file called MCU_Config, In there SYS_FREQ is defined.
Code:
#ifndef _MCU_CONFIG_H
#define _MCU_CONFIG_H
#define SYS_FREQ 80000000
In another header file i want to use the definition SYS_FREQ but i get an error telling me that i have an undeclared first use for SYS_FREQ
Code:
#ifndef _DELAY_H
#define _DELAY_H
#include <xc.h>
//#define SYS_FREQ 80000000 // RUNNING AT 80MHz
/////////////////////////
// FUNCTION PROTOTYPES //
/////////////////////////
void Delay_mS(int msec); //Initialise UART1 Communication
#endif
This is the .c file where SYS_FREQ is called.
Code:
#include "Delay.h"
void Delay_mS(int msec)
{
unsigned int tWait;
tWait=(SYS_FREQ / 2000)*msec; // Calculate clock cycles required
_CP0_SET_COUNT(0); // Set Core Timer count to 0
while (_CP0_GET_COUNT()<tWait); // Wait until Core Timer count reaches the number we calculated earlier
}
If i uncomment SYS_FREQ in the header file then the program works as expected.
If i include MCU_Config.h then i get multiple errors about multiple definitions.
SYS_FREQ is used in a couple of places in my program. On 3 different UARTS Delay and probably will be used elsewhere as it develops.
I dont want to be changing all these header files should i ever change the frequency.
So is it possible to have this defined in one place and allow all files to use it?
This is my main()
Code:
// Section: Included Files
#include "MCU_Config.h"
#include "UART1_Comms.h"
#include "VT100.h"
#include "Delay.h"
#include <xc.h>
#include <stdio.h>
#include <stdbool.h>
#include <proc/p32mx575f256l.h>
#define LED1 LATBbits.LATB7
void main()
{
// Main loop while(1)
{
LED1 = 0;
Delay_mS(1000);
LED1 = 1;
Delay_mS(1000);
}
}