As I understand it, using #include has the effect of loading that file into to code at that point, whereas modules are compiled separately, is that right?
Below are the definitions and prototypes as at present. I want to separate this code (plus the associated function definitions) into 4 modules. Turning the included file [1] into a .C file, and each of [2], [3] and [4]. Note that there are function calls from one section to another: for example main() makes a call to tCal() in [2], and tCal() makes a call to testBtn() in [3].
Everything I have tried causes dozens of errors, can anyone tell me what needs to go where?
Code: Select all
// mikroElektronica Libraries used: ADC, CONVERSIONS, EEPROM
#include "nokia3310.h" // I want this to be a separate .C file [1]
#include <built_in.h>
typedef unsigned short int byte;
#define ModeControl PORTB // Step = b0-b2, control = b3, Btn = b4
#define TCal_Ena ModeControl.F3 // Go to Tank Cal if b3=0
#define Btn_Key ModeControl.F4 // Button pressed if b4=0
#define FuelADC 0 // use ADC 0 for fuel sensor
#define BufSize 128 // Size of array for EEPROM storage
#define MaxEntries (BufSize - 8) // maximum number of entries in table
#define MaxStore (BufSize - 3) // EE address: max # data tabMax
#define StepStore (BufSize - 2) // EE address: step switch data gaugeStep
#define ChkStore (BufSize - 1) // EE address: checksum of table
// Global variables
byte volatile fuelLevel; // fuel level from ADC made 8 bit
byte volatile gaugeStep; // fuel step value, saved in EE StepStore
byte fuelCalTab[BufSize]; // lookup table for fuel sensor calibration
byte tabMax; // index of last entry in table, saved in EE MaxStore
char txt4[4], txt7[7]; // temporary variables to hold conversion strings
byte i, j; // misc loops
// Tank Cal Function Prototypes [2]
void tCal(void); // Calibrate Tank Gauge Step value and calibration points
void tCalModeMsg(void); // CLS, LCD line 0 = "TANK CAL SET"
void tCalBootMsg(void); // LCD line 1 = "REBOOT TO EXIT"
void tCalBtnMsg(void); // LCD line 5 = "CONTINUE BTN ?"
void tCal3Msg(void); // All 3 messages above to LCD
void tCalStMsg(void); // LCD line 4 = "STORING DATA", 1 S delay, clear line
// IO Function Prototypes [3]
byte getFuel(void); // Get ADC for fuel level as 0-255
byte testBtn(void); // Return 1 if button pressed, 100ms delay x 2
// EEPROM Function Prototypes [4]
void loadEEPROM(void); // EEPROM data GSE: fuelCalTab[], tabMax, gaugeStep
void writeEE(byte addr, byte val);// write EEPROM address with val, delay 20mS
byte readEE(byte addr); // return value at EEPROM address, delay 20mS
// Tank Cal Function Definitions
// [code snipped]
/*-----------------------------------------
Main Program
-----------------------------------------*/
void main( void )
{
// [code snipped]
}