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 "get_string" in #int_rda

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



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

problem with "get_string" in #int_rda
PostPosted: Tue Apr 01, 2008 4:31 pm     Reply with quote

I am trying to receive a string through the serial port that only updates when new data is sent.

the string will be sent at random time intervals so thought i should use #int_rda but once the string has been sent the micro does not leave the interrupt.

is there also a way to clear the String in "array" or does one have to use a for statement?

the high/low pin d2 is an LED to see if the code is looping.


Code:
#include <16F877a.H>
#device icd=true
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud = 19200, xmit=PIN_C6, rcv = PIN_C7, ERRORS)

#include <input.c>
#include <Flex_LCD420.c>

#define BUF_SIZE  25

char array[BUF_SIZE];

//=====================================================================

#int_rda
void Serial_isr()
   {
      get_string(array, BUF_SIZE);  // Get string from serial port
   }

//=====================================================================

void main()
   {
   enable_interrupts(int_rda);
   enable_interrupts(GLOBAL);
   
   lcd_init();
   printf(lcd_putc, "\f");
   delay_ms(100);

         while(1)
            { 
               output_high(pin_d2);
               delay_ms(100);
               
               printf(lcd_putc, "\f\r%s", array);           // Display string recieved
               
               output_low(pin_d2);
               delay_ms(100);
            }
   }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 01, 2008 7:07 pm     Reply with quote

Try this. This program combines the Ex_Sisr.c with the get_string()
function. Instead of calling getc(), get_string() now calls bgetc(), so
that it gets characters from the receive buffer that is filled byint_rda.
Example of output:
Quote:

Enter a string of text: hello world
You typed: hello world

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}


void my_get_string(char* s, unsigned int8 max) {
   unsigned int8 len;
   char c;

   --max;
   len=0;
   do {
     //c=getc();  // Commented out.
       c = bgetc();   // Call bgetc() instead of getc()
     
       if(c==8) {  // Backspace
        if(len>0) {
          len--;
          putc(c);
          putc(' ');
          putc(c);
        }
     } else if ((c>=' ')&&(c<='~'))
       if(len<=max) {
         s[len++]=c;
         putc(c);
       }
   } while(c!=13);
   s[len]=0;
}

#define STRING_SIZE 40

//===================================
void main()
{
char input_str[STRING_SIZE];

enable_interrupts(int_rda);
enable_interrupts(global);

while(1)
  { 
   printf("Enter a string of text: ");
   my_get_string(input_str, STRING_SIZE-1);     
   printf("\n\rYou typed: %s \n\r\n\r", input_str);

  }

}
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Tue Apr 01, 2008 9:12 pm     Reply with quote

Thanks PCM

but i ran that exact code you posted but it doesn't seem to work. Using the CCS serial terminal it say"Enter a string of text:" then i enter a "michael" and it echo's "michael" into the serial window but then doesn't do anything else. if i continue to send more data it i presumes fills the buffer and then stops echoing to the port and totally stops working.
Ttelmah
Guest







PostPosted: Wed Apr 02, 2008 3:27 am     Reply with quote

You do need to hit the carriage return key, to say that the string has finished.

Best Wishes
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Wed Apr 02, 2008 1:23 pm     Reply with quote

what is the carriage return key?

once the string has been typed i push send and thats it. what else am i supposed to do?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 02, 2008 2:04 pm     Reply with quote

Normally, you just type the text into HyperTerminal or some other
terminal program, and then press the Enter key on your PC keyboard.
Here is a screenshot of HyperTerminal. It comes with Windows:
http://www.brothersoft.com/internet/miscellaneous/screenshots/hyperterminal-private-edition_5661.html
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 02, 2008 2:15 pm     Reply with quote

umka wrote:
what is the carriage return key?
I'm so glad we have internet these days. Now the smart people will surf to the Google website and find the answers much quicker there than they would get an answer in a forum.

umka wrote:
once the string has been typed i push send and thats it. what else am i supposed to do?
How does the program know the end of the string is reached? You need to send a special character here, the 'Carriage Return' code (ASCII value 13, abbreviated CR, generated by the enter/return key on your keyboard). Check also your CCS manual in the chapter on the gets() function.
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Wed Apr 02, 2008 3:18 pm     Reply with quote

thats what i have been doing. As stated above i have been using the terminal that comes with the ccs ide.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 02, 2008 4:15 pm     Reply with quote

The 'send' button in SIOW.exe doesn't send a carriage return (0D).
It just transmits the hex bytes that you have typed into the lower box.

Instead of doing that, just click on the black area and type your text in, and press the Enter key on your PC.

Or use hyperterminal.
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Wed Apr 02, 2008 4:30 pm     Reply with quote

thanks yet again PCM works a treat
Guest








PostPosted: Sun Apr 13, 2008 9:09 am     Reply with quote

its working good in the hyperterminal.. thanks alot PCM... do u mind explain more about the working of the program? because i'm still a beginner in CCS and i'm trying to learn more to complete my project...

welldone!
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