View previous topic :: View next topic |
Author |
Message |
anulikwutsayll
Joined: 01 Dec 2011 Posts: 2
|
can i receive character from RS232 while Timer0 is working? |
Posted: Thu Dec 01, 2011 10:12 am |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Dec 01, 2011 10:19 am |
|
|
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
|
|
Posted: Thu Dec 01, 2011 11:08 am |
|
|
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 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
anulikwutsayll
Joined: 01 Dec 2011 Posts: 2
|
|
Posted: Thu Dec 01, 2011 10:10 pm |
|
|
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 |
|
|
|