Você está na página 1de 40

SMS CONTROLLED DEVICE

1
BTech 2014 Department of EEE
CHAPTER 1
INTRODUCTION


SMS Controlled Device is a circuit that lets you operate your home appliances like
lights and water pumps from your office or any other remote places. So if you forgot
to switch off the lights or other appliances while going out, it helps you to turn off
the appliances with your cell phone. Your cell phone works as the remote control for
your home appliances. You can control the desired appliances by sending the
corresponding SMS. The system also helps let you know the relay status.

GSM based Control System implements the emerging applications of the GSM
technology. Using GSM networks, a control system has been proposed that will act
as an embedded system which can monitor and control appliances and other devices
locally using built-in input and output peripherals.Remotely the system allows the
user to effectively monitor and control the house/office appliances and equipments
via the mobile phone set by sending commands in the form of SMS messages and
receiving the appliances status.

It comprises of PIC 16F876A micro controller, 16X2 LCD, ULN 2003 relay driver,
GSM Modem, 3 relays, 3 switches for operating the relay manually and a power
system is also incorporated to power the relay driver.

For controlling the three relays we require six coded words :

R1: Relay 1 ON
R2: Relay 2 ON
R3: Relay 3 ON

r1: Relay 1 OFF
r2: Relay 2 OFF
r3: Relay 3 OFF

This coded words are send by SMS from a GSM phone to a GSM module which is
incorporated in the SMS Controlled Device Circuit. The SMS received by the GSM
module is send via serial communication to the PIC 16F876A micro controller. The
SMS received is temporarily stored in an array. The microcontroller checks whether
the coded words are there with in the data received. If the coded words are found in
the data it takes the necessary action ie, to control the relay driver which in turn
control the relay.

A 16X2 LCD is also incorporated in the circuit to show the device status. The relays
can also be controlled manually with switches. The relay driver is operated with the
help of power system connected externally which is also being soldered in the PCB.
A relay driver is used to interface the relays with the microcontroller. The inter
facing is necessary because the PIC works at +5V supply and relay works at +12V.


SMS CONTROLLED DEVICE
2
BTech 2014 Department of EEE

CHAPTER 2
BLOCK DIAGRAM



Fig 1: Block diagram of SMS Controlled Device

In this project GSM module is used to transmit and receive message. The received
message is received by PIC6F876A by serial communication. It checks whether the
coded word are there within the received message. If so it perform the desired
operation. The relays at the out put is interfaced to the PIC micro controller via a
relay driver ULN 2003A. This is used because relay works at 12V and PIC at 5V.
We can also control the relay manually with switches connected to the PIC.
Status of the all relays are displayed in the LCD. Supply to PIC micro controller and
relays are also incorporated in the board.










SMS CONTROLLED DEVICE
3
BTech 2014 Department of EEE
CHAPTER 3
HARDWARE DESCRIPTION

3.1 CIRCUIT DIAGRAM
Schematic diagram


Fig 2 schematic diagram so SMS Controlled Device

SMS CONTROLLED DEVICE
4
BTech 2014 Department of EEE
PCB DESIGN






Fig 3 PCB layout of SMS controlled Device






















SMS CONTROLLED DEVICE
5
BTech 2014 Department of EEE
3.2 COMPONENTS


Main Components used are:
1) PIC 16F876A
2) Liquid Crystal Display
3) 12V Relay and ULN 2003 relay driver
4) GSM module SIM 900A
5) Push Button


3.2.1 PIC 16F876A
PIC is a family of modified Harvard architecture microcontrollers made by
Microchip Technology, derived from the PIC1650 originally developed by General
Instrument's Microelectronics Division. The name PIC initially referred to
"Peripheral Interface Controller'" now it is "PIC'" only.
made it cost less than CPUs that required a quartz "erase window" for erasing
EPROM.

Core Architecture

The PIC architecture is characterized by its multiple attributes:
Separate code and data spaces (Harvard architecture).
A small number of fixed length instructions
Most instructions are single cycle execution (2 clock cycles, or 4 clock cycles in 8-bit
models), with one delay cycle on branches and skips
One accumulator (W0), the use of which (as source operand) is implied (i.e. is not
encoded in the opcode)
All RAM locations function as registers as both source and/or destination of math
and other functions.
A hardware stack for storing return addresses
A small amount of addressable data space (32, 128, or 256 bytes, depending on the
family), extended through banking
Data space mapped CPU, port, and peripheral registers
ALU status flags are mapped into the data space
The program counter is also mapped into the data space and writable (this is used to
implement indirect jumps).
There is no distinction between memory space and register space because the RAM
serves the job of both memory and registers, and the RAM is usually just referred to
as the register file or simply as the registers.





