Contoh Program AVR Simulasi Modem Wavecom

untuk dasar AT Command bisa baca disini :

Beberapa  AT Command (dan respon modem)  yg sering digunakan antara lain

Dari AVR/PC Dari Modem keterangan…………………
AT <CR><LF>OK<CR><LF>  attention
ATE0 <CR><LF>OK<CR><LF>  Echo dimatikan
AT+CMGF=1 <CR><LF>OK<CR><LF>  set ke mode text
<CR><LF>+CGMI: “SM”,1<CR><LF>  interupsi/notif pemberitahuan ada sms baru
AT+CMGR=1 <CR><LF>+CMGR: “REC  READ ,” +6289661513602″ ,,”15/12/05,10:38: 19+28″ <CR><LF> <isi sms><CR><LF>OK<CR><LF>  baca sms indek no 1
AT+CMGL=”ALL”  +CMGL: 1,”REC READ”, “+6283840367773”,, “15/10/ 20,16:02: 28 + 28″ <isi sms> <CR><LF>OK<CR><LF>

+CMGL: 2,”REC READ”, “+628384036799”,, “15/10/ 20,16:02: 28 + 28” <isi sms> <CR><LF>OK<CR><LF>

list semua isi sms
AT+CMGD=2 <CR><LF>OK<CR><LF> hapus sms indek ke 2
AT+CMGS=<no hp> <CR><CTRL-Z>  <CR><LF>OK<CR><LF> kirim sms

Berikut ini contoh respon modem dalam bentuk text

<CR><LF>+CMGR: “REC READ”,”+6289661513602″,,”15/12/05,10:38:19+28″<CR><LF>
tes2 <CR><LF>OK<CR><LF>

Jika  kita convert per byte karakter nya dlm bentuk hexa menjadi sbb:

0D 0A 2B 43 4D 47 52 3A 20 22 52 45 43 20 52 45 41 44 22 2C 22 2B 36 32 38 39 36 36 31 35 31 33
36 30 32 22 2C 2C 22 31 35 2F 31 32 2F 30 35 2C 31 30 3A 33 38 3A 31 39 2B 32 38 22 0D 0A 74 65
73 32 0D 0A 0D 0A 4F 4B 0D 0A


Silahkan di lanjutkan ya…

smsmodemwavecom

 

/*****************************************************
Chip type : ATmega16
Clock frequency : 11,059200 MHz

program AVR pura pura jadi modem

*****************************************************/

#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
// .equ __lcd_port=0x18 ;PORTB
// .equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>

void process_command();
unsigned int parsing_data();
char compare(char *str1, char *str2);

unsigned int REGISTERS[15];
unsigned char data_in[16],alamatSlave;
unsigned char data_count;
unsigned char ada_data;

char lcd[25],dataString[20], dataChar,adaAwalPaket;
char alamatTemp[5],alamat;
char ok[]=”\r\nOK\r\n”;
char sms[]=”\r\n+CMGR: \”REC UNREAD\”,\”+6289661513602\”,\”98/10/01,18 :22 :11+00\”,\r\nrelay#01#ON\r\n” ;
//=====================================
char AT[]=”AT”;
char ATE0[]=”ATE0″;
char ATCMGF[]=”AT+CMGF=1″;
char ATCMGD[]=”AT+CMGD=1″ ;
char ATCMGR[]=”AT+CMGR=1″ ;
char ATCMGS[]=”AT+CMGS=1″ ;
char error[]=”\r\nerror\r\n”;

//ceritanya kalau tombol di tekan ada sms masukkirim notif +CMTI ke AVR
interrupt [EXT_INT0] void ext_int0_isr(void)
{
delay_ms(60);
putchar(‘+’);
putsf(“CMTI : \”SM\”,1″);
delay_ms(60);
}

// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
dataChar=UDR;

if(adaAwalPaket==0)
{
adaAwalPaket=1;
data_count=0;
}

if(adaAwalPaket==1) //karakter setelah @ disimpan
{
data_in[data_count] = dataChar;

if (data_in[data_count] == ‘\n’) // jika data batas akhir ‘\n’ simpan paket data sbg string
{
data_in[data_count]=0x00; //akhir sebuah string adalah byte 0x00 (NULL)
adaAwalPaket=0;
ada_data = 1;
data_count = 0;
lcd_gotoxy(0,0);
lcd_puts(data_in);
return;
}
else //data blm sampe ‘\n’
{
data_count++;
}
//============
}

}

// Declare your global variables here

void main(void)
{
PORTD=0x04;
DDRD=0x00;
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Baud rate: 9600
UCSRA=0x00;
UCSRB=0x98;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// INT0: On
// INT0 Mode: Low level
GICR|=0x40;
MCUCR=0x00;
MCUCSR=0x00;
GIFR=0x40;

// LCD module initialization
lcd_init(16);

// Global enable interrupts
#asm(“sei”)

while (1)
{
// Place your code here
if(ada_data) // not null
{
process_command() ;
ada_data = 0;
};

};// eof while
} //eof main
unsigned int parsing_data()
{

return 0;
}

char compare(char *str1, char *str2)
{
if(!strcmp(str1,str2)){
return 1; }
else {
return 0;}
}

void process_command()
{

if(compare(data_in,AT))
{
puts(ok);
return ;
}
if(compare(data_in,ATE0))
{
lcd_gotoxy(0,1);
lcd_putsf(“minta echo off”);
puts(ok);
return ;
}

if(compare(data_in,ATCMGF))
{
lcd_gotoxy(0,1);
lcd_putsf(“minta MODE TEX”);
puts(ok);
return ;
}

if(compare(data_in,ATCMGR))
{
lcd_gotoxy(0,1);
lcd_putsf(“minta data sms”);
puts(sms);
puts(ok);
return ;
}

puts(error);

return;
}

Advertisements

About pccontrol

Berisi Tutorial Menggunakan PC untuk mengontrol Peralatan dengan cara mudah & praktis.

Posted on 01/12/2015, in AVR, Daftar isi. Bookmark the permalink. Leave a comment.

Komentar ,Saran atau Pertanyaan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: