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

CHAPTER 1.

OVERVIEW

1
1.1 INTRODUCTION

This project consists of a handheld range finding device using


ultrasonic transducer and a PIC micro controller. A two-line LCD display is used to
display the measurements. There is a 40kHz transmitter and receiver. The 40kHz-
transmission signal is generated via a square wave outputted from the PIC. The PIC is
then used to calculate the time of flight (TOF) for the sound wave that is bounced off
of distant objects. The return signal is amplified using two opamp amplifiers. There
are three potentiometers that need to be calibrated for correct operation. One controls
the contrast of the LCD display. Another controls the amplification of the third stage
of the amplifier system. The third controls the voltage offset that connects to the base
of a NPN switching transistor. The measurement range of the device is one to ten feet.
Further distances can be measured, but due to circuit noise erroneous measurements
can be obtained for longer distances. The absolute maximum range that can be
measured is about twenty feet.

A measurement is initiated via the send button. When first depressed


the 40kHz pulse is sent out through the transmitter. After the PIC has completed the
transmission pulse the receiver stage is entered. The receiver stage waits a certain
amount of time before checking for signal reception. The receiver stage of the code
waits for a specified amount of time based on the mask value. This wait period is to
insure that the receiver does not register the transmission signal as the return signal
and also to ignore the return signal bounced back from small obstructions that are
between the device and the object that a measurement is being made to. If the mask is
set to zero then the minimum default wait period is performed. This period of time is
the time it takes for the transmitted signal to travel 1 ft and to return. Given the speed
of sound, 1125 ft/s, and an actual distance of 2 ft this wait time is approximately
1.8ms. If the mask is greater than 0 then the wait period is the time that it takes for
sound to travel 2 meters times the mask. This serves to make the mask value the
approximate distance in meters below which a return signal will be ignored. This time
period is approximately 5.8ms.

2
After the wait period has elapsed the PIC clears any interrupt flags and
begins looking for an interrupt triggered by the reception of the signal. The PIC goes
through a loop checking for the return signal and if it is not detected then a counter is
incremented. This loop is repeated until either the counter is full or the signal is
received. If the counter becomes full then the value of 0 meters is displayed.
Otherwise the calculation phase is entered.
After the signal is received the calculation phase is entered. Each counter value of 562
equates to 1 meter. The distance waited based on the mask value and the distance
calculated from the counter value are added together. The feet and inch distance is
then calculated from the distance in meters. The two values are then displayed on the
LCD

3
CHAPTER 2. DESCRIPTION OF COMPONENTS

4
2.1 POWER SUPPLY

The input to the circuit is applied from the regulated power supply. The a.c. input i.e.,

230V from the mains supply is step down by the transformer to 12V and is fed to a

rectifier. The output obtained from the rectifier is a pulsating d.c voltage. So in order

to get a pure d.c voltage, the output voltage from the rectifier is fed to a filter to

remove any a.c components present even after rectification. Now, this voltage is given

to a voltage regulator to obtain a pure constant dc voltage.

230V AC
50Hz D.C
Output

Step down Bridge


transformer Rectifier Filter Regulator

Fig1: Regulated Power supply

5
Transformer:

Usually, DC voltages are required to operate various electronic equipment and these

voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the

a.c input available at the mains supply i.e., 230V is to be brought down to the required

voltage level. This is done by a transformer. Thus, a step down transformer is

employed to decrease the voltage to a required level.

Fig2: Transformer

Rectifier:

The output from the transformer is fed to the rectifier. It converts A.C. into pulsating

D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge

rectifier is used because of its merits like good stability and full wave rectification.

6
Fig3: rectifier

The Bridge rectifier is a circuit, which converts an ac voltage to dc voltage using both
half cycles of the input ac voltage. The Bridge rectifier circuit is shown in the figure.
The circuit has four diodes connected to form a bridge. The ac input voltage is applied
to the diagonally opposite ends of the bridge. The load resistance is connected
between the other two ends of the bridge.

For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas
diodes D2 and D4 remain in the OFF state. The conducting diodes will be in series
with the load resistance RL and hence the load current flows through RL.

For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct
whereas, D1 and D3 remain OFF. The conducting diodes D2 and D4 will be in series

with the load resistance RL and hence the current flows through RL in the same
direction as in the previous half cycle. Thus a bi-directional wave is converted into a
unidirectional wave.

7
Fig4: rectifier wave forms

8
Filter:

Capacitive filter is used in this project. It removes the ripples from the output of
rectifier and smoothens the D.C. Output received from this filter is constant until the
mains voltage and load is maintained constant. However, if either of the two is varied,
D.C. voltage received at this point changes. Therefore a regulator is applied at the
output stage.

Voltage regulator:

As the name itself implies, it regulates the input applied to it. A voltage
regulator is an electrical regulator designed to automatically maintain a constant
voltage level. In this project, power
supply of 5V and 12V are required.
In order to obtain these voltage
levels, 7805 and 7812 voltage
regulators are to be used.

Fig5: regulator

The first number 78 represents positive supply and the numbers 05, 12 represent the
required output voltage levels. The L78xx series of three-terminal positive
regulators is available in TO-220, TO-220FP, TO-3, D2PAK and DPAK
packages and several fixed output voltages, making it useful in a
wide range of applications. These regulators can provide local on-
card regulation, eliminating the distribution problems associated
with single point regulation. Each type employs internal current
limiting, thermal shut-down and safe area protection, making it
essentially indestructible. If adequate heat sinking is provided, they
can deliver over 1 A output current. Although designed primarily as
fixed voltage regulators, these devices can be used with external
components to obtain adjustable voltage and currents.

9
Limitations:

The DC output voltage changes with a change in AC supply voltage. For example if
an A.C. voltage decreases by 6% then DC voltage also decreases by 6%.

The DC output voltage decreases considerably with the increase in load due to voltage
drop in transformer, rectifier and filter circuits. These variations in DC output may
affect the performance of electronic circuits. For instance the frequency of oscillation
will change in an oscillator and in transmitter the output may be destroyed. Thus it is
concluded that ordinary power supply is not suitable for some of the electronic
circuits for instance, with such circuits we have to employ a regulated power supply,
which gives a fixed output.

Necessity of regulated power supply:

The DC level of an ordinary power supply changes due to the following reasons.

Variations in AC mains voltage: the permissible variation in the mains voltage


as per Indian electricity rules is +/- 6% of its rated value. But in India the variation in
voltage is much more than its rated value. That is why the DC voltage of an ordinary
power supply changes to such an extent that the electronic device refuses to work
satisfactorily.

Voltages drop in internal resistance: the internal resistance of an ordinary power