SMS CONTROLLED DEVICE
6
BTech 2014 Department of EEE
Data space (RAM)

PICs have a set of registers that function as general purpose RAM. Special purpose
control registers for on-chip hardware resources are also mapped into the data space.
The addressability of memory varies depending on device series, and all PIC devices
have some banking mechanism to extend addressing to additional memory. Later
series of devices feature move instructions which can cover the whole addressable
space, independent of the selected bank. In earlier devices, any register move had to
be achieved via the accumulator.
To implement indirect addressing, a "file select register" (FSR) and "indirect
register" (INDF) are used. A register number is written to the FSR, after which reads
from or writes to INDF will actually be to or from the register pointed to by FSR.
Later devices extended this concept with post- and pre- increment/decrement for
greater efficiency in accessing sequentially stored data. This also allows FSR to be
treated almost like a stack pointer (SP).
External data memory is not directly addressable except in some high pin count
PIC18 devices.

Advantages

Small instruction set to learn
RISC architecture
Built in oscillator with selectable speeds
Easy entry level, in circuit programming plus in circuit debugging PICKit units
available for less than $50
Inexpensive microcontrollers
Wide range of interfaces including IC, SPI, USB, USART, A/D, programmable
comparators, PWM, LIN, CAN, PSP, and Ethernet[8]
Availability of processors in DIL package make them easy to handle for hobby use.

Limitations

One accumulator
Register-bank switching is required to access the entire RAM of many devices
Operations and registers are not orthogonal; some instructions can address RAM
and/or immediate constants, while others can only use the accumulator
The following stack limitations have been addressed in the PIC18 series, but still
apply to earlier cores:










SMS CONTROLLED DEVICE
7
BTech 2014 Department of EEE
PIN DIAGRAM

Fig 4 Pin diagram of PIC16F876A
SPECIFICATION
Operating frequency

20MHZ

Resets(and delays)


POR, BOR
(PWRT, OST)

Flash Program Memory
(14 bit word)
8K


Data memory(bytes)

368

EEPROM


256

Interrupt

14

I/O ports

ports A, B, C

Capture/compare/PCOM module

2

Timers

3

Serial communication MSSP, USART
10 bit analog to digital module

5 i/p channel

Analog comparator

2

Instruction set 35 instructions
Table 1 Specifications of PIC16F876A
SMS CONTROLLED DEVICE
8
BTech 2014 Department of EEE
3.2.2 16X2 LCD

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very
commonly used in various devices and circuits. These modules are preferred over
seven segments and other multi segment LEDs. The reasons being: LCDs are
economical; easily programmable; have no limitation of displaying special &
even custom characters (unlike in seven segments), animations and so on.
A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In
this LCD each character is displayed in 5x7 pixel matrix. This LCD has two
registers, namely, Command and Data. The command register stores the command
instructions given to the LCD. A command is an instruction given to LCD to do a
predefined task like initializing it, clearing its screen, setting the cursor position,
controlling display etc. The data register stores the data to be displayed on the LCD.
The data is the ASCII value of the character to be displayed on the LCD. Click to
learn more about internal structure of a LCD







Fig 5 LCD




SMS CONTROLLED DEVICE
9
BTech 2014 Department of EEE






















Table 2 specification of LCD



















SMS CONTROLLED DEVICE
10
BTech 2014 Department of EEE
3.2.3 GSM Module


A GSM modem is a specialized type of modem which accepts a SIM card, and
operates over a subscription to a mobile operator, just like a mobile phone. From the
mobile operator perspective, a GSM modem looks just like a mobile phone.

When a GSM modem is connected to a computer, this allows the computer to use the
GSM modem to communicate over the mobile network. While these GSM modems
are most frequently used to provide mobile internet connectivity, many of them can
also be used for sending and receiving SMS and MMS messages
.
A GSM modem can be a dedicated modem device with a serial, USB or Bluetooth
connection, or it can be a mobile phone that provides GSM modem capabilities.

