Вы находитесь на странице: 1из 55

MICROCONTROLLER

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.

Under the guidance of


Ms. G.A.KARAMBELKAR
(Lecturer– Dept. of Physics)

Through
LOKMANYA TILAK POST GRADUATE CENTER,
RATNAGIRI
2017-2018

2
DECLARATION

As required by the University, I wish to state that the work


embodied in this project titled ‘’MICROCONTROLLER
BASEDMEDICINEREMINDER‘’from our own contribution to project work
carried out under the guidance of Ms. G. A.KARAMBELKARlecturer,
Department of Physics,GogateJogalekar College,Ratnagiri.

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

4 System Block Diagram 28


5 Circuit Diagrams 29
6 System Software-: 30
System Description
User manual
Steps for user
Flowchart
calculation
Programs

7 Conclusion 51
8 Applications , Advantages and Limitations 52
9 Future Enhancement 53
10 References 54

4
ACKNOWLEDGEMENT

It is a pleasure to acknowledge all who have provided help, inspiration


and encouragement to complete this project.

We must put on record our deepest gratitude and respect towards


Dr.M.M.BELEKAR, The Head of Physics Department for his help and
encouragement during the preparation of project.

We are very much thankful to respected Ms.G.A.KARAMBELKAR,


Lecturer in Physics department, for her unfailing guidance and constant
encouragement. She solved clearly each and every doubt in our project during
the project work.

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:

8051 ANSHUMAN kit

FEATURES OF 8051 MICROCONTROLLER

MCS-51 is a family of 8-bit microcontrollers by Intel, designed


around HMOS technology.
Operating frequency is 12MHz.
Available in ROM/EPROM/EEPROM versions.
Separate 64K program and 64K data memory.
Multiply and Divide instructions available.
Has a Boolean processor and supports bitwise operations.
Available in CHMOS versions also.
32 I/O lines can be either used as four 8-bit ports or 32 I/Os.
16-bit address bus multiplexed with Port 0 and Port. Port 0 is also
data bus.

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(Pins 32-39)

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(Pins 1-8)

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(Pins 21-28)

Port 2 is also an 8-bit quasi-bi-directional I/O port. Port pins are pulled high
internally. It is multiplexed with the

higher order address bus.

P3.0 RXD serial input


P3.1 TXD serial output
P3.2 external interrupt
P3.3 external interrupt
P3.4 T0 timer/counter 0 external input
P3.5 T1 timer/counter 01external input
P3.6 external data memory write strobe
P3.7 external data memory write strobe

Port 3(Pins 10-17)

Alternate Function of Port 3Pins

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

Fig. (A) Program Memory of 8051

13
Table: Program Memory of 8051 and Program Execution

Status of Program execution from Program execution from 1000H


pin 0000H through 0FFFH through 0FFFFH

High (1) Internal program memory External program memory


Low (0) External program memory External program memory

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

FFH FFH Data


Special Indirectly
Function Addressab Memory
Register le (128
Of 8051
(128 bytes)
80H 80H
bytes)

64K
7FH
Special Function
Registers (128 bytes)
0000H
(Direct and Indirectly
00H Addressable)

(Internal Data Memory) (External Data Memory)

Fig. (B) Internal and External Data Memory of 8051

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).

(MSB) (LSB) (LSB)

Bit Addressable On-Chip


RAM (Individual bits can
be addressed with bit
addresses ranging from
00H to 7FH)

Bank 3 (R0 through R7)

Bank 2 (R0 through R7)

Bank 1 (R0 through R7)

Bank 0 (R0 through R7)

Fig. © On-Chip RAM (Lower 128 bytes)


15
Program Status Word (PSW):-

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 (PSW.7):-

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 (PSW.6):-

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):-

FO is available to user as a general-purpose flag. This flag can be set/cleared


by software, or its status can be observed by software. The user can define its
role. These are bits for selecting one of the four register banks. Each of these

16
register banks consists of registers R0 through R7. The register banks are
selected as below.

RS1 RS0 Register bank Address range in the on-chip RAM


selected
0 0 Bank 0 00-07H
0 1 Bank 1 08-0FH
1 0 Bank 2 10-17H
1 1 Bank 3 18-1FH

