Hi,
I have started working on the code to program the PIC16f877a connected with GSM modem TC35i and an LED board. I need have a start up for the code what header files should I include and how would I control the LED's by giving an sms. i will be waiting for assistance. Thank you in advance.
If your command that you send as SMS is 10 characters wide then use a ring buffer (array) of say 12 or 15 elements. Every time there is a serial interrupt check if index is equal to buffer length. If yes, reset the buffer to 0. As the command in SMS will be the last part it will get stored in the buffer. To do this you have to read the message index every few seconds by issuing AT+CMGR=message_index\r\n command. Then parse and extract the command to another array and test if received command (message) matches with any messages hard-coded. If yes then take necessary action. Don't use big buffers as bank switching is a problem with 16F devices.
Thanx alot for such a good knowledge... I have started to work on the code... the source file which came along with the modem contains the header file of #include reg52. but that works for 8051 micro-controller as I am using PIC16f877a. But well yeah I started to make the code which is some thing like this : (This shows the sending part but I will need to recieve the messege from Modem to PIC16f877a controller to turn on/off LED's.)
#ifndef __CPU_16F877__#error "This program is tailored for PIC16F877 controller"#endif// Include all the header files needed#include "io16f877.h"#include "USART.h"#include "DELAYS.h"// define the ports used#define TEST_LED RD7#define PB RB0//initialize IO portsvoid initialize_IO_ports(void){
TRISD =0x00;//Port D is output.
TRISC =0x40;//RX = 0, TX = 1.
TRISB =0xFF;//Port B is input.//clear the output port
PORTD =0x00;}void send(unsignedchar data[],int length){unsignedint i;for(i=0;i {
DelayMs(10);
TXREG=data[i];while(!TRMT);
DelayMs(10);}}// main functionvoid main(){unsignedchar flag =0;unsignedchar atset[]="AT\r\n";unsignedchar testset[]="AT+CMGF=1\r\n";unsignedchar numset[]="AT+CMGS=\"83434778\"\r\n";unsignedchar message[]="hello";// initialization of the peripherals to be used by// calling the respective initialization function.
initialize_IO_ports();
init_uart();
TXREG =0x00;while(1){if(PB ==0){
DelayMs(80);if(PB ==0){
flag = ~flag;}}if(flag){
TXEN =0;
TEST_LED =1;
TXEN =1;//enable transmission
send(atset,sizeof(atset));
DelayMs(30);
send(atset,sizeof(atset));
DelayMs(30);
send(atset,sizeof(atset));//to configure the GSM module
DelayMs(30);
send(textset,sizeof(textset));
DelayMs(20);
send(numset,sizeof(numset));
DelayMs(20);
send(message,sizeof(message));
DelayMs(20);
TXREG=0x1A;//end of filewhile(!TRMT);
flag = ~flag;//flag toggle at the end of transmission}//end of if }//end of while }// end of main