A GSM modem exposes an interface that allows applications such as SMS to send
and receive messages over the modem interface. The mobile operator charges for this
message sending and receiving as if it was performed directly on a mobile phone. To
perform these tasks, a GSM modem must support an extended AT command set
for sending/receiving SMS messages.

GSM modems can be a quick and efficient way to get started with SMS, because a
special subscription to an SMS service provider is not required. In most parts of the
world, GSM modems are a cost effective solution for receiving SMS messages,
because the sender is paying for the message delivery

This GSM Modem can accept any GSM network operator SIM card and act just like
a mobile phone with its own unique phone number. Advantage of using this modem
will be that you can use its RS232 port to communicate and develop embedded
applications. Applications like SMS Control, data transfer, remote control and
logging can be developed easily.
The modem can either be connected to PC serial port directly or to any
microcontroller through MAX232. It can be used to send and receive SMS or
make/receive voice calls. It can also be used in GPRS mode to connect to internet
and do many applications for data logging and control. In GPRS mode you can also
connect to any remote FTP server and upload files for data logging.
This GSM modem is a highly flexible plug and play quad band SIM900A GSM
modem for direct and easy integration to RS232 applications. Supports features like
Voice, SMS, Data/Fax, GPRS and integrated TCP/IP stack.


SMS CONTROLLED DEVICE
11
BTech 2014 Department of EEE
Applications
SMS based Remote Control & Alerts
Security Applications
Sensor Monitoring
GPRS Mode Remote Data Logging

Features
Status of Modem Indicated by LED
Simple to Use & Low Cost
On board switching type power supply regulator
RS232 output





PINOUT




Fig 6 pinout of GSM Module
Network LED

The Network LED indicates the various status of GSM module eg. Power on,
Network registration & GPRS connectivity. When the modem is powered up, this
NETWORK LED will blink every second. After the Modem registers in the network
(takes between 10-60 seconds), this LED will blink in step of 3 seconds at slow rate.
At this stage you can start using Modem for your application,showing that modem is
registered with the network.

SMS CONTROLLED DEVICE
12
BTech 2014 Department of EEE
Send and Receive SMS

For sending SMS in text Mode:
AT+CMGF=1 press enter
AT+CMGS=mobile number press enter
Once The AT commands is given > prompt will be displayed on the screen. Type
the message to sent via SMS. After this, press ctrl+Z to send the SMS. If the SMS
sending is successful, ok will be displayed along with the message number.
For reading SMS in the text mode:
AT+CMGF=1 Press enter
AT+CMGR= no.
Number (no.) is the message index number stored in the sim card. For new SMS,
URC will be received on the screen as +CMTI: SM no. Use this number in the
AT+CMGR number to read the message.

The ground terminal of the GSM module and PIC are common. The transmission pin
of the GSM module is connected to the receiving pin of the PIC micro controller.
likewise the receiving pin of the GSM module is connected to the transmission pin of
the micro controller.


AT COMMANDS FOR SMS


AT+CSMS

select message service

AT+CMPS

preffered message storage

AT+CMGF

message format

AT+CSCA

service centre address

AT+CSMP

set text mode parameters

AT+CSPH

show text mode parameters

AT+CSCB
select cell broadcast message type
SMS CONTROLLED DEVICE
13
BTech 2014 Department of EEE


AT+CSAS

save settings


AT+CRES

restore settings

AT+CNMI

new message indication to TE

AT+CMGL
List messages

AT+CMGR
read messages


AT+CMGS

send messages

AT+CMSS

send message from storage

AT+CMGW


write to memory


AT+CMGD


delete messages

Table 3 AT Commands for SMS
















SMS CONTROLLED DEVICE
14
BTech 2014 Department of EEE
3.2.4 Push Button




Fig 7 push button

A push-button (also spelled pushbutton) or simply button is a simple switch
mechanism for controlling some aspect of a machine or a process. Buttons are
typically made out of hard material, usually plastic or metal. The surface is usually
flat or shaped to accommodate the human finger or hand, so as to be easily
depressed or pushed. Buttons are most often biased switches, though even many
un-biased buttons (due to their physical nature) require a spring to return to their
un-pushed state. Different people use different terms for the "pushing" of the
button, such as press, depress, mash, and punch














SMS CONTROLLED DEVICE
15
BTech 2014 Department of EEE
3.2.5 12V Relay and Relay Driver

12V RELAY

