You are on page 1of 31

Chapter 1 Introduction

1.1 Embedded system and its requirement An embedded system is a computer system with a dedicated function within a larger mechanical or electrical system, often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today. Embedded systems contain processing cores that are either microcontrollers or digital signal processors (DSP). Requirement of embedded system Easy to use Easy in repair Space efficient Power efficiency Reliable Time saving

Simple and cost efficient 1.2 555 timer

The 555 timer IC is an integrated circuit (chip) used in a variety of timer, pulse generation, and oscillator applications. The 555 can be used to provide time delays, as an oscillator, and as a flip-flop element. Derivatives provide up to four timing circuits in one package. Three types Astable(none of the state is stable) Bistable- bith the states are stable. Triggering force is needed at both the states. Monostable(input force needed to change state, no force needed to bring back to the original state)

1.3

Flip flop

A flip-flop or latch is a circuit that has two stable states and can be used to store state information. A flip-flop is a bistable multivibrator. The circuit can be made to change state by signals applied to one or more control inputs and will have one or two outputs. It is the basic
1

storage element in sequential logic. Flip-flops and latches are a fundamental building block of digital electronics systems used in computers, communications, and many other types of systems. 1.4 Digital clock

Two types1. Synchronous- the clock input is same 2. Asynchronous- the clock input is different

1.5

Counter a counter is a device which stores (and sometimes displays) the number of times a particular event or process has occurred, often in relationship to a clock signal. A counter is always edge triggered Two types of counter1. Positive edge triggered 2. Negative edge triggered

Examples of counters are decade counter and up-down counter. 1.6 1. 2. 3. 4. Classification of microcontroller BITS( 4,8,16,32) Memory(embedded, external) Instruction set(CISC, RISC) Architecture( Vann- Newmann, Harvard)

We have learned about the different Types of sensors 1. 2. 3. 4. 5. 6. IR sensor LDR sensor PIR sensor RF sensor Ultrasonic sensor Photo diode sensor

We also learned as how to generate Custom Character generation and also about to send the data in the lcd using 4 bit data and finally a project is made using all these concept. In the initial

classes we learned to make up down counter,decade counter, traffic light,keypad using logic gates. The concept about switch connecting to microcontroller is also made clear to us further the concept of voltage follower and op-amp is made clear to us.

Chapter 2 Company profile


Lovely Professional University (LPU) is a private semi-residential university created under the state government private university act. LPU claims to be the largest private university in India in terms of number of students on a single campus and is situated on 600+ acres of green area on NH-1 at the entry of Jalandhar city. The university has more than 25,000 students from 26 states and 16 countries. It is recognized by UGC under Section 2(f) of UGC Act 1956. The Lovely Faculty of Technology and Sciences was ranked #2 on the CSR-GHRDC Engineering Colleges Survey 2011. It was ranked #29 Lovely Professional University was declared as the Best ICT Enabled University of the Year by the Ministry of Communications and IT, Government of India This summer Lovely Professional University (LPU) has initiated a program called In House Summer Training in Embedded Systems . This program has helped a lot in educating us ,it helped in a way to get to know about the technology basically embedded science. The program initiated from very basic knowledge and on the last day of the training it proved to be a very successful technical program. The basic knowledge that were imparted to us includes : 2.1 Engineering Engineering is the application of scientific, economic, social, and practical knowledge in order to design, build, and maintain structures, machines, devices, systems, materials and processes. It may encompass using insights to conceive, model and scale an appropriate solution to a problem or objective. The discipline of engineering is extremely broad, and encompasses a range of more specialized fields of engineering, each with a more specific emphasis on particular areas of technology and types of application. 2.2 Engineer An engineer is a professional practitioner of engineering, concerned with applying scientific knowledge, mathematics, and ingenuity to develop solutions for technical problems. Engineers design materials, structures, and systems while considering the limitations imposed by practicality, regulation, safety, and cost. To use social, technical and self knowledge to maintain or invent a device for optimum solution. 2.3 Difference between electronics and electrical Electrical is transmitting or operated by electricity while Electronics are the science development and application of devices and systems involving the flow of electrons. Electronics deals with semiconductor while electrical deals with conductor.
4

