CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Controller Resetting

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
plzhelp
Guest







Controller Resetting
PostPosted: Mon Nov 27, 2006 5:38 am     Reply with quote

Hi everyone

In my code the PIC16f877a is randomly resetting. here is the code

Code:


#include <16F877A.h>
#device *=16
#fuses HS,NOPROTECT,NOWDT,NOLVP
#use delay(clock=20000000)
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#use rs232(baud=19200,xmit=pin_E1,rcv=pin_E2,parity=N,stream=pc)

//switch is on C0-->C3

int value,i;

void switch_read()
{
    value = input_c();//use pull down resistors!!!

   for(i=4;i<8;i++)
   {
      bit_clear(value,i);
   }

     fprintf(pc,"\n\ri read:%u",value);

}
void switch_write()
{

    switch(value)
   {
      case 1:
         output_c(0);
           fprintf(pc,"\n\routput: 0");
         break;
      case 2:
         output_c(1);
           fprintf(pc,"\n\routput: 1");
         break;
      case 3:
         output_c(2);
           fprintf(pc,"\n\routput: 2");
         break;
      case 4:
         output_c(3);
           fprintf(pc,"\n\routput: 3");
         break;
      case 5:
         output_c(4);
           fprintf(pc,"\n\routput: 4");
         break;
      case 6:
         output_c(5);
           fprintf(pc,"\n\routput: 5");
         break;
      case 7:
         output_c(6);
           fprintf(pc,"\n\routput: 6");
         break;
      case 8:
         output_c(7);
           fprintf(pc,"\n\routput: 7");
         break;
      case 9:
         output_c(8);
           fprintf(pc,"\n\routput: 8");
         break;
      case 10:
         output_c(9);
           fprintf(pc,"\n\routput: 9");
         break;
      case 11:
         output_c(10);
           fprintf(pc,"\n\routput: 10");
         break;
      case 12:
         output_c(11);
           fprintf(pc,"\n\routput: 11");
         break;
   }

}

void main()
{

   setup_adc( ADC_OFF );

   fprintf(pc,"\n\rstart\n\r");

   while(1)
   {
      output_low(pin_E0);

      delay_ms(40);

      switch_read();

      output_high(pin_E0);

      delay_ms(40);

      switch_write();

      delay_ms(3000);
   }
}


I have also noticed that when i comment out the 'switch_write()' funtion then the controller does not reset.


Dont quite know whats going on

Many thanx
Ttelmah
Guest







PostPosted: Mon Nov 27, 2006 6:27 am     Reply with quote

Realistically, probably electrical noise. What does output_c actually drive?. What suppression have you got close to the PIC?. How is your supply generated?. There is nothing in the code that wll itself 'cause' a reset.

However as a seperate comment, why store the same thing multiple times?.
Code:

void switch_write(void) {
   output_c(--value);
   fprintf(pc,"\n\routput: %d",value);
}

Is a hell of a lot simpler...

Best Wishes
tsupuntu



Joined: 05 May 2006
Posts: 9

View user's profile Send private message

EMI/EMC
PostPosted: Mon Nov 27, 2006 10:59 am     Reply with quote

I think Reset from trace PCB of your.You should learning Electromagnetic EMI/EMC
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 27, 2006 11:05 am     Reply with quote

See this thread for links on the "random resets" problem:
http://www.ccsinfo.com/forum/viewtopic.php?t=27638&start=4
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Nov 27, 2006 1:36 pm     Reply with quote

Cant see exactly what you are doing - but it does look like you read Port C, and then in 'switch_write' you write back out to Port C. But if you have pressed a switch and the output wants to go the opposite way then the processor will likely reset?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group