Overflow Flag (PSW.2):-

Overflow flag (OV) is set as a result of an arithmetic operation (addition,


subtraction, multiplication and division), provided there is a carry out of bit 6,
but not out of bit7 or a carry out of bit 7 but not out of bit 6; otherwise it is
cleared.

Parity Flag (PSW.0):-

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.

Data Pointer (DPTR):-

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.

Programming 8051 Timers:

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.

Basic registers of the timer:

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.

TMOD (timer mode) register:

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:

The following are the characteristics andoperations 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.After 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 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.

It must be emphasized that mode 2 is an 8-bit timer. However, it has an auto-


reloading capability. In auto reload, TH is loaded with the initial count and a
copy of it is given to TL. This reloading leaves TH unchanged, still holding a
copy of the original value. This mode has many applications, including setting
the baud rate in serial communication.

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.

IT0 and IT1:

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.

IE0 and IE1:

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.

TR0 and TR1:

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.

TF0 and TF1:

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 emits light, in the range of Infrared frequency. IR light is invisible to us


as its wavelength (700nm – 1mm) is much higher than the visible light range.
Everything which produce heat, emits infrared like for example our human
body. Infrared have the same properties as visible light, like it can be focused,
reflected and polarised like visible light.

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:

Photodiode is considered as Light dependent Resistor (LDR), means it has very


high resistance in absence of light and become low when light falls on it.
Photodiode is a semiconductor which has a P-N junction, operated in reverse
Bias, means it start conducting the current in reverse direction when Light falls
on it, and the amount of current flow is proportional to the amount of Light.

24
This property makes it useful for IR detection Photodiode looks like a LED, with
a Black colour coating on its outer side.

IR sensor is very popular sensor, which is used in many applications in


electronics, like it is used in Remote control system, motion detector, Product
counter, Line follower Robots, Alarms etc.

IR sensor basically consist an IR LED and a Photodiode, this pair is generally


called IR pair or Photo coupler. IR sensor work on the principal in which IR LED
emits IR radiation and Photodiode sense that IR radiation. Photodiode
resistancechanges according to the amount of IR radiation falling on it, hence
the voltage drop across it also changes and by using the voltage comparator
(like LM358) we can sense the voltage change and generate the output
accordingly.

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.

A strong magnetic fieldproduced inside a solenoid can be used to magnetise a


piece of magnetic material like soft iron,when placed inside the coil. The
magnet so formed is called anelectromagnet.When we run a current through
asolenoid,we get asuper strong magnet because the magnetic field is
concentrated inside the coil. This can be incredibly useful in our everyday
lives.We use this principle for making a lock system.

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-:

open box code


no.
no anyone 0
1 1
2 2
1,2 3
3 4
1,3 5
2,3 6
1,2,3 7
4 8
1,4 9
2,4 0A
1,2,4 0B
3,4 0C
1,3,4 0D
2,3,4 0E
All boxes 0F

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.

Further the system works as given in system description.

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 -:

Consider ,N’timer= 255 = (FF)H

T = N’timer* T (m.c)

= 255 * 1.6 µseconds

= 408 µseconds

T1 = 408µseconds * 255

= 0.104seconds

40
Subroutine for accessing timing and medicine boxes-:

Memory Label Hex code Instructions Comment


