Wednesday, March 23, 2011

CrazyEngineers Forum - Other Engineering Trades

CrazyEngineers Forum - Other Engineering Trades


Controlling industrial hazards using GSM intimation and feedback

Posted: 23 Mar 2011 12:15 AM PDT

Hey Godfather I am currently working on a project controlling industrial hazards using GSM intimation and feedback..... has someone worked on a smilar project...... thanks in advance bro.... i have brought in all the hardware the GSM modem is working fine the only problem i am facings is with the code..... i have the code but i don't think the problem is in my ATMEGA16 development board i am using VMlab as my simulator
here is the c code i am using to this code.... to test my board and GSM modem

#include <avr/io.h>
#include <avr/interrupt.h>
#include <string.h>
#include <util/delay.h>
int counter=0;
char rx[25];

unsigned int i=0;
unsigned char once=1;
char dummy[]={13, 0};
char d2[]={26,0};

void main (void)
{

// set PORTC for output
DDRC = 0xFF;
// PORTC=0xFF;
TCCR0=0x05;
TIMSK=0x01;
SREG=0x80;

DDRB=0x0C;
PORTB=0x10;

// PORTC =0xFF;
UCSRA=0x60;
//UCSRB=0x18; //only transmitter & receiver is enabled
UCSRB=0x98; //rx tx enabled, interrupt enabled
UCSRC=0x86; //Asynchronuous, no parity, one stop bit, 8 bit character size


UCSRC &=0x7F; //using URSEL bit
//It generates 9600 baudrate at 7.3728MHz
UBRRH=0x0;
UBRRL=0x2F;
// for 115200 baudrate at 7.3728MHz
// UBRRH=0x0;
// UBRRL=0x03; //BE SURE TO CHANGE THIS FOR SIMULATION///////////////////////////////
/////////////////////////////


asm ("SEI");

while(1){


if((PINB & 0x10) == 0x10)
PORTC |= 0x80;
else
PORTC &= 0x0;


}
}
void send(char* str)
{
unsigned char len;
len=strlen(str);
for(int i=0;i<len;i++)
{
_delay_ms(100);
while((UCSRA & 0x20) == 0x0);
UDR=str[i];
}

}

ISR(USART_RXC_vect)
{

rx[i]=UDR;
i++;
if(rx[i-2]==13 && rx[i-1]==10)
{
rx[i-1]='\0';
rx[i-2]='\0';
i=0;
if(strcmp(rx,"Call Ready")==0){
PORTC |= 0x40;
_delay_ms(5000);
send("AT");
send(dummy);
}

else if(strcmp(rx,"OK")==0){
if(once==1){
PORTC |= 0x20;
send("AT+CMGS=\"+923334491947\"");

send(dummy);
once++;
}
else if(once==2){
PORTC |= 0x08;
once++;
}
}
for(int j=0;j<25;j++)
rx[j]=0;
}
else if(strcmp(rx,"> ")==0)
{
PORTC |= 0x10;
send("ATMEGA16L says Hello");
send(d2);
}


}

ISR(TIMER0_OVF_vect)
{
counter++;

if(counter==60)
{
PORTB |=0x08;
// counter=0;
TIMSK=0x0;//Disable timer interrupt to free-up controller

}

}

No comments:

Post a Comment