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.

C Program help Plz.... MikroC compiler for PIC16F877A

Status
Not open for further replies.

ryusgnal

Advanced Member level 4
Full Member level 1
Joined
Oct 4, 2005
Messages
102
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,298
Location
Malaysia
Activity points
1,992
mikroc watchdog timer function

I wrote this program using Mikroelektronika MikroC compiler for PIC16F877A. The problem is, it keep repeating sending 'J' Character to USART terminal although there is no looping command. how to stop that and send just one 'J' character to USART terminal? Help plzzz....

Here is the code:

void main()
{
Usart_Init(9600);
Usart_Write('J');
}
 

clear watchdog timer no mikroc

Hi!
The problem is in ur code. It should be like this

void main()
{
Usart_Init(9600);
Usart_Write('J');
while(1)
{
//your code goes here
};
}

Now this code will write the character 'J' only once and then enter the endless while loop. If you will not use this while loop then the processor will keep on initilizing the USART and sending the character 'J'.
The point is that the microcontroller should always be executing some code, in ur previous code the controller was doing nothing after the UsartWrtie('J'); function.

Regards.
 

using watchdog with mikroc

Actually the PIC should goto sleep if main has terminated, but it seems it's getting reset ?
 

Re: C Program help Plz....

waseem said:
Hi!
The problem is in ur code. It should be like this

void main()
{
Usart_Init(9600);
Usart_Write('J');
while(1)
{
//your code goes here
};
}

Now this code will write the character 'J' only once and then enter the endless while loop. If you will not use this while loop then the processor will keep on initilizing the USART and sending the character 'J'.
The point is that the microcontroller should always be executing some code, in ur previous code the controller was doing nothing after the UsartWrtie('J'); function.

Regards.

I have done this, but it still looping.
 

Re: C Program help Plz....

Hi!
Check your watch dog timer. It should be disabled. If it is not disabled then it will reset the device each time it timesout. It can disabled in the configuration fuses.
Regards.
 

    ryusgnal

    Points: 2
    Helpful Answer Positive Rating
C Program help Plz....

I think you have to put the 'END' instruction.
 

Re: C Program help Plz....

waseem said:
Hi!
Check your watch dog timer. It should be disabled. If it is not disabled then it will reset the device each time it timesout. It can disabled in the configuration fuses.
Regards.

It Works!!! Thanks so much!!!

:D:D:D
 

Re: C Program help Plz....

if the watchdog is activated and the time you had set to the watchdog timer overflows, then the PIC is reset. that's why its reset.
 

Re: C Program help Plz....

aupa said:
if the watchdog is activated and the time you had set to the watchdog timer overflows, then the PIC is reset. that's why its reset.

I disable watchdog timer using default setting in MikroC. Can anyone give me simple explanation about watchdog timer? what is it for?
 

Re: C Program help Plz....

Hi!
The watchdog timer is a simple protection against code lockup.If your code locks in an undesireable endless loop the watchdog timer overflows and resets the device. In your PC use you would have come across a situation in which the PC "hangs" and refuses to do anything. The only solution is to press the reset switch and thus restart the processor.
The watchdog timer in a controller does exactly that in an automatic manner.
Actually the watchdog is a simple timer that runs of an internal RC oscillator and is independent of the controller's main oscillator. It has a normal overflow time which is specified in the controllers data sheet. In some cases (e.g PIC) its overflow time can be changed by using a prescaler.
If the watchdog timer is enabled then we have to clear (make its counter zero) it repeatedly from time to time to prevent it from overflowing and thus generating a reset.The PIC assembly language has a special instruction for it CLRWD(clear watchdog).
If in our normal program flow we donot clear it then it will generate a reset signal which will reset the controller and the code will be once again executed right from the start (as was happeining in your case)

Hope this helps u understand.
Regards.
 
Re: C Program help Plz....

waseem said:
Hi!
The watchdog timer is a simple protection against code lockup.If your code locks in an undesireable endless loop the watchdog timer overflows and resets the device. In your PC use you would have come across a situation in which the PC "hangs" and refuses to do anything. The only solution is to press the reset switch and thus restart the processor.
The watchdog timer in a controller does exactly that in an automatic manner.
Actually the watchdog is a simple timer that runs of an internal RC oscillator and is independent of the controller's main oscillator. It has a normal overflow time which is specified in the controllers data sheet. In some cases (e.g PIC) its overflow time can be changed by using a prescaler.
If the watchdog timer is enabled then we have to clear (make its counter zero) it repeatedly from time to time to prevent it from overflowing and thus generating a reset.The PIC assembly language has a special instruction for it CLRWD(clear watchdog).
If in our normal program flow we donot clear it then it will generate a reset signal which will reset the controller and the code will be once again executed right from the start (as was happeining in your case)

Hope this helps u understand.
Regards.

Thanks so much
 
Hi,
Will be glad either Waseem, ryusngle or some1 else help me. Am also using mikroC from Mikroelectronika, and my version is not licensed. (Am using the freely donloadable version.)

For pic16f877a USART communication I too found a code as shown in the blog.

but it doesnot compile for me. It says USART_Init is undeclared.

What can be the case here?

If i use UART1_init it works. USART is not identified.

Hoping to hear soon.
Thanks.
 

Hi Anuradha1,
You're most probably using the latest version (or one of the latest ones). In earlier versions, the function was USART_Init(). But in later versions, it became converted to UART1_Init().

Hope this helps.
Tahmid.
 

Thanks Thamid .

If it is so, hopefully my program will wrk whn loaded in to PIC.
 

ryusgnal has wrote
" I disable watchdog timer using default setting in MikroC."

Pls tell me how to disable the watch dog timer in pic16f877A.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top