supply is very large. Therefore output voltage changes to an extent when load is
connected across it. Some it reduces to very low extent due to which the electronic
component refuses to work. For instance consider a power supply of output voltage is
6V and internal resistance is 30 ohm. When a ratio receiver is connected across this
power supply it draws a current of 100 microamperes. There will be an internal
voltage drop 3V. The output voltage of power supply reduces to 3V and at such a low
voltage the receiver will not work at all.

10
CHAPTER 3. PIC MICROCONTROLLER

11
3. PIC 16F84 MICROCONTROLLER

3.1 FEATURES:

High Performance RISC CPU Features:

• Only 35 single word instructions to learn


• All instructions single-cycle except for program branches which are two-cycle
• Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle
• 1024 words of program memory
• 68 bytes of Data RAM
• 64 bytes of Data EEPROM
• 14-bit wide instruction words
• 8-bit wide data bytes
• 15 Special Function Hardware registers
• Eight-level deep hardware stack
• Direct, indirect and relative addressing modes
• Four interrupt sources:
- External RB0/INT pin
- TMR0 timer overflow
- PORTB<7:4> interrupt-on-change
- Data EEPROM write complete

Peripheral Features:
• 13 I/O pins with individual direction control
• High current sink/source for direct LED drive
- 25 mA sink max. per pin
- 25 mA source max. per pin
• TMR0: 8-bit timer/counter with 8-bit programmable prescaler
Special Microcontroller Features:
• 10,000 erase/write cycles Enhanced FLASH Program memory typical
• 10,000,000 typical erase/write cycles EEPROM Data memory typical
• EEPROM Data Retention > 40 years

12
• In-Circuit Serial Programming™ (ICSP™) – via two pins
• Power-on Reset (POR), Power-up Timer (PWRT), Oscillator Start-up Timer (OST)
• Watchdog Timer (WDT) with its own On-Chip RC Oscillator for reliable operation
• Code protection
• Power saving SLEEP mode
• Selectable oscillator options

Fig6: Microcontroller pin diagrams

CMOS Enhanced FLASH/EEPROM


Technology:
• Low power, high speed technology
• Fully static design
• Wide operating voltage range:
- Commercial: 2.0V to 5.5V
- Industrial: 2.0V to 5.5V
• Low power consumption:
- < 2 mA typical @ 5V, 4 MHz
- 15 mA typical @ 2V, 32 kHz

13
- < 0.5 mA typical standby current @ 2V

3.2 DEVICE OVERVIEW

This document contains device specific information for the operation of the
PIC16F84A device. Additional information may be found in the PICmicro™ Mid-
Range Reference Manual, (DS33023), which may be downloaded from the Microchip
website. The Reference Manual should be considered a complementary document to
this data sheet, and is highly recommended reading for a better understanding of the
device architecture and operation of the peripheral modules. The PIC16F84A belongs
to the mid-range family of the PICmicro® microcontroller devices. A block diagram
of the device is shown in Figure.

Fig7: PIC 16F84 block diagram

14
The program memory contains 1K words, which translates to 1024 instructions, since
each 14-bit program memory word is the same width as each device instruction. The
data memory (RAM) contains 68 bytes. Data EEPROM is 64 bytes. There are also 13
I/O pins that are user-configured on a pin-to-pin basis. Some pins are multiplexed
with other device functions. These functions include:
• External interrupt
• Change on PORTB interrupt
• Timer0 clock input

Table details the pinout of the device with descriptions


and details for each pin.

Table 1 : the pins of the PIC with descriptions and details for each pin.

15
3.3 MEMORY ORGANIZATION:

There are two memory blocks in the PIC16F84A. These are the program memory and
the data memory. Each block has its own bus, so that access to each block can occur
during the same oscillator cycle. The data memory can further be broken down into
the general purpose RAM and the Special Function Registers (SFRs). The operation
of the SFRs that control the “core” are described here. The SFRs used to control the
peripheral modules are described in the section discussing each individual peripheral
module. The data memory area also contains the data EEPROM memory. This
memory is not directly mapped into the data memory, but is indirectly mapped. That
is, an indirect address pointer specifies the address of the data EEPROM memory to
read/write. The 64 bytes of data EEPROM memory have the address range 0h-3Fh.

Program Memory Organization


The PIC16FXX has a 13-bit program counter capable of addressing an 8K x 14
program memory space. For the PIC16F84A, the first 1K x 14 (0000h-03FFh) are
physically implemented (Figure 2-1). Accessing a location above the physically
implemented address will cause a wraparound. For example, for locations 20h, 420h,
820h, C20h, 1020h, 1420h, 1820h, and 1C20h, the instruction will be the same. The
RESET vector is at 0000h and the interrupt vector is at 0004h.

Fig8: Program Memory

16
Data Memory Organization

The data memory is partitioned into two areas. The first is the Special Function
Registers (SFR) area, while the second is the General Purpose Registers (GPR) area.
The SFRs control the operation of the device. Portions of data memory are banked.
This is for both the SFR area and the GPR area. The GPR area is banked to allow
greater than 116 bytes of general purpose RAM. The banked areas of the SFR are for
the registers that control the peripheral functions. Banking requires the use of control
bits for bank selection. These control bits are located in the STATUS Register.

Fig9: Register file map

17
Instructions MOVWF and MOVF can move values from the W register to any
location in the register file (“F”), and vice-versa. The entire data memory can be
accessed either directly using the absolute address of each register file or indirectly
through the File Select Register (FSR).
Data memory is partitioned into two banks which contain the general purpose
registers and the special function registers. Bank 0 is selected by clearing the RP0 bit
(STATUS<5>). Setting the RP0 bit selects Bank 1. Each Bank extends up to 7Fh (128
bytes). The first twelve locations of each Bank are reserved for the Special Function
Registers. The remainder are General Purpose Registers, implemented as static RAM.

3.4 GENERAL PURPOSE REGISTER FILE:

Each General Purpose Register (GPR) is 8-bits wide and is accessed either directly
or indirectly through the FSR. The GPR addresses in Bank 1 are mapped to addresses
in Bank 0. As an example, addressing location 0Ch or 8Ch will access the same GPR.

Special Function Registers


The Special Function Registers (Figure 2-2 and Table 2-1) are used by the CPU and
Peripheral functions to control the device operation. These registers are static RAM.
The special function registers can be classified into two sets, core and peripheral.
Those associated with the core functions are described in this section. Those related to
the operation of the peripheral features are described in the section for that specific
feature

18
Table2 : special function register file

DATA EEPROM MEMORY


The EEPROM data memory is readable and writable during normal operation (full
VDD range). This memory is not directly mapped in the register file space. Instead it
is indirectly addressed through the Special Function Registers. There are four SFRs
used to read and write this memory. These registers are:
• EECON1
• EECON2 (not a physically implemented register)
• EEDATA
• EEADR
EEDATA holds the 8-bit data for read/write, and EEADR holds the address of the
EEPROM location being accessed. PIC16F84A devices have 64 bytes of data
EEPROM with an address range from 0h to 3Fh. The EEPROM data memory allows

