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

EX_SISR.C modification

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



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

EX_SISR.C modification
PostPosted: Fri May 18, 2018 2:04 am     Reply with quote

Hai,

I've modified "EX_SISR.C" file follow to my design.
I'm trying to get a "GOOD" reply when it receive "OK" signal, other than "OK" signal, it will be ignored.
My code below can be compiled, but it will not reply "GOOD" when I send "OK" signal. I need help to fix this problem.

Thanks in advance.


Code:

#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <string.h>
#include <input.c>
#include <stdio.h>
#include <stdlib.h>

#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() {

   enable_interrupts(int_rda); 
   enable_interrupts(global);
   
   printf("\r\n\Running...\r\n");


   do {
      delay_ms(10000);
      printf("\r\nBuffered data => ");

      while(bkbhit=="OK")

          printf("\r\nGOOD");         
     
   } while (TRUE);
}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri May 18, 2018 2:27 am     Reply with quote

What is/are the value(s) that your 'bkbhit' can have?
Have you looked at it? (Either by using a watch window or printing it)

Mike
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Fri May 18, 2018 2:58 am     Reply with quote

it seems that the 'bkbhit' can receive any character or numbers
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Fri May 18, 2018 3:26 am     Reply with quote

art wrote:
it seems that the 'bkbhit' can receive any character or numbers


No. bkbhit() returns just true (not zero) or false (zero). It tells you whether there are any characters in the buffer. it does not tell you what the character(s) are. So you call bkbhit() to tell you if its worthwhile reading stuff from the buffer.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 18, 2018 5:00 am     Reply with quote

also..
whenever you're using the HW UARTs of PICs, you need to add 'ERRORS' to #use RS232(...options...). This adds a small chunk of code that will prevent the UART from 'freezing' or 'locking' up should you not read the UART buffer faster than the data comes in.

If you check the code library or do a search for 'ex_sisr.c' in this forum, you'll find a lot of 'hits' about using it . Several deal with your question.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri May 18, 2018 10:48 pm     Reply with quote

Also, if bkbhit _did_ return the data, you can't compare 'strings' in C with ==.
There is a lot of basic learning needed here... Sad
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