Professional Documents
Culture Documents
BY
GWAGWA O. TUBUKARE
NAU/ECE/2008366010P
ii
CERTIFICATION
The thesis a microcontroller- based mains switch control system
presented by GWAGWA O. TUBUKARE has been read and certified to
have met requirement of the Department of Electronics and Computer
Engineering in the Faculty of Engineering, in project presentation to acquire
a Masters Degree in Engineering.
GWAGWA O. TUBUKARE
..
NAU/ECE/2008366010P
Signature
iii
Date
APPROVAL
system has been approved for the department of Electronics and Computer
Engineering:
BY
------------------ Engr. Prof. H.C. Inyiama
Supervisor
-----------Date
-----------Date
------------Date
------------------Prof. O.D.Onukwuli
Dean of Faculty of Engineering
-----------Date
------------Date
iv
DEDICATION
To the Lord God Almighty who is the owner of my life and for His divine
providence, love and care.
ACKNOWLEDGEMENT
My sincere gratitude goes to my supervisor, Engr. Prof. H. C. Inyiama, who
has been so supportive to me throughout the period of this program. Also to
my head of department, Engr. (Dr) V. E. Idigo, for his quick response. My
regards to Engr. Dr. (Mrs.) C. C. Okezie, Engr prof. G.N. Onoh, Engr. (Dr)
Eric Okafor, Engr. C. U. Mezi, Engr. A.C. O. Azubogu, Engr. K Akpado,
Engr. C.O. Ohaneme, Engr. A.N. Isizoh, Mr. T.L. Alumona, Mrs. S.U.
Nnebe, Mr. S.P.C. Ndum, Engr. T.C. Okafor, Engr. O.O. Eze, Engr. H.
Ejiofor, Mr. U.P. Ajakor, Mr. C. Ogu,Mr. J.U. Oguejiofor, Mr. T. Onyeyili,
Engr. V.N. Okorogu, Mr. O.O. Nnaeto and staff of the Department of
Electronics and Computer Engineering. Greetings to all my friends, and
fellow classmates who supported me by their encouragement. May God
bless you all.
Special thanks to the members of my family, especially to my wife Mrs.
Gwagwa Mary and my children, Ufuoma Priscilla Gwagwa, Oghenekevwe
Joy Gwagwa, Ovie Gideon Gwagwa and Oghenetega Goodness Gwagwa
for their good courage and patience. May the LORD bless with you all.
vi
ABSTRACT
Many people tend to enjoy use of facilities without control even when there
are bills to settle to guarantee continuity. This project was born out of the
desire to prevent damages and time wastage on control of industrial
equipment. It is designed to control all the facilities (for example electrical
appliances) not only in the hospitality industry but also in organizations such
as schools, for security, safety and elimination of problems associated with
manual switching. The system is a microcontroller-based mains switch
control project which automatically controls AC loads connected to it
through a serial port interface. The switch control system can range from
simply controlling of light without leaving a seat, to being able to switch on
and off industrial electrical devices through a computer interface, so the
system produced will enable the switches to be controlled from one source
(computer system) by simply issuing a command through the interface on
the computer screen to save the time of going from one switch to another to
put on or off the industrial equipments since the switches can be controlled
from a remote system.
vii
TABLE OF CONTENTS
Title Page ... i
Unizik Logo.ii
Certification............ iii
Approval ... iv
Dedication . v
Acknowledgement .vi
Abstract . . ..vii
Table of content viii
Chapter One: Introduction
1. 1 Background 1
1.2 Objective .3
1.3 Significance of the Project...4
1.4The scope of the Project5
1.5 Block diagram Overview of the Project .. 6
Chapter Two: Literature Review
2.1 Introduction........
11
viii
ix
32
xii
1.1 BACKGROUND
Man has been in a continuous quest to improve his well being through
reactions to problems and challenges posed by his environment. For the past
decades, computer and computer communication had gained so much
attention and grown tremendously, that portable and affordable computers
have become ubiquitous. Statistics have shown that most people spend most
of their time on computers, connected together by a network (locally or
globally). Since much time is spent on computer systems, it becomes
necessary to design a device for controlling switches from computer.
Switches are so essential that one cannot avoid using them on a daily basis
for putting on or turning off electrical devices, and as a result of these, many
devices have been designed by man to help him conquer these problems and
challenges posed by physical contact with electricity [1]. The switch control
system can range from simply controlling of light without leaving a seat, to
being able to switch on industrial electrical devices through a computer.
There has to be an interface between industrial electrical devices and a
controller, the personal computer (PC) in this case. Interface is required so
1
that the PC can communicate with other devices. The interface used in this
work is the computer port interface [2]. The microcontroller-based mains
switch control system is made up of several devices connected together;
keypads that transmit commands to the device, the controller that is
programmed to put on or off the appliances automatically via a computer
system [9].
It has been observed that the manual switching of the industrial equipment
in the industrial sector has many problems associated with it, which
includes:
1.2
OBJECTIVES
for
microcontroller-based
mains
switch
control
system.
instrumentation
ovens,
and
and
hospital
electronic
5
games.
equipment,
programmable
Many automobiles
use
SUMMARY, ACHIEVEMENTS
BACKGROUND
RECOMMENDATION,
MICROPROCESSOR SWITCH
CONTROL SYSTEM
REVIEW ON
MICROPROCESSOR-BASED
SYSTEM IMPLEMENTATION
AND TESTING
RESEARCH METHODOLOGY
SYSTEM DESIGN
AND ANALYSIS
2.1 INTRODUUCTION
A control system is a device or set of devices used to manage, command,
direct or regulate the behaviour of other devices or system. The term control
system may be applied to the essentially manual controls that allow an
operator to, for example close and open a hydraulic press, where the logic
requires that it cannot be moved unless safety guards are in place.
There are two common classes of control systems with many variations and
combinations: logic or sequential controls and feedback or linear controls.
There is also fuzzy logic, which attempts to combine some of the design
simplicity of logic (the study of the principles of valid inference and
demonstration) with the utility of linear control. Some devices or systems
are not controllable. An automatic sequential control may trigger a series of
mechanical actuators (mechanical device form ring or controlling a
mechanism or system) in the correct sequence to perform a task. In the case
of linear feedback systems, a control loop, including sensors (a device that
measures a physical quantity and converts it into a signal which can be read
and cause the machinery to perform some operation. They are used to
sequence mechanical operations in many applications. Some techniques are
used in control system like the Derivative action which is a part concerned
with the rate of change of the error with time. This action makes control
system behave much more intelligently. The microcontroller- based switch
control system uses specialized equipment to control the switching of
electrical devices. Through the interface on the computer, one can switch
on/off electrical appliances from remote places. Sayers et al. (1991) noted
that technological advances in Digital Signal processor (DSPS), networking,
microprocessors, and programmable logic devices (PLDS) have empowered
designers with entirely new techniques and methodologies that were
economically unthinkable two decades ago. These advances, along with
increased performance demands, have fueled the push of digital technology
deeper into the controlled devices. The justification often quoted for this
push to digital control includes reproductively, increased stability, increased
resolution and decreased infrastructure costs (networks replace control
wiring) [4].
10
12
13
Timed Events
Employing a computer-controlled system typically includes software
that can be programmed to initiate activities. This capability provides
the ability to trigger, or initiate, pre-defined events at pre-scheduled
times or under predefined conditions. For example, the system can be
programmed to turn off all room lights, turn on fan, and turn on gate
lamps.
Keypad
A keypad is the least costly method to control light fixtures, lighting
scenes, audio/video (AV) equipment, or other devices. These are wall
plates, similar to a regular wall switch plate with 2 to 8 buttons on
them. Simply press a button to initiate the desired action. A single
button press may activate only one light fixture, many fixtures
located anywhere in the home, or lighting with AV events
simultaneously. Each plate has an engraved description as to what
each button will activate. Buttons can be illuminated for locating
them in the dark.
14
15
Hardwired Systems
This technology has existed for over 40 years. Hardwired systems
create a communications network within the home that is impervious
to the problems that are sometimes suffered by the other protocols
described above. This technology is most always used in new
construction due to the extremely reliable communication by a data
16
path over wire placed in the walls before they are covered. This is
known as pre-wiring the home for control. This system can also be
used during major home remodels and controlling other sections of
the home not being remodeled with one of the wireless methods
described above.
2.5 MANUAL SWITCHING SYSTEM.
The operation of manual switching system is by controlling the switching
by hands. One can switch something off: to turn off electric bulb or
industrial equipment or appliance with a switch or one can switch on: to turn
on electricity with a switch. A switch is a device for completing or breaking
a circuit [1]. In a Multi- throw switch, there are two possible transient
behaviour as you move from one position to another. In some switch
designs, the new contact is made before the old contact is broken. This is
known as make-before- break and ensures that the moving contact never
sees an open circuit. The alternative is break-before-make, where the old
contact is broken before the new one is made. This ensures that the two
contacts are never shorted to each other.
17
The two types of designs are in common use for different applications.
According to Leo Martins, placing parenthesis around all position rather
than the resting position can modify the on-off notation; for example, on
(on) - off- (on) switch can be switched on by moving the actuator in either
direction away from the center but returns to the control off position when
the actuator is released [24].
Push-to-make switch makes contact when the button is pressed and breaks
when the button is released. A push to break switch breaks contact when
the button is pressed and makes contact when it is released. An example of
push-to-break switch is a button used to release a door hold open by an
electromagnetic system. According to Chris Kotoroski, the word toggle is a
reference to the kind of mechanism or joint consisting of two arms, which
are almost in line with each other, connected with an elbow- like pivot.
Toggle switch is a generic class of electrical switch that uses a mechanical
lever, handle or rocking mechanism to activate it [7].
18
20
3.1.1 METHODOLOGY
Internationally Software Engineering has accepted standards for
transforming ideas in software. They include:
The structured system Analysis and Design methodology
(SSADM)
Prototyping
Experts system methodology
Usability engineering methodologies, etc.
The methodology applied in the system is prototyping and is discussed
below.
3.1.2 PROTOTYPING
The prototyping methodology is applied in the development of this
project. Prototyping is the process of building a model of a system. It
is a model of a system, built to show off certain features or to get a
working model before refining other parts of the design or just to
evaluate the feasibility of the system development. A system
prototype is a working system built to test ideas and assumptions
22
23
24
3.1.5
ADVANTAGES OF PROTOTYPING
25
2.
3.
(ON OFF) push- to- break switch is also for doorbell. This
switch can be ON in both positions, switching on a separate
device. In each case, it is often called a change over switch
example; a SPOT switch can be used to switch ON red lamp in
one position and a green lamp in another position.
Reed switch:
The contacts of a reed switch are closed by bringing a small
magnet near the switch. They are used in security circuits, for
27
The new system will save the time it takes the device and
operator in going from one switch to another.
COMPUTER
MAX - 232
MICROCONTROLLER
RELAY 1
APPLIANCE 1
RELAY 2
POWER CIRCUIT
APPLIANCE 2 ...
31
RELAY n
APPLIANCE n
4.0 INTRODUCTION:
In this chapter, the design of a switch control system is described for
controlling appliances such as bulbs using a computer system through a
serial port. The Graphical user interface (GUI) through which command is
given to the switch controller circuit is achieved with visual basic. The
system can control other appliances such as Television, Refrigerator, Ceiling
fan etc. This design is a prototype of a switch control system which can be
used in a large organization to control several electrical appliances
connected to it. There is an interface provided by visual basic programming
language, which contains ON buttons and OFF buttons through which
control command is sent to electrical devices. Therefore when any command
button is clicked to switch on or off, device signals go from the control
module through the serial port, serial cable to the Max- 232 interface which
amplifies the signals. The signal goes to the microcontroller and from the
microcontroller the signal gets to the relay through the transistor down to the
bulbs which are the receiving module. The design consists of two modules:
the hardware and the software modules both working together to achieve the
32
desired result. In the hardware module, the power source supplies current to
all the hardware component of the control box. Max 232 acts as buffer that
amplifies the signals coming from the computer. The 8051 microprocessor
used is the controller that controls the relay and makes it function like a
switch.
33
overcome the errors. Simulation efforts are necessary because errors are
typically much harder to fix if they are discovered late in the design process.
Simulation of redesigned version is to determine whether the errors have
disappeared. Figure 4.1 below is a design sequence. The loop is repeated
until the simulation indicates design successful.
Design Concept
Initial Design
Redesign
Simulation
No
Design Correct?
Yes
Design Successful
35
36
37
microcontroller are each connected respectively to the BASE pin of the three
corresponding transistor
38
electromagnetic
signal
such
39
as
radio,
television
or
other
40
41
42
RL3
OMIH-SH-124D
1K
MICRO
CONTROLLER
1K
1K
BC337
+5V IN4001
BC337
+5V
IN4001
RELAY 1
+5V IN4001
RELAY 2
BC337
RELAY 3
Vin
5 x 10 3
RECTIFIER
SMOOT
CIRCUIT
HING
Regulated 5VDC
VOLTAGE
REGULATOR
45
46
To relay
In
7812
In
4.5.1
7805
out
out
To other ICs
4.6 FUNCTIONS
In this design, a resistor (1000) is placed in series with each of the
transistors and one with a light- emitting diode (LED) to limit the current
passing through the Transistor and the LED respectively. The NPN transistor
(BC 337A) is used in the design of this project. This semiconductor device
provides current amplification. A small current of I mA flowing between
base and emitter can produce as large as 100MA or more in the collector
emitter circuit. Transistors are therefore widely used as current amplifiers
and as relay drivers. Transistor amplify current, they are used to amplify the
small output current from a logic chip so that it can operate a lamp (bulb) in
relay or other high current device. The B 337A NPN, which are low power
transistors are used to switch the relays coils. A transistor may be sued as
switch (either fully ON with maximum current, or fully OFF with no
current) and as an amplifier (always partly ON).
The amount of current amplification is called the current gain, hFE. When
transistor is saturated the collector current IC is determined by the voltage
and the external resistance in the collector circuit, not by the transistor
current gain.
48
49
communication
between
the
personal
computer
and
the
50
51
last three connections after you have built the circuit above to connect your
programmer to your PCs serial port.[18]
Five capacitors are normally required for the MAX232A. If you don't mind
the added expense, or you want to conserve board space, you can use the
MAX233 that doesn't require the 5 external capacitors; however the
MAX233 is considerably more expensive so I chose to use the 232 to keep
the project costs to a minimum [18].
53
54
The 8952 microcontroller has 40 pins functioning 1/0 port lines. Each pin
can operate as a control line or pin of the address or data bus. Each line can
operate independently in interfacing to single- bit devices like switches,
LEDS, transistors, speakers etc.
Port 0: port 0 is a dual-purpose port on pins 32-39 of the 8952 IC. It is use as
a general- purpose 1/0 port.
Port 1: port 1 pin is available for interfacing to external devices required. No
alternate function are assigned for port 1 pins, thus they are for interfacing to
external devices.
Port 2: Port 2 is a dual-purpose port as well as general-purpose 1/0 design
with external code memory or more than 256bytes of external memory.
Port 3: These pins are multifunctional with each having an alternate purpose
related to special features of the 8051.
RESET: This is on pin 9 of the 8952-microcontroller audio used for
resetting the device. The circuit is shown in the figure below;
GND: The on pin 20. It is an input pin and is used for the circuit ground of
the system.
ALE: This is on pin 30. It means Address Latch Enable. It is an output
function pin for latching the low byte of the address during access to
external memory.
EA: This is on pin 31. It is an input function pin for external access enables
it must be strapped to GND to enable the device to fetch code from external
program memory.
55
30F
30F
56
flow charts. This is a guide in writing the assembly language program that
runs the microcontroller. A program is an orderly sequence of machine
instructions that can be obtained using a high level or low level
programming language statement. The written program is burn in
microcontroller using EEPROM programmer. Shown below is a flow chart
that describes the action of this project.
58
START
NO
IS THE
YES
APPLIANCE
ON?
SWITCH ON THE
APPLIANCE
APPLIANCE
MAX-232
MICROPROCESSOR
RELAY 1
APPLIANCE 1
RELAY 2
RELAY n
APPLIANCE 2
APPLIANCE n
60
Jnb it is a short form of jump on bit. It checks if its first variable is set and
if true, it executes the second variable
Call it is a name used for calling a function
Scan it is used as a label in a program
Ret it is used for returning to a call from a subroutine.
Setb it is used for sending a 1 to a register or to a port.
61
5.0 INTRODUCTION
The various units of the microcontroller- based mains switch control system
(both the hardware and software subsystems) are implemented using
different circuitry formulations that satisfy the aim of the design, and
software coding using a specific software language that provide appropriate
control as specified in the design
Concerning the implementation of this system the hardware part of the
design; that is, the wired diagram of the system is shown. In chapter four the
design of the system was shown to be consisting of three circuits, the power
supply circuit, switching circuit and the data circuit. This chapter also states
the system operation of the device. Brief attention was given to the issue of
programming and the other constructions carried out during the design
process. The chapter five of this work will deal with the implementation of
the hardware and software designs, testing the system, and performance
evaluation.
62
63
64
33pf
33pf
U1
19
18
XT AL1
XT AL2
RST
10k
29
30
31
TO DEVICE I/O
P1.0/T2
P1.1/T2EX
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
P3.0/RXD
P3.1/T XD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
TO KEYPAD
1
2
3
4
5
6
7
8
PSEN
ALE
EA
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
39
38
37
36
35
34
33
32
10u
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
CRYST AL
AT89C55
67
Pre-implementation testing.
ii.
Post-implementation testing.
68
69
STATE
STATUS
APPLIANCE
ON
Bulb
OFF
Bulb
ON
Bulb
OFF
Bulb
ON
Bulb
OFF
Bulb
70
state ON or OFF bulbs, when the command button of any relay is clicked,
signals goes from there to desirable bulb.
When relay 1 is off the status will display A but when it is ON, the status
will display B.
Also when relay 2 is off the status will display C, when it is ON the status
will display D.
Finally when relay 3 is off the status will display E but the relay is ON the
status will display F.
71
72
12V
Vcc
RELAY
10F
1K
11.0592MHZ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30F
8952
40
1K
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21
12V
RELAY
1K
20
30F
12V
RELAY
1K
73
6.0 SUMMARY
In summary, the project work (A microcontroller-based mains switch control
system) was introduced in chapter one giving us an insight that it was a
microcontroller- based mains switch control system interfaced to a personal
computer through which appliances could be switched ON or OFF without
leaving ones seat. In chapter two of the research work, various literatures on
the topic under study were reviewed analyzing the invention, operations,
function of microcontroller to control appliances. Chapter three provides an
analysis of the existing system and proposed system as well as the
methodology. Chapter four was based on the system design. Chapter five
dealt with the system implementation and testing of the entire
microcontroller- based mains switch control system. Finally this project is
able to switch ON or OFF a device using computer system via serial port.
The system was designed in such a way that maintenance and repairs are
easily done in case of any faults. Soldering techniques and practical
74
electronic were carefully studied and the experience gained from it was
instrumental to the success of this project
6.1 PROBLEMS ENCOUNTERED
Some problems were encountered in the cause of developing the prototype
of this system. Most prominent is the issue of frequent power failure from
the public power supply. This prolonged the wiring time. Secondly, the
problem of some components initially tested okay not functioning on circuit
board during testing.
The saving of the time it takes the operator going from one switch to
another is a delight to the Operator.
75
6.3 RECOMMENDATIONS
(a)
(b)
(c)
(d)
6.4 CONCLUSION
The result achieved in the design and construction of the microcontrollerbased mains switch control system is actually a move away from manual
mode of switching to that of automation. For the fact that the materials used
are locally sourced make room for cost effectiveness of design and economic
application viable.
The system was designed in such a way that maintenance and repairs are
easily done in case of any faults.
77
REFERENCES
78
80
org 00h
mov SCON,#01010000b
mov TMOD,#00100000b
mov a,PCON
setb acc.7
mov PCON,a
mov TH1,#250
setb TR1
relay1 equ p0.0
relay2 equ p0.1
relay3 equ p0.2
CPU EQU 40
CPUIN EQU 41
clr RI
clr TI
mov p0, #00h
CLR P2.0
81
CSEG
ORG 0040H
CALL recal_1
NOP
CALL recal_2
NOP
CALL recal_3
NOP
JMP START
82
ORG 0100H
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cjne a, #'A', next
MOV CPU, #'A'
CALL SAVE_1
clr relay1
call delay
jmp start
next: cjne a, #'B', next1
MOV CPU, #'B'
CALL SAVE_1
setb relay1
call delay
jmp start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
next1: cjne a, #'C', next2
MOV CPU, #'C'
CALL SAVE_2
clr relay2
83
call delay
jmp start
next2: cjne a, #'D', next3
MOV CPU, #'D'
CALL SAVE_2
setb relay2
call delay
jmp start
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
next3: cjne a, #'E', next4
MOV CPU, #'E'
CALL SAVE_3
clr relay3
call delay
jmp start
NEXT5:
CALL DELAY
JMP START
save_1:
NOP
jmp save
save_2:
NOP
jmp save
save_3:
NOP
jmp save
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
inc byte_addr
nop
nop
nop
nop
nop
87
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
error: CLR TI
MOV SBUF #'F'
JNB TI, $
SETB P2.0
ret
recal: MOV BLK_ADDR,#000B ;INITIALIZE 2K BLOCK
MOV BYTE_DATA,#00h ;BYTE DATA
MOV PAGE_DATA,#0aaH ;PAGE DATA
nop
nop
nop
nop
nop
CALL SELECT_RD ;CALL BYTE READ ROUTINE
mov a, dataout
cjne a, #'{', error
INC BYTE_ADDR
nop
nop
nop
88
nop
nop
CALL SELECT_RD ;CALL BYTE READ ROUTINE
mov CPUIN, dataout
INC BYTE_ADDR
nop
nop
nop
nop
nop
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ION1:cjne a, #'C', ION2
clr relay2
call delay
RET
ION2:cjne a, #'D', ION3
setb relay2
call delay
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ION3:cjne a, #'E', ION4
clr relay3
call delay
RET
ION4:cjne a, #'F', ION5
setb relay3
call delay
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ION5:CALL DELAY
RET
90
errooooor:
CLR TI
MOV SBUF #'E'
JNB TI, $
SETB P2.0
RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;next line
;************** BYTE WRITE *****************
BYTE_WR: CALL START_BIT ;SEND START BIT
MOV A,#SLV_ADDR ;FIRST 4 SLAVE ADDRESS
MOV R7,#4H
;BITS
CALL SHFTO
MOV A,BLK_ADDR
MOV R7,#3H
CALL SHFTO
MOV A,#00H
MOV R7,#1H
;WRITE
CALL SHFTO
CALL SLAVE_ACK
MOV A,BYTE_ADDR ;BYTE ADDRESS
MOV R7,#8H
CALL SHFTO
CALL SLAVE_ACK
MOV A,BYTE_DATA ;BYTE DATA
91
MOV R7,#8H
CALL SHFTO
CALL SLAVE_ACK
CALL STOP_BIT ;STOP BIT
CALL ACK_POL ;CALL ACK POLLING, WAIT
RET
;*******************************************
MOV R4,#0FH
;2K BLOCK
CALL SHFTO
MOV A,BLK_ADDR
MOV R7,#3H
CALL SHFTO
MOV A,#00H
MOV R7,#1H
;FOR WRITE
93
CALL SHFTO
CALL SLAVE_ACK ;SEND ACKNOWLEDG
MOV R7,#3H
CALL SHFTO
MOV A,#1H
MOV R7,#1H
;FOR READ
CALL SHFTO
CALL SLAVE_ACK
MOV R7,#8H
CLOCK8: SETB SCL
;CLOCK IN DATA
NOP
MOV C,SDA
CLR SCL
94
MOV A,DATAOUT
RRC A
MOV DATAOUT,A
DJNZ R7,CLOCK8
CALL NO_ACK
CALL STOP_BIT
RET
;*******************************************
SEQ_RD:
CALL START_BIT ;START BIT
MOV A,#SLV_ADDR ;DUMMY WRITE TO FIRST
MOV R7,#4H ;2K BLOCK
CALL SHFTO
MOV A,BLK_ADDR ;2K BLOCK ADDRESS
MOV R7,#3H
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;line 5
CALL SHFTO
MOV A,#00H ;R/W BIT SET TO 0
MOV R7,#1H ;FOR WRITE
CALL SHFTO
CALL SLAVE_ACK
95
NOP
CLR SCL
NOP
DJNZ R7,ONE_BYTE
CALL MSTR_ACK
;ACKNOWLEDGE
DJNZ R6,NXT_BYTE
96
MOV R7,#8H
LST_BYTE: SETB SCL
NOP
CLR SCL
NOP
DJNZ R7,LST_BYTE
CALL NO_ACK ;NO ACKNOWLEDGE
CALL STOP_BIT ;STOP BIT
RET
;*******************************************
;************** ACK_POL ********************
ACK_POL: MOV R3,#40H
;# OF TIMES TO POLL
;SEND ACKNOWLEDGE
JC ACK_LOOP
MOV SDA,C
SETB SCL
DJNZ R7,NXTSHF
RET
;*******************************************
;************** START BIT ******************
START_BIT: SETB SCL
;START BIT
NOP
SETB SDA
NOP
CLR SDA
NOP
CLR SCL
RET
;*******************************************
;************** STOP BIT *******************
STOP_BIT: CLR SDA
;STOP BIT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;line 4
NOP
SETB SCL
98
NOP
SETB SDA
RET
;*******************************************
NOP
SETB SDA
NOP
NOP
SETB SCL
NOP
NOP
NOP
MOV C,SDA
CLR SCL
;SAVE TO CARRY
RET
;*******************************************
END
100
101
102