Wednesday 6 April 2016

pic - c18 coding advice / braces error / function declaration help


I have almost NO experience coding so please excuse the crude style and verbose commenting. I am trying to sample from 4 sensors (1 every 15 minutes). I thought it would be more efficient to have the delay and data_write functions as separate functions to call but that's just not working out very well. I consistently get the following error:




Error [1302] old style function declarations not supported



at the end of the data_write function no matter where or how I put the braces (nested, same line, eliminate, etc.) delay function doesn't give the error whether it's before or after the data_write function.


Please feel free to recommend a better layout for me. Also, I really don't have any understanding of the data memory so this routine is probably crap, I know. It's strangely not giving me any errors though so I'll not look that gift horse in the mouth just yet.


=====================================


    #include 
#include
#include
#include
#include


int result; // used in ADC result handling
int i; // used in delay loop/function
int data_adr=0x64; // used in data_write function. initial=d100

// assuming 4MHz oscillator => 8fosc. Tinst= (4)*Tosc = (4)*(250ns) = 1us
// all 4 sensors should read every minute so each will begin sequentially,
// after 15sec delay from previous ADC conversion completes.

void delay (void); // delay function prototype declaration

void data_write (int, int); // data-write function prototype declaration

main()
{
// I think I need a while (1) loop here to repeat the loop forever???

// sensor 1 configured to port AN0
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_5ANA_0REF, ADC_CH0 & ADC_INT_OFF);
//configures ADC for port AN0 = sensor 1 input
delay(); // call the delay function

ConvertADC(); // initiate conversion of sensor1 @ AN0
while(BusyADC()); // waiting to complete conversion
result=ReadADC(); // read the result of sensor1 @ AN0
data_write(); // call data_write function
CloseADC();


// sensor 2 configured to port AN1
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_5ANA_0REF, ADC_CH1 & ADC_INT_OFF);
//configures ADC for port AN1 = sensor 2 input

delay();
ConvertADC();
while(BusyADC());
result=ReadADC();
data_write ();
CloseADC();

// sensor 3 configured to port AN2
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_5ANA_0REF, ADC_CH2 & ADC_INT_OFF);
//configures ADC for port AN2 = sensor 3 input

delay();
ConvertADC();
while(BusyADC());
result=ReadADC();
data_write ();
CloseADC();

// sensor 4 configured to port AN3
OpenADC(ADC_FOSC_8 & ADC_RIGHT_JUST & ADC_5ANA_0REF, ADC_CH3 & ADC_INT_OFF);
//configures ADC for port AN3 = sensor 4 input

delay();
ConvertADC();
while(BusyADC());
result=ReadADC();
data_write ();
CloseADC();

return (result);
}


// Delay function sequence
void delay (void)
{ // 15second delay routine
// 15sec/Tinst= 15sec/1us
// = 15*10^6 Tinst = 10K * 1500
// Delay10KTCYx(1)= 0.01sec
// = (10K)*(250)*(6)
i=6;
while(i>0) {
Delay10KTCYx(250); // 2.5sec delay

i=i--; // run 6 times for total 15sec delay loop
}
return;
}

// data write sequence
void data_write (data_adr, result) {
_asm
movlw data_adr // starting data memory address = data_adr
movwf EEADR,A

movlw result // gets data stored in "result" variable
movwf EEDATA,A // places data into data memory holder
bcf EECON1,EEPGD,A // points to data memory
bcf EECON1,CFGS,A // access data eeprom
bsf EECON1,WREN,A // enable write to data EEPROM
bcf INTCON,IE,A // disable interrupt
movlw 0x55 // start flash erase sequence
movwf EECON2,A
movlw 0xAA
movwf EECON2,A // end flash erase sequence

bsf EECONN1,WR,A // enable bit to start the write operation
bsf INTCON,GIE,A // re-enable interrupt
bcf EECON1,WREN // restores the write command to =disabled
_endasm

data_adr = data_adr+2;
if (data_adr >= 0xC6) // if address >= d'198
data_adr = 0x64; // resets starting point to d'100

return; }


Answer



All of the other answers have good points, and point out other problems, but the specific reason you're getting the error old style function declarations not supported is because your data_write function declaration is missing the types. It needs to be changed from


void data_write (data_adr, result)

to


void data_write (int data_adr, int result)

No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...