Address Address
7800 START 12,06,1D LCALL (061D) Clear Display
MOV
7803 90,73,30 DPTR,#(7330) Display 'SET TIME'
7806 12.06,06 LCALL (MSGOUT)
7809 12,60,00 LCALL (DELAY) Delay
780C 12,06,1D LCALL (061D) Clear Display
780F 90,73,00 MOV DPTR,#(7300)
Display 'M'
7812 12,06,06 LCALL (MSGOUT)
7815 12,65,00 LCALL (Delay) Delay
7818 12,65,00 LCALL (6500) R3 =(counter for morning)
781B 12,61,00 LCALL (6100 ) Dec. to hex conversion
781E F5,22 MOV (22)H,A (22)H=A
7820 12,06,1D LCALL (061D) Clear Display
7823 90,73,10 MOV DPTR,#(7310)
Display 'A'
7826 12,06,06 LCALL (MSGOUT)
7829 12,60,00 LCALL (DELAY) Delay
R3 =(counter for
782C 12,65,00 LCALL (6500) Afternoon)
782F 12,61,00 LCALL (6100)
7832 F5,23 MOV (23)H,A (23)H=A
7834 12,06,1D LCALL (061D) Clear Display
7837 90,73,20 MOV DPTR,#(7320)
Display 'N'
783A 12,06,06 LCALL (MSGOUT)
783D 12,60,00 LCALL (DELAY) Delay
7840 12,65,00 LCALL (6500) R3 =(counter for Night)
7843 12,61,00 LCALL (6100) Dec. to hex conversion
7846 F5,22 MOV (24)H,A (24)H=A
7848 12,06,1D LCALL (061D) Clear Display
784B 90,73,10 MOV DPTR,#(7340) Display 'SAB'
784E 12,06,06 LCALL (MSGOUT) (select morning box)

7851 12,60,00 LCALL (DELAY) Delay

41
Hex
Memory Label Instructions Comment
code
Address Address
R3 =(no. of morning
7854 12,65,10 LCALL (6510) boxes)

7857 F5,25 MOV (25)H,A (25)H=A


7859
12,06,1D LCALL (061D) Clear Display
785C
90,73,50 MOV DPTR,#(7350) Display 'SAB'
(select afternoon box)
785F
12,06,06 LCALL (MSGOUT)

7862 12,60,00 LCALL (DELAY) delay


R3 (no. of afternoon
7865 12,65,10 LCALL (6510) boxes)

7868 F5,26 MOV (26)H,A (26)H=A


786A
12,06,1D LCALL (061D) Clear Display
786D
90,73,60 MOV DPTR,#(7360) Display 'SAB'
(select night box)
7870
12,06,06 LCALL (MSGOUT)

7873 12,60,00 LCALL (DELAY) delay

7876 12,65,10 LCALL (6510) R3 =(no. of night boxes)

7879 F5,27 MOV (27)H,A (27)H=A

787B 22 RET Return from subroutine

42
Main Program-:

Label Hex
Memory Instructions Comment
Address code
Address

74F0 START 12,78,00 LCALL (7800)H subroutine to enter the


timing and box no.

74F3 12,73,50 LCALL (7350)H subroutine to display -


-WFT--

74F6 79,00 MOV R1,#(00)H R1 =(00)H

74F8 7A,00 MOV R2,#(00)H R2 =(00)H

74FA 7B,00 MOV R3,#(00)H R3 =(00)H

74FC 7C,00 MOV R4,#(00)H R4 =(00)H

74FE 90,20,23 MOV DPTR,#(2023)H

7501 74,02 MOV A,#(02)H Initialize vector location

7503 F0 MOVX @DPTR,A

7504 A3 INC DPTR Increment DPTR

7505 74,70 MOV A,#(70)H

7507 F0 MOVX @DPTR,A Set


7508 A3 INC DPTR ISR
location
7509 74,00 MOV A,#(00)H

750B F0 MOVX @DPTR,A

750C 75,89,02 MOV TMOD,#(02)H Set mode 2 with timer 0

750F 75,8C,00 MOV TH0,#(00)H THO = (00)H

7512 78,00 MOV R0,#(00)H R0 =(00)H

7514 D2,8C SETB TR0 TRO =1

7516 D2,A9 SETB ET0 ETO =1

7518 D2,AF SETB EA EA =1

751A rel 1 EB MOV A,R3 A = R3

751B rel 1 B5,22,FC CJNE A,(22)H Is A=M(22)H?


If not jump back

751E 12,06,1D LCALL (061D) Clear display

43
Memory Label Hex
Instructions Comment
Address Address code

7521 90,73,00 MOV DPTR,#(7300)H


Display 'M'
7524 12,06,06 LCALL (MSGOUT)

7527 12,69,00 LCALL (6900) Call subroutine

752A E5,25 MOV A,(25)H A = (25)H

752C F4 CPL A compliment A

752D F5,90 MOV (90)H,A (90)H=A

752F 12,76,FE LCALL (76FE) call subroutine

