Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing SIM300 with ATMEGA16

Status
Not open for further replies.

kendrepv07

Newbie level 4
Joined
Mar 31, 2011
Messages
5
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,324
Hi friends,
This is my code. i can send sms but can't read the received message using microcontroller. So please help. Thanks in advance.


#include <avr/io.h>
#include <util/delay.h>
#include <lcd_lib.C>
#define BAUDRATE 9600
#define PRESCALE (uint8_t)(((F_CPU / (BAUDRATE * 16.0))+.5) - 1)

char p[10];
void initialize(void);
uint8_t ReceiveByte( void );
void TransmitByte( uint8_t);
void TransmitString(uint8_t *);
void Init_Ports(void);

void initialize(void)
{
DDRA = 0x01;
UBRRL = PRESCALE; /* Set the baud rate */
UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and transmitter */
}

uint8_t ReceiveByte( void )
{
while ( !(UCSRA & (_BV(RXC))) ); /* Wait for incomming data */
return UDR;/* Return the data */
}

void TransmitByte(uint8_t data )
{
while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
_delay_ms(50);
}

void TransmitString(uint8_t *data)
{
while(*data)
{
TransmitByte(*data);
data++;
}
}

void init_port(void)
{
PORTA=0xFF;
DDRA=0xF0;

PORTB=0xff;
DDRB=0b10000000;

PORTC=0x00;
DDRC=0x00;

PORTD=0xFF;
DDRD=0x00;
}


void main(void)
{
unsigned int i;
uint8_t data;
initialize();
init_port();
LCDinit();
LCDclr();
while(1)
{
TransmitString("AT");
TransmitByte(0x0d);
_delay_ms(5000);
TransmitString("AT+CMGF=1");
TransmitByte(0x0d);
_delay_ms(5000);
TransmitString("AT+CSCS=\"GSM\"");
TransmitByte(0x0d);
_delay_ms(5000);
TransmitString("AT+CMGS=\"9028747438\"");
TransmitByte(0x0d);
_delay_ms(5000);
TransmitString("Hi this is your gsm modem sim300");
TransmitByte(0x1a);
_delay_ms(5000);
TransmitString("AT+CMGR=1");
TransmitByte(0x1d);
_delay_ms(5000);
for(i=0;i<=24;i++)
{
data=ReceiveByte();
}
for(i=0;i<=9;i++)
{
p=ReceiveByte();
}
p[10]='\0';
TransmitString("AT+CMGS=\"%s\"");
for(i=0;i<=9;i++)
{
TransmitByte(p);
}
TransmitByte(0x0d);
_delay_ms(5000);
break;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top