Академический Документы
Профессиональный Документы
Культура Документы
BASED
MEDICINE REMINDER
1
A
PROJECT REPORT ON
MICROCONTROLLER BASED MEDICINE REMINDER
Submitted to
The Mumbai University, Mumbai
In
Partial fulfillment of
M.Sc. in Physics
By
Miss. More Sampada V.
Miss. VichareAnuprita M.
Through
LOKMANYA TILAK POST GRADUATE CENTER,
RATNAGIRI
2017-2018
2
DECLARATION
This work has not been submitted for any other degree of this or any
other university.
Signature of candidates
Sampada More
AnupritaVichare
3
INDEX
Sr Page
Content No.
No.
1 Acknowledgement 5
2 Introduction 6
3 System Hardware-: 7
8051 ANSHUMAN kit
Timer and Interrupts
Mode 2 programming
IR sensor
Solenoid
7 Conclusion 51
8 Applications , Advantages and Limitations 52
9 Future Enhancement 53
10 References 54
4
ACKNOWLEDGEMENT
Last but not the least, we are thankful to all teachers and nonteaching
staff of the Physics department who directly or indirectly helped us to
complete this project.
- Participants
5
INTRODUCTION
In today’s world, many people have to take regular medicines for various
purposes. It may happen that a person forgets to take a dose of a medicine or
consumes a wrong medicine by mistake. To overcome these possibilities, we
are introducing the concept of a system called as “Medicine Reminder”.
In the system, the user is asked about the timing of taking various
medicines. The system contains 4 containers for the tablets from which user
can initially decide which tablets are to be taken at what time. There are 16
combinations of the boxes by which user can take any one of the combination.
According to the timing provided by the user, the system rings an alarm &
opens the container from which the user has to take the medicines at that
timing. The other containers remain locked. There is a locking system and LED
indication for each of the containers & only the LED of the opened container
glows at that time. The containers get locked automatically as the medicine
taken is sensed. If the medicines are not taken, the system gives alarm after a
specific time. Though the medicines are not taken, system gives an alert alarm
and the containers will get locked. Hence, the system works for morning,
afternoon, & night.
6
SYSTEM HARDWARE-:
Microcontroller 8051:
7
Block Diagram:-
8
8051 Pin Description:
Pin diagram of 8051 is shown in fig. One can easily see the pins
corresponding to the four ports P0,P1,P2 & P3.Port P0 and P3 pins are having
alternate functions. There are pins for power supply Vcc(Pin 40) and ground
(Pin 20).Pin 18 and 19 are for crystal connections. Finally, pins (Pin29),
ALE (Pin 30), (Pin 31) are Program Store Enable, Address Latch Enable and
External Acess,resp.
Pin diagram:-
9
XTAL2 (Pin 18)
Output of inverting amplifier that forms a part of the oscillator and input to the
internal clock generator .In case of external clock, it must be connected to
XTAL2.
XTAL1 (Pin19)
XTAL1 is the input to the inverting amplifier that forms part of oscillator circuit.
In case of external clock, this pin must be connected to ground.
VCC (Pin40)
VCC pin is connected to +5V power supply. Rated power supply current for
8031/8051 is 125 mA. For 8031/ 8051, maximum power dissipation rating is
1W.
VSS (Pin20)
VSS is the circuit ground. All the voltages are specified with respect to this pin.
For example, voltage on any pin with respect to VSS should be within -0.5 to
+7V range.
Port 0 is an 8-bit true bi –directional open drain I/O. Low order address and
data bus is also multiplexed with Port 0.Port 0 is open drain and must be pulled
high externally through a pull-up resistor.
Port 1 is an 8-bit quasi-bi-directional I/O. This term is due to the fact that Port
1 pins are internally pulled high with pull-up resistors. One has to configure it
either as i/p or o/p Writing a’1’ to the port latch cause it to act as input. When
10
configured as input, the port pin is pulled high and will source current if it is
made low externally.
Port 2 is also an 8-bit quasi-bi-directional I/O port. Port pins are pulled high
internally. It is multiplexed with the
Port 3 is again an 8-bit quasi-bi-directional I/O port. Port pins are pulled high
internally. There are other functions multiplexed with Port 3 pins. The
alternate function of Port 3 pins are related to external interrupts, serial port,
timer/counter and read/write control signal.
11
Pin 9(RST)
For resetting the device, the pin of 8051 is made high for two machine cycle,
while the oscillator is running.
ALE (Pin30)
Address latch enable (ALE) output is used for latching the low address byte
during external memory access.ALE is activated periodically with a constant
rate of 1/6 the oscillator frequency. However, during the external data
memory access, one ALE pulse is skipped.
(Pin29)
Program store enable ( ) is the output control signal activated every six
oscillator periods,while fetching the external program memory.It is the
readstrob to external program memory. During the internal program
execution, it remains high.
(Pin31)
External access ( ) pin, when held high, executes instruction from the
internal program memory till address 0FFFH,beyond this address,the
instruction are fetched from external program memory.If this pin is low, all the
instructions are fetched from the external memory. During normal operation,
this pin should not be floated.
12
Memory Organization:-
The MCS-51 has 64K external data memory, 64K program memory and
256 bytes of internal data memory. The program memory map of 8051 is
shown in fig. (A). The 64K program memory space of 8051 is divided into
internal and external memory. If the pin is high, then 8051 executes from
the internal program memory until the address exceeds 0FFFH.
FFFFH
External
Program External
Memory Program
Portion Memory
Of 8051
1000H
64K
0FFFH Internal
Program
Memory
0000H
(a) =1 (b) =0
13
Table: Program Memory of 8051 and Program Execution
After that, locations 1000H through 0FFFFH are executed from the external
memory portion. If pin is held low, then 8051 executes instructions from
external memory only. Above table shows this. The external 64K of data
memory can be accessed using MOVX instruction.
FFFFH
External
64K
7FH
Special Function
Registers (128 bytes)
0000H
(Direct and Indirectly
00H Addressable)
14
The internal data memory of 8051 is 256 bytes, which is divided into two parts
again. The lower 128 bytes (00H through 7FH) called as the internal data RAM
and the upper 128 bytes (80H through FFH) consists of special function
registers (SFRs). In case of 8032/52, the upper 128 bytes of internal data
memory are also addressable.
Even though the SFRs and upper 128 bytes of RAM have the same address
space, they are different and accessedthrough different addressing modes.
The lower 128 bytes of on-chip RAM are shown in fig. (C).
Program status word, or simply PSW, is an 8-bit register. Fig (D) shows
the PSW register. It consists of carry, auxiliary carry overflow and parity flags.
There are bits RS1 and RS0 for register bank selection. PSW is a bit addressable
register. Each of the PSW bits is referred as PSW.X. Thus, PSW.0 is the least
significant bit (LWB), which is a parity flag,There are bits RS1 and RS0 for
register bank selection. PSW is a bit addressable register. Each of the PSW
bitsis referred as PSW.X. Thus, PSW.0 is the least significant bit (LWB), which is
a parity flag, and the most significant bit(MSB) PSW.7 is the carry flag.
C AC F0 RS1 RS0 OV - P
Fig. Program Status Word
Carry flag is set when there is a carry out of 7th bit of result due to certain
arithmetic and logical operations.
Auxiliary Carry Flag (AC) is set when there is a carry out of 3rd bit, during
addition or subtraction operation and otherwise cleared. This is useful in BCD
arithmetic.
FO (PSW.5):-
16
register banks consists of registers R0 through R7. The register banks are
selected as below.
Parity flag indicated the number of ‘1’s in accumulator. If there are odd
number of ‘1’s in accumulator, then this odd parity will set the parity flag (P) to
1. For even parity, the parity flag will be cleared.
DPTR is a 16-bit register consisting of two bytes. The higher byte is referred to
as DPH, whereas then lower byte is referred to as DPL. The data pointer is
used for addressing the off-chip data and code with the MOVX and MOVC
commands, respectively. With 16-bit pointer DPTR, a maximum of 64K of off-
chip data memory and a maximmof 64K of off-chip program memory can be
17
addressed. It may be used as a general-purpose register also. There is an
instruction “INC DPTR” for incrementing 16-bit contents of DPTR. However,
there is no such instruction in 8051 to decrement the DPTR. It is also possible
to load the DPTR with a 16-bit immediate data using the MOV instruction.
Timer Registers:-
Register pairs (TH0, TL0), (TH1, TL1), (TH2, TL2) form 16-bit timer/counter
registers 0,1,2respectively.There are instructions for reading and writing these
registers byte-wise. Timer/Counter 2 is only available in 8052. The operation
may be timing or counting. Further, there are various modes in which timers
can be configured. For this purpose there are timer Control (TCON) and timer
mode registers (TMOD).
Ports 0 to 3:-
P0, P1, P2, P3 are the SFRs corresponding to four I/O ports respectively. Each
of these ports is bit addressable as well as byte addressable.
Control Registers:-TCON, TMOD, IE, IP, SCON, PCON contain the control and
status for interrupts, serial I/O and timer/counters.
The 8051has two timers: Timer 0 and timer1. They can be used either as
timers or as event counters. We will discuss the timer’s registers and then
show how to program the timers to generate time delays.
Both Timer 0 and Timer 1 are 16 bits wide. Since the 8051 has 8-bit
architecture, each 16-bit timer is accessed as two separate registers of low
byte and high byte. Each timer is discussed separately.
18
Timer 0 registers:
The 16-bit register of Timer 0is accessed as low byte and high byte. The low
byte register is called TL0 (Timer 0 low byte) and the high bit register is
refferedto as TH0 (Timer 0 high byte). These registers can be accessed like any
other register, such as A,B,R0,R1,R2,etc.For example, the instruction ‘’MOV
TL0,# 4FH’’ movesthe value 4FH into TH0, the low byte of Timer 0. These
registerscan also be read like any other register. For example, ‘’MOV R5, TH0’’
saves TH0 (high of timer 0) in R5.
Timer 1 register:
Timer 1 is also 16 bits, and its 16-bit register is split into two bytes, referred
to as TL1 (Timer 1 low byte) and TH1 ( Timer 1 high byte). These registersare
accessible in the sameway as the registers of Timer 0.
Both timers 0 and 1 use the same register, called TMOD, to set the various
timer operation modes. TMOD is an 8-bit register in which the lower bits are
set aside for Timer 0 and the upper 4 bits for Timer 1. In each case, the lower
two bits are used to set the timer mode and the upper two bits to specify the
operation. These options are discussed below.
M1,M0:
M0 and M1 select the timer mode. There are three modes: 0,1 and 2.Mode 0
is a 13 bit timer, mode 1 is 16 bit timer and mode 2 is an 8 bit timer. Mode 1
and 2 are used widely.
19
GATE: Gating control when set. The timer/counter is enabled only while the INTx
pin is high and the TRx control pin is set. When cleared, the timer is enabled
whenever the TRx control pin is set.
C/T:Timer or counter selected cleared for timer operation (input from internal
system clock).Set for counter operation (input from Tx input pin).
M1:Mode bit 1.
Mode 2 programming:
M2: Mode bit 0.
The following are the characteristics and operations of mode 2.
1.It is an 8-bit timer; therefore, it allows only values of 00 to FFH to be loaded into the
timer’s register TH.
2.After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL. Then the timer
must be started. This is done by the instruction “SETB TR0” for Timer0 and “SETB TR1” for
Timer1.This is just like mode 1.
3.Aftre the timer is started, it starts to count up by incrementing the TL register. It counts up
until it reaches its limit of FFH. When it rolls over from FFH to 00, it sets high the TF (timer
flag). If we are using Timer0, TF0 goes high; if we are using Timer1, TF1 is raised.
4.When the TL register rolls form FFH to 0 and TF is set to 1,TL is reloaded automatically
with the original value kept by TH register. To repeat the process, we must simply clear TF
and let it go without any need by the programmer to reload the original value. This makes
20
Mode 2 programming:
2.After TH is loaded with the 8-bit value, the 8051 gives a copy of it to TL.
Then the timer must be started. This is done by the instruction “SETB TR0” for
Timer0 and “SETB TR1” for Timer1.This is just like mode 1.
4.When the TL register rolls form FFH to 00 and TF is set to 1,TL is reloaded
automatically with the original value kept by TH register. To repeat the
process, we must simply clear TF and let it go without any need by the
programmer to reload the original value. This makes mode 2 an auto-reload, in
contrast with mode 1 in which the programmer has to reload TH and TL.
21
TCON REGISTER:
TR0 and TR1 flags are used to turn on or off the timers. These bits are parts of
a register called TCON (timer control). This register is an 8-bit register. The
upper four bits are used to store the TF and TR bits of both Timer0 and Timer1.
The lower four bits are set aside for controlling the interrupt bits. TCON
register is a bit-addressable register. Instead of using instructions such as
“SETB TR1”
and “CLR TR1”, we could use “SETB TCON.6” and “CLR TCON.6”, respectively.
TCON.0 and TCON.2 are referred to as IT0 and IT1, respectively. These two bits
set the low level or edge triggered modes of the external hardware interrupts
of the INT0 and INT1 pins. They are both 0 upon rest, which makes them low
level triggered. The programmer can make either of them high to make the
22
external hardware interrupt edge triggered. In the given system based on
8051, once they are set to 0 or 1 they will not be altered again since the
designer has fixed the interrupt as either edge or level triggered.
TCON.1 andTCON.3 are referred as IE0 and IE1, respectively. These bits are
used by 8051 to keep track of the edge-triggered interrupt only. In other
words, if the IT0 and IT1 are 0, meaning that the hardware interrupts are low
level triggered, IE0 and IE1 are not used at all. The IE0 and IE1 bits are used by
8051 only to latch the high to low edge transition on the INT0 and INT1 pins.
Upon the edge transition pulse on the INT0 (or INT1) pin, the 8051 marks the
IEx bit in the TCON register, jumps to the vector in the interrupt vector table,
and starts to execute the ISR.
IE0 and IE1 bits are used internally by 8051 to indicate whether an interrupt is
in use or not. In other words, the programmer is not concerned with these bits
since they are solely for internal use.
These arethe D4 and D6 bits of the TCON register. They are used to start or
stop the timers 0 and 1. Although we have used syntax such as “SETB TRX” and
“CLR TRX”, we could have used instructions such as “SETB TCON.4” and “CLR
TCON.4” since TCON is a bit-addressable register.
These are the D5 and D7 bits of the TCON register. They are used by timers and
1,respectively, to indicate if the timer has rolled over. Although we have used
the syntax “JNB TFX, target “ and “CLR TRX”, we could have used instructions
such as “JNB TCON.5, target” and “CLR TCON.5” since TCON is bit-addressable.
IR SENSOR
23
IR LED
IR LED looks like a normal LED and also operates like a normal LED, it
consumes 20mA current and 3volts power. IR LEDs have light emitting angle of
approx. 20-60 degree and range of approx. few centimetres to several feet, it
depends upon the type of IR transmitter and the manufacturer. Some
transmitters have the range in kilometres.
PhotoDiode:
24
This property makes it useful for IR detection Photodiode looks like a LED, with
a Black colour coating on its outer side.
The placing of IR LED and Photodiode can be done in two ways: Direct and
Indirect. In Direct incidence, IR LED and photodiode are kept in front of one
another, so that IR radiation can directly falls on photodiode. If we place any
object between them, then it stops the falling of IR light on photodiode.
25
And in Indirect Incidence, both the IR LED and Photo diode are placed in
parallel (side by side), facing both in same direction. In that fashion, when a
object is kept in front of IR pair, the IR light gets reflected by the object and
gets absorbed by photodiode. Note that object shouldn’t be black as it will
absorb all the IR light, instead of reflect. Generally IR pair is placed in this
fashion in IR sensor Module.
To build an IR module, we mainly need IR pair (IR LED and Photodiode) and
LM358 with some resistors and a LED.
26
Solenoid -:
A coil of many circular turns of insulated copper wire wrapped closely in the
shape of cylinder is called a solenoid. Magnetic fieldaround the solenoid is
similar as magnetic field around the bar magnet.In fact,one end of the solenoid
behaves as a magnetic north pole,while the other behaves as the south pole.
The magnetic field is uniform inside the solenoid.
27
SYSTEM BLOCK DIAGRAM -:
28
Circuit Diagrams-:
29
System Description :-
This system has been designedfor the medicine reminder using 8051
microcontroller.This kit is provided with buzzer and lock system.Lock
mechanism is indicated by LED.i.e if the LED is on,lock is open and if the LED is
off,lock is closed.
The system is first asked about the 3 timings andnumber of medicine boxes
necessary to the user for that particular timing. Medicineboxes are ofthe user
choice. There are 16combinations of the boxes for deciding the boxes.He can
decide how many and which medicine box he/she want for that
particulartiming.System contains 4 medicine boxes. An alarm is generatedto
indicate the desired timing& accordingly the corresponding container is
opened, while others are still locked.Containers getlockedautomaticallyas the
medicine taken is sensed. If the medicines are not taken, the system gives
alarm after a specifictime .Though the medicines are not taken, system will
gives a alert alarm and the containers will get locked.
30
User manual for deciding the medicine boxes-:
31
Steps to be followed by the user:
The system displays the message “SET TIME”, “M” for morning, “A” for
afternoon and “N” for night, “SMB” for select morning box, “SAB” for
select afternoon box, “SNB” for select night box.
The user has to enter the timing of the medicine he/she has to take in
morning, afternoon and night.
e.g- When “A” is displayed, enter the time at which afternoon medicines
should be taken.
Then the user has to select the containers of the medicine he/she has to
take in morning, afternoon and night.
e.g-When “SMB” is displayed, enter the box to be opened in morning. i.e
if “0F” is entered box 1,2,3 and 4 will be opened.
32
33
34
35
36
37
DELAY
FLOWCHART
START X
R0 =(0A) H : Count 1
A
R1=(FF) H :Count 2 IS
N R1=(00)H
R2=(FF)H :Count3 ?
R2 = R2-1 Y
R0=R0-1
IS
R2=(00)H
N ? IS N
R0=(00) H A
?
Y
R1 =R1 -1
Y
X STOP
38
39
Calculation -:
T = N’timer* T (m.c)
= 408 µseconds
T1 = 408µseconds * 255
= 0.104seconds
40
Subroutine for accessing timing and medicine boxes-:
41
Hex
Memory Label Instructions Comment
code
Address Address
R3 =(no. of morning
7854 12,65,10 LCALL (6510) boxes)
42
Main Program-:
Label Hex
Memory Instructions Comment
Address code
Address
43
Memory Label Hex
Instructions Comment
Address Address code
44
Memory Label Hex
Instructions Comment
Address Address code
Hex
Memory Label Instructions Comment
code
Address Address
6900 START C2,94 CLR PIN 1.4 pin 1.4=0
6902 12,60,00 LCALL (DELAY) delay
6905 D2,94 SET PIN 1.4 pin 1.4=1
Return from
6907 22 RET subroutine
45
Subroutine for tablet checking-:
46
Memory Label Hex
Instructions Comment
Address Address code
ASCII Codes-:
7310 41,03 A
7320 4E,03 N
47
2. ISR Program-:
3.Delay program -:
48
Decimal to Hex conversion program-:
Hex
Memory Label Instructions Comment
code
Address Address
6100 E5,30 MOV A, (30)H M(30)H =A
6102 54,0F ANL A #(0F)H
A AND with 0F
(upper nibble = 0 )
6104 FA MOV R2 ,A Reg.R2 =A
6105 E5,30 MOV A ,(30)H A= M(30)H
6107 54,F0 ANL A #(F0)H A AND with F0 (upper
nibble =0)
Hex
Memory Label Instructions Comment
code
Address Address
49
Monitor utility for accessing timing-:
Hex
Memory Label Instructions Comment
code
Address Address
6500 START 7D,3C MOV R5 #(06)H R5 = (06)H
6502 7E,02 MOV R6 #(02)H R6 =(02)H
6504 REL 1 12,04,7B LCALL (047B) NMIN (monitor utility)
6507 50,FB JNC (REL 1) Jump if CY =0
6509 8B,30 MOV (30)H ,R3 M(30)H =R3
650B 22 RET STOP
50
CONCLUSION
The system gives alert alarm to the user if the tablet is not taken.
51
APPLICATIONS, ADVANTAGES AND LIMITATIONS
Applications -:
Advantages -:
Limitations-:
At a time , how many tablets are taken from the box cannot be detected.
52
FUTURE ENHANCEMENT
53
REFERENCES
Microcontrollers-AJAY. V. DESHAMUKH
– M. A. MAZIDI.
54
SYSTEM SETUP
55