Fig 8 Relays

Relays are switches, the terminology applied to switches is also applied to relays;
arelay switches one or more poles, each of whose contacts can be thrown by
energizing the coil.

Normally SPDT switches are used. It basically consists of a coil and a SPDT switch.
The relay driver is used to isolate both the controlling and the controlled device. The
relay is an electromagnetic device, which consists of solenoid, moving contacts
(switch) and restoring spring and consumes comparatively large amount of power.
Hence it is possible for the interface IC to drive the relay satisfactorily. To enable
this, a driver circuitry, which will act as a buffer circuit, is to be incorporated
between them. The driver circuitry senses the presence of a high level at the input
and drives the relay from another voltage source. Hence the relay is used to switch
the electrical supply to the appliances. From the figure when we connect the rated
voltage across the coil the back emf opposes the current flow but after the short time
the supplied voltage will overcome the back emf and the current flow through the
coil increase. When the current is equal to the activating current of relay the core is
magnetized and it attracts the moving contacts. Now the moving contact leaves from
its initial position denoted (N/C) normally closed terminal which is a fixed
terminal. The common contact or moving contact establishes theconnection with a
new terminal which is indicated as a normally open terminal (N/O).
Whenever, the supply coil is withdrawn the magnetizing force is vanished. Now, the
spring pulls the moving contact back to initial position, where it makes a connection
makes with N/C terminal. However, it is also to be noted that at this time also a back
emf is produced. The withdrawal time may be in microsecond, the back emf may be
in the range of few kilovolts and in opposite polarity with the supplied terminals the
voltage is known as surge voltage. It must be neutralized or else it may damage the
system.










SMS CONTROLLED DEVICE
16
BTech 2014 Department of EEE

RELAY DRIVER



Fig 9 pin diagram of ULN2003A

The ULN2003AP/AFW Series are high_voltage, high_current darlington drivers
comprised of seven NPN darlington pairs.All units feature integral clamp diodes for
switching inductive loads. Applications include relay, hammer, lamp and display
(LED) drivers.

The ULN2003 is a monolithic high voltage and high current Darlington transistor
arrays. It consists of seven NPN Darlington pairs that feature high-voltage outputs
with common-cathode clamp diode for switching inductive loads. The collector-
current rating of a single Darlington pairs 500mA. The Darlington pairs may be
paralleled for higher current capability. Applications include relay drivers, hammer
drivers, lamp drivers, display drivers (LED gas Discharge), line drivers, and logic
buffers. The ULN2003 has a 2.7kW series base resistor for each Darlington pair for
operation directly with TTL or 5V CMOS devices.

Features
Output current (single output): 500 mA (max)
High sustaining voltage output: 50 V (min)
Output clamp diodes
Inputs compatible with various types of logic
Package Type-AP: DIP-16pin
Package Type-AFW: SOL-16pin





SMS CONTROLLED DEVICE
17
BTech 2014 Department of EEE
3.3 FLOW CHART




































START
BAUD RATE INITIALIZATION

GSM MODULE INITIALIZATION

RECEIVE MESSAGE

CHECK WHETHER
THE MESSAGE IS NEW

DECODE THE MESSAGE
CHECK WHETHER THE
CODE IS ACCEPTABLE

RELAY 1 WHETHER
ANY SWITCHING IS
NEEDED
RELAY 1 WHETHER
ANY SWITCHING IS
NEEDED
RELAY 1 WHETHER
ANY SWITCHING IS
NEEDED
SWITCH
SWITCH
SWITCH
SMS CONTROLLED DEVICE
18
BTech 2014 Department of EEE
3.4 POWER SYSTEM


Fig 10 Power System

15V is supplied to the input terminal. The voltage regulator 7412 is used to
regulate the 15V supply to 12V. Here 74 represents positive voltage level and 12
represents the regulated voltages. This regulated voltage is then passed through the
voltage regulator 7405. The voltage is regulated to 5V.















SMS CONTROLLED DEVICE
19
BTech 2014 Department of EEE
CHAPTER 4
INTERFACING OF COMPONENTS WITH PIC


PIC6F876A CONNECTION



Fig 11 PIC connections


Here the crystal used is of 20MHZ frequency. The MCLR pin is connected as a
voltage divider between a capacitor and a resistor. Vcc is applied to the resistor. The
capacitor charges. The pic is ON whenever the input to MCLR pin is 0 and when it
is 1 it becomes OFF state.













