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

RS232 Interrupt on CCS C

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



Joined: 18 Oct 2004
Posts: 21

View user's profile Send private message

RS232 Interrupt on CCS C
PostPosted: Wed Mar 02, 2005 8:18 am     Reply with quote

I want to implement a serial routine in my program; it is getting a character from the serial port, now while waiting for the incoming serial data, I still want to monitor some important event outside my microcontroller, how to implement this w/o this:


main

{
char x;
while(1)
x = getc();
...........
..........

}

Because as far as I know the program will stop at at getc() and will wait for an input before it will got to the next line.
Kasper



Joined: 14 Jan 2004
Posts: 88
Location: Aurora, Ontario, Canada

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 02, 2005 8:59 am     Reply with quote

set up the serial receive interrupt

Code:

#use rs232(baud=9600,  parity=N, xmit=PIN_C6, rcv=PIN_C7, stream=PORT1, bits=8, errors)   
void main(void) {
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

while(1)
}

#int_rda   
void handle_data(void) {
char Received;

Received=fgetc(PORT1); // PORT1 is what I called the stream,

}

[/code]
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Mar 02, 2005 9:02 am     Reply with quote

The key is to call kbhit() to see if a character is available before calling getc()

{
char x;
while(1)
if (kbhit()) x = getc();
...........
..........

}
_________________
The search for better is endless. Instead simply find very good and get the job done.
glenjoy



Joined: 18 Oct 2004
Posts: 21

View user's profile Send private message

PostPosted: Wed Mar 02, 2005 9:10 am     Reply with quote

Is the kbhit useful for keyboards input only? whta if the input is not from a PC but from another serial peripherals?
Ttelmah
Guest







PostPosted: Wed Mar 02, 2005 9:14 am     Reply with quote

Bbhit, really has nothing to do with 'keyboards'!. The name dates from the early 'standard' use of 'C', which was assumed to have a serial terminal attached. Hence 'kbhit', just reflects whether there is an incoming character from the serial, which was assumed in this configuration to be a 'keyboard' character.

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