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

Problem with TXD interrupt

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







Problem with TXD interrupt
PostPosted: Fri Sep 17, 2004 6:40 am     Reply with quote

Hello to everybody
I am using PIC16F877
and trying to write just a very simple program to send some characters through the RS232 to PC using interrupts just to start with.
So, could anybody help me and tell why the following code does not work
Thank you very much

#pragma device PIC16F877

#USE standard_IO(C)
#use delay (clock=4000000)

#include "SFR.h"
#include "DEFS.h"

void init(void);
void TXD_isr();

int index = 2;
unsigned char a;
unsigned char arr[] = {'a','b','c'};

//------------------------------------------------

void main(void)
{
init();

while(1)
{
if (ENABLE)
{
TXREG = a;
ENABLE = 0;
}
}
}
//---------------------------------------------------
#INT_TBE
void TXD_isr(void)
{

int i;
a = arr[i];
i++;

if (i>index)
{
i = 0;
}
ENABLE = 1;
PIR1bits.SSPIF = 0 ;

}
void init(void)
{
SET_TRIS_C(0xFE);
TXSTA = 0x26 ;
RCSTA = 0x90 ;
SPBRG = 25; // set_uart_speed(9600);

TXD_IE = 1 ;
SERIAL_IE = 1 ;

a = 'm';

ENABLE = 1 ;
INTCONbits.PEIE = 1 ;
enable_interrupts(INT_TBE);
enable_interrupts(GLOBAL);
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Fri Sep 17, 2004 6:51 am     Reply with quote

#pragma device PIC16F877 <- no pragma

TXD_IE = 1 ; <- is this the same enable_interrupts(INT_TBE); ?
SERIAL_IE = 1 ; <- What does this do?

INTCONbits.PEIE = 1 ; <- Why are you mixing methods of enabling ints? This does the same thing enable_interrupts(GLOBAL);

Quote:

#INT_TBE
void TXD_isr(void)
{

int i;
a = arr[i];
i++;


did you mean to do this
Code:

#INT_TBE
void TXD_isr(void)
{

  static int i=0;
  a = arr[i];
  i++;


Also to make sure that you turn off the Tx int after your last byte it sent or it will keep firing.
Guest








PostPosted: Fri Sep 17, 2004 7:05 am     Reply with quote

TXD_IE = 1 ; <- is this the same enable_interrupts(INT_TBE); ?
yes

SERIAL_IE = 1 ; <- What does this do?
SERIAL_IE = PIE1bits.SSPIE


INTCONbits.PEIE = 1 ; <- Why are you mixing methods of enabling ints? This does the same thing enable_interrupts(GLOBAL);

I understood that enable_interrupts(GLOBAL); enables only GIE bit
Is not it?

Quote:

#INT_TBE
void TXD_isr(void)
{

int i;
a = arr[i];
i++;


did you mean to do this
Code:

#INT_TBE
void TXD_isr(void)
{

  static int i=0;
  a = arr[i];
  i++;


If it is a static , so it won't change will it?
I meant the 'i' to be changed only within this function
anyway it is still not working :(
Also to make sure that you turn off the Tx int after your last byte it sent or it will keep firing.[/quote]
alexbilo



Joined: 01 Jun 2004
Posts: 39
Location: Trois-Rivi�res

View user's profile Send private message

PostPosted: Fri Sep 17, 2004 7:16 am     Reply with quote

Quote:

If it is a static , so it won't change will it?


Actually, declaring a variable as static means that it'll keep its value from one call of the function to the next. On the other hand, if it isn't static its value will be lost at the end of the function call.

Knowing this, you should declare it as static.

Good luck,
_________________
Alex
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Fri Sep 17, 2004 7:20 am     Reply with quote

Thank you for the explanation Alex
But it did not solve the problem
_________________
Alex
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Fri Sep 17, 2004 9:29 am     Reply with quote

The program works fine wen I run it step by step
But it does not do anything when I run it normally
_________________
Alex
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 17, 2004 11:21 am     Reply with quote

CCS has an example program for #int_tbe called EX_STISR.C.
That file is in this folder on your computer:
c:\Program Files\Picc\Examples

I also once wrote an example for #int_tbe. It's here:
http://www.ccsinfo.com/wwwboard/messages/1848.html
Guest








PostPosted: Mon Sep 20, 2004 5:54 am     Reply with quote

I have done it exactly the same way.
the problem is that the RBE interrupt occurs all the time
and the program never riches the main loop
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Sep 20, 2004 7:41 am     Reply with quote

Mark wrote:

Also to make sure that you turn off the Tx int after your last byte it sent or it will keep firing.


Yeah, that is what I told you Razz
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