View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
problems with functions in C |
Posted: Wed Nov 19, 2008 12:32 pm |
|
|
Hi
I make one program where I like call main function where now I have call fstop() but I think who is impossible correct?
but for correct this problem I make other program but I need call one function who stay before than where I stay in my case I need call fstop() into function codeok(). It only work if I call function fstop() before codeok(), but I can't...
some one can help me correct this program?
Quote: |
void codeok()
{
.....
if (sens==0) fstop();
else return;
}
void fstop()
{
....
}
void main ()
{
int8 start,sens,wait;
setup_timer_2(T2_DIV_BY_16,39,16);
enable_interrupts(INT_TIMER2);
start=0;
sens=0;
wait=0;
STATE=0;
output_low(RED);
output_high(GREEN);
while(1)
{
....
if (sens==0) fstop();
else codeok();
}
|
kind regards, Filipe |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Nov 19, 2008 2:39 pm |
|
|
Hi
thanks for your quickly reply
but if I use reset_cpu() function. I can save my states in EEPROM? this reset dont clean them?
regards |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 19, 2008 2:44 pm |
|
|
Don't ask. Make a test program.
Question: What does "reset_cpu()" do in a 16F628 program.
Compile this program:
Code: | #include <16F628.h>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
//===================
void main()
{
reset_cpu();
while(1);
} |
Look at the .LST file to see the ASM code. What does it do ?
It jumps to ROM address 0x0000 and re-starts the program.
Code: | .................... void main()
.................... {
0004: CLRF FSR
0005: BCF STATUS.IRP
0006: MOVLW 1F
0007: ANDWF STATUS,F
0008: MOVLW 07
0009: MOVWF CMCON
....................
.................... reset_cpu();
000A: CLRF PCLATH
000B: GOTO 000
....................
....................
.................... while(1);
000C: GOTO 00C
.................... } |
|
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Wed Nov 19, 2008 3:11 pm |
|
|
Hi PCM programmer
you are a good professor, I stay now start study this on my university, but I dont understand, and only open .LST file now...
it start for put in different address #fuses, after it call "reset_cpu()" and what it make? it start on 000?
where stay EEPROM address? for I can see if "reset_cpu()" removed eeprom information?
sorry but you can explain me more slow?
kind regards, Filipe |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 19, 2008 3:19 pm |
|
|
Jumping to 0x0000 restarts the program. It does not clear the eeprom.
The eeprom will only be cleared if you have a line of code in your
program to clear it. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Nov 19, 2008 3:39 pm |
|
|
No one would guess, that a fstop() function is related to eeprom anyhow. Wouldn't be a bad idea, if you start to tell, what you are trying to achieve. |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Nov 21, 2008 7:09 am |
|
|
Hi
For example if I declare functions at begin program the order of function don't matter.
but I make this
Quote: |
#include <18F452.h>
#fuses EC_IO,NOWDT,NOPROTECT,NOLVP
#use delay(clock=40000000)
#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader
//###### FUNCTIONS ######
void fstop();
void off();
void codeok();
//###### IN PORTS ######
#define DOOR PIN_B7
#define HBREAK PIN_B6
(...)
|
and with first example give me an error "Recursion no permitted(fstop)"
This is some problem with this compiler?
regards |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Fri Nov 21, 2008 8:57 am |
|
|
Quote: |
and with first example give me an error "Recursion no permitted(fstop)"
This is some problem with this compiler?
|
Correct - this compiler cannot do recursive calls
Ken |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Nov 21, 2008 11:48 am |
|
|
Hi
ok, I correct program with oder way...
some one question..
with this configuration
Quote: |
int16 TIME; // Variavel Global de Relogio - 1mS
#int_TIMER2 // a cada 1mS incrementa TIME
void TIMER2_isr(void)
{
TIME++;
}
(...)
void main ()
{
int8 start, count;
setup_timer_2(T2_DIV_BY_16,39,16);
enable_interrupts(INT_TIMER2);
STATE=0;
write_eeprom(0, STATE); //escreve o valor inicial do estado do circuito
start=0;
count=0;
output_low(RED);
output_high(GREEN);
while(1)
{
//STATE==1 circuito electrico curtado
//STATE==0 circuito electrico ligado
STATE = read_eeprom(0);
if (STATE==1) off();
while (TIME <= 20000) //espera 20seg que se meta o codigo e volta a falhar
{
if (input(RFID) == 1)
{
count++;
}
}
if (count==3) //sendo o cod igual a 3 pulsos
{
codeok();
}
else fstop();
|
on my main function only with this configuration my program wait 20seg and save this on variable sens?
I this which this not work :( |
|
|
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Fri Nov 21, 2008 7:45 pm |
|
|
Hi
for I wait some time for one operation (pulse) I can use this Timer2 configuration?
I only need which program for example wait 20sec which I click on switch(pulse) and after return if on this 20secs switch is pressed...
some one can help me?
regards |
|
|
|