"PORTING C" > How to assign a value to a define statement?
Hello,
This question is geared more towards seeking a voice of programming
experience.
I am running into a situation where I need some advice on how to do things.
Perhaps I am seeing this the wrong way. In summary, from main(), I would like
to call a defined macro called "Config_delay_timers", and in that macro I
would like to do some calculations where the result can be assigned to the
value of another #define statement.
Please view the following code:
==========================main.h
#ifndef TEST_H
#define TEST_H
// *** SYSTEM OSCILLATION *** //
#define Config_delay_timers(extCrys, fpllidiv, fpllmul, fpllodiv) \
FREQ = (((float)(extCrys/fpllidiv)*(float)(fpllmul/fpllodiv))*1000000)
#define CURR_SYS_OSC FREQ
#define OSC_PERIOD (1.0/CURR_SYS_OSC)
#endif // TEST_H //
=====================================main.c
#include <stdio.h>
#include "test.h"
int main()
{
Config_delay_timers(8, 2, 21, 8);
//SYSTEMConfig(CURR_SYS_OSC, SYS_CFG_ALL);
return 0;
}
===================================
I am getting an error where the compiler complains about FREQ is undefclared.
So how is one supposed to carry out a particular calculation via a define
macro and then further assign this result to other define variables in the
program.
I am thinking of mayby using #ifdef preprocessor command but I don't see how
this would be of any use in this particular case.
All help or reccomendations is very welcome and apprciated. Thanks in advance!
--
Best regards
Roberto