Pages

Kamis, 18 Februari 2010

KENDALI DAN AKUISISI DATA LEWAT SMS GSM

AVR-GSM is excellent board for adding remote monitoring and control in remote places by GSM cellular network. Do you want to switch on/off your local heating in your mountain house? To monitor the temperature at up to 8 remote points up to 30 meters away from the module? To listen to what happens in your house with silent call after you get message for alarm status? Then AVR-GSM is the board for you! It contains ATmega32 microcontroller and 3-band GSM GPRS module 900/1800/1900Mhz inside which covers most used GSM networks around the world. The GSM antenna is built into the board so there is no need for an antenna. AVR-GSM has two relays 240VAC/10A, two optoisolated inputs which could be connected to alarm sensors or just buttons for user actions (like call pre-loaded phone numbers), on-board temperature sensor and connector for additional up to 8 addressable remote temperature sensors at up to 30 meter distance from the module. Normal phone hook can be connected to this board and to allow user to speak, listen, take and place phone calls as normal stand alone cellular phone. AVR-GSM can be connected to PC with the USB connector and it is recognized as modem which could be used to add internet via GPRS to your computer.

Features:

* MCU: ATMega32 32KB Flash memory , 2KB RAM, 1KB EEPROM
* JTAG connector for programming and debugging with AVR-JTAG-L or AVR-JTAG-USB
* GSM GPRS 3-BAND MODULE 900/1800/1900Mhz with on-board GSM cellular antenna
* Li-ion backup battery for up to 200 hours of GSM module stand-by (no peripherals active)
* SIM card holder
* Two RELAYS 240VAC/10A
* Two optoisolated inputs
* USB interface
* Phone hook connector
* Buzzer (ringer)
* Status LED
* On-board temperature digital sesor
* Connector for remote temperature sensors up to 30meters far away from AVR-GSM
* Extension 26 pin connector for all unused ATMega32 ports
* PCB: FR-4, 1.5 mm (0.062"), soldermask, silkscreen component print



Contoh kode :

#include

#include

#include

#include





// Standard Input/Output functions

#include

#include

#include

#include

//#include "sms_comm.h"





#define CPU_freq 6000 KHz

#define FT232RL_RST PB2

#define BUTTON_DEAD_TIME 50

int s,button_filter;

int butflag=0;

// Declare your global variables here

char sms_read[]={'A','T','+','C','M','G','R','='};



char status[9]={'G','E','T','S','T','A','T','U','S'};

char getrelay1[9]={'G','E','T','R','E','L','A','Y','1'};

char setrelay1[9]={'S','E','T','R','E','L','A','Y','1'};

char getrelay2[9]={'G','E','T','R','E','L','A','Y','2'};

char setrelay2[9]={'S','E','T','R','E','L','A','Y','2'};

char gettemp[7]={'G','E','T','T','E','M','P'};

char nocarrier[10]={'N','O',' ','C','A','R','R','I','E','R'};

char callready[10]={'C','a','l ','l',' ','R','e','a','d','y'};

//char dial[14]={'A','T','D','0','8','7','6','0','4','1','1','0','1',';'};



unsigned long a;

unsigned char i=0;

unsigned char j,k,m;

unsigned char proba;

unsigned char temp_array [64];

double tempcalc,tempcalc2;

int index1;

int colcount=0;

unsigned const RING [6] = {'R', 'I', 'N', 'G', '\r'};

char sms_rec[12]={'C','M','T','I',':',' ','"','S','M','"',','};

char sms_send[10]={'A','T','+','C','M','G','S','=','"','+'};

//char sms_send2[]={'A','T','+','C','M','G','S','=','"','0','8','7','6','0','4','1','1','0','0','"'};

char sms_send_number[30];

char message[160];

char smsind[6];

char sms_number[16];

char sms_read_comm[13]; //SPP

int l=0;

int flag=0;

int com_out=0;

int ring_state=0;

int t=0;

int stopbuzzer=0;

char ok[2]={'O','K'};



#define RXB8 1

#define TXB8 0

#define UPE 2

#define OVR 3

#define FE 4

#define UDRE 5

#define RXC 7



#define FRAMING_ERROR (1<<<<<>9600 at 7.3278 ;0x26;-->baudrate 9600 at clock=6 MHz





// Timer(s)/Counter(s) Interrupt(s) initialization

//TIMSK=0x00;//timer interrupt disable

TIMSK=0x08;



// Analog Comparator initialization

// Analog Comparator: Off

// Analog Comparator Input Capture by Timer/Counter 1: Off

// Analog Comparator Output: Off

ACSR=0x80;

SFIOR=0x00;



PORTB &= ~(1<0))