2.4 SURFACE MOUNTING DEVICES Surface-mount technology (SMT) is a method for producing electronic circuits in which the components are mounted or placed directly onto the surface of printed circuit boards (PCBs). An electronic device so made is called a surface-mount device (SMD). 2.5 Embedded system An embedded system is a computer system with a dedicated function within a larger mechanical or electrical system, often with real-time computing constraints. It is embedded as part of a complete device often including hardware and mechanical parts. By contrast, a general-purpose computer, such as a personal computer (PC), is designed to be flexible and to meet a wide range of end-user needs. Embedded systems control many devices in common use today. Embedded systems contain processing cores that are either microcontrollers or digital signal processors (DSP). These are some of the part of that basic classes and finally on the last day we were done with our final project. The project that I chose is Digital Speedometer.

Chapter 3 Identification of the training / project


3.1 Digital speedometer : This instrument displays the speed of the vehicle.Speed of the vehicle can be measured using different technology ,it can be made possible by using IR SENSOR ,ULTRASONIC SENSOR,AND MODULES(ultrasonic sensor works on the speed of the sound while ir sensor works on the basis of line of sight) 3.2 Ultrasonic sensor -Ultrasonic ranging module HC - SR04 provides 2cm - 400cm noncontact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit. The basic principle of work: (1) Using IO trigger for at least 10us high level signal, (2) The Module automatically sends eight 40 kHz anddetect whether there is a pulse signal back. (3) IF the signal back, through high level , time of high output IO duration is the time from sending ultrasonic to returning. Test distance = (high level timevelocity of sound (340M/S) / 2, 3.3 Electric parameter -

Table 1 3.4 Timing diagram The Timing diagram is shown below. You only need to supply a short 10uS pulse to the trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range in proportion .We can calculate the range through the time interval between sending trigger signal and receiving echo signal. Formula: uS / 58 = centimeters or uS / 148 =inch; or: the range = high
6

level time * velocity (340M/S) / 2; we suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.

Figure 1 3.5 Attention:

The module is not suggested to connect directly toelectric, if connected electric, the GND terminal should be connected the module first, otherwise, it will affect the normal work of the plane requests as smooth as possible, otherwise ,it will affect the results of measuring.

3.6

Circuit diagram:

Figure 2

CHAPTER 4 IMPLEMENTATION DETAIL

A logic gate is an idealized or physical device implementing a Boolean function, that is, it performs a logical operation on one or more logical inputs, and produces a single logical output. Depending on the context, the term may refer to an ideal logic gate, one that has for instance zero rise time and unlimited fan-out, or it may refer to a non-ideal physical device . 4.1 Circuits using logic gates: The various circuits that are made using these logic gates,flip flops and 555 timer are: - Decade counter

Figure 3

- Digital clock

Figure 4 -Debouncing circuit

Figure 5 - PWM wave using 555 timer

10

Figure 6 -Half adder

Figure 7

11

- traffic light using logic gates

Figure 8 - Keypad using logic gates

-After logic gates basic circuit we jumped to learn the use of 8051 Microcontrollers.
12

4.2 Introduction to 8051 The basic description of 8051 : The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4 Kbytes of Flash Programmable and Erasable Read Only Memory (PEROM). The device is manufactured using Atmel's high density nonvolatile memory technology and is compatible with the industry standard MCS-51 instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides a highly flexible and cost effective solution to many embedded control applications. The AT89C51 provides the following standard features: 4 Kbytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16-bit timer/counters, five vector two-level interrupt architecture, a full duplex serial port, and on-chip oscillator and clock circuitry. In addition, the AT89C51 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Power down Mode saves the RAM contents but freezes the oscillator.

8051 microcontroller Pin Diagram

Figure 9
13

4.3 Pin Functions:-

ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. ALE is emitted at a constant rate of 1/6 of the oscillator frequency, for external timing or clocking purposes, even when there are no accesses to external memory. (However, one ALE pulse is skipped during each access to external Data Memory.) This pin is also the program pulse input (PROG) during EPROM programming.

PSEN: Program Store Enable is the read strobe to external Program Memory. When the device is executing out of external Program Memory, PSEN is activated twice each machine cycle (except that two PSEN activations are skipped during accesses to external Data Memory). PSEN is not activated when the device is executing out of internal Program Memory. EA/VPP: When EA is held high the CPU executes out of internal Program Memory (unless the Program Counter exceeds 0FFFH in the 80C51). Holding EA low forces the CPU to execute out of external memory regardless of the Program Counter value. In the 80C31, EA must be externally wired low. In the EPROM devices, this pin also receives the programming supply voltage (VPP) during EPROM programming. XTAL1: Input to the inverting oscillator amplifier. XTAL2: Output from the inverting oscillator amplifier. Port 0: Port 0 is an 8-bit open drain bidirectional port. As an open drain output port, it can sink eight LS TTL loads. Port 0 pins that have 1s written to them float, and in that state will function as high impedance inputs. Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Port 1 pins that have 1s written to them are pulled high by the internal pull-ups, and in that state can be used as inputs. As inputs, port 1 pins that are externally being pulled low will source current because of the internal pull-ups. Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. Port 2 emits the high-order address byte during accesses to external memory that use 16-bit addresses. In this application, it uses the strong internal pull-ups when emitting 1s. Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. It also serves the functions of various special features of the 80C51 Family VCC: Supply voltage VSS: Circuit ground potential

14

Port Structures and Operation: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: Port Pin Alternate Function:P3.0 RxD (serial input port) P3.1 TxD (serial output port) P3.2 INT0 (external interrupt) P3.3 INT1 (external interrupt) P3.4 T0 (Timer/Counter 0 external input) P3.5 T1 (Timer/Counter 1 external input) P3.6 WR (external Data Memory write strobe) P3.7 RD (external Data Memory read strobe) The alternate functions can only be activated if the corresponding bit latch in the port SFR contains a 1. Otherwise the port pin remains at 0.

4.4

Special Function Registers (SFRs):-

A Map of the on-chip memory area called the Special Function Register (SFR).In the SFRs 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 SFRs are described in the text that follows. Accumulator: ACC is the Accumulator register. The mnemonics for Accumulator-Specific instructions, however, refer to the Accumulator simply 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. Program Status Word:
15

The PSW register contains program status information as detailed in Figure.

4.5 Stack Pointer: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. 4.6 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. 4.7 Serial Data Buffer:The Serial Buffer is actually two separate registers, a transmit buffer and a receive buffer. When data is moved to SBUF, it goes to the transmit buffer and is held for serial transmission. (Moving a byte to SBUF is what initiates the transmission.) When data is moved from SBUF, it comes from the receive buffer. 4.8 Timer Registers Basic to 80C51:Register pairs (TH0, TL0), and (TH1, TL1) are the 16-bit Counting registers for Timer/Counters 0 and 1, respectively. 4.9 Control Register for the 80C51:Special Function Registers IP, IE, TMOD, TCON, SCON, and PCON contain control and status bits for the interrupt system, the Timer/Counters, and the serial port. They are described in later sections. 4.10 Basic Registers:A number of 8052 registers can be considered "basic." Very little can be done without them and a detailed explanation of each one is warranted to make sure the reader understands these registers before getting into more complicated areas of development.

4.11 The Accumulator:If you've worked with any other assembly language you will be familiar with the concept of an accumulator register. The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile

16

register the 8052 has due to the sheer number of instructions that make use of the accumulator. More than half of the 8052's 255 instructions manipulate or use the Accumulator in some way. For example, if you want to add the number 10 and 20, the resulting 30 will be stored in the Accumulator. Once you have a value in the Accumulator you may continue processing the value or you may store it in another register or in memory.

4.12 The Program Counter:The Program Counter (PC) is a 2-byte address that tells the 8052 where the next instruction to execute is found in memory. When the 8052 is initialized PC always starts at 0000h and is incremented each time an instruction is executed. It is important to note that PC isn't always incremented by one. Since some instructions are 2 or 3 bytes in length the PC will be incremented by 2 or 3 in these cases. The Program Counter is special in that there is no way to directly modify its value. That is to say, you can't do something like PC=2430h. On the other hand, if you execute LJMP 2430h you've effectively accomplished the same thing. It is also interesting to note that while you may change the value of PC (by executing a jump instruction, etc.) there is no way to read the value of PC. That is to say, there is no way to ask the 8052 "What address are you about to execute?" As it turns out, this is not completely true: There is one trick that may be used to determine the current value of PC. This trick will be covered in a later chapter.

4.13 The Data Pointer:The Data Pointer (DPTR) is the 8052s only user-accessible 16-bit (2-byte) register. The Accumulator, "R" registers, and "B" register are all 1-byte values. The PC just described is a 16bit value but isn't directly user-accessible as a working register. DPTR, as the name suggests, is used to point to data. It is used by a number of commands that allow the 8052 to access external memory. When the 8052 accesses external memory it accesses the memory at the address indicated by DPTR. While DPTR is most often used to point to data in external memory or code memory, many developers take advantage of the fact that it's the only true 16-bit register available. It is often used to store 2-byte values that have nothing to do with memory locations. 4.14 Addressing Modes:The addressing modes in the 80C51 instruction set are as follows: Direct Addressing:In direct addressing the operand is specified by an 8-bit address field in the instruction. Only internal Data RAM and SFRs can be directly addressed. Indirect Addressing:-

17

In indirect addressing the instruction specifies a register which contains the address of the operand. Both internal and external RAM can be indirectly addressed. The address register for 8bit addresses can be R0 or R1 of the selected bank, or the Stack Pointer. The address register for 16-bit addresses can only be the 16-bit data pointer register, DPTR. Register Instructions:The register banks, containing registers R0 through R7, can be accessed by certain instructions which carry a 3-bit register specification within the opcode of the instruction. Instructions that access the registers this way are code efficient, since this mode eliminates an address byte. When the instruction is executed, one of the eight registers in the selected bank is accessed. One of four banks is selected at execution time by the two bank select bits in the PSW. Register-Specific Instructions:Some instructions are specific to a certain register. For example, some instructions always operate on the Accumulator, or Data Pointer, etc., so no address byte is needed to point to it. The opcode itself does that. Instructions that refer to the Accumulator as A assemble as accumulator specific opcodes. Immediate Constants:The value of a constant can follow the opcode in Program Memory. For example, MOV A, #100 Loads the Accumulator with the decimal number 100. The same number could be specified in hex digits as 64H. Indexed Addressing:Only program Memory can be accessed with indexed addressing, and it can only be read. This addressing mode is intended for reading look-up tables in Program Memory A 16-bit base register (either DPTR or the Program Counter) points to the base of the table, and the Accumulator is set up with the table entry number. The address of the table entry in Program Memory is formed by adding the Accumulator data to the base pointer. Another type of indexed addressing is used in the case jump instruction. In this case the destination address of a jump instruction is computed as the sum of the base pointer and the Accumulator data. 4.15 Project done in training period: Digital speedometer: This instrument displays the speed of the vehicle.Speed of the vehicle can be measured using different technology ,it can be made possible by using IR SENSOR ,ULTRASONIC SENSOR,AND MODULES(ultrasonic sensor works on the speed of the sound while ir sensor works on the basis of line of sight)

The main components used here in this project are LCD,ULTRASONIC SENSOR,8051 MICROCONTROLLER etc
18

PIN

DIAGRAM

OF

L.C.D.

L.C.D.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Vss Vcc Vee RSR/W E DB0 DB1DB2 DB3DB4 DB5 DB6 DB7 LED+ LED-

Figure 10

PIN No. 1 2 3 4

SYMBOL Vss Vcc Vee RS

I/O ---I

DISCRIPTION GROUNDED +5V POWER SUPPLY Power supply to control contrast RS=0,select command register RS=1,select data register

R/W

R/W=0,for write R/W=1,for read

6 7-14

E DB0

I/O I/O

Enable The 8 bit data bus

Table 2 Circuit Description

19

In this interfacing we use the port 1 as a LCD control and port 2 as a LCD data. Switches connected on port 3 and LED connected on port 1. Whenever we use port 0 we have to connect pull up register externally to make it by directional because of by default port 0 is unidirectional i.e. only input port . All other ports have already inbuilt pull up register so no need to connect pull up register externally. P3.2 is used as external timer 0 interrupt connected to echo pin of ultrasonic sensor , P3.5 is used as triggering pin connected to triggering pin of ultrasonic sensor CONNECTION OF PULLUP REGISTER

Figure 11 Port 0 is also designated as AD0 AD7 allowing it to be used for both address and data when connection and 8051 to an external memory port 0 provides both address and data .The 8051 multiplexes address and data through port 0 to save pins. ALE indicates if port 0 as address or data .When ALE=0 it provides data D0-D7 but when ALE=1 it has address A0-A7.Therefore ALE is used for demultiplexing address and data with the help of a 74LS 373 latch. In 8051 based system where there is no external memory connection, the pins of port 0 must be connected externally to a 10k ohm pull-up register. This is due to fact that port 0 each and opens drain, unlike port1, port2 and port3. The 8051 has on chip oscillator but requires an external clock to run it. Most often a quartz crystal oscillator is connected to inputs XTAL1 and XTAL2. The quartz crystal oscillator connected to XTAL1 and XTAL2 also needs two capacitor of 30pF value. One side of each capacitor is connected to the ground

List of hardware. S.NO. 1. 2. Name of Hardware. 40 pin IC base 8051 microcontroller Quantity 1 1

20

3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16.

XTAL(11.0592Mhz) Capacitor 33pF 10k POT LCD 7085 regulator Pull-up resistor G.P. PCB Berg strip ULTRA SONIC SENSOR Wires Resistance Multimeter 12v DC supply source Soldering wires, soldering iron ,Flux

1 2 1 1 1 1 1 As required. 1 As required As required

Table 3

21

Chapter 5 Result and future scope

5.1 Conclusion: Knowing about the microcontroller has always been the matter of excitement for all of us. And summer training during the June 2013 was the one of the good opportunity to fulfill this. The training was as fruitful as expected. There we got the exposure about the 8051 microcontroller and its various basic electronics components used in developing an embedded system. We worked on keil tool software which is used to developed program for embedded system. The work experience in the Advanced Technology was quite nice. The trainers those were assigned to us were quite experience. The aim of our experiment is to create an efficient low cost Digital Speedometer. It was inspired by the fact that most of the modern-day vehicles use analog speedometers which have resolution of about 5kmph and the range is also limited.

5.2 Future scope

Historically auto motive vehicles have been provided with mechanical speedometers in which rotation of wheel of the vehicle or of a drive component of the transmission is transmitted as a torsional impulse the torsional force applied to the cable is typically transmitted to needle in the instrument panel which is deflected across a scale to indicate speed at which vehicle is travelling. The Principal dis advantage with such systems has been the requirement for a signal generating system independent of the conventional mechanical speedometer system associated with the auto mobile. It increases the cost of the vehicle. The Digital Speedometer we have designed can measure up to a speed of 999kmph with a resolution of 1kmph. Its rather inexpensive and can be used in almost all vehicles.

22

REFERENCES:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. http://www.Electronicsforu.com http://www .Circuiteasy.com http://www.8051projects.com http://www.electronics-lab.com http://www.microntroller.com http://www.wisc-online.com http://www.seminarprojects.com http://www.allaboutcircuits.com http://www.nptel.iitm.ac.in 10.BOOK ON EMBEDDEDSYSTEM BY MAZIDI 11.8051 MC ARCH,PROGRAM AND APPLICATION-KENNATH J AYALA

23

APPENDIX A system designer using a general-purpose microprocessor such as the Pentium or the 68040 must add RAM, ROM, I/O ports, and timers externally to make them functional. Although the addition of external RAM, ROM, and I/O ports makes these systems bulkier and much more expensive, they have the advantage of versatility such that the designer can decide on the amount of RAM, ROM and I/O ports needed to fit the task at hand. This is not the case with Microcontrollers.

LCD Commands Codes Code(HEX) 1 2 4 6 5 7 8 A C E F 10 14 18 1C 80 Command to LCD Instruction Register Clear Display Screen. Return Home. Decrement cursor( shift cursor to left) Increment cursor( shift cursor to lift) Shift display right Shift display left Display off, cursor off Display off, cursor on Dicplay on, cursor off Display on, cursor blinking Display on, cursor blinking Shift cursorposition to left Shift cursor position to right Shift the entire display to the left Shift to the entire display to the right Force cursor to beginning of first line

24

C0 38

Force cursor to beginning of second line 2 lines and 5*7 matrix

Table 4 Digital speedometer code : Code : #include<REGX51.h> #include<intrins.h> //for using _nop_() function #define port P2 #define dataport P1 sbit trig=P3^5; sbit rs=port^0; sbit rw=port^1; sbit e=port^2; void delay(unsigned int msec) { int i,j; for(i=0;i<msec;i++) for(j=0;j<1275;j++); }

void lcd_cmd(unsigned char item) // Function to send command to LCD { dataport = item; rs= 0;
25

rw=0; e=1; delay(1); e=0; return; }

