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

Receiving package on RS232

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



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

Receiving package on RS232
PostPosted: Fri May 08, 2009 1:19 pm     Reply with quote

Hi. This might be a silly question but I need to read a scanner into the pic with RS 232. The package looks similar to this +6007762002185.

What function or how should I go about doing it?
I am trying this at the moment but i am only receiving the first character.
Code:
#int_rda
void serial_isr()
{
 chan0=getc();
 chan1=getc();
 }

Any help would be appreciated.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 08, 2009 2:07 pm     Reply with quote

Look at the Ex_sisr.c file for an example of a serial receive buffer
with the #int_rda interrupt:
Quote:
c:\program files\picc\examples\ex_sisr.c



Also, does this string have any control characters on the end ?
For example, does it have a Carriage Return (0x0D) at the end ?
If so, then you could use the get_string() function to receive the string.
It's in this file:
Quote:
c:\program files\picc\drivers\input.c



There is also a version of get_string() that uses the #int_rda interrupt.
It's called bget_string(). It combines the ideas shown in the two
examples above. It's in this example file:
Quote:
c:\program files\picc\examples\ex_zmd.c
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Fri May 08, 2009 2:31 pm     Reply with quote

Thanks.

I have reused that code to see if it will work but i am not getting any data read out on the LCD. I do have the running and buffered part displaying on the lcd though. I know my rs232 port is working and the scanner is working as i can directly read the value into the pc.
This is what I have done using your flex driver combined with the example to test.

Code:
#include <18f4680.h>
#device adc=8
#fuses INTRC,NOWDT,NOPROTECT,PUT,NOXINST
#use delay(clock=8M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "flex_lcd.c"


#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 main() {
    lcd_init();
   enable_interrupts(global);
   enable_interrupts(int_rda);
   
    printf(lcd_putc,"\rRunning...\r\n");

               // The program will delay for 10 seconds and then display
               // any data that came in during the 10 second delay

   do {
      delay_ms(10000);
      lcd_gotoxy(1,1);
      printf(lcd_putc,"\rbuffered data => ");
      while(bkbhit)
      lcd_gotoxy(1,2);   
      printf(lcd_putc, bgetc() );
   } while (TRUE);
}



Could you maybe off hand see where my mistake is lying and why the value does not want to display? On SIOW the value is +6007762002185. The start bit +. I do not have an end bit in the stream.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 08, 2009 2:47 pm     Reply with quote

Does the string always have the same number of characters in it ?
Gerhard



Joined: 30 Aug 2007
Posts: 144
Location: South Africa

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

PostPosted: Fri May 08, 2009 3:17 pm     Reply with quote

Its a barcode reader but for my purpose yes, as i will be printing the codes myself.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 08, 2009 4:48 pm     Reply with quote

Quote:
do {
delay_ms(10000);

What is the purpose of this 10 second delay ?
Your #int_rda buffer is only 32 characters long. If you get two or more
packets during that 10 second interval, you will fill up the buffer and
start to over-write characters from a previous packet (it's a circular
buffer).

Quote:
lcd_gotoxy(1,1);
printf(lcd_putc,"\rbuffered data => ");

The flex lcd driver doesn't recognize the '\r' control character.
Look in the source code for the lcd_putc() function in the driver
to see what control chars it does recognize. You will find the one
that you should be using.

Quote:
while(bkbhit)
lcd_gotoxy(1,2);

Here you have a loop. As long as characters are available in the
buffer, you just keep setting the x,y coords to the start of the 2nd line.
Your code above is the equivalent of the following:
Code:
while(bkbhit == TRUE)
   {
      lcd_gotoxy(1,2);
   }

bkbhit is true if you have chars in the buffer. You need to think about
your logic some more.
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