timeout--;



if(timeout==0)// (rx_counter==0)

{

com_out=1;

return;

}

data=rx_buffer[rx_rd_index];

if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;

asm volatile("cli");



--rx_counter;



asm volatile("sei");



return data;

}



/////////////////////////////////////////////////////////////////////

// USART Receiver interrupt service routine

ISR(USART_RXC_vect)

//interrupt [USART_RXC] void usart_rx_isr(void)

{

char status,data;

status=UCSRA;

data=UDR;

if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)

{

rx_buffer[rx_wr_index]=data;

if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;

if (++rx_counter == RX_BUFFER_SIZE)

{

rx_counter=0;

rx_buffer_overflow=1;

};

};

}





///////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////

// Timer 1 output compare interrupt service routine

ISR(TIMER1_COMPB_vect)

{

t++;

TCNT1=0; //clear TCNT1 value(to imitate CTC mode on Timer 1 B)

//1.check whether to toggle or not(buzzer_enable);

if (stopbuzzer || (t==4000))

TCCR1A=0x0;//disconnect Timer/Counter 1 A/B Output pin



}

//////////////////////////////////////////////////////////////////////////////

unsigned char Compare (void)

{

unsigned char a, b;// temp;

b=0;

for (a=0; a<5; a++)

{

// temp = getchar_UART();



if (temp_array[b++] != RING[a]) return 0;

}

return 1;

}



///////////////////////////////////////////////////////////////////

unsigned char Compare2 (void)

{

unsigned char a, b;

b=0;

for (a=0; a!=11; a++)

{

if (temp_array[b++] != sms_rec[a]) return 0;

}

return 1;

}



////////////////////////////////////////////////////////////////////



unsigned char Comparereq (char* request)

{

unsigned char a, b;// temp;

b=0;

for (a=0; a!=9; a++)

{

// temp = getchar_UART();



if (temp_array[b++] != request[a]) return 0;

}

return 1;

}

//////////////////////////////////////////////////////////////////////

void gsmconfig()

{



Send_UART("ATE0");//disable ECHO characters

a=65535;

while(--a!=0);



if(!waitOK())

return 0;

com_out=0;



Send_UART("AT+CMGF=1");//set text SMS format

a=65535;

while(--a!=0);

if(!waitOK())

return 0;

com_out=0;

}

////////////////////////////////////////////////////////////////////



int waitOK()

{

//Feature:can exit by timeout

int l=0;

int flag=0;

char ok[2]={'O','K'};



while ((getchar_UART(100000)!=10)&& (!com_out))

{

l=l;

}

if(com_out)

return 0; //here exits by timeout



while(ok[l++]==getchar_UART(100000))

{

flag=flag+1;

}



while ((getchar_UART(100000)!=10)&& (!com_out) )

{

l=l;

}



return flag;

}

///////////////////////////////////////////////////////////

int waitplus()

{

com_out=0;

int l=0;

int flag=0;

while ( (getchar_UART(100000)!=10) && (!com_out))

{

l=l;

}



if(!com_out)

proba=getchar_UART(100000);

else return 0; //here exits by timeout



if(proba==43)

{

flag=flag+1;

}



return flag;

}



/////////////////////////////////////////////////////////////

void waitcarrier(void)

{

int l=0;

int flag=0;

com_out=0;



while ((getchar_UART(100000)!=10) && (!com_out))

{

l=l;

}



while(nocarrier[l++]==getchar_UART(100000)&& (!com_out))

{

flag=flag+1;

}



while ((getchar_UART(100000)!=10)&& (!com_out) )

{

l=l;

}



}

//////////////////////////////////////////////////////////////////////////////////////////

int call_ready(void)

{

//Feature: can exit by timeout

int l=0;

int flag=0;

int match=0;

//wait for a new line

while ((getchar_UART(100000)!=10) && (!com_out))

{

l=l;

}



while(!match)

{

if(rx_wr_index)

{

proba=getchar_UART(100000);

}

else return; //here exits by timeout

if (callready[l]==proba) //first symbol

{

l=l+1;

if (callready[l]==getchar_UART(100000)) //second symbol

{

match=match+1;

while(callready[++l]==getchar_UART(100000))

{

flag=flag+1;

}

}

else l=0;

}

}

//wait for a new line

while ( getchar_UART(100000)!=10)

{

l=l;

}

com_out=0; //reset timeout flag

return match;

}








Sumber : http://www.toko-elektronika.com


Tidak ada komentar:

Posting Komentar