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

can i receive character from RS232 while Timer0 is working?

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



Joined: 01 Dec 2011
Posts: 2

View user's profile Send private message

can i receive character from RS232 while Timer0 is working?
PostPosted: Thu Dec 01, 2011 10:12 am     Reply with quote

hi, everyone

this is my code

Code:

#include <16F688.h>                                         
#fuses HS ,NOWDT,NOPROTECT                                 
#use delay(clock=20000000)                                 
#use rs232(baud=9600, xmit=PIN_C3, rcv=PIN_C2 ,stream=PC)   

char A;                                 
int int_count = 0;                                         

void main ()                                               //main function
{
   set_tris_a(0xFC);                                        //Set PortA
   enable_interrupts(GLOBAL);                         //All Interrupts on
   enable_interrupts(INT_TIMER0);                //Turn on Interrupt TIMER0
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);      //setup timer
   set_timer0(0);
   
   while(TRUE)
   {
       A = fgetc (PC);
       if A == 'e'
       {
         == do something ==
       }
   }
}


#INT_TIMER0                                          //Function Interrupt TIMER0
void Timer0_ISR()
{
   if(int_count++>19)
   {
      ++i;
      int_count =0;
   }
   if(i>5000)
   {
      == do something ==
   }
}



thanks for help in advance
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 01, 2011 10:19 am     Reply with quote

hmm..
Try it and find out ! Simple enough.

You will need to add 'errors' to the use RS232(....) options though...
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Dec 01, 2011 11:08 am     Reply with quote

i can answer this very simply:

even if you tried to add an interrupt driven RS-232 receive routine-
sooner or later ( but probably sooner) because this is software RS-232- THIS WILL DISTORT reception and your RX ( && ||) TX data will be corrupt too.
this is especially acute since your fast timer rollover will darned near SATURATE the pic capability.

LOL do the math !!
you are generating almost 20,000 INTS / second !!!!

take it to the $$ bank - you MUST be VERY VERY new to pic programming is all i can guess Exclamation
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 01, 2011 3:36 pm     Reply with quote

Quote:

int int_count = 0;


if(i>5000)
{
== do something ==
}

The datatype is wrong. It should be int16.

It's a very common problem for new CCS users:
http://www.ccsinfo.com/forum/viewtopic.php?t=46501&start=3
http://www.ccsinfo.com/forum/viewtopic.php?t=46125&start=6
anulikwutsayll



Joined: 01 Dec 2011
Posts: 2

View user's profile Send private message

PostPosted: Thu Dec 01, 2011 10:10 pm     Reply with quote

Thanks for suggestion.

And sorry about my simple question, I don't know that it's simple.

I have miss out this line when I typing.
Quote:

int int_count = 0;
int16 i = 0;

Thanks for all advice Smile
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