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 support@ccsinfo.com

printf does not work

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



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

printf does not work
PostPosted: Tue May 06, 2008 9:05 am     Reply with quote

Below is my code. My code work fine and print "Pic controller" on serial port on portb pin4 interupt. But when i add serial interupt #INT_RDA, printf stop printing on portb pin4 interupt.
I want to know why.
Can any one explain the problem, why serial port interupt stop sending data on serial pin on portb interupt
Code:

#include <16f870.h>
#fuses HS, NOWDT, PUT, NOBROWNOUT, PROTECT, NOLVP, NOCPD
#use delay(clock=20000000)

#byte PORTA = 5
#byte PORTB = 6
#byte PORTC = 7
#define SET 1
#define RESET 0

struct VARIABLES
{
unsigned char data;
unsigned int serial ;
unsigned int ON_OFF;
}
ABC;

#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7)

#INT_RDA
RDA_isr()
{
   ABC.data = getch();
}

void main() {

   enable_interrupts(INT_RDA);
   enable_interrupts( INT_RB);
   enable_interrupts(GLOBAL);

      SET_TRIS_A(0x00);
      SET_TRIS_C(0xBF);
      SET_TRIS_B(0XFF);

while(1)
{

      output_low(PIN_A1);
      delay_ms(1000);
      output_high(PIN_A1);
      delay_ms(1000);
}
}

#int_rb
rb_isr() {
    byte ch, last_b;
    ch = last_b ^ portb;
    last_b = portb;
    if (bit_test(ch,4 ) && !bit_test(last_b,4)){
           //b4 went low
      delay_ms(50);
      printf("Pic controller");
      output_low(PIN_A2);
      delay_ms(1000);
      output_high(PIN_A2);
      delay_ms(1000);
    }
   delay_ms (100);  //debounce
}
Matro
Guest







PostPosted: Tue May 06, 2008 9:14 am     Reply with quote

Try :
Code:

#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)


You have to be aware that when an ISR is executed, all interrupts are disabled.
Your #INT_RB ISR is very very long to execute and that's very dangerous.
Moreover, having a printf() in an ISR is never good.

Matro.
ashrafkhatri



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

PostPosted: Tue May 06, 2008 9:24 am     Reply with quote

then how can i print on serial pin , while pressing portb pin4. and also include #int_RDA in my code as wel for recieving data
Matro
Guest







PostPosted: Tue May 06, 2008 9:29 am     Reply with quote

The best is to only set a flag in the #INT_RB ISR.
In your main() endless loop you check this flag. And if it is set you process the data (printf(), ...) and finally clear the flag.

Matro
ashrafkhatri



Joined: 06 May 2008
Posts: 14

View user's profile Send private message

PostPosted: Tue May 06, 2008 9:46 am     Reply with quote

Thanks for your replying

Do you mean i use
#int_rb noclear in my code

how can i set flags and reset it in main loop in C language
could you post a sample code for my better understanding
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Tue May 06, 2008 10:53 am     Reply with quote

In your interrupt isr set a global flag myisr_got_achar=true declare it as global (Ex int8 myglobal_flag int8 myisr_got_achar) to indicate a specific condition as having occured ( Ex interrupt so a keypress or interrupt received a char) . In the main code initialize the global Ex flag myisr_got_achar=false and and in the main loop check to see if it was set by the isr if so do the appropriate action in the main routine ( Ex if( myisr_gat_achar ==true) printf(" char recvd"))
then clear the flag Ex flag myisr_got_achar=false so a future event if it happens can re-trigger it).
Stay with byte size vars don't use word size since they take more than one instruction to assign them allowing for a rare situation in which an interrupt could happen between instructions.
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