void lcd_data(unsigned char item) // Function to send data to LCD { dataport = item; rs= 1; rw=0; e=1; delay(1); e=0; return; }

void lcd_data_string(unsigned char *str) // Function to send string to LCD { int i=0; while(str[i]!='\0') { lcd_data(str[i]); i++;
26

delay(1); } return; }

void send_pulse(void) //to generate 10 microseconds delay { TH0=0x00;TL0=0x00; trig=1; _nop_();_nop_();_nop_();_nop_();_nop_(); _nop_();_nop_();_nop_();_nop_();_nop_(); trig=0;

unsigned int get_range(void) { int i,j; int timerval_1; int timerval_2; int range1=0; int range2=0; int range=0; int s; send_pulse();
27

delay(40); timerval_1 = TH0; timerval_1 = (timerval_1 << 8) | TL0; TH0=0xFF;TL0=0xFF; range1=timerval_1/59; // to get distance ( in cm ) for(i=0;i<500;i++) for(j=0;j<1275;j++); send_pulse(); delay(40); timerval_2= TH0; timerval_2 = (timerval_2 << 8) | TL0; TH0=0xFF;TL0=0xFF; range2=timerval_2/59; range= range2-range1; if(range<35000) {//actually you need to use 38000 but the sensor may not work at higher levels range = (range * 0.02 ) ;// there is a delay of 0.5 sec therefore the distance ( cm --> m ) is to be divided by time ( 0.5 sec ) s=range/100; range=range%100; lcd_cmd(0x81); delay(2); lcd_data_string("output:(m/s)"); delay(2); lcd_cmd(0x8a); // 0.5 sec delay

28

delay(2); if(s!=0) { lcd_cmd(0x06); delay(2); lcd_data(s+48); delay(2); s=range; range=range/10; lcd_data(range+48); delay(2); s=s%10; lcd_data(s+48); delay(2); }

else { lcd_cmd(0x06); s=range/10; range=range%10; lcd_data(s+48); delay(2); lcd_data(range+48); delay(2);


29

lcd_data(' '); delay(2); } } else { range=0; // indicates that there is no obstacle in front of the sensor lcd_cmd(0x06); lcd_data(0); } return range; }

void main() { lcd_cmd(0x38); delay(2); lcd_cmd(0x0c); delay(2); lcd_cmd(0x01); delay(2); lcd_cmd(0x81); delay(2); lcd_data_string("start"); delay(20);
30

TMOD=0x09;//timer0 in 16 bit mode with gate enable TR0=1;//timer run enabled TH0=0x00;TL0=0x00;

P3=0x04;//setting pin P3.2 ( INT0 )

while(1) {

get_range(); }

31

You might also like