make[2]: *** [dist/default/production/ELQUEVAPA.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
#include <xc.h>
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (Power-up Timer is disabled)
#pragma config CP = OFF //
extern int aux=0;
extern int aux2=0;
void show (int var)
{
var++;
show(aux2);
}
void main(void) {
INTCON=0b10010000;
TRISB=0x02;
TRISA=0x01;
while (!PORTAbits.RA1)
{
show(aux);
}
if (PORTAbits.RA1)
{
INTCONbits.GIE=0;
}
return;
}
Not sure about the meaning of the above error, but your code has a wrong declaration. You are instantiating the function show() within itself.
extern int var =0
void show (int aux)
{
aux++;
return;
}
void main (void)
{
show (var) ;
show (var);
return;
}
So there, var must be 2?
.
No, it should be '1'
You are post incrementing with aux++.
How Can I make a variable which do not destroy in the return?
I did that but I'm not sure where to declare static int var. If I have to declare it in each funtion or globalYou can declare the variable within any function as static. This way the variable stay local, but with the ability to do not loose its content after leaving out of the function.
void interrupt tc_int (void) // interrupt function
{
if(INTCONbits.T0IF && INTCONbits.T0IE)
{ // if timer flag is set & interrupt enabled
TMR0 -= 250; // reload the timer - 250uS per interrupt
INTCONbits.T0IF = 0; // clear the interrupt flag
PORTB = 0x40; // toggle a bit to say we're alive
}
}
But how Can I pass a variable to this funtion?
If you need a specific value inside the interrupt function, you need to compute it separately and make it available to the interrupt function using a global variable.
volatile int myVar;
void interrupt myISR(void)
{
myVar++;
}
I already mentioned the endless recursion in post #9. In this case (missing termination condition), program execution will always fail, independent of the call stack model. We are just talking about how it fails.Probably too late now but I want to go back to the comments about the recursive function.
The way you have written the 'show' function in the first post will certainly cause problems at run time as there is no conditional statement to stop the recursive calling of the function.
I don't think you have anywhere said exactly which device you are using but some have a special 'call stack' that only contains a few entries and other devices create a stack in memory. In either case you will have problems.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?