19
byte read and writes. A byte write automatically erases the location and writes the
new data (erase before write). The EEPROM data memory is rated for high
erase/write cycles. The write time is controlled by an on-chip timer. The write time
will vary with voltage and temperature as well as from chip to chip. Please refer to
AC specifications for exact limits. When the device is code protected, the CPU may
continue to read and write the data EEPROM memory. The device programmer can
no longer access this memory.

Fig10 : EECON1 register

Reading the EEPROM Data Memory

To read a data memory location, the user must write the address to the EEADR register and then set
control bit RD (EECON1<0>). The data is available, in the very next cycle, in the EEDATA register;
therefore, it can be read in the next instruction. EEDATA will hold this value until another read or until it
is written to by the user (during a write operation).

Fig11 : Example data EEPROM READ

20
Memory

To write an EEPROM data location, the user must first write the address to the EEADR register and the
data to the EEDATA register. Then the user must follow a specific sequence to initiate the write for each
byte.

The write will not initiate if the above sequence is not exactly followed (write 55h to EECON2, write AAh
to EECON2, then set WR bit) for each byte. We strongly recommend that interrupts be disabled during
this code segment.

Fig 12: data EEPROM write

TABLE 3: Registers/bits associated with data EEPROM

3.5 I/O PORTS

Some pins for these I/O ports are multiplexed with an alternate function for the
peripheral features on the device. In general, when a peripheral is enabled, that pin
may not be used as a general purpose I/O pin.

PORTA and TRISA Registers

PORTA is a 5-bit wide, bi-directional port. The corresponding data direction register
is TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an
input (i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a

21
TRISA bit (= 0) will make the corresponding PORTA pin an output (i.e., put the
contents of the output latch on the selected pin).
Reading the PORTA register reads the status of the pins, whereas writing to it will
write to the port latch. All write operations are read-modify-write operations.
Therefore, a write to a port implies that the port pins are read. This value is modified
and then written to the port data latch. Pin RA4 is multiplexed with the Timer0
module clock input to become the RA4/T0CKI pin. The RA4/T0CKI pin is a Schmitt
Trigger input and an open drain output. All other RA port pins have TTL input levels
and full CMOS output drivers.

Fig 13: Block diagram of pins RA3:RA0 and RA4

Table 4: Port A functions

Table 5: Registers associated with Port A

22
PORTB and TRISB Registers

PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register
is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input
(i.e., put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISB
bit (= 0) will make the corresponding PORTB pin an output (i.e., put the contents of
the output latch on the selected pin).
Each of the PORTB pins has a weak internal pull-up. A single control bit can turn on
all the pull-ups. This is performed by clearing bit RBPU (OPTION<7>). The weak
pull-up is automatically turned off when the port pin is configured as an output. The
pull-ups are disabled on a Power-on Reset. Four of PORTB’s pins, RB7:RB4, have an
interrupt-on change feature. Only pins configured as inputs can cause this interrupt to
occur (i.e., any RB7:RB4 pin configured as an output is excluded from the
interruption- change comparison). The input pins (of RB7:RB4) are compared with
the old value latched on the last read of PORTB. The “mismatch” outputs of
RB7:RB4 are OR’ed together to generate the RB Port Change Interrupt with flag bit
RBIF (INTCON<0>). This interrupt can wake the device from SLEEP. The user, in
the Interrupt Service Routine, can clear the interrupt in the following manner:
a) Any read or write of PORTB. This will end the mismatch condition.
b) Clear flag bit RBIF.
A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end
the mismatch condition and allow flag bit RBIF to be cleared. The interrupt-on-
change feature is recommended for wake-up on key depression operation and
operations where PORTB is only used for the interrupt-on-change feature. Polling of
PORTB is not recommended while using the interrupt-on-change feature.

23
Fig 14: Pin diagram of RB3:RB0 Pin diagram of RB7:RB4

TABLE 6: Port B functions and Registers associated with it.

24
3.6 RESET:

The PIC16F84A differentiates between various kinds of RESET:


• Power-on Reset (POR)
• MCLR during normal operation
• MCLR during SLEEP
• WDT Reset (during normal operation)
• WDT Wake-up (during SLEEP)

Figure shows a simplified block diagram of the On-Chip RESET Circuit.

The MCLR Reset path has a noise filter to ignore small pulses. The electrical
specifications state the pulse width requirements for the MCLR pin. Some registers
are not affected in any RESET condition; their status is unknown on a POR and
unchanged in any other RESET. Most other registers are reset to a “RESET state” on
POR, MCLR or WDT Reset during normal operation and on MCLR during SLEEP.
They are not affected by a WDT Reset during SLEEP, since this RESET is viewed as
the resumption of normal operation.

Table gives a description of RESET conditions for the program counter (PC) and the
STATUS register.
Table gives a full description of RESET states for all registers. The TO and PD bits
are set or cleared differently in different RESET situations (Section 6.7). These bits
are used in software to determine the nature of the RESET.

25
SIMPLIFIED BLOCK DIAGRAM OF ON-CHIP RESET CIRCUIT:

Fig 15: Simplified block diagram of on chip reset circuit

RESET CONDITION FOR PROGRAM COUNTER AND THE STATUS REGISTER:

Table 6: Reset conditions for PC and status register

26
RESET CONDITIONS FOR ALL REGISTERS

Table 7: reset condition for all registers

27
CHAPTER 4. SENSORS,AMPLIFIERS,LCD

28
4.1 Ultrasonic sensor:
The ultrasonic sensor for the air is made by Nippon Ceramic Company. This
sensor separates into the two kinds for the transmitter and the receiver. For the
transmitter, it is T40-16 and for the receiver, it is R40-16. T shows the thing for the
transmitter and R shows the thing for the receiver. 40 show the resonant frequency of
the ultrasonic. (40 kHz) 16 shows the diameter of the sensor. The one of the terminal
is connected with the case, when grounding; the terminal on the side of the case
should be used. More information please refers Data sheet 0f ULTRASONIC
SENSOR.

Fig 16: ultrasonic sensor made by Nippon Ceramic Company

Compared to the five senses of human, ultrasonic sensor is the role of "ear".When
driven from an alternating voltage source of suitable frequency, piezoelectric ceramic
mechanically distorts in its shape to the applied voltage generating a sound field.
Conversely an ceramic subjected to such a sound field will generate a voltage
proportional to its intensity. This is piezoelectric phenomenon.Air transmission
ultrasonic sensor implementing piezoelectric ceramic elements radiates or receives
ultrasonic sound in the air.It covers wide applications in measurement and
communications.We can offer a wide range of standard products or can provide
optimized solutions to your specific requirements.

