# sms based control of home appliances

Status
Not open for further replies.

#### erminesh11

##### Newbie level 4
im placing my code here that i used to communicate atmega16 with pc on hyperteminal. it is working fine. my concern is regarding using at commands in my code. how could i start...

Code:
#define F_CPU 16000000UL

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

#include<avr/io.h>
#include<util/delay.h>

void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();

int main()
{
unsigned char value;
DDRD=0xff;
DDRA=0xff;
DDRB=0x07;

_delay_ms(50);		// delay of 50 mili seconds
usart_init();		// initialization of USART
while(1)
{

value=usart_getch();
usart_putch(value);
}
return 0;
}

void usart_init()
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
// Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 << UCSZ1);
// Use 8-bit character sizes

UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..
// into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}

void usart_putch(unsigned char send)
{
while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte
}

unsigned int usart_getch()
{
while ((UCSRA & (1 << RXC)) == 0);
return(UDR); // return the byte
}

#### ckshivaram

do a search in the forum before you post any thread... these have been addressed and solutions provided from many years.......

#### erminesh11

##### Newbie level 4
had a lot of search..... unable to find specific coding procedure for atmega16...

---------- Post added 17-04-11 at 00:39 ---------- Previous post was 16-04-11 at 23:16 ----------

can anyone provide me solution for this....????

#### ckshivaram

there are many solutions for 8051... please dont tell you did not find it... from years i am giving solution for it... atmega is not much different from 8051... take the code and guidelines procedure and modify it for your controller....

#### sherazi

##### Banned
you should first mention which module u want to use , .. the first place is to look at the modules user manual ... it will show u what At cammands to use ...

sending an at command to a module is just like u send any data to serial port or hyperterminal as far as code is concerned ... search 8051projects.net for gsm and u will get lots of results ! if u still dont get started .... tell us what u dont understand and what u understood?

#### erminesh11

##### Newbie level 4
yes sir... i know that... if i get a readymade code then how will i learn to write it.... as you can see i had already posted the code. im not good in c programming. im having trouble in how to use the at commands in the code.. i had gone through a lot of posts..no doubt they are much helpful.. but still im facin prob...

---------- Post added at 19:15 ---------- Previous post was at 19:12 ----------

hello sherazi, thanx....im having problem in using the at commands in the code. im using sim300 gsm module. everything is working perfect... only concern is how i should program atmega16 to act like a hyperterminal...?

#### ckshivaram

in a simple way , assuming that you know how to write serial communication program...

write a serial comm program, where you send AT in your program... then wait for serial data to be received... compare the incoming data with character 'K' (type OK from hyperterminal). if it is K then send next at command and again wait for response from hyperterminal.....

if you can write this program then there is nothing else to write for GSM......

#### [xx]eternal

##### Newbie level 1
Hi im also doing a similar project.Im using pic16f877a and a Sony Ericsson K750i phone as my receiver.I use the unused SE data cable DCU-60 and make some modification(I peel off the rubber exterrior)and had managed to determine all the pins connected with the wires inside.the pins for the data cable is as follow:
Sony Ericsson C702, C902, C905, F305, G502, G700, G705, G900, K205i, K310i, K320i, K330, K510i, K530i, K550i, K610i, K630i, K660i, K750i, K770i, K790i, K800i, K810i, K850i, M600i, P1i, P990i, R300, R306, S302, S500i, T303, T650i, T700, W200i, W300i,

my problem is to which pins should i connect in order to have serial communication with my MCU(is that DTMS/DFMS or CTMS/CFMS)??BTW i knew tat both CTMS and CFMS is used as DATA+/DATA- for USB protocols,since pic16f877a doesnt have USB module I assume i cannot connect CTMS/CFMS to my circuit.I had also tried DTMS/DFMS but stil cant managed to get any result.

my circuit is as follow:

pic(tx)------->k750(DTMS);
pic(rx)-------->k750(DFMS);

the following code is a first stage tester,which mean if i can get the message stored in my phone i am succeed.pls help......
void main()
{
unsigned char temp;
unsigned char a;
unsigned char b;
//set I/O input output
TRISB = 0b00000011; //configure PORTB I/O direction
TRISD = 0b00000000; //configure PORTD I/O direction

//Configure UART
SPBRG=129; //set baud rate as 9600 baud
BRGH=1; //baud rate high speed option
TXEN=1; //enable transmission
TX9 =0; //8-bit transmission
RX9 =0; //8-bit reception
CREN=1; //enable reception
SPEN=1; //enable serial port
temp=RCREG;
temp=RCREG;

while(1)
{
if(SW1==0)
{
delay(10000);
sync();
uart_str("AT+CMGW=24");

uart_send(0x0D);

uart_str("079106xxxxxxx11000A9xxxxxxxx000AA0CC8F71D14969741F977FD07");

uart_send(0x1A);
led1=!led1;
delay(5000);
}
}
}

======================================================
void sync(void)
{
unsigned char c;
c = 'u';
for( ;c>128;c--)
{
uart_send(c);
}

Status
Not open for further replies.