SMS CONTROLLED DEVICE
20
BTech 2014 Department of EEE
LCD INTERFACING WITH PIC 16F876A



Fig 12 LCD interfacing with PIC

The command to LCD are sent in the form of ASCII code to the LCD. The LCD
itself contains a micro controller inside it and pin 1 and 2 are connected to the supply
and ground respectively for the purpose of working of the microcontroller. Pin 15
and 16 are connected to VCC and the ground for backlight. Pin 3 is connected to 2.3
for the contrast adjustment. Here the PIC act as master and the LCD as slave

Port B is used for interfacing the PIC 16F876A with LCD. The LCD can be
interfaced with PIC either as 8 bit or as 4 bit. Here in this circuit it is 4 bit. RB4,
RB5, RB6, RB7 pins of PIC is connected with D4, D5, D6, D7 pins of LCD. The RS
and Enable pins of LCD are connected to RB2 and RB3 pins of PIC. R/W pin is
grounded. So total there are 6 i/o lines .















SMS CONTROLLED DEVICE
21
BTech 2014 Department of EEE
GSM module interfaced with PIC 16F876A


GSM module is interfaced with PIC 16F876A through serial communication. AT
commands are used to control the GSM module. To control the GSM module send a
message to it using AT commands with help of PIC 16F876A.
GSM Modem - RS232 - SIM900A
.


Fig 13 GSM Module
Easy interface with microcontroller/PC for Calling, SMS, Remote Control, Data
Logging, Alarm etc applications


This GSM Modem can accept any GSM network operator SIM card and act just like
a mobile phone with its own unique phone number. Advantage of using this modem
will be that you can use its RS232 port to communicate and develop embedded
applications. Applications like SMS Control, data transfer, remote control and
logging can be developed easily.


SMS CONTROLLED DEVICE
22
BTech 2014 Department of EEE

INTERFACING OF SWITCHES WITH THE PIC

Fig 14 interfacing switches with PIC
Switches are used to control the relay manually. Button type switches are used. This
connected to the port A pins of the micro controller. Here RA0, RA1, RA2 pins of
the micro controllers are connected to the switches. When the switch is pressed VCC
is grounded and the relay is turned ON. Likewise if the switch is opened the
corresponding relay is turned OFF.











SMS CONTROLLED DEVICE
23
BTech 2014 Department of EEE

INTERFACING OF RELAY AND RELAY DRIVERS


Fig 15 interfacing of relay and relay drivers with PIC

Relay driver ULN 2003A is used to interface between relay and the micro
controller. It is necessary because relay works at 12V and the PIC works at 5V
supply. So it is necessary to have the relay driver. The relay driver is connected to
the port c pins of the PIC 16F876A. Here we are taking only 3 outputs ie, we are
only controlling 3 appliances.
The RC0, RC1, RC2 pins of the PIC is connected to the input pins I1,I2, I3 of the
relay driver. It can also be extended if necessary. Corresponding outputs from the
relay driver are taken and connected to the relays.
LEDS are connected before the relay driver. When the signal from the PIC is high
the output of ULN goes low. As a result the current starts flowing through the coil.
The coil act as a magnet and the switch changes its state from normally opened state
to normally closed state. As a result the appliance connected to the relay is ON.
Likewise, if the signals from PIC goes low the output of relay driver goes high and
the current doesnt flow through the coil. The coil is not magnetised so the switch
remains in normally opened state. The 12V suppy to the relay driver is obtained with
the help of power supply system incorporated with in the pic.

SMS CONTROLLED DEVICE
24
BTech 2014 Department of EEE

SMS DEVICE CONTROLLER




Fig 16 SMS Device Controller





















SMS CONTROLLED DEVICE
25
BTech 2014 Department of EEE


5. RESULT AND CONCLUSION

5.1 RESULT

The circuit of our project was designed and implemented. The circuit worked as per
the desired specification given. The relays are working properly. When the supply is
given the LCD displays MACE then it displays SMS DEVICE
CONTROLER. Then the LCD displays relay status. It displays r1 r2 r3. All
relays are at OFF condition at start. LEDs are connected at the output. The LEDs
glows when the corresponding relays are ON or it doesnt glows. This circuit is very
useful as the devices can be controlled from remote places.



























