![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
milkman41
Joined: 16 Jun 2008 Posts: 30
|
AT Commands/Interrupts help |
Posted: Tue Jul 01, 2008 8:39 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Wed Jul 02, 2008 12:07 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
milkman41
Joined: 16 Jun 2008 Posts: 30
|
|
Posted: Wed Jul 02, 2008 12:24 pm |
|
|
Ah I see, well thank you very much PCM. Also, Guest up there ^^ was me. |
|
![](templates/subSilver/images/spacer.gif) |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|