View previous topic :: View next topic |
Author |
Message |
glenjoy
Joined: 18 Oct 2004 Posts: 21
|
RS232 Interrupt on CCS C |
Posted: Wed Mar 02, 2005 8:18 am |
|
|
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
|
|
Posted: Wed Mar 02, 2005 8:59 am |
|
|
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
|
|
Posted: Wed Mar 02, 2005 9:02 am |
|
|
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
|
|
Posted: Wed Mar 02, 2005 9:10 am |
|
|
Is the kbhit useful for keyboards input only? whta if the input is not from a PC but from another serial peripherals? |
|
|
Ttelmah Guest
|
|
Posted: Wed Mar 02, 2005 9:14 am |
|
|
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 |
|
|
|