SMS CONTROLLED DEVICE
26
BTech 2014 Department of EEE
5.2 CONCLUSION

The project we have undertaken has helped us gain a better perspective on various
aspects related to our course of study as well as practical knowledge of electronic
equipments and communication. We became familiar with software analysis,
designing,implementation, testing and maintenance concerned with our project.

The extensive capabilities of this system are what make it so interesting. From the
convenience of a simple cell phone, a user is able to control and monitor virtually
any electrical devices. This makes it possible for users to rest assured that their
belongings are secure and that the television and other electrical appliances was not
left running when they left the house to just list a few of the many uses of this system
.
The end product will have a simplistic design making it easy for users to interact
with This will be essential because of the wide range of technical knowledge that
homeowners have.


























SMS CONTROLLED DEVICE
27
BTech 2014 Department of EEE
REFERENCE

1. www.datasheetcatalog.com

2. http://www.engineersgarage.com LCD 16x2 DATA SHEET

3. http://www.circuitstoday.com /

4. Microcontrollers And Applications, Satish Shah
,Oxford Publications.

5. Microcontrollers and Embedded Systems, Mohammad Ali
Mazidi.

6. Microprocessors and Microcontrollers by Ayala

7. Wikipedia
www.wikipedia.com

8. www.efy.com

9. POWER ELECTRONICS by Dr. P.S BIMBHARA












SMS CONTROLLED DEVICE
28
BTech 2014 Department of EEE
SOFTWARES USED
1. Cadsoft Eagle Proffessional
2. Mikroc_Pro_Pic_2011 v
3. Proteus.Proffesional.V8



















APPENDIX A
SMS CONTROLLED DEVICE
29
BTech 2014 Department of EEE

PROGRAM

// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit; // LCD module connections
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

sbit sw1 at RA0_bit;
sbit sw2 at RA1_bit;
sbit sw3 at RA2_bit;

sbit rel1 at RC0_bit;
sbit rel2 at RC1_bit;
sbit rel3 at RC2_bit;
SMS CONTROLLED DEVICE
30
BTech 2014 Department of EEE

const code char cmgs[]={"AT+CMGS="};
const code char cmgr[]={"AT+CMGR=1\r\n"};
const code char cmgf[]={"AT+CMGF=1\r\n"};
const code char at_[]={"AT\r\n"};
const code char cmgd[]={"AT+CMGD=1\r\n"};

const code char home1[]={"9562950719"};
const code char home2[]={"9544522337"};
const code char home3[]={"9995931777"};

const code char rl1[]={"RELAY 1 "};
const code char rl2[]={"RELAY 2 "};
const code char rl3[]={"RELAY 3 "};

const code char on[]={"ON"};
const code char of[]={"OFF"};

unsigned char urt_read,ser[80],ser_p,urt_pr,cust;
unsigned char i,flag=0;

void uart_send(unsigned char dat)
{
uart1_write(dat);
delay_ms(20);
}

SMS CONTROLLED DEVICE
31
BTech 2014 Department of EEE
char* codetxt_to_ramtxt(const char* ctxt)
{
static char txt[25];
char i;
for(i =0; txt[i] = ctxt[i]; i++);

return txt;
}

void delay(unsigned char del)
{
while(del)
{
delay_ms(100);
del--;
}
}

void interrupt()
{
if(PIR1.RCIF)
{
PIR1.RCIF=0;
urt_pr=urt_read;
urt_read=UART1_Read();

if((urt_read=='C')&&(urt_pr=='+')) ser_p=0;
SMS CONTROLLED DEVICE
32
BTech 2014 Department of EEE

if((urt_read=='1')&&(urt_pr=='R')) rel1=1;

if((urt_read=='1')&&(urt_pr=='r')) rel1=0;

if((urt_read=='2')&&(urt_pr=='R')) rel2=1;

if((urt_read=='2')&&(urt_pr=='r')) rel2=0;

if((urt_read=='3')&&(urt_pr=='R')) rel3=1;

if((urt_read=='3')&&(urt_pr=='r')) rel3=0;

ser[ser_p]=urt_read;
ser_p++;
if(ser_p>80)
ser_p=0;

}
}

