Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

Status
Not open for further replies.

jbrathod88

Junior Member level 3
Joined
Oct 14, 2010
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Ahmedabad, India
Activity points
1,556
Hi all,

I use MikroC, can also use Hi-tech C.
In the code for my project, I cannot call any function from the interrupt routine. I want particular function to run in my code when i press the switch.
I do not want to update any value in interrupt and scan it in idle condition and run according to it.
I found that it may be the problem of stack limitation.

My questions are,
1> Can I allot the User RAM area to store the stack values. If yes then how to do in MikroC? - Any other solutions are invited for MikroC.
2> will I face the same problem in Hi-tech C in MPLAB?
3> Any solution for the given problem?( Except from setting the values in the interrupt routine )

-- I have attached the project file. You will get the whole idea about it.
Please avoid the mistakes ( you will find many ) as the program is in the first stage. I have stated the problem in the interrupt routine.

Suggestions and complements are welcome.
Any help will be appreciated.

Thanks for reading.
 

Attachments

  • Project-Clock_with_Alarm.zip
    37.4 KB · Views: 106
Last edited:

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

if you have read data sheet it is clear that stack pointer is not read able or write able . To create software stack you need to push status register some where but there is no push instruction or pop .

- - - Updated - - -

remember 8 level deep stack and u called a function from isr ,and in that function goto inst is used which require stack , u called an other function in that function ? So analyze does stack exceeds 8 levels?
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

I don't think that there is the stack limitation problem. Because I can run the same-like code in MPLAB Hi-Tech C without getting this type of error.
So currently I have to translate the code for Hi-Tech compiler and proceed further in it.

I believe that MikroC has any type of settings which controls the stack or stops to use stack by changing it, we can allow the func. calls( It has many project settings ).
I don't find any problem in Hi-Tech except that it uses much of the program and data space for the same code ( I use Lite edition).

--------------------------------------------------- This is just for Hi-Tech installation.-----------

I have faced many problems in Installing Hi-tech. MPLAB could not able to detect Hi-tech. I got the error "No valid installed HI-TECH compiler drivers".
I have reinstalled MPLAB and Hi-tech many times but Hi-Tech did not display in MPLAB Language Tool-chain.

And After many tries I found the solution that is -> For windows 7,
1> Uncheck the option "Run in compatibility mode" for MPLAB.exe
2> Do the same for picc.exe in the Hi-Tech->bin directory and
3> Allow that two programs in any firewall or System protection software( I have Private-firewall ).

-------------------------------------- I found that many peoples faced this problem so I just needed to share my experience of this.

I would love to make code in MikroC if I can do function calls from interrupt.
 
Last edited:

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

If you are familiar with assembly for PIC than you will be able to understand , actually stack is not read able or write able n in case when we need function call in interrupt what actual compiler does , it does not save registers , put write destination value to program counter where your function exists and you can do this in mikroc also by using inline assebly
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

put write destination value to program counter where your function exists and you can do this in mikroc also by using inline assebly
How can I do this in MilroC. Please give me a short example. can I use GOTO for that?. Thanks.
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

Dear i use maximum CCS Compiler . But from mikroC i have come to know it allows to function call in interrupt . N your program is full of bugs and so i could not debug it to know problem . I think there is an other issue with program .Did you debug it and are you sure it goes to interrupt ?
I have made a simple program and called a function in interrupt and it works fine.

unsigned int cnt;
void my_function();
void interrupt() {
TMR0 = 90;
my_function();
INTCON = 0x20;
}

void main() {

TMR0 = 90;
INTCON = 0xA0;
RP0_bit = 1;
RP1_bit = 0;
OPTION_REG = 0x86;
RP0_bit = 0;
RP1_bit = 0;


while(1){}
}

void my_function(){
asm{nop}
Now make your program bugs free first and if there is some stack problem than follow my last thread but i don't think now there should be any problem . First correct your program
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

@ligo.george,
Thanks george. But this code does not use interrupt, and I want to use interrupt for which I have faced the problem. but thanks for the link.
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

Now make your program bugs free first and if there is some stack problem than follow my last thread but i don't think now there should be any problem . First correct your program

As I have said.

-- I have attached the project file. You will get the whole idea about it.
Please avoid the mistakes ( you will find many ) as the program is in the first stage. I have stated the problem in the interrupt routine.

Now,
Try to compile given code( this is the modification of your code ) and you will find the error of "Reentrancy is not allowed" that I want to get rid of.

unsigned int cnt;
void writecmd(unsigned char);


void interrupt()
{
TMR0 = 90;
writecmd(0x03);
INTCON = 0x20;
}

void main()
{
writecmd(0x03);
TMR0 = 90;
INTCON = 0xA0;
RP0_bit = 1;
RP1_bit = 0;
OPTION_REG = 0x86;
RP0_bit = 0;
RP1_bit = 0;

while(1);
}


void writecmd(unsigned char a)
{
PORTC=a;
}

This is the simple and bugs free code and you can examine what is going on.
Here there should not a problem of stack as I can make this type of code work in Hi-Tech C compiler.

I have successfully made the code for detecting switch and updating values in Hi-Tech C by calling a function Switch_press();.

I have attached the file for Hi-Tech. There is no any type of error generated in it. But that I can't do in MikroC.
View attachment switch-detect.zip
Compile this code in Hi-Tech and simulate in the Proteus( .DSN file I have attached before ). You will get all of what i want to say.
Thanks.

- - - Updated - - -

In proteus, press the upper most switch of the 4-switches for going to the setting. Then press the rest in order for-> '+', '-', 'Enter'.
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

Functions reentrancy is allowed if the function has no parameters and local variables, or if the local variables are placed in the Rx space. Remember that the PIC has stack and memory limitations which can varies greatly between MCUs.............

Modify like it
unsigned int cnt;
void writecmd();
unsigned char a;
void interrupt()
{
TMR0 = 90;
a=3;
writecmd();
INTCON = 0x20;
}

void main()
{
a=3;
writecmd();
TMR0 = 90;
INTCON = 0xA0;
RP0_bit = 1;
RP1_bit = 0;
OPTION_REG = 0x86;
RP0_bit = 0;
RP1_bit = 0;

while(1);
}

void writecmd(){
PORTC=a;
}
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

So much Sorry for late replying,

The code you have posted is error free. But here I want to pass the data from PORTB switch input to the function which executes instruction according to switch position( it means 'a' will be variable ). So I cannot predefine the data in main function.
Here also void writecmd() function will receive the data to be write to the LCD so it must be considered to take the value or data from the caller. I cannot predefine it.
I don't think that there is any stack limitation problem because i can compile it in Hi-Tech.
I don't know that this is the limitation or compiler's cons. But I hope that MikroC developers will do something about it.

I have now continue to code my program in MPLAB as it allows all of that.

BTW, Thanks all for help.:smile:. I will try to post my full project if it done.
 

Re: Need help in my project of "Clock with Selectable Alarm" using PIC16F877A.

Dear this is all about stack , if you dissamble your program and observe its assembly you will be come to know tha all this . But this depends upon compiler ,in mikroc you can't pass argument to a function from its interrupt routine . Other compiler lie mplab and hitech , handle it in an other way . And it is all about you what you feel easy ...... Best of luck
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top