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.

Programming PIC16f877a to control LED board from GSM Modem TC35i

Status
Not open for further replies.

HammadLakhani

Junior Member level 2
Joined
Oct 7, 2013
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Karachi, Pakistan, Pakistan
Activity points
261
Hi,
I have started working on the code to program the PIC16f877a connected with GSM modem TC35i and an LED board. I need have a start up for the code what header files should I include and how would I control the LED's by giving an sms. i will be waiting for assistance. Thank you in advance.
 

If your command that you send as SMS is 10 characters wide then use a ring buffer (array) of say 12 or 15 elements. Every time there is a serial interrupt check if index is equal to buffer length. If yes, reset the buffer to 0. As the command in SMS will be the last part it will get stored in the buffer. To do this you have to read the message index every few seconds by issuing AT+CMGR=message_index\r\n command. Then parse and extract the command to another array and test if received command (message) matches with any messages hard-coded. If yes then take necessary action. Don't use big buffers as bank switching is a problem with 16F devices.
 
Thanx alot for such a good knowledge... I have started to work on the code... the source file which came along with the modem contains the header file of #include reg52. but that works for 8051 micro-controller as I am using PIC16f877a. But well yeah I started to make the code which is some thing like this : (This shows the sending part but I will need to recieve the messege from Modem to PIC16f877a controller to turn on/off LED's.)



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#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 {
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

 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top