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

RS232 + getc + 16F876

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



Joined: 01 Nov 2006
Posts: 5
Location: Bahia -> Brazil

View user's profile Send private message Send e-mail

RS232 + getc + 16F876
PostPosted: Wed Nov 01, 2006 8:59 am     Reply with quote

Hi there

I'm tring send a mensage by hyperterminal to PIC 16F876 whit crystal 4MHz by rs232.

My problem is some times the pic reset. I make a initial mensage to indicate the de PIC is working, after the program enter in a while loop to reseive a caracter and show the caracter on the screem.

But some times this show the inital mensage and the caracter pressured, showing that the pic was reseted (I think).

the code source:
Code:
#include <16F876.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
//#fuses XT,NOLVP,NOWDT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,RESTART_WDT)  // Jumpers: 8 to 11, 7 to 12

short int conta=0;

void main()
{
   char teste='@';
   
   printf("\n\r+------------------------------------------------------------------+");
   printf("\n\rTeste de RS232"); // initial mensage

   do {
        printf("\r\nValor atual: %c\r\n",teste);
      delay_ms(5);
          printf("\n\rAperte uma letra: ");
   
      teste = getc();
   
      delay_ms(5);
          printf("\r\nA letra foi %c\r\n",teste);
      delay_ms(5);
   
     } while(1);
}


I try make a aplication whit get_string() but don't work fine, now I'm trying make whit getc().

thank you!!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Nov 01, 2006 9:35 am     Reply with quote

First see if RESTART_CAUSE will tell you why the PIC reset. RESTART_CAUSE is one of the CCS functions. Also make sure you have good power supply bypass caps close to the PIC.
_________________
The search for better is endless. Instead simply find very good and get the job done.
__JEREK__



Joined: 01 Nov 2006
Posts: 5
Location: Bahia -> Brazil

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 01, 2006 11:35 am     Reply with quote

SherpaDoug, thank you for your reply!!! I search the CCS exemplo end make the following modification in code source:

Code:
#include <16F876.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
//#fuses XT,NOLVP,NOWDT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)  // Jumpers: 8 to 11, 7 to 12

short int conta=0;

void main()
{

char teste='@';


///////////////////////////////////////////// NOVO C�DIGO DE ERRO IMPLEMENTADO
   switch ( restart_cause() )
   {
      case WDT_TIMEOUT:
      {
         printf("\r\nWDT_TIMEOUT\r\n");
         break;
      }
   
   case WDT_FROM_SLEEP:
   {
         printf("\r\nWDT_FROM_SLEEP!\r\n");
         break;   
   }


      case NORMAL_POWER_UP:
      {
         printf("\r\nNORMAL_POWER_UP\r\n");
         break;
      }

//   case BROWNOUT_RESTART:
   case MCLR_FROM_SLEEP:
   {
         printf("\r\nMCLR_FROM_SLEEP\r\n");
         break;   
   }
   }

///////////////////////////////////////////// FIM DO NOVO C�DIGO DE ERRO IMPLEMENTADO   

   
   printf("\n\r+------------------------------------------------------------------+");
   printf("\n\rTeste de RS232 N003");

   do {
        printf("\r\nValor atual: %c\r\n",teste);
      delay_ms(5);
          printf("\n\rAperte uma letra: ");
   
      teste = getc();
   
      delay_ms(5);
          printf("\r\nA letra foi %c\r\n",teste);
      delay_ms(5);
   
     } while(1);
}


now when the pic restart the mensage code is NORMAL_POWER_UP!!! this mean that I have a trouble whith my power supply, I'm right??

thank you for your help!!!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Nov 01, 2006 12:26 pm     Reply with quote

Yes, the PIC is sensing the power interrupted and is starting its program over. How is your circuit built? Do you have an oscilloscope?
_________________
The search for better is endless. Instead simply find very good and get the job done.
__JEREK__



Joined: 01 Nov 2006
Posts: 5
Location: Bahia -> Brazil

View user's profile Send private message Send e-mail

PostPosted: Wed Nov 01, 2006 12:38 pm     Reply with quote

my circuit is a programing board, as the picture:



and I don't have oscilloscope, I think now I need make a circuit out of this borad in a protoboar, but I need buy a IC MAX232 to do this!!!

thank you for your help SherpaDoug!!!
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