29
4.2 Low power operational amplifiers (LM358):

This IC is the single power supply-type operational amplifier. This IC is used for the
detection of the received signal. The comparator can be used. The LM358 consists of
two independent, high gain, internally frequency compensated operational amplifiers
which were designed specifically to operate from a single power supply over a wide
range of voltages. Operation from split power supplies is also possible and the low
power supply current drain is independent of the magnitude of the power supply
voltage. Application areas include transducer amplifiers, dc gain blocks and all the
conventional op amp circuits, which now can be more easily implemented in single
power supply systems. More information please refers Data sheet 0f LM358.

Fig 17 : Low power operational amplifier.

30
4.3 16 CHARACTER LCD DISPLAY (HD 44780):

The dot-matrix liquid crystal display controller and driver LSI displays
alphanumeric, Japanese kana characters, and symbols. It can be configured to
drive a dot-matrix liquid crystal display under the control of a 4 or 8-bit
microprocessor. Since all the functions such as display RAM, character
generator, and liquid crystal driver, required for driving a dot-matrix liquid
crystal display are internally provided on one chip, a minimal system can be
interfaced with this controller/driver. A single HD44780U can display up to
one 8-character line or two 8-character lines.

Fig 18: LCD display

The HD44780U dot-matrix liquid crystal display controller and driver


LSI displays alpha numerics, Japanese kana characters, and
symbols. It can be configured to drive a dot-matrix liquid crystal
display under the control of a 4- or 8-bit microprocessor. Since all
the functions such as display RAM, character generator, and liquid
crystal driver, required for driving a dot-matrix liquid crystal display
are internally provided on one chip, a minimal system can be
interfaced with this controller/driver. A single HD44780U can display
up to one 8-character line or two 8-character lines. The HD44780U

31
has pin function compatibility with the HD44780S which allows the
user to easily replace an LCD-II with an HD44780U. The HD44780U
character generator ROM is extended to generate 208 5 X 8 dot
character fonts and 32 5 X 10 dot character fonts for a total of 240
different character fonts. The low power supply (2.7V to 5.5V) of the
HD44780U is suitable for any portable battery-driven product
requiring low power dissipation.

The most commonly used Character based LCDs are based on


Hitachi's HD44780 controller or other which are compatible with
HD44580. In this tutorial, we will discuss about character based
LCDs, their interfacing with various microcontrollers, various
interfaces (8-bit/4-bit), programming, special stuff and tricks you
can do with these simple looking LCDs which can give a new look to
your application.

4.3.1 Pin Description


The most commonly used LCDs found in the market today are 1
Line, 2 Line or 4 Line LCDs which have only 1 controller and support
at most of 80 charachers, whereas LCDs supporting more than 80
characters make use of 2 HD44780 controllers.

Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller
has 16 Pins (two pins are extra in both for back-light LED
connections). Pin description is shown in the table below.

32
Pin no. 1 VSS Power supply (GND)
Pin no. 2 VCC Power supply (+5V)
Pin no. 3 VEE Contrast adjust
0 = Instruction input
Pin no. 4 RS
1 = Data input
0 = Write to LCD module
Pin no. 5 R/W
1 = Read from LCD module
Pin no. 6 EN Enable signal
Pin no. 7 D0 Data bus line 0 (LSB)
Pin no. 8 D1 Data bus line 1
Pin no. 9 D2 Data bus line 2
Pin no. 10 D3 Data bus line 3
Pin no. 11 D4 Data bus line 4
Pin no. 12 D5 Data bus line 5
Pin no. 13 D6 Data bus line 6
Pin no. 14 D7 Data bus line 7 (MSB)

Table 9: Character LCD pins

33
4.3.2Sending Commands to LCD:
To send commands we simply need to select the command register. Everything is
same as we have done in the initialization routine. But we will summarize the
common steps and put them in a single subroutine. Following are the steps:

• Move data to LCD port


• select command register
• select write operation
• send enable signal
• wait for LCD to process the command

