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

AT Commands/Interrupts help

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



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

AT Commands/Interrupts help
PostPosted: Tue Jul 01, 2008 8:39 am     Reply with quote

Hi all,
First off, I am pretty much a newb when it comes to programming, in particular with PICs, so yeah. Anyway, I'm having trouble with this code, and I'm not entirely sure why (probably due to my limited knowledge of programming). The program tries to get the signal strength from a modem (actually a modem emulator on the computer), and then based on the signal strength lights one of three LEDs; red is poor signal, yellow is decent signal, and green is good signal. If no response is received from the modem, the leds flash as an error message. The code itself is simple, it checks all of the characters captured during a 6.5 second period for a 0, 1, 2, 3, 4, or 5, which lights an led and raises a flag.


Code:

/*#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
*/ //This is all included in the protoalone.h file called below

#include <protoalone.h>
#include <utility.c> //contains the function flash_leds() used later on

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

   int i = 0, flag = 0;

   enable_interrupts(int_rda);
   #if defined(__PCD__)
   enable_interrupts(intr_global);
   #else
   enable_interrupts(global);
   #endif

   //printf("\r\n\Running...\r\n");

   printf("AT+CSQ");

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

      delay_ms(6500);
      printf("\r\nBuffered data => ");
      //while(bkbhit)
      //  putc( bgetc() );
   for(i = 0; i < BUFFER_SIZE; i++) {
      if(buffer[i] == '0' || buffer[i] == '1') {
         output_low(RED_LED);
         flag = 1;
      }
      if(buffer[i] == '2' || buffer[i] == '3') {
         output_low(YELLOW_LED);
         flag = 1;
      }
      if(buffer[i] == '4' || buffer[i] == '5') {
         output_low(GREEN_LED);
         flag = 1;
      }
   }
   if(flag == 0)
      flash_leds(); //ERROR MESSAGE
   } while (TRUE);
}



The problem is I haven't been able to get the program to work, it doesn't receive any response from the modem and flashes the leds every time. I figure its probably something really stupid like the AT Commands (I have never before used AT Commands, and yes, I have read up on them, read the technical documents for the modem I'm using, and all of that), but if you guys could help, that would be much appreciated.

Thanks,
-Nick
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 01, 2008 2:11 pm     Reply with quote

Quote:
printf("AT+CSQ");

Read ckielstra's post in this thread. Notice the character that he puts
at the end of an "AT" command string:
http://www.ccsinfo.com/forum/viewtopic.php?t=26731
Guest








PostPosted: Wed Jul 02, 2008 12:07 pm     Reply with quote

Thanks, that really helps, haha...what exactly is \r? I've never come across it in any of my programming courses (correction - programming course), though I've been using it in some of the code I've been working on.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 02, 2008 12:12 pm     Reply with quote

Look at documentation on "escape sequences" for printf. See the
list near the end of this page:
http://web.mit.edu/10.001/Web/Course_Notes/c_Notes/tips_printf.html
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

PostPosted: Wed Jul 02, 2008 12:24 pm     Reply with quote

Ah I see, well thank you very much PCM. Also, Guest up there ^^ was me.
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri Jul 04, 2008 5:40 pm     Reply with quote

I

on terminal for example when your press "ENTER" in code you need put "\n"

see this site http://www.developershome.com/sms/howToSendSMSFromPC.asp

I make all my mobile controllers with this help

regards
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