7532 rel 2 EB MOV A,R3 A = R3

7533 rel 2 B5,23,FC CJNE A,(23)H Is A = M(23)H?


If not jump back

7536 12,06,1D LCALL (061D) Clear display

7539 90,73,10 MOV DPTR,#(7310)H


Display 'A'
753C 12,06,06 LCALL (MSGOUT)

753F 12,69,00 LCALL (6900) subroutine for buzzer

7542 F5,26 MOV A,(26)H A = (26)H

7544 F4 CPL A compliment A

7545 F5,90 MOV (90)H,A (90)H=A

7547 12,76,FE LCALL (76FE) subroutine for LED

754A rel 3 EB MOV A,R3 A = R3

754B rel 3 B5,24,FC CJNE A,(24)H Is A = M(24)H?


If not jump back

754E 12,06,1D LCALL (061D) Clear display

7551 90,73,20 MOV DPTR,#(7320)H


Display 'N'
7554 12,06,06 LCALL (MSGOUT)
7557 12,69,00 LCALL (6900) subroutine for buzzer

44
Memory Label Hex
Instructions Comment
Address Address code

755A E5,27 MOV A,(27)H A = (27)H

755C F4 CPL A compliment A

755D F5,90 MOV (90)H,A (90)H=A

755F 12,76,FE LCALL (76FE) call subroutine


Clear display
7562 12,06,1D LCALL (061D)

7565 BB,0A,FD CJNE R3,#(0A)H Is R3 = (0A)H?


If not jump here

7568 7B,00 MOV R3,# (00)H R3 = (00)H

756A Back 02,75,1A LJMP (751A) Jump back

Subroutine for buzzer-:

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-:

Memory Label Hex


Instructions Comment
Address Address code

76FE 7C,00 MOV R4,#(00)H R4=(00)H


7700 F5,2A MOV (2A)H,A (2A)H=A
7702 C2,5E CLR 5E clear bit 5E
7704 20,50,0A JB (50)H(NEXT) jump if bit set
7707 20,95,07 JB (1.5)(NEXT) jump if bit set
770A 12,60,00 LCALL (DELAY) Delay
770D D2,90 SET P1.1 set pin 1.1
770F D2,50 SET (50)H set bit (50)H
7711 NEXT 20,51,0A JB (51)H(NEXT1) jump if bit set
7714 20,96,07 JB P(1.6)(NEXT1) jump if bit set
7717 12,60,00 LCALL (DELAY) Delay
771A D2,91 SET P1.6 set pin 1.6
771C D2,51 SET (51)H set bit (51)H
771E NEXT1 20,52,0A JB (52)H(NEXT2) jump if bit set
7721 20,97,07 JB P(1.7)(NEXT2) jump if bit set
7724 12,60,00 LCALL (DELAY) Delay
7727 D2,92 SET P1.7 set pin 1.7
7729 D2,52 SET (52)H set bit (52)H
772B NEXT2 20,53,0A JB (53)H(NEXT3) jump if bit set
772E 20,B1,07 JB P(3.1)(NEXT3) jump if bit set
7731 12,60,00 LCALL (DELAY) Delay
7734 D2,93 SET P3.1 set pin 3.1
7736 D2,53 SET (53)H set bit (53)H
7738 NEXT3 E5,2A MOV A, (2A)H A=(2A)H
CJNE A,#(FF)H
773A B4,FF,02 (HERE) jump if acc. Is
not equal to (FF)H

46
Memory Label Hex
Instructions Comment
Address Address code

773D 80,18 SJMP (AHEAD) Jump ahead


773F HERE 20,5E,08 JB (5E)H(AHEAD1) jump if bit set
7742 BC,01,BF CJNE R4,#(01)H
jump if R4 is not
equal to (01)H
7745 12,69,00 LCALL (6900) call subroutine
7748 D2,5E SET (5E)H set (5E)H
774A AHEAD1 BC,02,B7 CJNE R4,#(02)H
jump if R4 is not
equal to (02)H
774D 12,64,00 LCALL (6400) call subroutine
7750 12,60,00 LCALL (DELAY) Delay
7753 74,FF MOV A,(FF)H A=(FF)H
7755 F5,90 MOV (90)H,A (90)H=A
7757 AHEAD 22 RET return from
subroutiune

