Professional Documents
Culture Documents
Technology, Kakkanad
INDEX
NO CONTENTS PAGE NO
1 INTRODUCTION 2
2 INTERFACING OF ANALOG TO DIGITAL CONVERTER 3
WITH MICROCONTROLLER
3 INTRODUCTION TO SERIAL COMMUNICATION 8
4 MICRO-CONTROLLER ARCHITECTURE 14
5 INTERFACING AN LCD TO THE AT89C51 34
6 SENSOR INTERFACING 38
7 POWER SUPPLY DESIGN 40
8 PROGRAMMING SECTION 41
9 PCB DESIGN 45
10 SERIAL COMMUNICATION PC-MICROCONTROLLER 46
CHAPTER 1:
INTRODUCTION
developing an indigenous data acquisition system, of which the hardware part of the
whole project is our immediate concern. The literal meaning of a data acquisition system
is to acquire data, to process it and display it. The hardware section, which deals with the
acquiring and displaying of the data, makes use of a Sensor, Analog to Digital converter,
parameter. This electrical signal is then provided to an ADC which converts the analog
signal to an equivalent digital signal which is provided to the micro controller. The micro
controller transmits the data serially to another micro controller (remote station) which
Parallel
Serial
ADC804 Microcontroller
8051 PC
CHAPTER 2:
2.1 INTERFACING OF ADC WITH MICROCONTROLLER
OBJECTIVE:
Our project is ‘PC BASED DATA ACQUISITION’. As a part of this
project, our main aim is to implement the hardware section of this module. The hardware
section consists of the sensors, ADC, micro controllers.
Parallel
Serial
ADC804 Microcontroller Microcontroller
8051 8051
LCD
Display /
DAC
Fig 1: Block schematic of hardware section
CIRCUIT COMPONENTS:
1. Controlling section
2. Analog to digital converter
3. Display Section
4. Sensors
5. Light emitting diodes
6. Power Supply
2.2 ANALOG TO DIGITAL CONVERTER (ADC):
An ADC is used to translate the analog signals to digital number so that
micro controller can read them. A widely used ADC chip is ADC804.
2.2.1 ADC804:
The ADC804 IC is an analog-to-digital converter in the family of ADC800
series from National Semiconductor. It works with +5 volts and has a resolution of 8bits.
Conversion time is another major factor in judging an ADC. It can be defined as the time
taken by the ADC to convert the analog to digital value. In the ADC804, the conversion
time varies depending on the clocking signals applied to the CLK R and CLK IN pins, it
cannot be faster than 110 microseconds.
Vcc
Vin+ D0
Vin- D1
A GND D2
Vref/2 D3
CLk R D4
CLK IN D5
CS D6
RD D7
D GND WR
INTR
ADC 804 Pin Out
CS:
Chip select is an active low input used to activate the ADC chip.
RD(READ):
This is an input signal and is active low. The ADC converts the analog input to
its binary equivalent and holds it in an internal register. RD is used to get the converted
data out of the ADC chip.
WR(WRITE):
This is an active low input used to inform the ADC804 to start the conversion.
The ADC804 starts conversion only when WR makes a low to high transition.
INTR(INTERRUPT):
This is an output pin and is active low. It is a normally high pin when the
conversion is finished, it goes low to signal the CPU that the converted data is ready to be
picked up.
Vcc:
This is the +5v power supply. It is also used as a reference voltage when the Vref/2
input is open.
Vref/2:
It is an input voltage used for the reference voltage. If this pin is not connected
,the analog input voltage for the ADC804 is in the range of 0 to 5v(same as that of Vcc
supply). Vref/2 is used to implement analog input voltages other than 0-5v. For instances
if the analog input range needs to be 0-4V, Vref/2is connected to 2V.
D0-D7:
D0-D7(where D7 is the MSB , D0 is the LSB).are the digital data output pins.
These are tri-state buffered and the converted data is accessed only when CS=0 and RD is
forced low.
Dout= Vin/(step size)
Dout=digital data output (in decimal)
Vin= analog input voltage
Step size=(resolution) it is the smallest change, which is ( 2*Vref/2)/256 for an 8-bit
ADC.
CAPTER: 3
All IBM PC and compatible computers are typically equipped with two serial ports
and one parallel port. Although these two types of ports are used for communicating with
external devices, they work in different ways. A parallel port sends and receives data
eight bits at a time over 8 separate wires. This allows data to be transferred very quickly;
however, the cable required is more bulky because of the number of individual wires it
must contain. Parallel ports are typically used to connect a PC to a printer and are rarely
used for much else. A serial port sends and receives data one bit at a time over one wire.
While it takes eight times as long to transfer each byte of data this way, only a few wires
are required. In fact, two-way (full duplex) communications is possible with only three
separate wires - one to send, one to receive, and a common signal ground wire.
Serial Cables can be longer than Parallel cables. The serial port transmits a '1' as -3 to
-25 volts and a '0' as +3 to +25 volts where as a parallel port transmits a '0' as 0v and a
'1' as 5v. Therefore the serial port can have a maximum swing of 50V compared to the
parallel port which has a maximum swing of 5 Volts. Therefore cable loss is not going
to be as much of a problem for serial cables than they are for parallel.
You don't need as many wires than parallel transmission. If your device needs to be
mounted a far distance away from the computer then 3 core cable (Null Modem
Configuration) is going to be a lot cheaper that running 19 or 25 core cable. However
you must take into account the cost of the interfacing at each end.
Infra Red devices have proven quite popular recently. You may of seen many
electronic diaries and palmtop computers which have infra red capabilities build in.
However could you imagine transmitting 8 bits of data at the one time across the
Uni.Reg.No : 26034 – 10 –
Rajagiri School of Engineering &
Technology, Kakkanad
Uni.Reg.No : 26034 – 11 –
Rajagiri School of Engineering &
Technology, Kakkanad
2. Data bits are transmitted /received with reference to the edges of the clock signal.
3. All data transfer is thus synchronized to this clock. Typical examples include Serial
Programming Interface(SPI) and (Inter Integrated communications(I2C))
4. High speed of data communications possible. Typically > 1 M bit/second.
The clock signals is the control signal whose edges are used to shift data serially in both
directions between one device to another. The rising edges of the clock signal is used to
shift data from the first device to the second device one bit at a time. Similarly the falling
edge of the clock signal is used to shift the data from the second device to the first device
one bit at a time.
The data transmitted from the first device to the second device take a finite time delay
from the rising edge of the clock pulse. The finite time delay is used to the physical
delays in the gates and other circuitry used. The data shifted in to the first device from the
second device is on the falling edge of the clock. Here again the data has to be stable a
finite amount of time before and after the falling edge of the clock pulse. The finite time
before the corresponding edge is called the setup delay. This delay is required for the data
to stabilize before the clock edge occurs. Similarly the data has to be valid a finite
amount of time after the clock edge. This is again to ensure data validity. In addition to
this, manufactures of devices specify timings on the rate of rise, rate of fall, clock ON –
time, clock- OFF-time, clock frequency and much more.
Certain synchronous protocol formats are designed in such a way that the bi-
directional transfers happen simultaneously on the rising edge of the clock signal.
In some systems in order to maintain data integrity, the parity bit of the character
byte is included in the data frame. This means that for each character (7-or 7-bit,
depending on the system) we have a single parity bit in addition to start and stop bits. The
parity bit is odd ,or even. In the case of an odd parity bit the number of data bits,
including the parity bit, has an odd number of ones. Similarly, in an even parity bit
system the total number of bits, including the parity bit, is even.
Uni.Reg.No : 26034 – 12 –
Rajagiri School of Engineering &
Technology, Kakkanad
Uni.Reg.No : 26034 – 13 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 4:
MICRO-CONTROLLER ARCHITECTURE
The Atmel 89C51 forms the main processing unit of the board. AT89C51 is a 40
pin IC and has 4 Ports P0 to P3 and has an 8 bit architecture.
Uni.Reg.No : 26034 – 14 –
Rajagiri School of Engineering &
Technology, Kakkanad
Uni.Reg.No : 26034 – 15 –
Rajagiri School of Engineering &
Technology, Kakkanad
A map of the on-chip memory area called the Special Function Register
(SFR) space is shown in Figure 2. Note that in the SFR s not all of the addresses are
occupied. Unoccupied addresses are not implemented on the chip. Read accesses to these
addresses will in general return random data, and write accesses will have no effect. User
software should not write 1s to these unimplemented locations, since they may be used in
other 80C51 Family derivative products to invoke new features. The functions of the SFR
s are described in the text that follows.
Accumulator :
ACC is the Accumulator register, it is generally used for temporary storage
with in the CPU, simply referred as A..
B Register:
The B register is used during multiply and divide operations. For other
instructions it can be treated as another scratch pad register.
Uni.Reg.No : 26034 – 16 –
Rajagiri School of Engineering &
Technology, Kakkanad
The Stack Pointer register is 8 bits wide. It is incremented before data is
stored during PUSH and CALL executions. While the stack may reside anywhere in on-
chip RAM, the Stack Pointer is initialized to 07H after a reset. This causes the stack to
begin at locations 08H.
Data Pointer:
The Data Pointer (DPTR) consists of a high byte (DPH) and a low byte
(DPL). Its intended function is to hold a 16-bit address. It may be manipulated as a 16-bit
register or as two independent 8-bit registers.
Ports 1 & 3:
P1 and P3 are the SFR latches of Ports 0, 1, 2, and 3, respectively. Writing a
one to a bit of a port SFR (P0, P1, P2, or P3) causes the corresponding port output pin to
switch high. Writing a zero causes the port output pin to switch low. When used as an
input, the external state of a port pin will be held in the port SFR (i.e., if the external state
of a pin is low, the corresponding port SFR bit will contain a 0; if it is high, the bit will
contain a 1).
Special Function Registers IP, IE, TMOD, TCON, SCON, and PCON
Uni.Reg.No : 26034 – 17 –
Rajagiri School of Engineering &
Technology, Kakkanad
Contain control and status bits for the interrupt system, the Timer/Counters,
and the serial port. They are described in later sections.
All four ports in the 80C51 are bidirectional. Each consists of a latch
(Special Function Registers P0 through P3), an output driver, and an input buffer. The
output drivers of Ports 0 and 2, and the input buffers of Port 0, are used in accesses to
external memory. In this application, Port 0 outputs the low byte of the external memory
address, time-multiplexed with the byte being written or read. Port 2 outputs the high
byte of the external memory address when the address is 16 bits wide. Otherwise, the
Port 2 pins continue to emit the P2 SFR content.
All the Port 3 pins are multifunctional. They are not only port pins, but also
serve the functions of various special features as listed below:
4.4 Timer/Counters
The 80C51 has two 16-bit Timer/Counter registers: Timer 0 and Timer 1.
Both can be configured to operate either as timers or event counters (see Figure 6). In the
“Timer” function, the register is incremented every machine cycle. Thus, one can think
Uni.Reg.No : 26034 – 18 –
Rajagiri School of Engineering &
Technology, Kakkanad
of it as counting machine cycles. Since a machine cycle consists of 12 oscillator periods,
the count rate is 1/12 of the oscillator frequency. In the “Counter” function, the register is
incremented in response to a 1-to-0 transition at its corresponding external input pin, T0
or T1. In this function, the external input is sampled during S5P2 of every machine cycle.
When the samples show a high in one cycle and a low in the next cycle, the count is
incremented. The new count value appears in the register during S3P1 of the cycle
following the one in which the transition was detected. Since it takes 2 machine cycles
(24 oscillator periods) to recognize a 1-to-0 transition, the maximum count rate is 1/24 of
the oscillator frequency. There are no restrictions on the duty cycle of the external input
signal, but to ensure that a given level is sampled at least once before it changes, it should
be held for at least one full cycle. In addition to the “Timer” or “Counter” selection,
Timer 0 and Timer 1 have four operating modes from which to select.
Uni.Reg.No : 26034 – 19 –
Rajagiri School of Engineering &
Technology, Kakkanad
The “Timer” or “Counter” function is selected by control bits C/T in the
Special Function Register TMOD. These two Timer/Counters have four operating modes,
which are selected by bit-pairs (M1, M0) in TMOD. Modes 0, 1, and 2 are the same for
both Timers/Counters. Mode 3 is different. The four operating modes are described in the
following text.
Mode 0:
Putting either Timer into Mode 0 makes it look like an 8048 Timer, which is
an 8- bit counter with a divide-by-32 prescaler. Figure 7 shows the Mode 0 operation as it
applies to Timer 1. In this mode, the Timer register is configured as a 13-bit register. As
the count rolls over from all 1s to all 0s, it sets the Timer interrupt flag TF1. The counted
input is enabled to the Timer when TR1 = 1 and either GATE = 0 or INT1 = 1. (Setting
GATE = 1 allows the Timer to be controlled by external input INT1, to facilitate pulse
width measurements). TR1 is a control bit in the Special Function Register TCON
(Figure 8). GATE is in TMOD. The 13-bit register consists of all 8 bits of TH1 and the
lower 5 bits of TL1. The upper 3 bits of TL1 are indeterminate and should be ignored.
Setting the run flag (TR1) does not clear the registers. Mode 0 operation is the same for
the Timer 0 as for Timer1. Substitute TR0, TF0, and INT0 for the corresponding Timer 1
signals in Figure 7. There are two different GATE bits, one for Timer 1 (TMOD.7) and
one for Timer 0 (TMOD.3).
Mode 1:
Uni.Reg.No : 26034 – 20 –
Rajagiri School of Engineering &
Technology, Kakkanad
Mode 1 is the same as Mode 0, except that the Timer register is being run
with all 16 bits.
Mode 2:
Mode 2 configures the Timer register as an 8-bit Counter (TL1) with
automatic reload, as shown in Figure 9. Overflow from TL1 not only sets TF1, but also
re loads TL1 with the contents of TH1, which is preset by software. The reload leaves
TH1 unchanged. Mode 2 operation is the same for Timer/Counter 0.
Mode 3
Timer 1 in Mode 3 simply holds its count. The effect is the same as setting
TR1 = 0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate counters. The logic
for Mode 3 on Timer 0 is shown in Figure 10. TL0 uses the Timer 0 control bits: C/T,
GATE, TR0, INT0, and TF0. TH0 is locked into a timer function (counting machine
cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls
the “Timer 1” interrupt. Mode 3 is provided for applications requiring an extra 8-bit timer
on the counter. With Timer 0 in Mode 3, an 80C51 can look like it has three
Timer/Counters. When Timer 0 is in Mode 3, Timer 1 can be turned on and off by
switching it out of and into its own Mode 3, or can still be used by the serial port as a
baud rate generator, or in fact, in any application not requiring an interrupt.
Uni.Reg.No : 26034 – 21 –
Rajagiri School of Engineering &
Technology, Kakkanad
The serial port is full duplex, meaning it can transmit and receive
simultaneously. It is also receive-buffered, meaning it can commence reception of a
second byte before a previously received byte has been read from the register. (However,
if the first byte still hasn’t been read by the time reception of the second byte is complete,
one of the bytes will be lost.) The serial port receive and transmit registers are both
accessed at Special Function Register SBUF. Writing to SBUF loads the transmit register,
and reading SBUF accesses a physically separate receive register.
Mode 0:
Serial data enters and exits through RxD. TxD outputs the shift clock. 8 bits are
transmitted/received (LSB first). The baud rate is fixed at 1/12 the oscillator frequency.
Mode 1:
10 bits are transmitted (through TxD) or received (through RxD): a start bit (0), 8
data bits (LSB first), and a stop bit (1). On receive, the stop bit goes into RB8 in Special
Function Register SCON. The baud rate is variable.
Uni.Reg.No : 26034 – 22 –
Rajagiri School of Engineering &
Technology, Kakkanad
Mode 2:
11 bits are transmitted (through TxD) or received (through RxD): start it (0), 8
data bits (LSB first), a programmable 9th data bit, and a stop bit (1). On Transmit, the 9th
data bit (TB8 in SCON) can be assigned the value of 0 or 1. Or, for example, the parity
bit (P, in the PSW) could be moved into TB8. On receive,
the 9th data bit goes into RB8 in Special Function Register SCON, while the stop bit is
ignored. The baud rate is programmable to either 1/32 or 1/64 the oscillator frequency.
Mode 3:
11 bits are transmitted (through TxD) or received (through RxD): a start bit (0),
8 data bits (LSB first), a programmable 9th data bit, and a stop bit (1). In fact, Mode 3 is
the same as Mode 2 in all respects except baud rate. The baud rate in Mode 3 is variable.
In all four modes, transmission is initiated by any instruction that uses SBUF as a
destination register. Reception is initiated in Mode 0 by the condition RI = 0 and REN =
1. Reception is initiated in the other modes by the incoming start bit if REN = 1.
When the master processor wants to transmit a block of data to one of several
slaves, it first sends out an address byte which identifies the target slave. An address byte
differs from a data byte in that the 9th bit is 1 in an address byte and 0 in a data byte.
With SM2 = 1, no slave will be interrupted by a data byte. An address byte, however, will
interrupt all slaves, so that each slave can examine the received byte and see if it is being
addressed. The addressed slave will clear its SM2 bit and prepare to receive the data
bytes that will be coming.
Uni.Reg.No : 26034 – 23 –
Rajagiri School of Engineering &
Technology, Kakkanad
The slaves that weren’t being addressed leave their SM2s set and go on about
their business, ignoring the coming data bytes.SM2 has no effect in Mode 0, and in Mode
1 can be used to check the validity of the stop bit. In a Mode 1 reception, if SM2 = 1, the
receive interrupt will not be activated unless a valid stop bit is received.
The serial port control and status register is the Special Function Register
SCON, shown in Figure 11. This register contains not only the mode selection bits, but
also the 9th data bit for transmit and receive (TB8 and RB8), and the serial port interrupt
bits (TI and RI).
Baud Rates:
Uni.Reg.No : 26034 – 24 –
Rajagiri School of Engineering &
Technology, Kakkanad
The baud rate in Mode 0 is fixed: Mode 0 Baud Rate = Oscillator Frequency
/ 12. The baud rate in Mode 2 depends on the value of bit SMOD in Special Function
Register PCON. If SMOD = 0 (which is the value on reset), the baud rate is 1/64 the
oscillator frequency. If SMOD = 1, the baud rate is 1/32 the oscillator frequency.
Mode 2 Baud Rate = 2SMOD * 64/ Oscillator Frequency
In the 80C51, the baud rates in Modes 1 and 3 are determined by the Timer 1
overflow rate.
Uni.Reg.No : 26034 – 25 –
Rajagiri School of Engineering &
Technology, Kakkanad
4.6 Interrupts:
Uni.Reg.No : 26034 – 26 –
Rajagiri School of Engineering &
Technology, Kakkanad
The 89C51 provides 5 interrupt sources. These are shown in Figure 12. The
External Interrupts INT0 and INT1 can each be either level-activated or transition-
activated, depending on bits IT0 and IT1 in Register TCON. The flags that actually
generate these interrupts are bits IE0 and IE1 in TCON. When an external interrupt is
generated, the flag that generated it is cleared by the hardware when the service routine
is vectored to only if the interrupt was transition-activated. If the interrupt was level-
activated, then the external requesting source is what controls the request flag, rather than
the on-chip hardware. The Timer 0 and Timer 1 Interrupts are generated by TF0 and TF1,
which are set by a rollover in their respective Timer/Counter registers (except see Timer
0 in Mode 3). When a timer interrupt is generated, the flag that generated it is cleared by
the on-chip hardware when the service routine is vectored to. The Serial Port Interrupt is
generated by the logical OR of RI and TI.
Neither of these flags is cleared by hardware when the service routine is vectored to. In
fact, the service routine will normally have to determine whether it was RI or TI that
generated the interrupt, and the bit will have to be cleared in software. All of the bits that
generate interrupts can be set or cleared by software, with the same result as though it
had been set or cleared by hardware. That is, interrupts can be generated or pending
interrupts can be canceled in software.
Each of these interrupt sources can be individually enabled or disabled by setting or
clearing a bit in Special Function Register IE (Figure 18). IE also contains a global
disable bit, EA, which disables all interrupts at once.
Uni.Reg.No : 26034 – 27 –
Rajagiri School of Engineering &
Technology, Kakkanad
Same priority level are received simultaneously, an internal polling sequence determines
which request is serviced. Thus within each priority level there is a second priority
structure determined by the polling sequence as follows:
1. IE0 (highest)
2. TF0
3. IE1
4. TF1
5. RI+TI (lowest)
Note that the “priority within level” structure is only used to resolve
Simultaneous requests of the same priority level. The IP register contains a number of
unimplemented bits. IP.7, IP.6, and IP.5 are reserved in the 80C51. User software should
not write 1s to these positions, since they may be used in other 8051 Family products.
The interrupt flags are sampled at S5P2 of every machine cycle. The samples
are polled during the following machine cycle. If one of the flags was in a set condition
at S5P2 of the preceding cycle, the polling cycle will find it and the interrupt system will
generate an LCALL to the appropriate service routine, provided this hardware-generated
LCALL is not blocked by any of the following
Conditions:
Uni.Reg.No : 26034 – 28 –
Rajagiri School of Engineering &
Technology, Kakkanad
Any of these three conditions will block the generation of the LCALL to the interrupt
service routine. Condition 2 ensures that the instruction in progress will be completed
before vectoring to any service routine. Condition 3 ensures that if the instruction in
progress is RETI or any access to IE or IP, then at least one more instruction will be
executed before any interrupt is vectored to. The polling cycle is repeated with each
machine cycle, and the values polled are the values that were present at S5P2 of the
previous machine cycle. Note that if an interrupt flag is active but not being responded to
for one of the above conditions, if the flag is not still active when the blocking condition
is removed, the denied interrupt will not be serviced. In other words, the fact that the
interrupt flag was once active but not serviced is not remembered. Every polling cycle is
new. The polling cycle/LCALL sequence is illustrated in Figure 20.
Note that if an interrupt of higher priority level goes active prior to S5P2 of the machine
cycle labeled C3 in Figure 20, and then in accordance with the above rules it will be
vectored to during C5 and C6, without any instruction of the lower priority routine
having been executed. Thus the processor acknowledges an interrupt request by
executing a hardware-generated LCALL to the appropriate servicing routine. In some
cases it also clears the flag that generated the interrupt, and in other cases it doesn’t. It
never clears the Serial Port flag. This has to be done in the user’s software. It clears an
external interrupt flag (IE0 or IE1) only if it was transition-activated. The hardware-
generated LCALL pushes the contents of the Program Counter on to the stack (but it does
not save the PSW) and reloads the PC with an address that depends on the source of the
interrupt being vectored to, as shown below:
IE0: 0003H
TF0: 000BH
IE1: 0013H
TF1: 001BH
RI+TI: 0023H
Uni.Reg.No : 26034 – 29 –
Rajagiri School of Engineering &
Technology, Kakkanad
Execution proceeds from that location until the RETI instruction is encountered.
Uni.Reg.No : 26034 – 30 –
Rajagiri School of Engineering &
Technology, Kakkanad
a good reset, the RST pin must be high long enough to allow the oscillator time to start-
up (normally
a few ms) plus two machine cycles. Note that the port pins will be in a random state until
the oscillator has started and the internal reset algorithm has written 1s to them. With this
circuit, reducing VCC quickly to 0 causes the RST pin voltage to momentarily fall below
0V. However, this voltage is internally limited, and will not harm the device.
U 1
3 9 2 1
3 8 P 0 . 0 / A D 0 P 2 . 0 / A 8 2 2
3 7 P 0 . 1 / A D 1 P 2 . 1 / A 9 2 3
3 6 P 0 . 2 / A D 2 P 2 .2 /A 1 0 2 4
3 5 P 0 . 3 / A D 3 P 2 .3 /A 1 1 2 5
3 4 P 0 . 4 / A D 4 P 2 .4 /A 1 2 2 6
3 3 P 0 . 5 / A D 5 P 2 .5 /A 1 3 2 7
3 2 P 0 . 6 / A D 6 P 2 .6 /A 1 4 2 8
P 0 . 7 / A D 7 P 2 .7 /A 1 5
1 1 0
2 P 1 . 0 P 3 .0 /R XD 1 1
3 P 1 . 1 P 3 .1 /T XD 1 2
4 P 1 . 2 P 3 .2 /IN T O 1 3
5 P 1 . 3 P 3 .3 /IN T 1 1 4
6 P 1 . 4 P 3 .4 /T O 1 5
7 P 1 . 5 P 3 .5 /T 1 1 6
V C C 8 P 1 . 6 P 3 .6 /W R 1 7
P 1 . 7 P 3 .7 /R D
C 9 1 9 2 9
1 0 M F D 1 8 XT A L 1 P S E N
9 XT A L 2 3 0
R S T A L E /P R O G
R 3 3 1
E A /V P P
1 0 K
A T 8 9 C 5 1
C 4 C 3
1 8 p F 1 8 p F
;
Fig 13: Power-on reset connection
Uni.Reg.No : 26034 – 31 –
Rajagiri School of Engineering &
Technology, Kakkanad
CMOS Power Reduction Mode:
CMOS versions have two power reducing modes, Idle and Power Down.
The input through which backup power is supplied during these operations is VCC.
Figure 23 shows the internal circuitry which implements these features. In the Idle
modes (IDL = 1), the oscillator continues to run and the Interrupt, Serial Port, and Timer
blocks continue to be clocked, but the clock signal is gated off to the CPU. In Power
Down (PD = 1), the oscillator is frozen. The Idle and Power
Down Modes are activated by setting bits in Special Function Register PCON. The
address of this register is 87H. Figure 24 details its contents. In the NMOS devices the
PCON register only contains SMOD. The other four bits are implemented only in the
CMOS devices. User software should never write 1s to unimplemented bits, since they
may be used in other 80C51 Family products.
Idle Mode:
An instruction that sets PCON.0 causes that to be the last instruction
executed before going into the idle mode, the internal clock signal is gated off to the CPU
but not to the Interrupt, Timer, and Serial Port functions. The CPU status is preserved in
its entirety; the Stack Pointer, Program Counter, Program Status Word, Accumulator, and
all other registers maintain their data during Idle.
The port pins hold the logical states they had at the time Idle was activated. ALE and
PSEN hold at logic high levels. There are two ways to terminate the Idle. Activation of
any enabled interrupt will cause PCON.0 to be cleared by hardware, terminating the Idle
mode. The interrupt will be serviced, and following RETI, the next instruction to be
executed will be the one following the instruction that put the device into Idle. The flag
bits GF0 and GF1 can be used to give an indication if an Interrupt occurred during
normal operation or during an Idle. For example, n instruction that activates Idle can also
set one or both flag bits. When Idle is terminated by an interrupt, the interrupt service
routine can examine the flag bits. The other way of terminating the idle mode is with a
hardware reset. Since the clock oscillator is still running, the hardware reset needs to be
held active for only two machine cycles (24 oscillator periods) to complete the reset. The
Uni.Reg.No : 26034 – 32 –
Rajagiri School of Engineering &
Technology, Kakkanad
signal at the RST pin clears the IDL bit directly and asynchronously. At this time the CPU
resumes program execution from where it left off; that is, at the instruction following the
one that invoked the Idle Mode. As shown in Figure, two or three machine cycles of
program execution may take place before the internal reset algorithm takes control. On-
chip hardware inhibits access to the internal RAM during this time, but access to the port
pins is not inhibited, so, the insertion of 3 NOP instructions is recommended following
the instruction that invokes idle mode. To eliminate the possibility of unexpected outputs
at the port pins, the instruction following the one that invokes Idle should not be one that
writes to a port pin or to external Data RAM.
Uni.Reg.No : 26034 – 33 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 5:
INTERFACING AN LCD TO THE 89C51
This section describes the operation modes of LCD’s, then describes how to
program and interface an LCD to an 8051.
In recent years the LCD is finding wide spread use replacing LED’s (seven
segment LED’s or other multi -segment LED’s). This is due to the following reasons:
While Vcc and Vss provide +5v and ground, respectively, Vee is used for
controlling the LCD contrast.
Uni.Reg.No : 26034 – 34 –
Rajagiri School of Engineering &
Technology, Kakkanad
There are two very important registers inside the LCD. The RS pin is used for
their selection as follows. If RS=0, the instruction command code register is selected,
allowing the user to send a command such as clear display, cursor at home, etc. If RS=1
the data register is selected, allowing the user to send data to be displayed on the LCD.
R/W, read/write:
R/W input allows the user to write information to the LCD or read
information from it. R/W=1 when reading; R/W=0 when writing.
E, enable:
The enable pin is used by the LCD to latch information presented to its data pins.
When data is supplied to data pins, a high-to-low pulse must be applied to this pin in
order for the LCD to latch in the data present at the data pins. This pulse must be a
minimum of 450ns wide.
D0-D7
The 8-bit pins, D0- D7, are used to send information to the LCD or read the
contents of the LCD’s internal registers. To display letters and numbers, we send ASCII
codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS=1.There
are also instruction command codes that can be sent to the LCD to clear the display or
force the cursor to the home position or blink the cursor,
We also use RS=0 to check the busy flag bit to see if the LCD is ready to
receive information. The busy flag is D7 and can be read when R/W=1 and RS=0, as
follows: if R/W=1, RS=0. When D7=1(busy flag=1) , the LCD is busy taking care of
internal operations and will not accept any new information. When D7=0, the LCD is
ready to receive new information.
Uni.Reg.No : 26034 – 35 –
Rajagiri School of Engineering &
Technology, Kakkanad
1. VSS -- Ground
2. VCC -- +5V power supply.
3 VEE -- Power supply to control
Contrast.
4. RS 1 RS=0 to select command
Uni.Reg.No : 26034 – 36 –
Rajagiri School of Engineering &
Technology, Kakkanad
Register,
RS=1 to select data
register
5 R/W 1 R/W=0 for write, R/W=1
For read
6 E I/O Enable
7 DB0 I/O the 8 bit data bus
8 DB1 I/O the 8 bit data bus
9 DB2 I/O the 8 bit data bus
10 DB3 I/O the 8 bit data bus
11 DB4 I/O the 8 bit data bus
12 DB5 I/O the 8 bit data bus
13 DB6 I/O the 8 bit data bus
14 DB7 I/O the 8 bit data bus
15 LCD+ -- VCC
16 LCD- -- Ground
Uni.Reg.No : 26034 – 37 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 6:
SENSOR INTERFACING:
VC C
R 2
10 K
J8
1
2
LD R
Fig 17:LDR connection
Uni.Reg.No : 26034 – 38 –
Rajagiri School of Engineering &
Technology, Kakkanad
VC C
R 6
10K
LD R
VC C
VR 2 U 6B
8
5
3
10 K +
7
6
2
- Buzzer
LM 358
4
J5
3
1 VR 1
2
3 2 10 K
LM 35
U 6A
1
3
+
1
2
-
LM 358
4
Uni.Reg.No : 26034 – 39 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 7:
U 2
D I1 +12V P o w e r su p p ly LM 7805 +5V
A C 1 3
J2 V IN VO U T
G N D
1N 4007 C 2
2
3 10 m fd
D I2 C 1
2
1 2 -0 -1 2 v a .c A C
2 2 0 0 M F D /2 5 v
1N 4007
Power supply is built by using center tapped rectifier, filter and regulators. 7805 is used
for 5v.
Uni.Reg.No : 26034 – 40 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 8:
PROGRAMMING SECTION
Uni.Reg.No : 26034 – 41 –
Rajagiri School of Engineering &
Technology, Kakkanad
L1: MOV A,P1
MOV P2,A
MOV SBUF, A
LOOP: JNB TI, LOOP
CLR TI
DJNZ R3,L1
DJNZ R2,L2
DJNZ R1,L3
DJNZ R0,L4
SJMP REPEAT
END
Uni.Reg.No : 26034 – 42 –
Rajagiri School of Engineering &
Technology, Kakkanad
CALL COMMAND
MOV A,#80H
CALL COMMAND
CLR RI
DIV: MOV A,R7
MOV B,#10
DIV AB
MOV R1,A
MOV R2,B
MOV A,R1
MOV B,#10
DIV AB
MOV R6,A
MOV R5,B
MOV DPTR,#300H
CLRA
MOV A,R6
MOVC A,@A+DPTR
ACALL DATA
MOV DPTR,#300H
CLR A
MOV A,R5
MOVC A,@A+DPTR
ACALL DATA
MOV DPTR,#300H
CLRA
MOV A,R2
MOVC A,@A+DPTR
ACALL DATA
LJMP HERE
COMMAND: MOV P1,A
Uni.Reg.No : 26034 – 43 –
Rajagiri School of Engineering &
Technology, Kakkanad
CLR P3.2
SETB P3.4
CLR P3.4
MOV R3,#32
M:MOV R4,#255
N:DJNZ R4,N
DJNZ R3,M
RET
ORG 300H
DB ‘0’
DB ‘1’
DB ‘2’
DB ‘3’
DB ‘4’
DB ‘5’
DB ‘6’
DB ‘7’
DB ‘8’
DB ‘9’
Uni.Reg.No : 26034 – 44 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 9:
PCB DESIGN:
Orcad is used to prepare PCB and schematic. Orcad capture is used to draw
the schematic, Orcad layout is used to draw the PCB layout.
Netlist is generated from schematic drawn in orcad capture. It is imported
in Orcad layout, placed and routed the PCB.
9.1 PCB Preparation:
Prepare
Schematic in
Orcad Capture
Generate Netlist
for Layout
Prepare
Schematic in
Orcad Capture
Generate Gerber
file and make
printouts
Uni.Reg.No : 26034 – 45 –
Rajagiri School of Engineering &
Technology, Kakkanad
CHAPTER 10:
Interface serially ATMEL89C51 with a standard IBM PC and to transfer the data
received by the PC to another PC using JAVA socket programming.
10.2 Objectives:
Uni.Reg.No : 26034 – 46 –
Rajagiri School of Engineering &
Technology, Kakkanad
Fig. 21
10.4 Theory:
MICRO-CONTROLLER
Micro Controller used in this circuit is AT89C51. It is a 40 pin IC. It has 4 Ports P0 to P3.
Uni.Reg.No : 26034 – 47 –
Rajagiri School of Engineering &
Technology, Kakkanad
The voltage level used in 89C51 is 5V (TTL)and that used in RS232 standards is 12V.So
the PC cannot be connected directly to the microcontroller. Between these two MAX232
is used as a voltage level converter. It can convert 5V to 12V while transmitting signals
from microcontroller to PC and also convert 12V to 5V while transmitting signals from
PC to microcontroller.
Fig. 22
Uni.Reg.No : 26034 – 48 –
Rajagiri School of Engineering &
Technology, Kakkanad
Fig. 25
This loop back plug can come in extremely handy when writing Serial / RS232
Communications Programs. It has the receive and transmit lines connected together, so
that anything transmitted out of the Serial Port is immediately received by the same port.
If you connect this to a Serial Port an load a Terminal Program, anything you type will be
immediately displayed on the screen.
10.5.1 Algorithm:
1. Start
2. Initialize port1
3. Wait for a data in port1
4. If there is data receive it and display it
5. Save the character received to a file named file.txt
6. Else check for any keystroke
7. If there is a keystroke send it to port 1
8. Go to step3
Uni.Reg.No : 26034 – 49 –
Rajagiri School of Engineering &
Technology, Kakkanad
Algorithm:
1. Start
2. Set timer 1 in mode 2
3. Set baud rate to 9600
4. Set SCON in mode1
5. Start timer 1
6. Set P1=01101110b
7. Receive a value from PC serially
8. Display the value in P1
9. Transmit the value to PC
10. Go to step 7
11. Stop
Program Code:
ORG 00H
SJMP MAIN
ORG 30H
MAIN:
MOV TMOD,#20H ;timer 1, mode 2(auto reload)
MOV TH1,#-3 ;9600 baud rate
MOV SCON #50H ;8 bit, 1 stop bit, REN enabled
SETB TR1 ;start timer 1
MOV A,#66h
MOV P1,A
AGAIN:
CLR RI
LOOP:
JNB RI LOOP
MOV A,SBUF ;receiving a byte
MOV P1,A
CLR TI
MOV SBUF,A ;transmitting a byte
ALOOP:
JNB TI ALOOP
SJMP AGAIN
Uni.Reg.No : 26034 – 50 –
Rajagiri School of Engineering &
Technology, Kakkanad
Using HyperTerminal:-
Uni.Reg.No : 26034 – 51 –
Rajagiri School of Engineering &
Technology, Kakkanad
Uni.Reg.No : 26034 – 52 –
Rajagiri School of Engineering &
Technology, Kakkanad
Uni.Reg.No : 26034 – 53 –
Rajagiri School of Engineering &
Technology, Kakkanad
BIBLIOGRAPHY
Uni.Reg.No : 26034 – 54 –
Rajagiri School of Engineering &
Technology, Kakkanad
CONCLUSION
hardware part can be upgraded to be used in the data acquisition system, for which the
ADC has to be replaced with MCP3201. The ‘brain’ of the data acquisition can be
upgraded from AT89C51 to TINI, for greater efficiency. Different parameters can be
Uni.Reg.No : 26034 – 55 –