Академический Документы
Профессиональный Документы
Культура Документы
OVERVIEW
1
1.1 INTRODUCTION
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
230V AC
50Hz D.C
Output
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
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.
The DC level of an ordinary power supply changes due to the following reasons.
10
CHAPTER 3. PIC MICROCONTROLLER
11
3. PIC 16F84 MICROCONTROLLER
3.1 FEATURES:
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
13
- < 0.5 mA typical standby current @ 2V
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.
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 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.
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.
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.
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.
18
Table2 : special function register file
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.
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).
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.
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 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.
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
24
3.6 RESET:
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:
26
RESET CONDITIONS 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.
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.
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.
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.
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)
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:
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);
To send data we simply need to select the data register. Everything is same as the
command routine. Following are the steps:
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:
37
5.2 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.
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
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:
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
44
btfss FSR,5
goto CLRA2
goto SETUP
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'
46
retlw ' '
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
47
call CLRPRM ;yes, so clear EEPROM
TXIT: movlw 10
movwf LOOPB ;set transmission loop to
;10
clrf COUNT0 ;clear counters
clrf COUNT1
bsf PORTA,0
bsf SAVE,0
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
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
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
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
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
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
movf ANSA2,W
xorlw 48
btfss STATUS,Z
goto SHOWIN2
movlw ' ' ;blank leading zero
movwf ANSA2
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
55
goto GETCM3
return
call DIVIDE
movf ANSA1,W
movwf INCH1
movf ANSA2,W
movwf INCH2
return
56
movwf FEET2
return
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
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
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
59
movf INDF,W ;check for zero value
incf FSR,F
iorwf INDF,W
btfsc STATUS,Z
goto DEC4
DECA2: addlw 6
btfss STATUS,DC
60
goto DEC4
clrf INDF
incf FSR,F
incf INDF,F
movf INDF,W
goto DECA2
DEC4: movlw 48
iorwf ANSA1,F
iorwf ANSA2,F
iorwf ANSA3,F
iorwf ANSA4,F
61
iorwf ANSA5,F
return
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
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
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
;...............
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
.END
66
6.2 APPLICATIONS:
5. High and ultra high ultrasound waves are used in Acoustic microscopy
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.
68
BIBLIOGRAPHY & REFERENCES
Websites:
www.microchip.com
TEXT BOOKS:
69
APPENDIX
ASCII CODES:
70