CODE:
void LCD_command(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 0; //Selected command register
LCD_rw = 0; //We are writing in instruction register
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
// Using the above function is really simple
// var will carry the command for LCD
// e.g.
//
// LCD_command(0x01);

Sending Data to LCD

To send data we simply need to select the data register. Everything is same as the
command routine. Following are the steps:

• Move data to LCD port


• select data register
• select write operation
• send enable signal
• wait for LCD to process the data

34
Keeping these steps in mind we can write LCD command routine as.

CODE:
void LCD_senddata(unsigned char var)
{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 1; //Selected data register
LCD_rw = 0; //We are writing
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
// Using the above function is really simple
// we will pass the character to display as argument to function
// e.g.
//
// LCD_senddata('A');

35
CHAPTER 5. BLOCK DIAGRAM,OPERATION

36
5.1 BLOCK DIAGRAM OF PROJECT:

Fig19 : Block diagram of the project

37
5.2 SCHEMATIC DIAGRAM:

Fig 20:Schematic diagram

38
5.3 Operation of the kit:

LCD Interface:

The LCD is driven by the PIC via a 4bit interface. Pins RB0-RB3 on the PIC
connects to the 4bit mode data pins on the display. The Enable and RS pins on the
display are connected to RB4 and RB5 on the PIC. The contrast is connected to a 47-
kOhm potentiometer that is connected between VCC and GND. This adjusted to set
the correct display contrast. Power and ground is also connected directly to the
display device. On power up the PIC initializes the display and sets it for 4bit
operation. A welcome message is then displayed. After a measurement is made or the
mask value is changed display code routines are called to print these response
messages on the display.

Transmitter Circuit:
The 40kHz transmitter is connecting directly to pins RA0 and RA1 on the
PIC. The PIC oscillates at a frequency of 40kHz between high and low on RA0 and
low and high on RA1. This produces a 40kHz square wave with a peak to peak
voltage of about 10 volts. This signal is transmitted for approximately 130us per
measurement.

Receiver Circuit:
A 40kHz receiver is connected between ground and the input of one half of a
LM358 op-amp (single source dual op-amp). The signal from the receiver goes
through three stages of amplification. The first two stages amplify the signal 100
times, effectively providing 10,000 times amplification. The third stage of
amplification is an adjustable gain amplifier. The input resistance is a variable resistor
that ranges between 1-kOhm and 47-kOhm. The feedback resistor is a 50-kOhm
resistor. This provides an additional amplification between 1 and 50 times. The final
output from the amplifier circuit is connected directly to the base of the NPN
switching transistor. Also connected to the base of the switching transistor is a voltage
offset provided by a 10-kOhm potentiometer connected between VCC and GND. This

39
provides the extra push that the signal needs to reach the switching region of the
transistor. The signal provides spikes that add to the offset voltage and switch the
transistor into the on state.
The collector of the NPN transistor is connected directly to ground and the
emitter is connected to a 10-kOhm resistor that is in turn connected to VCC.
Also connected to the emitter is the RB7 pin on the PIC. When the transistor is in the
off state the voltage at the emitter is just slightly below VCC. When the transistor is in
ON-state, the voltage at the emitter drops to ground or very near. It is this transition
that triggers the interrupt flag within the PIC. This interrupt flag is read to determine
if the return signal has been received yet.

Fig21: Receiver section

Distance Calculation:

A measurement is initiated via the send button. When first depressed the
40kHz pulse is sent out through the transmitter. After the PIC has completed the
transmission pulse the receiver stage is entered. The receiver stage waits a certain
amount of time before checking for signal reception. The receiver stage of the code
waits for a specified amount of time based on the mask value. This wait period is to
insure that the receiver does not register the transmission signal as the return signal
and also to ignore the return signal bounced back from small obstructions that are

40
between the device and the object that a measurement is being made to. If the mask is
set to zero then the minimum default wait period is performed. This period of time is
the time it takes for the transmitted signal to travel 1 ft and to return. Given the speed
of sound, 1125 ft/s, and an actual distance of 2 ft this wait time is approximately
1.8ms. If the mask is greater than 0 then the wait period is the time that it takes for
sound to travel 2 meters times the mask. This serves to make the mask value the
approximate distance in meters below which a return signal will be ignored. This time
period is approximately 5.8ms.
After the wait period has elapsed the PIC clears any interrupt flags and begins
looking for an interrupt triggered by the reception of the signal. The PIC goes through
a loop checking for the return signal and if it is not detected then a counter is
incremented. This loop is repeated until either the counter is full or the signal is
received. If the counter becomes full then the value of 0 meters is displayed.
Otherwise the calculation phase is entered.
After the signal is received the calculation phase is entered. Each counter
value of 562 equates to 1 meter. The distance waited based on the mask value and the
distance calculated from the counter value are added together. The feet and inch
distance is then calculated from the distance in meters. The two values are then
displayed on the LCD

General Operating Procedures:

The power switch is first turned on and the display will read “PRESS SEND KEY”.
The send key is the red button. Pressing this button will cause the device to take a
measurement. As long as the send key is depressed the device will continue to take
successive measurements. The measurement in meters and feet/inches are given on
the display. To measure the distance to a far object point the end of the device with
the round, silver transceivers at the object. Press the send key and the distance will be
measured. The black button controls the mask. The value of the mask is shown at the
bottom right hand corner of the display. Pressing the mask button will cause this value
to cycle from 0 to 4. The value is the number of meters below which the device will
not listen for an echo. This is used if there is some obstruction in the way and you
wish to measure to an object past the obstruction.

41
10. ASSEMBLY LANGUAGE CODE:

INDF: .EQU $00


OPTION: .EQU $01
PCL: .EQU $02
STATUS: .EQU $03
FSR: .EQU $04
PORTA: .EQU $05
TRISA: .EQU $05
PORTB: .EQU $06
TRISB: .EQU $06
EEDATA: .EQU $08
EECON1: .EQU $08
EEADR: .EQU $09
EECON2: .EQU $09
INTCON: .EQU $0B

MISC1: .EQU $0C ;misc use


MISC2: .EQU $0D ;misc use
COUNT0: .EQU $0E ;counter 0
COUNT1: .EQU $0F ;counter 1
RECORD0: .EQU $10 ;recording store LSB
RECORD1: .EQU $11 ;recording store MSB
FEET1: .EQU $12 ;feet byte 1 LSB
FEET2: .EQU $13 ;feet byte 2 MSB
ANSA1: .EQU $14 ;answer byte 1 LSB
ANSA2: .EQU $15 ;answer byte 2 MSB
ANSA3: .EQU $16 ;answer byte 3 MSB
ANSA4: .EQU $17 ;answer byte 4 LSB
ANSA5: .EQU $18 ;answer byte 5 MSB
ANSA6: .EQU $19 ;answer byte 6 MSB

42
TOP0: .EQU $1A ;top of division byte 1LSB
TOP1: .EQU $1B ;top of division byte 2NSB
TOP2: .EQU $1C ;top of division byte 3MSB
DIV1: .EQU $1D ;divider byte 1 LSB
DIV2: .EQU $1E ;divider byte 2 MSB
LOOPB: .EQU $1F ;loop counter B
STORE1: .EQU $20 ;general store 1
STORE2: .EQU $21 ;general store 2
LOOPA: .EQU $22 ;loop counter A - for LCD
;only
RSLINE: .EQU $23 ;bit 4 = RS line flag for
;LCD
CLKCNT: .EQU $24 ;pre-counter for CLOCK
METRE0: .EQU $25 ;metres byte 1 LSB
METRE1: .EQU $26 ;metres byte 2 NSB
METRE2: .EQU $27 ;metres byte 3 MSB
INCH1: .EQU $28 ;inches byte 1 LSB
INCH2: .EQU $29 ;inches byte 2 MSB
MASK: .EQU $2A ;foreground mask value (1
;per metre)
ZERO: .EQU $2B ;zero count flag
LOOPW: .EQU $2C ;eeprom write counter
LOOPR: .EQU $2D ;eeprom read counter
SAVE: .EQU $2E ;SAVE flag

W: .EQU 0
F: .EQU 1
C: .EQU 0
DC: .EQU 1
Z: .EQU 2
GIE: .EQU 7 ;global interrupt bit
RBIF: .EQU 0 ;RB4-RB7 change interrupt
;flag

43
WR: .EQU 1 ;eeprom write initiate
;flag
WREN: .EQU 2 ;eeprom write enable flag
RD: .EQU 0 ;eeprom read enable flag

.ORG $0004
goto START
.ORG $0005

START: clrf PORTA


movlw %01000000
movwf PORTB
PAGE1
movlw %00011100
movwf TRISA ;Port A0-A1 as output, A2-
;A4 as input
movlw %11000000
movwf TRISB ;Port B0-B5 as output, B6-
;B7 as input
movlw %00000101 ;set timer ratio 1:64
movwf OPTION ;pull-ups on (bit 7 = 0)
PAGE0

CLRINT: bcf INTCON,GIE ;disable all interrupts


btfsc INTCON,GIE ;are all interrupts
;disabled?
goto CLRINT ;no, try again

CLRALL: movlw $0C ;clear registers


movwf FSR
CLRA2: clrf INDF
incf FSR,F
btfss FSR,4
goto CLRA2

44
btfss FSR,5
goto CLRA2
goto SETUP

TABLCD: ADDWF PCL,F ;LCD initialisation table


RETLW %00110011 ;initialise lcd – first
;byte
RETLW %00110011 ;2nd byte (repeat of
;first)
RETLW %00110010 ;set for 4-bit operation
RETLW %00101100 ;set for 2 lines
RETLW %00000110 ;set entry mode increment
;each address
RETLW %00001100 ;set display on, cursor
;off, blink off
RETLW %00000001 ;clear display
RETLW %00000010 ;return home, cursor & RAM
;to zero
;end initialisation table

TBDEC1: ADDWF PCL,F ;table for decimalisation


;lsb
retlw $0A ;lsb of 10
retlw $64 ;lsb of 100
retlw $E8 ;lsb of 1000
retlw $10 ;lsb of 10000

TBDEC2: ADDWF PCL,F ;table for decimalisation


;msb
retlw 0 ;msb of 10
retlw 0 ;msb of 100
retlw $03 ;msb of 1000
retlw $27 ;msb of 10000

45
MESSAG1: addwf PCL,F
retlw 'K'
retlw 'I'
retlw 'T'
retlw ' '
retlw 'B'
retlw 'Y'
retlw ''
retlw 'A '
retlw 'T'
retlw 'U'
retlw 'L'
retlw 'S'
retlw 'A '
retlw 'V'
retlw 'L'
retlw 'A'

MESSAG2: addwf PCL,F


retlw 'P'
retlw 'R'
retlw 'E'
retlw 'S'
retlw 'S'
retlw ' '
retlw 'S'
retlw 'E'
retlw 'N'
retlw 'D'
retlw ' '
retlw 'K'
retlw 'E'
retlw 'Y'
retlw ' '

46
retlw ' '

SETUP: call PAUSIT ;delay

clrf LOOPB ;clr LCD set-up loop


LCDSET: movf LOOPB,W ;get table address
call TABLCD ;get set-up instruction
call LCDLIN ;perform it
incf LOOPB,F ;inc loop
btfss LOOPB,3 ;has last LCD set-up
instruction now been done?
goto LCDSET ;no
call PAUSIT ;delay

clrf LOOPB
call LCD1
TITLE1: movf LOOPB,W ;get table address
call MESSAG1 ;get set-up instruction
call LCDOUT ;perform it
incf LOOPB,F ;inc loop
btfss LOOPB,4
goto TITLE1

clrf LOOPB
call LCD21
TITLE2: movf LOOPB,W ;get table address
call MESSAG2 ;get set-up instruction
call LCDOUT ;perform it
incf LOOPB,F ;inc loop
btfss LOOPB,4
goto TITLE2

btfsc PORTA,3 ;is STORE switch on RA3


;pressed?

47
call CLRPRM ;yes, so clear EEPROM

INTRPT: btfsc PORTA,2 ;is SEND switch on RA2


;pressed?
call TXIT ;yes
btfsc PORTA,3 ;is STORE switch on RA3
;pressed?
call STOREIT ;yes
btfsc PORTA,4 ;is MASK switch on RA4
;pressed?
call MASKIT ;yes
btfss PORTB,6 ;is RECALL switch on RB6
pressed?
call RECALL ;yes
goto INTRPT

TXIT: movlw 10
movwf LOOPB ;set transmission loop to
;10
clrf COUNT0 ;clear counters
clrf COUNT1
bsf PORTA,0
bsf SAVE,0

BEAMIT: nop ;send 40kHz signal


nop ;command qty sets
;freq/mark-space
nop
nop
nop
nop
nop
nop
comf PORTA,F ;toggle push-pull RA0/RA1

48
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
comf PORTA,F ;toggle push-pull RA0/RA1
decfsz LOOPB,F
goto BEAMIT
clrf PORTA
call RECEIVE

call LCD9
movlw ' '
call LCDOUT
movlw ' '
call LCDOUT
movlw ' '
call LCDOUT
movlw 'L'
call LCDOUT
movlw 'I'
call LCDOUT
movlw 'V'
call LCDOUT
movlw 'E'
call LCDOUT

49
call PAUSIT ;pause
call PAUSIT
return

RECEIVE: movf MASK,W


btfsc STATUS,Z
goto MASK0
movf MASK,W
movwf LOOPB

MASK1: movlw 2 ;masking delays


movwf ANSA2
movlw 48
movwf ANSA1

MASK2: movlw 4
movwf ANSA3
MASK3: decfsz ANSA3,F
goto MASK3

decfsz ANSA1,F
goto MASK2
decfsz ANSA2,F
goto MASK2
decfsz LOOPB,F
goto MASK1

MASK0: bcf INTCON,RBIF ;clear RB4-RB7 interrupt


;change flag
bcf ZERO,0
LISTEN: btfsc INTCON,RBIF ;has echo been heard? (int
;change on RB7)
goto SHWCNT ;yes
movlw 1 ;no, so inc COUNT0

50
addwf COUNT0,F
movf STATUS,W
andlw 1
addwf COUNT1,F ;add Carry to COUNT1
btfss STATUS,C ;is there a Carry?
goto LISTEN ;no
bsf ZERO,0
goto METRES

SHWCNT: movlw 30 ;add equivalent count for


;transmission time
addwf COUNT0,F
btfsc STATUS,C
incf COUNT1,F
movf MASK,W
btfsc STATUS,Z
goto METRES

movwf LOOPB ;add 490 to count for each


;MASK value
MASKAD: movlw 234 ;(= LSB 234, MSB 1)
addwf COUNT0,F
btfsc STATUS,C
incf COUNT1,F
incf COUNT1,F
decfsz LOOPB,F
goto MASKAD

METRES: movf COUNT0,W


movwf RECORD0
movf COUNT1,W
movwf RECORD1

call GETMMS ;calculate millimetres

51
call LCD1 ;show metres on line 1
;part 1
movlw METRE1
call DECIMAL ;decimalise metres
movf ANSA5,W
movwf ANSA6
movf ANSA4,W
movwf ANSA5
movlw '.'
movwf ANSA4
movlw 6
movwf LOOPB
movlw ANSA6
movwf FSR

movf ANSA6,W
xorlw 48
btfss STATUS,Z
goto SHOWMT
movlw ' ' ;blank leading zero
movwf ANSA6

SHOWMT: call SHOWDEC


movlw 'm'
call LCDOUT
movlw 't'
call LCDOUT
movlw ' '
call LCDOUT

call GETINS ;calculate feet & inches


call GETFEET
call INVERT ;correct for final inches
movf TOP1,W

52
bcf STATUS,C
btfss ZERO,0 ;is ZERO set?
addlw 12 ;no
movwf INCH1
movf STATUS,W
andlw 1
addwf TOP2,W
movwf INCH2
movf INCH1,W
xorlw 12
btfss STATUS,Z
goto SHOWFT
clrf INCH1
clrf INCH2
incfsz FEET1,F
goto SHOWFT
incf FEET2,F

SHOWFT: call LCD21


movlw FEET1
call DECIMAL ;decimalise feet
movlw 3
movwf LOOPB
movlw ANSA3
movwf FSR

movf ANSA3,W
xorlw 48
btfss STATUS,Z
goto SHWFT2
movlw ' ' ;blank leading zero
movwf ANSA3
movf ANSA2,W
xorlw 48

53
btfss STATUS,Z
goto SHWFT2
movlw ' ' ;blank leading zero
movwf ANSA2

SHWFT2: call SHOWDEC


movlw 'f'
call LCDOUT
movlw 't'
call LCDOUT

SHOWIN: movlw INCH1


call DECIMAL ;show remaining inches
movlw 2
movwf LOOPB
movlw ANSA2
movwf FSR

movf ANSA2,W
xorlw 48
btfss STATUS,Z
goto SHOWIN2
movlw ' ' ;blank leading zero
movwf ANSA2

SHOWIN2: call SHOWDEC


movlw 'i'
call LCDOUT
movlw 'n'
call LCDOUT
movlw ' '
call LCDOUT
call SHOWSW
return

54
GETMMS: clrf METRE0 ;muliply x 1.78 (MSB 1,
;LSB 200)
movf COUNT0,W ;(a count of 562 = 1
;metre)
movwf METRE1 ;(1000/562 = 1.77935943)
movf COUNT1,W
movwf METRE2

movf COUNT0,W
btfsc STATUS,Z
goto GETCM2
movwf LOOPB
GETCM1: movlw 200
addwf METRE0,F
movf STATUS,W
andlw 1
addwf METRE1,F
movf STATUS,W
andlw 1
addwf METRE2,F
decfsz LOOPB,F
goto GETCM1

GETCM2: movf COUNT1,W


btfsc STATUS,Z
return
movwf LOOPB
GETCM3: movlw 200
addwf METRE1,F
movf STATUS,W
andlw 1
addwf METRE2,F
decfsz LOOPB,F

55
goto GETCM3
return

GETINS: movlw 25 ;divide by 25.4 for inches


;measurement
movwf DIV2 ;set divider msb for 25
movlw 102 ;set lsb for 102 (= 0.4
;decimal as binary)
movwf DIV1
movf METRE1,W
movwf STORE1
movf METRE2,W
movwf STORE2

call DIVIDE
movf ANSA1,W
movwf INCH1
movf ANSA2,W
movwf INCH2
return

GETFEET: movlw 12 ;divide by 12.0 for feet


;measurement
movwf DIV2 ;set divider msb for 12
movlw 0 ;set lsb for 0
movwf DIV1
movf INCH1,W
movwf STORE1
movf INCH2,W
movwf STORE2
call DIVIDE
movf ANSA1,W
movwf FEET1
movf ANSA2,W

56
movwf FEET2
return

DIVIDE: movf STORE1,W


movwf TOP1
movf STORE2,W
movwf TOP2
clrf TOP0

clrf ANSA1
clrf ANSA2
movf TOP1,W ;is TOP = zero?
iorwf TOP2,W
btfsc STATUS,Z
goto DIVIDE3 ;yes
call INVERT ;invert TOP for adding
;instead of subtraction

DIVIDE2: movf DIV1,W ;add lsb of DIV to lsb of


;TOP
addwf TOP0,F
movlw 1
andwf STATUS,C ;add carry flag to msb of
;TOP
addwf TOP1,F
movlw 1
andwf STATUS,C ;add carry flag to msb of
;TOP
addwf TOP2,F
btfsc STATUS,C ;is there a carry?
goto DIVIDE3 ;yes
movf DIV2,W ;no, add msb of DIV to msb
;of TOP
addwf TOP1,F

57
movlw 1
andwf STATUS,C ;add carry flag to msb of
;TOP
addwf TOP2,F
btfsc STATUS,C ;is there a carry?
goto DIVIDE3 ;yes
incfsz ANSA1,F ;no, inc counter lsb, is
;there a zero rollover?
goto DIVIDE2 ;no
incf ANSA2,F ;yes, inc counter msb
goto DIVIDE2
DIVIDE3: return

LCD210: movlw %11001010


goto LCDLIN
LCD28: movlw %11001000
goto LCDLIN
LCD21: movlw %11000000
goto LCDLIN
LCD11: movlw %10001011
goto LCDLIN
LCD9: movlw %10001001
goto LCDLIN
LCD8: movlw %10001000
goto LCDLIN
LCD1: movlw %10000000

LCDLIN: BCF RSLINE,4 ;clear RS flag - sets LCD


;command/line

LCDOUT: MOVWF STORE1 ;temp store data for LCD


MOVLW 20 ;set min time between
;sending full bytes to LCD
MOVWF LOOPA

58
DELAY: DECFSZ LOOPA,F
GOTO DELAY
CALL SENDIT ;send MSB
CALL SENDIT ;send LSB
BSF RSLINE,4 ;set RS flag (default is
;flag set)
return

SENDIT: SWAPF STORE1,F ;get and send data nibble


MOVF STORE1,W
ANDLW 15
IORWF RSLINE,W ;OR the RS bit
MOVWF PORTB ;output the byte
BSF PORTB,5 ;set E high
BCF PORTB,5 ;set E low
RETURN

PAUSIT: MOVLW 10 ;delay set


MOVWF CLKCNT
CLRF INTCON
PAUSE: BTFSS INTCON,2 ;has a timer time-out been
detected?
GOTO PAUSE ;no
BCF INTCON,2 ;yes
DECFSZ CLKCNT,F ;dec loop, is it zero?
GOTO PAUSE ;no
RETURN ;yes

DECIMAL: clrf ANSA1


clrf ANSA2
clrf ANSA3
clrf ANSA4
clrf ANSA5
movwf FSR

59
movf INDF,W ;check for zero value
incf FSR,F
iorwf INDF,W
btfsc STATUS,Z
goto DEC4

movf INDF,W ;copy value into TOP


movwf TOP2
decf FSR,F
movf INDF,W
movwf TOP1
movlw 4
movwf LOOPB
movlw ANSA5
movwf FSR

DECA1: clrf STORE2


decf LOOPB,W
call TBDEC1
movwf MISC1
decf LOOPB,W
call TBDEC2
movwf MISC2
call ADDIT
movwf INDF
decf FSR,F
decfsz LOOPB,F
goto DECA1
movf TOP1,W
movwf INDF

DECA2: addlw 6
btfss STATUS,DC

60
goto DEC4
clrf INDF
incf FSR,F
incf INDF,F
movf INDF,W
goto DECA2

ADDIT: call INVERT ;invert to allow adding


ADDIT2: incf STORE2,F
movf MISC1,W
addwf TOP1,F
movlw 1
andwf STATUS,W
addwf MISC2,W
addwf TOP2,F
btfss STATUS,C
goto ADDIT2

call INVERT ;invert to allow adding


movf MISC1,W ;subtract last addition
;value
addwf TOP1,F
btfsc STATUS,C
incf TOP2,F
movf MISC2,W
addwf TOP2,F
decf STORE2,W
return

DEC4: movlw 48
iorwf ANSA1,F
iorwf ANSA2,F
iorwf ANSA3,F
iorwf ANSA4,F

61
iorwf ANSA5,F
return

SHOWDEC: movf INDF,W


call LCDOUT
decf FSR,F
decfsz LOOPB,F
goto SHOWDEC
return

INVERT: comf TOP1,F


incf TOP1,F
btfsc STATUS,Z
decf TOP2,F
comf TOP2,F
return

MASKIT: incf MASK,F


movf MASK,W
xorlw 10
btfsc STATUS,Z
clrf MASK

SHOWSW: call LCD210


movlw 'M'
call LCDOUT
movlw 'a'
call LCDOUT
movlw 's'
call LCDOUT
movlw 'k'
call LCDOUT
movf MASK,W
btfsc STATUS,Z

62
goto SW2
movf MASK,W
iorlw 48
call LCDOUT
movlw 'm'
goto SW3
SW2: movlw ' '
call LCDOUT
movlw '0'
SW3: call LCDOUT
call PAUSIT
call PAUSIT
call PAUSIT
return

SHWCT4: btfss PORTB,6 ;is RECALL switch on RB6


;pressed?
goto SHWCT4 ;yes
call PAUSIT
return

STOREIT: btfss SAVE,0 ;is SAVE flag set?


return ;no
bcf SAVE,0
movf RECORD0,W
movwf STORE1
movf LOOPW,W
call SETPRM
movf RECORD1,W
movwf STORE1
incf LOOPW,F
movf LOOPW,W
call SETPRM
incf LOOPW,F

63
call LCD11 ;show record count on line
;1 cell 11
bcf STATUS,C
rrf LOOPW,W
movwf COUNT0
clrf COUNT1
movlw COUNT0
call DECIMAL
call BLANKS

call LCD9 ;show record count on line


;1 cell 9
movlw 'S'
call LCDOUT
movlw 'A'
call LCDOUT
movlw 'V'
call LCDOUT
movlw 'E'
call LCDOUT
movlw 'D'
call LCDOUT

WAITIT: btfsc PORTA,3 ;is STORE switch on RA3


;pressed?
goto WAITIT
call PAUSIT
return

CLRPRM: clrf LOOPA


clrf STORE1
CLRPR2: movf LOOPA,W
call SETPRM

64
incf LOOPA,F
btfss LOOPA,5
goto CLRPR2
CLRPR3: btfsc PORTA,3 ;is STORE switch on RA3
;pressed?
goto CLRPR3 ;yes, so wait
return

BLANKS: movlw 5
movwf LOOPB
movlw ANSA5
movwf FSR

movlw 4
movwf LOOPA
ZERO1: movf INDF,W ;blank leading zeros
xorlw 48
btfss STATUS,Z
goto SHWCT2
movlw 32
movwf INDF
decf FSR,F
decfsz LOOPA,F
goto ZERO1

SHWCT2: movlw ANSA5


movwf FSR
call SHOWDEC
return

;...............

;WRITE DATA TO EEPROM ROUTINE:

65
;This routine is entered with W holding
;the eeprom byte address at which data
;is to be stored. The data to be stored
;is held in STORE1.
SETPRM: movwf EEADR ;Now copy W into EEADR to set
;eeprom address
PAGE1
bsf EECON1,WREN ;enable write flag
PAGE0
movf STORE1,W ;get data value from STORE1 and
;hold in W
movwf EEDATA ;copy W into eeprom data byte
;register

return ;and return

;READ DATA FROM EEPROM ROUTINE:

;This routine is entered with W holding


;the eeprom byte address to be read.
PRMGET: movwf EEADR ;Now copy W into EEADR to set
;eeprom address
PAGE1 ;
BSF EECON1,RD ;enable read flag
PAGE0
movf EEDATA,W ;read eeprom data now in EEDATA
;into W
return ;and return

.END

66
6.2 APPLICATIONS:

1. Researchers have successfully used ultrasound to regenerate dental material

2. Ultrasound is used when characterizing particulates through the technique


of ultrasound attenuation spectroscopy or by observing electro acoustic
phenomena.

3. In rheology, an acoustic rheometer relies on the principle of ultrasound.


In fluid mechanics, fluid flow can be measured using an ultrasound flow
meter.

4. Ultrasound also plays a role in Sonic weaponry.

5. High and ultra high ultrasound waves are used in Acoustic microscopy

6. Audio can be propagated by modulated ultrasound.

7. Obstetric ultrasound is primarily used to:

8. Date the pregnancy (gestational age)


9. Confirm fetal viability
10. Determine location of fetus, intrauterine vs ectopic
11. Check the location of the placenta in relation to the cervix
12. Check for the number of fetuses (multiple pregnancy)
13. Check for major physical abnormalities.
14. Assess fetal growth (for evidence of intrauterine growth restriction (IUGR))
15. Check for fetal movement and heartbeat.
16. Determine the sex of the baby

67
6.3 CONCLUSION:

A common use of ultrasound is in range finding; this use is also called SONAR,
(sound navigation and ranging). This works similarly to RADAR(radio detection and
ranging): An ultrasonic pulse is generated in a particular direction. If there is an object
in the path of this pulse, part or all of the pulse will be reflected back to the
transmitter as an echo and can be detected through the receiver path. By measuring
the difference in time between the pulse being transmitted and the echo being
received, it is possible to determine how far away the object is.

The measured travel time of SONAR pulses in water is strongly dependent on the
temperature and the salinity of the water. Ultrasonic ranging is also applied for
measurement in air and for short distances. Such method is capable for easily and
rapidly measuring the layout of rooms.

Although range finding underwater is performed at both sub-audible and audible


frequencies for great distances (1 to several kilometers), ultrasonic range finding is
used when distances are shorter and the accuracy of the distance measurement is
desired to be finer. Ultrasonic measurements may be limited through barrier layers
with large salinity, temperature or vortex differentials. Ranging in water varies from
about hundreds to thousands of meters, but can be performed with centimeters to
meters accuracy.

68
BIBLIOGRAPHY & REFERENCES

Websites:
 www.microchip.com

TEXT BOOKS:

 The 8051 Micro controller and embedded systems by Mazidi.

 The 8051 Micro controller Architecture, programming &


Applications by Kenneth J.Ayala.

69
APPENDIX

ASCII CODES:

70

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