PDA

View Full Version : Connecting PIC16F877 with GSM modem ADH8066



jennalin
- 15th September 2011, 10:28
Hi guys,
I am currently working a project which aims to send people sms through the control of PIC. I have following problems:
1. Not sure whether can I directly connecting UART port of GSM with UART port of PIC, or should I add a MAX232 chip instead?
2. Not sure whether I connected ADH8066 modem correctly, I am new to this topic and from I obtained from its datasheet, only ONKEY, VBAT, RX0, GND and GPIO10 for indicator.
3. My code is attached and please help me find out the possible errors.
Thanks.

PS. This project is due in two weeks time and I am planning to do the GSM module receiving sms part after the sending part is successful.

#ifndef __CPU_16F877__
#error "This program is tailored for PIC16F877 controller"
#endif

// Include all the header files needed
#include "io16f877.h"
#include "USART.h"
#include "DELAYS.h"

// define the ports used
#define TEST_LED RD7
#define PB RB0

//initialize IO ports
void initialize_IO_ports(void)
{
TRISD = 0x00; //Port D is output.
TRISC = 0x40; //RX = 0, TX = 1.
TRISB = 0xFF; //Port B is input.
//clear the output port
PORTD = 0x00;
}

void send(unsigned char data[],int length)
{
unsigned int i;
for(i=0;i<length;i++)
{
DelayMs(10);
TXREG=data[i];
while(!TRMT);
DelayMs(10);
}
}
// main function
void main()
{
unsigned char flag = 0;
unsigned char atset[]="AT\r\n";
unsigned char testset[]="AT+CMGF=1\r\n";
unsigned char numset[]="AT+CMGS=\"83434778\"\r\n";
unsigned char message[]="hello";

// initialization of the peripherals to be used by
// calling the respective initialization function.
initialize_IO_ports();
init_uart();
TXREG = 0x00;

while(1)
{
if(PB == 0)
{
DelayMs(80);
if(PB == 0)
{
flag = ~flag;
}
}

if(flag)
{
TXEN = 0;
TEST_LED = 1;
TXEN = 1; //enable transmission

send(atset,sizeof(atset));
DelayMs(30);
send(atset,sizeof(atset));
DelayMs(30);
send(atset,sizeof(atset)); //to configure the GSM module
DelayMs(30);
send(textset,sizeof(textset));
DelayMs(20);
send(numset,sizeof(numset));
DelayMs(20);
send(message,sizeof(message));
DelayMs(20);
TXREG=0x1A; //end of file
while(!TRMT);

flag = ~flag; //flag toggle at the end of transmission

}//end of if
}//end of while

}// end of main

mackrackit
- 15th September 2011, 10:41
Hi,

You will have better luck getting an answer on the Micrchip forum. We do Pic Basic Pro here.
http://melabs.com/

jennalin
- 20th September 2011, 13:50
Hi,
I can already receive my message but the message is blank. Why is that happening? Anyone can help me solve this problem? Thanks.