Professional Documents
Culture Documents
HA NOI - 2014
HA NOI - 2014
AUTHORSHIP
I hereby declare that the work contained in this thesis is of my own and has not been
previously submitted for a degree or diploma at this or any other higher education
institution. To the best of my knowledge and belief, the thesis contains no materials
previously published or written by another person except where due reference or
acknowledgement is made.
Signature:
SUPERVISORS APPROVAL
I hereby approve that the thesis in its current form is ready for committee examination
as a requirement for the Bachelor of Engineering and Technology degree at the
University of Engineering and Technology.
Signature:
ii
ACKNOWLEDGEMENT
First of all, I would like to express special thanks to Assoc. Prof. Tran Duc-Tan
who always guides me, points out the mistakes, and gives me the instructions and
comments during the time to realize this work. Without his supervising, I would
have many difficulties to finish this thesis.
Secondly, I want to give my sincerely thanks to the faculty members and staffs of
the Faculty of Electronics and Telecommunication, VNU-UET for their
enthusiasm to guide me to for the background of knowledge
I also greatly appreciate all members of the MEMS Lab who always facilitate me
to do this thesis, answer my questions in a familiar way and share their experience
for me as well as make me feel comfortable and better in studying
Finally, I want to give the best thank to my parents, my relatives and my friends
who always encourage, take care me during the studying and researching period.
Sincerely
Nguyen Van Tinh
iii
ABSTRACT
A simple fall can have devastating consequences for the elderly. If it happens, they
can become disoriented, immobilized, or knocked unconscious and unable to call
for help. This thesis aims to create a portable device to monitor the falls in older
adults by using a micro controller PIC18f4520, a 3-DOF acceleration sensor
ADXL345, a GSM/GPRS modem SIM900 and an embedded fall detection
algorithm. The human activities can be sensed by the 3-DOF accelerometer. The
acceleration signals are brought to the micro controller to monitor and alert the
fall. If the people fall, an alert message would be sent to their relative through the
GSM/GPRS modem. The experiment device has been tested carefully and it can
be applied to real application after the carefully evaluation and analyses.
iv
Table of Contents
vi
List of Figures
vii
viii
List of Tables
ix
ABBREVATIONS
DOF
Degree Of Freedom
ZCR
MCU
Microcontroller Unit
SMS
GPRS
LCD
I2C
UART
SPI
CCS
Chapter 1
INTRODUCTION
1.1 Motivation
Every year in the world, approximately 28-35% of people aged of 65 and over
experience falls. The frequencies of falls are different between aged and appear to
vary in among countries as well. For example, every year by the research of in
South- East Asia Region found that in China 6-13%, another found that in Japan
20% of elderly fell. Meanwhile in Europe region 30% of people over 65 and 50%
of those over 80 years fell each year, the same research found that in Region of
American the proportion of older adults who fell each year ranging from 21.6% in
Barbados to 34% in Chile [1] [2] .
Experiencing a fall unobserved can be dangerous, highly probability of get serious
injury consequence or due to death if treatment is not providence in time. By the
research, the falls mortality rates account for 40% all of injury and the cost of fall
injury in older person reached for hundreds of millions of dollars [1] [3] .
Chapter 2
In this section, we will describe brief about our method and schedule of function
working in our system.
The sensor used in this project was one 3-axis accelerometer, particular was
ADXL345 accelerometers manufacturing by Analog Devices Company. Our
accelerometer was positioned in the waist body so that y-axis must parallel with
Earths gravity. A 3-axis ADXL345 sensor is return in a real-valued estimate of
the acceleration along the x, y and z-axes from which velocity and orientation
angle can be estimated. Reading data from sensor with sample rate was 10Hz and
processing within buffer 10 data. By applying the threshold, posture recognition
module will show us whenever we standing, walking, lying or in null state. The
function of fall detection module is detecting the fall events base on threshold. . If
the system detects the falling event, by combination with posture period time
after event of fall, it automatically sends an SMS message through GSM/GPRS
modem SIM900 to the responsive contact.[7] .
Here is our proposed system of automatic falls detect system in elderly, in which
accelerometer ADXL345 returns the value of acceleration in 3-axis. MCU is
center of processing and control within system, LCD 16x2 is display the values of
acceleration 3 axis x, y, z or signal control and function of SIM900 module is send
SMS message to relative contacts.
2.1 Hardware
2.1.1 MCU PIC18f4520
The SIM900 GSM/GPRS Shield provides you a way to use the GSM cell phone
network to receive data from a remote location. The shield allows you to achieve
this via any of the three methods:
-
Audio
GPRS Service
The GPRS Shield is compatible with all boards which have the same form factor
(and pin out) as a standard Adriano Board. The GPRS Shield is configured and
controlled via its UART using simple AT commands. Based on the SIM900
module from SIMCOM, the GPRS Shield is like a cell phone. Besides the
communications features, the GPRS Shield has 12 GPIOs, 2 PWMs and an ADC.
Highlight feature:
- Quad-Band 850 / 900/ 1800 / 1900 MHz - would work on GSM networks
in all countries across the world.
-
12
SIM interface:
STATUS
NETLIGHT
Network status
SIM_VDD
SIM_DATA
SIM_DAT input/output
SIM_CLK
SIM clock
SIM_RST
SIM reset
Serial port: RXD and TXD for UART communication between MCU and
SIM900 module
14
Figure 2-12: I2C protocol between sensor ADXL345 and MCU [12] .
The physical I2C bus
This is just two wires, called SCL and SDA. SCL is the clock line. It is used to
synchronize all data transfers over the I2C bus. SDA is the data line. The SCL &
SDA lines are connected to all devices on the I2C bus. There needs to be a third
wire, which is just the ground or 0 volts. There may also be a 5volt wire is power
is being distributed to the devices. Both SCL and SDA lines are "open drain"
drivers. What this means is that the chip can drive its output low, but it cannot
drive it high. For the line to be able to go high, you must provide pull-up resistors
to the 5v supply. There should be a resistor from the SCL line to the 5v line and
another from the SDA line to the 5v line. You only need one set of pull-up
resistors for the whole I2C bus, not for each device, as illustrated below [11] :
15
16
Data is transferred in sequences of 8 bits. The bits are placed on the SDA line
starting with the MSB (Most Significant Bit). The SCL line is then pulsed high,
then low. Remember that the chip cannot really drive the line high, it simply "lets
go" of it and the resistor actually pulls it high. For every 8 bits transferred, the
device receiving the data sends back an acknowledge bit, so there are actually 9
SCL clock pulses to transfer each 8 bit byte of data. If the receiving device sends
back a low ACK bit, then it has received the data and is ready to accept another
byte. If it sends back a high then it is indicating it cannot accept any further data
and the master should terminate the transfer by sending a stop sequence [11] .
Clock
The standard clock (SCL) speed for I2C up to 100KHz. Philips do define faster
speeds: Fast mode, which is up to 400KHz and High Speed mode which is up to
3.4MHz [11] .
I2C Device Addressing
All I2C addresses are either 7 bits or 10 bits. All of our modules and the common
chips you will use will have 7-bit addresses. This means that you can have up to
128 devices on the I2C bus, since a 7-bit number can be from 0 to 127. When
sending out the 7-bit address, we still always send 8 bits. The extra bit is used to
inform the slave if the master is writing to it or reading from it. If the bit is zero
the master is writing to the slave. If the bit is 1 the master is reading from the
slave. The 7-bit address is placed in the upper 7 bits of the byte and the
17
Read/Write (R/W) bit is in the LSB (Least Significant Bit). The address of slave
ADXL345 is 0x53 [11] .
the I2C address of the slave with the R/W bit low (even address) and the internal
register number you want to write to. Now you send another start sequence
(sometimes called a restart) and the I2C address again - this time with the read bit
set. You then read as many data bytes as you wish and terminate the transaction
with a stop sequence [11] .
-
In this case, the sender and receiver must agree on timing parameters (Baud Rate)
prior transmission and special bits are added to each word to synchronize the
sending and receiving units [10] .
Figure 2-14: Basic UART packet form: 1 start bit, 8 bits data, 1 parity and 1
stop bit [10]
Every operation of the UART hardware is controlled by a clock signal, which runs
at much faster rate than the baud rate. Transmitting and receiving UARTs must be
set at the same baud rate, character length, parity, and stop bits for proper
operation. The typical format for serial ports used with PC connected to modems
is 1 Start bit, 8 data bits, no Parity and 1 Stop bit.
UART is the simplest form of communication between microcontroller and PC.
However, due to the mushrooming growth of technology, serial port is slowly
being replaced by other means of communication port such as USB to RS-232
[10] .
2.3.3 Timer
Timer as the name suggests pertain to time-related operations. They are mostly
used for exact delay generation. Timers are also used in various other operations
like PWM signal generation, auto-triggering of several other peripherals. In our
project, we used timer0 for calculating data sample rate and timer1 for calculating
exactly time to detect falls.
20
Each of the four timers of Pic f84520 has certain special features some of which
are explained below. The detailed list of these features can be obtained from
PIC18f4520 datasheet.
Timer0
-
Timer1
-
Timer3
-
Interrupt on overflow
Timer3 can be multiplexed with other peripherals like ADC etc. and
generates special event triggering for CCP (Capture, Compare and PWM)
events.
Ttimer 1/ Ftimer
Where FOSC is Clock source frequency (Crystal). Prescaler is integer number takes
the basic timer clock frequency (power of 2 from 0 -
2nbit )
This means that when Timer runs, it will take Ttimer sec to increment its value at
every count.
22
2.4 Algorithms
2.4.1 System architecture
The posture recognition and fall detection process describe in this project is
divided to several phases such as show in Figure 17.
The first is in the real world in which sensor accelerometers ADXL345 is
positioned in waist body region. The next phase is sensory part, after sampled rate
with 10Hz; the data received from the accelerometer was in the form of a threevalued vector of floating point numbers that represented the individual
accelerations of sensor ADXL345 in the x, y, z-axes subtracted by the gravity
vector G. The acceleration values was recorded in meters per second squared (
m
2
s
).Thus, lay flat on a level surface, the expected reading of the accelerometer would
be approximately [0.0, 9.81]. In this phase we has signal process step before data
get into attribute extraction module to formulated mean, orientation, standard
deviation. The last final phase is data mining body posture recognition and fall
detection. Each of these modules gives an output: the real time posture of body
and fall or not fall events [4] [7] [9] .
yt .xt (1 ). yt 1
Where yt is our filtered signal, yt 1 is the previous filtered signal, xt the
accelerometer reading and the smoothing factor.
- Average
Next process step, we accumulated the output data, and then took average over
buffer 10 for making data more accuracy.
- Offset
Finally, we took offset of output average data. Consequently gravitational
acceleration response in some position satisfied with real life.
24
The comparison of walking state is show before and after low-pass filter and
average.
18
An
16
Null
14
Lying
L2 gia toc
12
10
Standing
Walking
10
20
30
Thoi gian - s
40
50
60
18
An
16
Null
14
Lying
L2 gia toc
12
10
Standing
Walking
10
20
30
Thoi gian - s
40
50
60
26
respectively, with requirement result simulation in MATLAB has the same with
the experiments.
27
28
Flowchart of algorithm:
Fall detection
Posture recognition
Posture after 7s of
Final
Fall
decision
Fall
Standing
Dont care
False
Fall
Walking
Dont care
False
Fall
Lying
Dont care
False
Standing or Walking
False
Lying or Null
True
Standing or Walking
False
Lying or Null
True
Fall
Fall
Lying
Null
29
Posture
reocognition
Fall detection
Posture after
7s of fall
Final decision
A*B*C
Standing
Walking
Lying
Null
Looking at the table, if fall detection event occur, if state of posture recognition in
this time is still walking, standing the fall decision final will be discarded. In the
same with another case if posture in the time of fall is lying or null, but after 7
second, the posture is standing or walking, final decision is false too.
Analysis of the algorithms
The data from accelerometer ADXL345 is stored in buffer of suitable length,
mention again, in our case it is fixed as 10 samples, as the sampling rate is fixed as
10 Hz, then we will take average over the buffer length, the purpose of this to get
data that are more accurate. Lowering or high the window size, will affect the
decision of posture recognition. The reason behind that the, the zero crossing rate
requires a constant oscillation for particular the amount of time to figure out the
between states of walking and momentary jitter (no state) [7].
30
Value
2
4
10
15
34
35
By do one more experiment in Figure 2-28, we got the correct detect of fall in
final decision in nearly 60 second.
37
Fdatasamplerate
1
Tcoderunning time
38
Where
Fdatasamplerate is
is code running
39
Chapter 3
Imagine of system
40
41
43
Conclusions
The fall monitoring system is still a new application in Vietnam and it has good
potential to develop and commercialize. During the period I follow this research
direction, I have study some posture recognition and fall detection algorithms.
After that, I have proposed an improvement in algorithms in order to enhance the
device's performance. Firstly, the algorithms have been simulated in MATLAB
environment. After that, it can be re-programmed in C language which is suitable
with the micro controller. I have also learned how to design and develop a real
device and how to program it. For the hardware part, I has learned how to work
with the accelerometer ADXL345, process the data and filter noise from it; I also
study about: 1) I2C to communicate between sensor and the microcontroller, 2)
UART to communicate between the microcontroller with the GSM/GPRS modem
SIM900 in order to send message to relative, 3) timers in the micro controller. I
also have built a database of postures and falls. The experiment device has been
tested carefully. In lab experiment, the device can offer to an accuracy of 85%. It
can be applied to real application after further evaluation and analyses.
44
References
[1] Marilyn Langfeld, Adina Murch,Ann Feild. WHo Global report on falls
Prevention in older Age. France: World Health Organization, 2007.
[2] Fact sheet: Prevention of Falls among Elderly. Athens-GREECE: Center for
Research and Prevention of Injuries-CEREPRI Department of Hygiene &
Epidemiology, 2012.
[3] Report of Cost of Falls Injury in Older Persons in United States. Atlanta:
Center for Disease Control and Prevention National Center for for Injury
Prevention and Control (NCIPC), http://www.cdc.gov, 2013.
[4] Hristijan Gjoreski, Mitja Lutrek, Matja Gams. "Accelerometer Placement for
Posture Recognition and Fall Detection." Intelligent Environments (IE),
2011 7th International Conference on. Nottingham: IEEE, 25-28 July 2011.
[5] Petar Mostarac, Roman Malari, Marko Jurevi, Hrvoje Hegedu, Aim LayEkuakille, Patrizia Vergallo. "System for monitoring and fall detection of
patients using mobile 3-axis accelerometers sensors." Medical
Measurements and Applications Proceedings (MeMeA). Bari: IEEE, 30-31
May 2011.
[6] NingJia. "Detecting Human Falls with a 3-Axis Digital Accelerometer." July
2009. http://www.analog.com/.
[7] BharadwajS. Fall Detection with Posture recognition on Android Smart
phone. December 2012. https://github.com.
[8] Jonathan Tomkun, Binh Nguyen. "Design of a F all Detection and Prevention
System for the Elderly." Electrical and Biomedical Engineering Design
Project, Ontario, Canada, 2010.
[9] Sauvik Das, LaToya Green, Beatrice Perez, Michael Murphy. "Detecting User
Activities using the Accelerometer on Android Smartphones." 30 July ,
2010. https://www.truststc.org.
[10] WWKong. UART Universal Asynchronous Receiver and Transmitter.
December 2010. http://tutorial.cytron.com.
[11] Gerry. Using the I2C Bus. n.d. http://www.robot-electronics.co.uk/.
[12] Analog Devices. "3-Axis, 2 g/4 g/8 g/16 g Digital Accelerometer." n.d.
http://www.analog.com/.
[13] Microchip Technology Incorporated. "PIC18F2420/2520/4420/4520 Data
Sheet." 2004. http://www.microchip.com/.
45
Appendix A
/* Name : Nguyen van Tinh K55D
Title: Fall_detection of elderly people
- Reading and data process from adxl345
- use timer0 to determine time sampling data
- use timer1 to determine time is real fall occur(>=7s)
- use period interupt uart to send SMS
- Apply algorithm fall include:
- Posture recognition
- falldetection
- Final decision
- send SMS through GSM Sim900
*/
#include <18f4520.h>
// MCU
#device HIGH_INTS = TRUE
// To use priority interrupt of Timer1
#include <MATH.H>
//============================== Initialize system step ============================//
#use delay (clock=20000000)
// Clock Crystal 20 Mhz
#use rs232 (baud=9600, xmit=PIN_C6, rcv=PIN_C7) // UART communication
#use i2c (Master,sda=PIN_C0, scl=PIN_C1)
// I2C interface
#fuses HS, NOPROTECT, BROWNOUT, PUT, NOLVP // Setup the complier
#include <lcd_lib_4bit.c>
// LCD 16x2 library
#define DEVICE1 (0x53)
// Address of ADXL345 sensor
#include <stdio.h>
#include <stdlib.h>
//========================== Define ADXL345 register address =======================//
#define BW_RATE
44
#define POWER_CTL
45
#define DATA_FORMAT
49
#define DATAX0
50
#define DATAX1
51
#define DATAY0
52
#define DATAY1
53
#define DATAZ0
54
#define DATAZ1
55
#define FIFO_CTL
56
//======================== Define variable and Threshold value =======================//
const int FiFo = 10 ;
// window size
const float th = 10 ;
// to remove dc Th
const float th1 = 0.7;
// threshold to check walking or null
const int th2 = 4.0 ;
// threshold to check lying or standing
const float sigma = 0.15 ;
// remove jiter
const float value = 1.3;
// threshold compare to detect fall Th4
int id, power;
signed int16 aXout[FiFo] ;
// FiFo buffer array
signed int16 aYout[FiFo] ;
signed int16 aZout[FiFo] ;
signed int16 Acce_OutputX = 0 ;
// Output 3-axis ADXL345 variable
signed int16 Acce_OutputY = 0 ;
signed int16 Acce_OutputZ = 0 ;
46
float aXoutAverage = 0 ;
float aYoutAverage = 0 ;
float aZoutAverage = 0 ;
float gx = 0 ;
float gy = 0 ;
float gz = 0 ;
float g = 0 ;
// Averages variable
// An norm aceleration
47
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
timer0_ini();
ini_adxl345();
reset();
at_command();
reset();
for (i=0 ;i <= FiFo-1; i++ )
{
aXout[i] = 0 ;
aYout[i] = 0 ;
aZout[i] = 0 ;
}
while(true)
{
// loop
if(flag0 == 1)
// if interrupt Timer0 occur
{
flag0 = 0;
output_low(PIN_B1);
id= read(0x53,0x00);
power=read(0x53,0x2D);
//------------------------------------------ receive value from ADXL345---------------------------------------- //
Acce_OutputX = (read(DEVICE1,DATAX1)*256) | (read(DEVICE1,DATAX0));
Acce_OutputY = (read(DEVICE1,DATAY1)*256) | (read(DEVICE1,DATAY0));
Acce_OutputZ = (read(DEVICE1,DATAZ1)*256) | (read(DEVICE1,DATAZ0));
//-------------------------------- Queue of data before signal process------------------------------------------- //
for(i= 0 ; i <= FiFo-2;i++ )
{
aXout[i] = aXout[i+1];
aYout[i] = aYout[i+1];
aZout[i] = aZout[i+1];
}
aXout[FiFo-1] = Acce_OutputX ;
aYout[FiFo-1] = Acce_OutputY ;
aZout[FiFo-1] = Acce_OutputZ ;
//------------------------------------------------ Average the data -------------------------------------------------//
for(i=0 ; i <= FiFo-1 ; i++ )
{
aXoutAverage = aXoutAverage + (float)aXout[i];
aYoutAverage = aYoutAverage + (float)aYout[i];
aZoutAverage = aZoutAverage + (float)aZout[i];
}
aXoutAverage = aXoutAverage / ( float )FiFo ;
aYoutAverage = aYoutAverage / ( float )FiFo ;
aZoutAverage = aZoutAverage / ( float )FiFo ;
//---------------------------------------------------- Convert to m/s^2 and Offset ------------------------------- //
gx = aXoutAverage*3.9/1000;
// +-2g SCALE = 3.9 mg/LSB (g unit)
gy = aYoutAverage*3.9/1000;
gz = aZoutAverage*3.9/1000;
gx = gx*9.81 - 0.5 ;// V0ff set V = V(d0) - [V(+)-V(-)/2]
gy = gy*9.81 - 0.5 ;
gz = gz*9.81 - 0.5 ;
48
49
{
diff[i+1]= a_vec[i+1] - a_vec[i];
}
i = 2;
while((i<FiFo-1)&&(flag != 2))
{
if(diff[i] < 0 && diff[i+1] > 0 && flag ==1)
{
tmin = i ;
flag = flag + 1;
}
else if (diff[i] > 0 && diff[i+1] < 0&& flag ==0)
{
tmax = i;
flag = flag +1;
}
i++;
}
minmax_attr = a_vec[tmax]-a_vec[tmin];
if(minmax_attr < value || tmax < tmin)
{
tmin = 0;
tmax = 0;
}
if(tmin != tmax)
{
for(i = tmin ;i < tmax;i++)
{
fall_decisionsignal[i] = 1 ;
}
}
tmin = 1;
tmax = 1;
flag = 0;
//============================ Final Fall decision =============================//
for(i = 0;i <= FiFo-1;i++)
{
if((decision_signal[i] == 10 && fall_decisionsignal[i] == 1) || (decision_signal[i] == 15 &&
fall_decisionsignal[i] == 1))
{
vitringa = i ;
timer1_ini();
enable_interrupts(INT_TIMER1);
break;
}
}
//======================== Check posture after 7s to decide send SMS ================//
if(flag1 == 1) // // lying > 7s -> Send SMS
{
dem1 = 0;
flag1 =0;
DISABLE_INTERRUPTS(INT_TIMER1);
if( decision_signal[vitringa] == 10 ||decision_signal[vitringa] == 15 )
50
{
dem1 = 0;
output_high(PIN_B1);
delay_ms(1000);
send_sms();
output_low(PIN_B1);
DISABLE_INTERRUPTS(INT_TIMER1);
}
}
//====================== Detele variable, array for next process ==================== //
aXoutAverage = 0 ;
aYoutAverage = 0 ;
aZoutAverage = 0 ;
for(i = 0 ; i <= FiFo-1 ;i++)
{
decision_signal[i] = 0;
zrc[i] = 0;
fall_decisionsignal[i] = 0;
}
}
}
}
//=================================End of main ================================//
//=============================== Function write in I2C ===========================//
void write(int device, byte address, byte val)
{
i2c_start();
i2c_write(device<<1);
i2c_write(address);
i2c_write(val);
i2c_stop();
}
//=========================== Function read in I2C ===============================//
byte read(int device, byte address)
{
int value;
i2c_start();
i2c_write(device<<1);
i2c_write(address);
i2c_start();
i2c_write(device<<1|0x01);
value=i2c_read(0);
i2c_stop();
return value;
}
// ================================= Timer0 initialize ============================//
void timer0_ini(void)
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT); // T_tm0=T_osc*4*256
set_timer0(0); // counter from 0
enable_interrupts(INT_TIMER0);
51
}
// ================================= Timer1 initialize ============================//
void timer1_ini(void)
{
setup_timer_1 ( T1_INTERNAL | T1_DIV_BY_8 );
set_timer1(0);
dem1 =0;
}
// ================================ Timer0 interrupt service ========================//
#INT_TIMER0
void interrupt_timer0_isr(void)
{
clear_interrupt(int_timer0);
set_timer0(0); // counter from 0
dem0++;
if(dem0 == 10 ) // f = 8hz
{
flag0 = 1;
dem0 = 0;
}
}
// ================================= Timer1 interrupt service =====================//
#INT_TIMER1
void interrupt_timer1_isr(void)
{
clear_interrupt(int_timer1);
set_timer1(0);
dem1++;
if(dem1 ==80)
{
flag1 = 1;
dem1 =0 ;
}
}
// ========================== Function check interrupt in UART ======================//
#INT_RDA FAST // period interrupt
void ngat()
{
c=getc();
if(c=='\r') c1=c;
if(c=='\n') c2=c;
if(c=='O') c3=c;
if(c=='K') c4=c;
if(c=='\r') c5=c;
if(c =='\n')c6=c;
if(c1=='\r' && c2=='\n' && c3=='O' && c4=='K'&& c5 =='\r'&& c6=='\n') new_sms=1;
}
// =========================== Function to reset SIM900 ===========================//
void reset(void)
{
int i ;
new_sms =0;
52
c1 = 0x00;
c2 = 0x00;
c3 = 0x00;
c4 = 0x00;
c5 = 0x00;
c6 = 0x00;
}
// ========================= Function check AT- Command =========================//
void at_command(void)
{
int8 j = 0;
j=0;
while(j++)
{
printf("AT\n\r");
// wait for interrupt
if(new_sms ==1)
{
new_sms = 0;
printf("AT-OK");
delay_ms(100);
break;
}
}
}
// ============================ Function to send SMS ============================//
void send_sms(void)
{
int i ;
printf("AT+CMGS=\"01667646812\"\r\n");
// Contact relative'number to send SMS
i = 0;
delay_ms(2000);
printf(" PHAT HIEN NGA !");
// contain of SMS
putc(26);
// ending message 26
printf("\"\r\n");
delay_ms(1000);
printf("Gui tin nhan...");
delay_ms(100);
printf("Da gui tin..");
delay_ms(100);
}
53