ASCII Codes-:

Address ASCII codes Messages


7300 40,03 M

7310 41,03 A

7320 4E,03 N

7330 53,45,54,20,54,49,4D,45,03 SET TIME

7340 53,4D,42,03 SMB

7350 53,41,42,03 SAB

7360 53,4E,42,03 SNB

7380 57,46,54,03 WFT

47
2. ISR Program-:

Memory Label Hex code Instructions Comment


Address Address
7000 START 08, INC R0 Increament Reg. R0 by 1
7001 B8,FF,10 CJNE R0 # (FF)H IS Reg.R0 =(FF)H if not
return to main program

7004 78,00 MOV R0 # (00)H Reg. R0 =(00)H


7006 09, INC R1 Increament Reg. R1 by 1
7007
B9,OA,0A CJNE R1 # (0A)H IS Reg.R1 =(0A)H if not
return to main program

700A 79,00 MOV R1 # (00)H Reg. R1 =(00)H


700C 0A, INC R2 Increase Reg.R2 by 1
700D BA,3C,04 CJNE R2 #(3C)H
Is Reg. R2 =(3C)H if not
return to main program
7010 7A,00 MOV R2 #(00)H Reg.R2 =(00)H
7012 0B INC R3 Increase Reg.R3 by 1
7013 0C INC R4 Increase Reg.R4 by 1
Return to main
7014 32 RET I program

3.Delay program -:

Memory Label Hex code Instructions Comment


Address Address
6000 START 7D,0A MOV R5,#(0A)H R5 =(0A)H

6002 REL 3 7E,FF MOV R6,#(FF)H R6 =(FF)H


6004 REL 2 7F,FF MOV R7 # (FF)H R7 =(FF)H

6006 REL 1 DF,FE DJNZ R7,(REL 1) Decrement R7 if # (00)

6008 DF,FA DJNZ R6,(REL 2) Decrement R6 if # (00)

600A DD,F6 DJNZ R5,(REL 3) Decrement R5 if #(00)


Return to main
RET
600C 22 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)

6109 C4 SWAP A Swap nibble within acc.


610A 75,F0,0A MOV B#(0A)H Reg.B =(0A)H
610D A4 MUL AB Multiply Acc. &Reg.B
610E 2A ADD A ,R2 A = A+ R2
610F 22 RET STOP

Subroutine for master buzzer-:

Hex
Memory Label Instructions Comment
code
Address Address

6400 START C2,B2 CLR PIN 3.2 pin 3.2=1

6402 12,60,00 LCALL (DELAY) Delay

6405 D2,B2 SET PIN 3.2 pin 3.2=1

6407 22 RET Return from subroutine

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

Monitor utility for accessing medicine boxes-:

Memory Label Hex


Instructions Comment
Address Address code
6510 START 7D,3C MOV R5 #(06)H R5 = (06)H
6512 7E,02 MOV R6 #(02)H R6 =(02)H
6514 REL 1 12,04,7B LCALL (047B) NMIN (monitor utility)
6517 50,FB JNC (REL 1) Jump if CY =0
6519 22 RET STOP

50
CONCLUSION

This systemis fully automated.

Itis userfriendly system.

Only the required container is opened at a time, avoiding the


consumption of a wrong medicine.

The system gives alert alarm to the user if the tablet is not taken.

51
APPLICATIONS, ADVANTAGES AND LIMITATIONS

Applications -:

For aged persons


For avoiding confusion of tablets

Advantages -:

Low cost and easy to use


Comfortable to user
Proper medicines are taken at proper timing.

Limitations-:

At a time , how many tablets are taken from the box cannot be detected.

52
FUTURE ENHANCEMENT

The information abouttablet i.e. tablet is taken or not, can besend to


the caretaker mobile using GSM module.

53
REFERENCES

Microcontrollers-AJAY. V. DESHAMUKH

The 8051 microcontroller & embedded systems by

– M. A. MAZIDI.

ANSHUMAN user guide.

54
SYSTEM SETUP

55

Вам также может понравиться