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

Serial interrupt problem

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



Joined: 11 Apr 2010
Posts: 13

View user's profile Send private message

Serial interrupt problem
PostPosted: Sat Nov 12, 2011 10:42 am     Reply with quote

I am using a wireless transceiver, at the receiver end my code does not work. Although i did the same logic in PIC16F877, but now while doing so in PIc16F873A, it does work. Probably i am doing some mistake for this type, but by datasheet and notes, these both PICs seems to be similar. Here is the code at receiver side.

Code:
#include <16F873A.H>
#fuses XT, NOWDT, BROWNOUT,
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=ami)


int q=0,a=0,b=0;
char Rcv;

ser(){
if (Rcv=='Q'){
   if(q==0){
   output_high(pin_b6);
   a=1;}
   
   else {
   output_low(pin_b6);
   b=1;
   }
}
if(a==1){
q=1;a=0;}
if(b==1){
q=0;b=0;}


}

#INT_RDA       
void SerialInt()
{
   Rcv=getchar();
   output_low(pin_a0);delay_ms(200);output_high(pin_a0);
   delay_ms(1000);
   ser();
   
}

void main (){
enable_interrupts(global);     
enable_interrupts(int_rda);   
printf("hello");
output_low(pin_b6);
while(1){
output_high(pin_a0);
}
}
temtronic



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

View user's profile Send private message

PostPosted: Sat Nov 12, 2011 11:01 am     Reply with quote

1) add 'errors' to the use rs232(.....) options.

2) Get RID of the delays in the serial ISR !!!!!!!!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sat Nov 12, 2011 11:19 am     Reply with quote

Seriously, get rid of the delays in the interrupt.
Look at the EX_SISR code, and do your processing in a loop in the main.

As it stands, this code _will_ hang the chip's UART, if there is a character received in the 1.2seconds of delay time.
Possibly even a little noise on the receiver, and a fractional difference in what the chips accept as a 'high', however you are just being 'lucky' with the 873....
Add the keyword ERRORS to the RS232 declaration (will stop the code from actually getting hung), but fix the problem as well.
Generally, any ISR, should _just_ handle the hardware event that has been signaled (in this case, get one character that has been received), and get out again ASAP. Doing anything much else, is potentially asking for trouble.....

Best Wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sat Nov 12, 2011 11:20 am     Reply with quote

I see Temtronic has made the same comment while I was posting. Smile

Best Wishes
Aamir



Joined: 11 Apr 2010
Posts: 13

View user's profile Send private message

PostPosted: Fri Nov 18, 2011 3:36 pm     Reply with quote

Thanks guys, will certainly try it.

As for the delay, actually I put it just because I don't need 2 3 entries at a moment....so I thought this might work.

As for errors...can anyone tell me how it is done? mind my question, I am little beginner to C.
Aamir



Joined: 11 Apr 2010
Posts: 13

View user's profile Send private message

PostPosted: Fri Nov 18, 2011 3:37 pm     Reply with quote

By the way, has anyone ever face any problem with 20MHz crystal in pic16f873?
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Fri Nov 18, 2011 3:55 pm     Reply with quote

Not really.
Generally, provided HS is selected (for the 20MHz you ask about), and the crystal is a parallel resonant, fundamental mode type, the PIC oscillator is pretty reliable.
Crystals with low drive levels, may require a series resistor. This is particularly the case on some of the 'first generation' 18 chips with PLL modules, which tended to lock onto an overtone, if the crystal is overdriven. However on older chips like the 16F873, this was rare.
Generally good design round the oscillator pins though is always critical. Short runs, don't have the ground plane round the oscillator pins (have a small ring round this area, and exclude the ground plane).
Microchip do several application notes about board layout, and crystal selection, follow these, and the oscillators work.

Best Wishes
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