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

RECEIVE TxT HELP

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



Joined: 02 Feb 2013
Posts: 8

View user's profile Send private message

RECEIVE TxT HELP
PostPosted: Tue Mar 05, 2013 9:18 pm     Reply with quote

Hello Masters, pls help me debug this code i'm using, i made it as a reference from farazwan post. but it doesn't work. i just place 2 LED's at pin B0 and B1 just to show that i can command to lit the two leds.. I only got 1 week to finish my project . pls help me. Thanks much.

Quote:
#include <16f877a.h>
#include <stdlib.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=GSM)
#include <lcd.c>
#use fast_io(C)
#use fast_io(B)

#define LCD_E PIN_D0
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2
#define LCD_D4 PIN_D4
#define LCD_D5 PIN_D5
#define LCD_D6 PIN_D6
#define LCD_D7 PIN_D7

#define LED1 PIN_B0 // LED 1
#define LED2 PIN_B1 // LED 2

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

#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 initialize();
int DM();
void read_sms();
int get_cmd();
void do_cmd();
void del_sms();

short sms_mode=0;

volatile int counter_search=0; //counter to traverse the array
volatile int counter_read=0; //counter to fill the array

Volatile int HitCounter=0; // for string comparison
Volatile int Next_CMD=0;


volatile Char Recieve_String[70]; //buffer for incoming data

void main()
{
lcd_init();
set_tris_b(0x00);
output_b(0x00);

initialize();
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);


while(true)
{if(sms_mode==1)
{
lcd_putc("\f");
lcd_gotoxy(1,1);
printf(lcd_putc,"%c",Recieve_String[counter_read]);
delay_ms(3000);
DM();
read_sms();
get_cmd();
do_cmd();
del_sms();
sms_mode=0;
counter_read=0;
}

lcd_putc("\f");

}
}


void initialize()
{
printf("AT\n\r");
delay_ms(500);

printf("AT+CMGF=1\n\r"); //It inhabits the text mode sms
delay_ms(500);

lcd_putc("\f");
lcd_gotoxy(1,1);
lcd_putc("GSM MODEM");
lcd_gotoxy(1,2);
lcd_putc("INITIALIZED");
delay_ms(1000);
}

int DM()
{

const char StrCMTI[]={"+CMTI"};

counter_read=0;

While(counter_read<=16) // read all data
{
output_high(PIN_B1); // signal ready to receive sms
}
counter_read=0;

Delay_ms(500); // ignore all remaining characters recieved..if any.
output_low(PIN_B1); // off receive ready light.
counter_search=2;

HitCounter=0;

while((HitCounter!=5)&&(counter_search<8))
{
if(Recieve_String[counter_search]==StrCMTI[counter_search-2])
HitCounter++;

counter_search++;
}

if(HitCounter==0x05)
Return(1);
else return(0);
}

void read_sms()
{
counter_read=0;
lcd_putc("\f");
lcd_gotoxy(0,1);
lcd_putc("READ SMS");
delay_ms(1000);

fprintf(GSM, "AT+CMGR=1\r\n"); // send command, MEMORY LOCATION OF SMS IS ALWAYS ONE, SINCE I DELETE THEM AFTER PROSCESING

delay_ms(3000);
}

int get_cmd()
{
const char CMD1[8][7]={"LED1 0","LED1 1","LED2 0","LED2 1"};

int offset=0;
int store_counter=0;
counter_search=0;


while((Recieve_String[counter_search]!='!')&&(counter_search<69)) // wait till command indicator is found '!'
{
counter_search++;
}

counter_search=counter_search+1; // increment one to actual first letter of command
store_Counter=counter_search; // store current position for multiple searches
NEXT_CMD=0; // NEXT_CMD keeps track of the command being read, thus used

while((HitCounter!=6)&&(NEXT_CMD<8)) // compare to all commands in list.
{
counter_search=store_Counter; // initialize counter search with stored counter value.
offset=0; // since value of counter is unknown use a separate counter for the const array
HitCounter=0; // counts number of equal letters found.

while((HitCounter!=6)&&(offset<=6)) // keeps the counters in check...to not overshoot. and compares the strings
{
if(Recieve_String[counter_search]==CMD1[NEXT_CMD][offset]) // if letter is found
{HitCounter++;
offset++;
counter_search++;
}
}

if(HitCounter==6) // if 6 chars found...exit..
{
Return(1);
}

NEXT_CMD++; // if increase to search next command.

}

Return(0);
}

void do_cmd()
{
lcd_putc("\f");
lcd_gotoxy(0,1);
lcd_putc("do command");
delay_ms(1000);

if(NEXT_CMD==0)output_low(PIN_B0);
if(NEXT_CMD==1)output_high(PIN_B0);

if(NEXT_CMD==2)output_low(PIN_B1);
if(NEXT_CMD==3)output_high(PIN_B1);
}

void del_sms()
{
counter_read=0;

printf("AT+CMGD=1"); //send command
putchar(0x0D); //send return

While(counter_read<=15) // get all returned text
{
}

counter_read=0;

Delay_ms(500); // ignore all remaining characters received

}

#INT_RDA
void SerialInt()
{int t;

buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t;

while (kbhit())
{
Recieve_String[counter_read]=getchar();

if(Recieve_String[counter_read]=='+'){//first character of phone number
counter_read=0;//to begin to write the var buffer from the 1 st position

sms_mode=1;
}
counter_read++;
}
return;
}
Mike Walne



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

View user's profile Send private message

PostPosted: Wed Mar 06, 2013 3:08 am     Reply with quote

As it stands you've got little chance of help here.

1) You don't appear to have read the forum guidelines.
2) With what appears to be little understanding you've taken plagiarised someone elses code, modified it, expected it to work, then complained that it does not.
3) You have not learnt to use the code button (it make code easier to read, preserves formatting if you have any).


I suggest:-

a) Read the forum guidelines.
b) Start from the beginning with a simple LED flasher and proceed from there. It'll be quicker when you understand what you're doing.
c) Use the CCS provided code for most of your tasks.
d) Come back for help with a specific problem.

Mike
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Mar 06, 2013 7:50 am     Reply with quote

.... so you modified farzwan's code, which is a modified version of my code....

you are the 3rd step of evolution that started from a very basic and crude code sample...

aside from Mike's suggestions:

what is your final goal?
simply control LEDs? ... or something else involving sms?

did you get the original code working?
its very hard for you to understand what is going on if you simply copy and compile code.

its even harder to modify already modified code without understanding the original code first.

the original code as posted works (its terrible, but it does work).
you probably have to tailor it a bit to work with your module.

the first thing your need to do is confirm that the module is actually talking to the pic...

G
_________________
CCS PCM 5.078 & CCS PCH 5.093
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