void welcome()
{
TRISA=0x07;
ADCON1=0x06;
TRISC=0x80;

SMS CONTROLLED DEVICE
33
BTech 2014 Department of EEE
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
LCD_OUT(1,6,"MACE");

PIR1=0x00;
INTCON=0xC0;
PIE1=0x20;

UART1_Init(9600); // Initialize UART module at 9600 bps
delay_ms(10); // Wait for UART module to stabilize

uart1_write_text(codetxt_to_ramtxt(at_));
delay(15);

Lcd_Cmd(_LCD_CLEAR); // Clear display
LCD_OUT(1,6,"SMS");
LCD_OUT(2,1,"DEVICE CONTROLER");

uart1_write_text(codetxt_to_ramtxt(cmgf));
delay(15);
uart1_write_text(codetxt_to_ramtxt(cmgd));

delay(15);
Lcd_Cmd(_LCD_CLEAR); // Clear display
}

SMS CONTROLLED DEVICE
34
BTech 2014 Department of EEE
void send_stat1()
{
uart1_write_text(codetxt_to_ramtxt(cmgs));
uart_send(34);

uart1_write_text(codetxt_to_ramtxt(home1));

uart_send(34);
uart_send(13);
delay(10);

uart1_write_text(codetxt_to_ramtxt(rl1));
if(rel1) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart1_write_text(codetxt_to_ramtxt(rl2));
if(rel2) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart1_write_text(codetxt_to_ramtxt(rl3));
if(rel3) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart_send(10);
SMS CONTROLLED DEVICE
35
BTech 2014 Department of EEE
uart_send(13);
delay(3);
uart_send(26);
}

void send_stat2()
{
uart1_write_text(codetxt_to_ramtxt(cmgs));
uart_send(34);

uart1_write_text(codetxt_to_ramtxt(home2));


uart_send(34);
uart_send(13);
delay(10);

uart1_write_text(codetxt_to_ramtxt(rl1));
if(rel1) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart1_write_text(codetxt_to_ramtxt(rl2));
if(rel2) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

SMS CONTROLLED DEVICE
36
BTech 2014 Department of EEE
uart1_write_text(codetxt_to_ramtxt(rl3));
if(rel3) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart_send(10);
uart_send(13);
delay(3);
uart_send(26);
}

void send_stat3()
{
uart1_write_text(codetxt_to_ramtxt(cmgs));
uart_send(34);

uart1_write_text(codetxt_to_ramtxt(home3));


uart_send(34);
uart_send(13);
delay(10);

uart1_write_text(codetxt_to_ramtxt(rl1));
if(rel1) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);
SMS CONTROLLED DEVICE
37
BTech 2014 Department of EEE

uart1_write_text(codetxt_to_ramtxt(rl2));
if(rel2) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart1_write_text(codetxt_to_ramtxt(rl3));
if(rel3) uart1_write_text(codetxt_to_ramtxt(on));
else uart1_write_text(codetxt_to_ramtxt(of));
uart_send(10); uart_send(13);

uart_send(10);
uart_send(13);
delay(3);
uart_send(26);
}

void disp()
{
if(rel1==1)
LCD_OUT(2,1,"R1");
else
LCD_OUT(2,1,"r1");

if(rel2==1)
LCD_OUT(2,4,"R2");
else
SMS CONTROLLED DEVICE
38
BTech 2014 Department of EEE
LCD_OUT(2,4,"r2");

if(rel3==1)
LCD_OUT(2,7,"R3");
else
LCD_OUT(2,7,"r3");
}


void main()
{
PORTC=0x00;
welcome();

send_stat1();



while(1)
{
disp();
if(!sw1)
{
rel1=~rel1;
delay(10);
while(!sw1);
}
SMS CONTROLLED DEVICE
39
BTech 2014 Department of EEE

if(!sw2)
{
rel2=~rel2;
delay(10);
while(!sw2);
}

if(!sw3)
{
rel3=~rel3;
delay(10);
while(!sw3);
}

if((ser[3]=='I')&&(ser[2]=='T')&&(ser[1]=='M')&&(ser[0]=='C'))
{
for(i=0;i<75;i++)
ser[i]=0;

uart1_write_text(codetxt_to_ramtxt(cmgr));
flag=1;
delay(20);

uart1_write_text(codetxt_to_ramtxt(cmgd));
delay(15);

SMS CONTROLLED DEVICE
40
BTech 2014 Department of EEE
send_stat1();
delay(20);
send_stat2();
delay(20);
send_stat3();
delay(20);
}

}

}

Você também pode gostar