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

RS 232 INTERRUPT PROBLEM

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



Joined: 01 Dec 2003
Posts: 21
Location: Milan Italy

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

RS 232 INTERRUPT PROBLEM
PostPosted: Wed Jan 04, 2006 7:37 am     Reply with quote

Shocked

HI ALL !!

I HAVE TRY TO MANAGE INTERRUPTS.

I MUST TURN ON RXLED ( IN MY CODE ) AFTER EVERY RX 232 INTERRUPT BUT IN THIS WAY I SEE LED ON ONLY AFTER THE SECOND
PUSH BUTTON .


SOMEONE CAN TELL ME A RIGHT WAY........


#if defined(__PCH__)
#include <18F452.h>
#include <string.H>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,ERRORS)
#endif

#include <input.c>

#define STX 0x02 // Start of Transmition
#define ETX 0x03 // End of Transmition
#define AD 0x55
#define SEMICOLON 0x3B

#define LED1 PIN_B0
#define LED2 PIN_B1
#define LED3 PIN_B2
#define LED4 PIN_B3
#define LED5 PIN_B4
#define LED6 PIN_B5
#define RFLED PIN_A1
#define RXLED PIN_A2
#define PUSH_BUTTON PIN_D0

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

#define BUFFER_SIZE 9

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

#DEFINE BUFFER_COMPARE

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

// GLOBALS
static int8 char_rcved, data_valid, next_in;
static int8 buffer_overflow, stream_complete;
static int8 sermssg[BUFFER_SIZE];


/////////////////////////////////////////////////////////////////////

static int8 stringa[10]= {STX,0,0,0,1,1,SEMICOLON,AD,ETX};

// a string always ends with a NULL, so 9 char + NULL = [10]

////////////////////////////////////////////////////////////////////////

set_tris_b(0x00);
set_tris_d(0b11111111);
set_tris_a(0b00000000);

//------------------------------------------------------------------------------
#INT_RDA
void isr_serial_rcv()
{
char_rcved = getc(); // Get the incoming char

if ( char_rcved == STX )
{ next_in = 0; // Init the index
data_valid = TRUE; // Enable buffering
buffer_overflow = FALSE;
}

if ( data_valid )
{ sermssg[next_in] = char_rcved;
next_in++;

if ( next_in > BUFFER_SIZE ) // String longer than expected
{ data_valid = FALSE; // Stop buffering
buffer_overflow = TRUE;
}

if ( char_rcved == ETX )
{ data_valid = FALSE; // Stop buffering
stream_complete = TRUE;
}
}
}

void main()
{
delay_ms(400);
//set_tris_b(0x00);
//set_tris_d(0b11111111);
//set_tris_a(0b00000000);


stream_complete = FALSE;
enable_interrupts(GLOBAL);

while(1)
{
enable_interrupts( INT_RDA );

do{ // While stream_complete

do{
output_high(LED6);
delay_ms(200);
output_low(LED6);
delay_ms(200);
}while(input(PUSH_BUTTON));
(!input(PUSH_BUTTON));


output_b(0x00);
output_low(RXLED);
delay_ms(2000);

printf("\x2");
printf("0001wdloa;1;");
printf("\xFF");
printf("\x3");

//RX STX,0,0,0,1,1,SEMICOLON,AD,ETX RXLED ON

output_high(LED1);

delay_ms(2000);
////////////////////////////////// INTERRUPT
}while ( !stream_complete );


do{ // While stream_complete

do{
output_high(LED5);
delay_ms(200);
output_low(LED5);
delay_ms(200);
}while(input(PUSH_BUTTON));
(!input(PUSH_BUTTON));

output_b(0x00);
output_low(RXLED);
delay_ms(2000);

printf("\x2");
printf("0001wdloa;2;");
printf("\x80");
printf("\x3");

//RX STX,0,0,0,1,1,SEMICOLON,AD,ETX RXLED ON

output_high(LED2);

delay_ms(2000);
//////////////////////////////////INTERRUPT

}while ( !stream_complete );

if ( stream_complete )
{
stream_complete = FALSE; // IMPORTANT: If not the program re-enter

if ( !buffer_overflow )
{
disable_interrupts( INT_RDA );


#IFDEF BUFFER_COMPARE //////////////////////////////////////////////////////////

if (strcmp(stringa,sermssg))
{
output_high(RXLED);
}
#ENDIF //////////////////////////////////////////////////////////////////////////

} // if ( !buffer_overflow )

if ( buffer_overflow )
{// something wrong related to incoming string
output_b(0xff);
delay_ms(100); // Just to see a change in output_b
buffer_overflow = FALSE; // clear the fault !!!!
}

} // if ( stream_complete )

} // while(1)

} // void main()
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