DIGITAL FUEL METER

August 1, 2017 | Author: Muhammad Taufiq Sharif | Category: Pic Microcontroller, Integrated Development Environment, Microcontroller, Electronic Circuits, Ultrasound
Share Embed Donate


Short Description

A system using PIC16F877A and assembly language...

Description

Table of Contents CHAPTER 1 .............................................................................................................................. 3 INTRODUCTION .................................................................................................................. 3 1.1

PROJECT BACKGROUD ...................................................................................... 3

1.2

PROBLEM STATEMENT...................................................................................... 5

1.3

OBJECTIVES .......................................................................................................... 6

1.4

SCOPE ..................................................................................................................... 7

CHAPTER 2 .............................................................................................................................. 8 LITERATURE REVIEW ....................................................................................................... 8 2.1

WHY USE PIC16F877A ......................................................................................... 8

2.2

WHY USE ULTRASONIC SENSOR HC - SR04. ................................................. 9

2.3

WHY USE LCD-DS-LCD-162A. ......................................................................... 10

CHAPTER 3 ............................................................................................................................ 11 METHODOLOGY ............................................................................................................... 11 3.1

WORK PROGRESS FLOW ................................................................................. 11

3.2

METHODS (PROGRAM USED) ......................................................................... 12

3.3

HARDWARE DEVELOPMENT.......................................................................... 17

3.4

SOFTWARE DEVELOPMENT ........................................................................... 22

CHAPTER 4 ............................................................................................................................ 30 RESULT AND ANALYSIS: ............................................................................................... 30 CHAPTER 5 ............................................................................................................................ 35 COST EVALUATION…………………………………………………………………….35 5.1

BILLS OF MATERIALS AND COMPONENTS……………………………….35

5.2

OVERALL PROTOTYPE PRICE……………………………………………….36

CHAPTER 6………………………………………………………………………………….37 CONCLUSION .................................................................................................................... 38 6.1 RECOMMENDATION .............................................................................................. 39 REFERENCES ........................................................................................................................ 41 APPENDICES ......................................................................................................................... 42

2

CHAPTER 1

INTRODUCTION

1.1

PROJECT BACKGROUD

For this project, „Digital Car's Fuel Detector‟ has been picked as the main application regarding the ultrasonic sensors. This is due to the aspects that the technology can be used for measuring wind speed and direction (anemometer), tank or channel level, and speed through air or water. This ultrasonic criterion perfectly fixes the need of sensor to detect the fuels level in the car tank. When measuring the tank or channel level, the sensor measures the distance to the surface of the fluid. Ultrasonic sensors work on a principle which evaluates attributes of a target by interpreting the echoes from radio or sound waves respectively. Ultrasonic sensors functioned particularly similar to radar or sonar. Besides that, it is also known as transceiver where they both transmit and receive signal. Ultrasonic sensors generate high frequency sound waves and evaluate the echo which is received back by the sensor. Sensors calculate the time interval between sending the signal and receiving the echo to determine the distance to an object. The illustration on how the ultrasonic sensor works based on its wave propagated is shown in Figure 1 and Figure 2. When the wave is propagated back the time taken is recorded and produced by the ultrasonic to be inserted in the calculation below to obtain the exact distance travelled by the wave.

T = time between when an ultrasonic wave is emitted and when it is received Division by 2 is because the sound wave has to travel to the object and back.

3

Figure 1: wave is transmitted and reflected back

Figure 2 : the distance is determined based on time elapsed

This principle is being used to detect the indicator in the container and display back the value of the remaining fuel in the tank. This application is suitable with the project as the sensor is also propagated its wave and will always remind the user about the fuel level in the tank.

4

1.2

PROBLEM STATEMENT

This project acts as an effort to overcome the running out of the fuel in the vehicles‟ fuel tanks. „Digital Car's Fuel Detector‟ is invented to detect the fuel level in the car tank as the input and the percentage of the tank from its full capacity will be displayed on the LCD screen. This eventually should ease the user to estimate the fuel that they need to have for their journey. At the same time this type of product will save the fuel from being wasted and in another way consume the cost of the user itself. As for now it may seem useless but this product is somehow will benefits the user in the future as the value of fuel is unstable and that will affect the amount that we used every day as it will not be the same as before.

5

1.3

OBJECTIVES

1. To design a digital fuel detector for cars which is assembly based program using PIC. 2. To implement the function of ultrasonic sensor to detect the level of the fluid in the tank. 3. To develop a digital fuel detector that is able to show car‟s fuel percentage on LCD screen as the output.

6

1.4

SCOPE

The scope of the project has been narrowed to specific functions and capabilities. The proposed title for the project capped around few limitations. The project is based on Programmable Integrated Circuit PIC 16F877A where LCD screen and ultrasonic sensor will be equipped together. The chosen PIC is used since the course for “Microprocessor and Microcontroller” only covers PIC16 areas. Besides that, PIC16 is a widely used microcontroller and its instruction set, tutorials and examples are easy available especially on the internet. This fuel tanks detector is suitable to be applied on anything that used a covered top container or oblique material tank where the quantity or volume inside it cannot be seen through from the outside. For this project, a fuel tank such as vehicles is used as an inspiration to this idea, where the detector will display how many percentage of the material inside it has being used. Therefore, the customer scope of this project mainly focusing on people with vehicles such as motors, cars, lorries and others. An LCD display which is one of the products of Cytron Technologies model DSLCD-162A will be used as a display output device. The LCD display also is widely used in electronic projects and easily available at any electronic stores. The sensor that will be used are limited to Ultrasonic sensor which also a Cytron Technologies product model HC-SR04. These are the sensor that will be used in the project to sense the fuel‟s level in a container. Some of applications can be used for light or heavy usage. Robust Digital Fuel Level is Sensor is an example which is suitable for standard and heavy application. The project that will be built are more to standard use since the system are expected will be running with low 5V DC power supply. At the end of the project, the location involved for testing the project only in Universiti Tun Hussein Onn Malaysia (UTHM) Batu Pahat, Johor and nearby area.

7

CHAPTER 2

LITERATURE REVIEW

2.1

WHY USE PIC16F877A

For years, ultrasonic sensors have been used in a wide range of applications including fish finders, parking sensors in cars and burglar alarms. There are some others ultrasonic application of ultrasonic sensor that can benefits the mankind. These are some of the important review regarding of the Digital Car‟s Fuel Detector.

Figure 3 : Microcontroller of PIC16F877A

A microcontroller is a compact microcomputer designed to govern the operation of embedded systems in motor vehicles, robots, office machines, complex medical devices, mobile radio transceivers, vending machines, home appliances, and various other devices. A typical microcontroller includes a processor, memory, and peripherals. As for this project microcontroller of PIC16F877A is used. This PIC acts as the brain of this project as it will conduct what particular components action during the particular time.

8

2.2

WHY USE ULTRASONIC SENSOR HC - SR04.

Figure 4 : Ultrasonic sensor of HC - SR04.

Ultrasonic sensor comes from two different words, which are ultrasonic (ultrasound) and sensor. Ultrasound is an acoustic wave with a very high frequency, beyond human hearing. Since the audible frequency range is said to be between 20Hz and 20 kHz, ultrasound generally means acoustic waves above 20 kHz. Bats, with their echolocation (biological ultrasonic radar), can hear sounds up to 200 kHz, way above the capabilities of the human ear. Whereas sensor can be define as a device that detects and responds to some type of input from the physical environment. The specific input could be light, heat, motion, moisture, pressure, or any one of a great number of other environmental phenomena. Ultrasonic ranging module HC - SR04 is used as the input in this project as it provides 2cm - 400cm non-contact measurement function, the ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit.

9

2.3

WHY USE LCD-DS-LCD-162A.

Figure 5 : Liquid Crystal Display of LCD-DS-LCD-162A.

LCD (liquid crystal display) is the technology used for displays in notebook and other smaller computers. LCD also comes as a separate component which is portable and suitable to be used in all electrical projects that needs a display as the output. A specific LCD is picked to display the output for this project, which is LCD-DS-LCD162A.

10

CHAPTER 3

METHODOLOGY

3.1

WORK PROGRESS FLOW

PLANNING Making researches on topics that will be proposed. 5V DC power supply schematic circuit will be obtained from any available sources such as internets or books.

DESIGN Topics proposed among team members. Best topic for group project will be confirm to avoid same topic with the other groups. Size, cost, materials used are considered during this process.

BUDGET List of all components and material that will be used. The total cost of proposed project calculated. Method of obtaining materials that will be used are discussed during this process.

PROPOSAL Previous researches and information will be compiled into project proposal.

PROJECT PROGRESSION Circuit will be designed using selected software and fabricated on PCB. Related electronic components will be soldered throughout this process.

FINDINGS Circuit will be simulated. Circuit also will be tested and any related data and outcomes will be collected for future references and revisions.

ANALYSING AND PROJECT TESTING The project‟s simulation results will be analyzed. The results will be compared. Any error or failure in this project will be overcame. Last touch for project‟s prototype will be made. Project will be tested and verified during this phase.

FINAL REPORT AND PRESENTATION

Figure 6 : The progress flowchart

11

3.2

METHODS (PROGRAM USED)

Throughout the process of making the project prototype, a number of methods are used to make the project prototype complete successfully. In a group with four members, individual skills such as circuit designing, soldering and prototype modelling on each group members are shown during the process of making the prototype. As for technical part, the main circuit and power supply circuit are designed by using Proteus 7.8 software. Applications such as ISIS Professional 7 and ARES Professional 7 are provided by Proteus 7.8. ISIS Professional 7 is used for circuit schematic designing and analyzing purposes while ARES Professional 7 is used for designing printed circuit board layout. The body of the prototype are made from scratch by using unused polystyrene blocks, plastic board and unused bottle flask. As the conclusion the software that is being used to accomplished this project are: 1. Proteus Professional 7.8 2. ARES Professional 7 3. ISIS Professional 7 4. MPLAB IDE

12

3.2.1 Proteus Professional 7.8

Figure 3.2.1: Proteus 7.8 software loading screen

Proteus Professional 7.8 is an application framework that enables users to edit current schematic or design files also with creating a new one between schematic and PCB. The Proteus Professional 7.8 is casually intended for prospective customers who wish to evaluate professional level products. It differs from Proteus Lite or other kind of free circuit schematic designer where it does not allow users to save, print or design their own microcontroller based, electronics and electric circuit. Proteus Professional 7.8 does include all features offered by the other professional system including net list based PCB design with autoplacement, auto-routing and graph based simulation. The Proteus Design Suite combines schematic capture, SPICE circuit simulation, and PCB design to make a complete electronics design system. Throughout of project process, two of Proteus Professional 7.8 applications used are ARES Professional 7 and ISIS Professional 7.

13

3.2.2 ARES Professional 7:

Figure 3.2.2: ARES Professional 7 application icon

ARES Professional 7[1] is a high performance net list based PCB design packages where is it perfectly complements with their ISIS schematic capture software. Any schematic circuit designed can be easily converted into PCB layout. Auto router and components auto placer tools are provided for easy components placing and copper routing. Other than that, options such as copper route size and wire grid size can be adjusted according to user‟s choice.

3.2.3 ISIS Professional 7:

Figure 3.2.3: ISIS Professional application icon ISIS

[2]

one of the main part in Proteus system, and is far more advance than just

another schematics package. It combines a powerful design environment with the ability to define most aspects of the drawing appearance. Flexible schematic designing with various lists of components such as resistors, sensors, LCDs, capacitors and many more are granted by ISIS. The flexibility of circuit designing comes when components and wires can be easily dragged and dropped onto the schematic workspace. Assembly program are uploaded into this application for circuit simulation.

14

3.2.4 MPLAB IDE MPLAB IDE software are produced by Microchip Company and it is used to write assembly language program. Since the project program are written is assembly language, any process related with assembly programming such as writing assembly codes, program executing and debugging are done by using MPLAB IDE software. Microchip has a large suite of software and hardware development tools integrated within one software package. MPLAB IDE is a free, integrated toolset for the development of embedded applications on Microchip's PIC and dsPIC microcontrollers. It is called an Integrated Development Environment (IDE) as it provides a single integrated environment to develop code for embedded microcontrollers.

Figure 3.2.4.1: Microchip MPLAB IDE log

MPLAB IDE are easy to be used and a host of free software components are included for fast application development and debugging. MPLAB IDE are served as single, unified graphical user interface for additional Microchip and third party software and hardware development tools. Assembler, debugger, editor, project manager and execution engines are the main components of MPLAB IDE.

15

Figure3.2.4.2: Some of MPLAB IDE components

The project manager provides integration and communication between the IDE and the language tools. The editor is a full-featured programmer's text editor that also serves as a window into the debugger. The assembler can be used stand-alone to assemble a single file, or can be used with the linker to build a project from separate source files, libraries and recompiled objects. The linker is responsible for positioning the compiled code into memory areas of the target microcontroller. The Microchip debugger allows breakpoints, single stepping, watch windows and all the features of a modern debugger for the MPLAB IDE. It works in conjunction with the editor to reference information from the target being debugged back to the source code. There are software simulators in MPLAB IDE for all PICmicro MCU and dsPIC DSC devices. These simulators use the PC to simulate the instructions and some peripheral functions of the PICmicro MCU and dsPIC DSC devices. Optional in-circuit emulators and in-circuit debuggers are also available to test code as it runs in the applications hardware [3].

16

3.3

HARDWARE DEVELOPMENT

POWER SOURCE

To make a controller function, a power source of 5V is needed to power up the PIC. Therefore, a 5VDC power supply is built up using the current from the power adapter. Power adapter is chosen to replace the transformer function. This is because of the safety reason and materials expenditures. When an adapter is used as a power source to generate 5V power supply, the probability of the circuit to damage or exploded is decreases as power adapter is more reliable than the transformer that is known as its complication to stable the performance. Beside that the expenditures that need to be calculated when a transformer exploded is much higher whereas an adapter seldom undergone such problem. Figure 9 is the power source circuit that has been tested and worked properly.

Figure 7 : Schematic diagram of power source

17

Figure 8 : Power source circuit board

Figure 9 : The circuit tested

18

LCD

In this project, the most commonly used character based LCD, which is based on Hitachi‟s HD44780 controller, has been used. The HD44780 standard requires 3 control lines as well as 8 I/O lines for the data bus for the 8-bit LCD interface. For an 8-bit data bus, it will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus). The data bus consists of 8 lines. In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7. The three control lines are referred to as EN, RS, and RW. The EN line is called “Enable.” This control line is used to instruct the LCD that the data is sending to it. Initially, this line is low (0) and then set the other two control lines and/or put data on the data bus. When the other lines are completely ready, bring EN high (1) and wait for the minimum amount of time required by the LCD datasheet, and end by bringing it low (0) again. Next, the RS line is the “Register Select” line. When RS is low (0), the data is to be treated as a command or special instruction, such as clear screen and position cursor. When RS is high (1), the data being sent is text data which should be displayed on the screen. For example, to display the letter “S” on the screen the RS line has been set high. Lastly, the RW line is the “Read/Write” control line. When RW is low (0), the information on the data bus is being written to the LCD. When RW is high (1), the program is effectively or reading the LCD.

19

Pin No.

Name

Description

1

Vss

Power Supply (GND)

2

Vcc

Power Supply (+5V)

3

Vee

Contrast Adjust

4

RS

0 = Instruction Input 1 = Data Input

5

R/W

0 = Write to LCD Module 1 = Read from LCD Module

6

EN

Enable Signal

7

DB0

Data bus line 0 (LSB)

8

DB1

Data bus line 1

9

DB2

Data bus line 2

10

DB3

Data bus line 3

11

DB4

Data bus line 4

12

DB5

Data bus line 5

13

DB6

Data bus line 6

14

DB7

Data bus line 7 (MSB)

Table 1: The character of the LCD pins

Figure 10: The LCD circuit connection

20

ULTRASONIC SENSOR The sensor has two opening on its front; one opening emits ultrasonic waves, while the other receives them. The ultrasonic Sensor measures the distance by timing how long it takes for an ultrasonic wave sent out by the emitter to bounce off an object and come back to the receiver. The speed of the sound is approximately 341m/s in air. The sensor uses this information, along with the time difference between sending and receiving the sound pulse, to determine distance to an object using this equation:

Figure 11 : HC-SR04 Ultrasonic sensor on the breadboard

T = time between when an ultrasonic wave is emitted and when it is received Division by 2 is because the sound wave has to travel to the object and back.

21

3.4

SOFTWARE DEVELOPMENT

The Figure 12 shows the overall view on how the program should work. Whereas the Figure2 until Figure19 is how the LCD program is being generated in the PIC itself. Lastly, the Figure20 and Figure21 describe the flow of the ultrasonic sensor in the program. START

Gap between ultrasonic sensor with object infront of it

Ultrasonic sensor detect the distance of the gap

Distance measurement in percentages send to PIC16F877A

PIC16F877A send data to output display

Display “FUEL USED: “ on LCD

Display the distance measurement in percentages on LCD

END

Figure 12 : Program flowchart

22

LCD INTERFACE:

Figure 13: Flow chart of the assembly code for the LCD interface (main)

23

Figure 14 : Flow chart of the assembly code for the LCD interface (initialisation)

24

Figure 15 : Flow chart of the assembly code for the LCD interface (M1 subroutine)

Figure 16 : Flow chart of the assembly code for the LCD interface (LINEA2 subroutine) 25

Figure 17 : Flow chart of the assembly code for the LCD interface (M2 subroutine)

Figure 18 : Flowchart of the assembly code for the LCD interface (continue)

26

Figure 19 : Flow chart of the assembly code for the LCD interface (continue)

27

ULTRASONIC SENSOR INTERFACE: BEGIN

Select bank 1

Set all pin at PORT A as output

Clear PORT B and PORT D.

Set pin RC2 as input

Set as digital pins using ADCON1 register (bit 0110)

Enable CCP1

Insert interrupt

Clear pin RC6

DELAY

Set pin RC6

SDELAY

Clear pin RC6

Clear TMR1H and TMR1L register NO

Test bit=1 for PIR1 and CCP1IF

YES Clear PIR1, CCPI1F and CCP1CON register NO

Test bit=1 for PIR1 and CCP1IF

YES Clear PIR1, CCPI1F and CCP1CON register

DISPLAY

END

Figure 20 : Ultrasonic interface flowchart_1

28

LINE1

Enable PORT D

DISPLAY

Display “RANGE :”

END

LINE1 LINE2

LINE2

Clear PORT D

Enable PORT D END

Data from ultrasonic sensor

Display distance value

Display “ cm”

END

Figure 21 : Ultrasonic flowchart_2

29

CHAPTER 4

RESULT AND ANALYSIS:

Before the controller part is being developed, the power source that needed to power up the PIC is being built and tested. The ideal voltage that needs to be produced by the power source circuit in order to operate the PIC is 5V. Analysing of circuits is done by using 2 methods which are by using ISIS Professional 7 application and testing with multimeter. Before PCB being printed out, the designed circuit are tested on breadboard for functionality test. Both power supply circuit and main application circuit are tested by using this method. Voltage flow in the circuit is measured by using ISIS and multimeter. Figure 22 is the result when the power source circuit is being testes\d, the value of the output is exactly 5V.

Figure 22: Power supply output voltage analysis at 5V

30

In order to retrieve the result, the PIC16F877A microcontroller at the schematic circuit in the Proteus software has been edited by selecting the .HEX program file of the assembly codes that has been built previously. After the schematic circuit has been simulated with the assembly codes generated in the PIC16F877A, the output display has shown “SALAM DR.SHAMIAN” strings, based on Figure 23.

Figure 23: The window view for editing the component of PIC16F877A

Figure 24: The output display on the schematic circuit

Finally, the assembly code has been downloaded into the PIC16F877A and the output display has been produced as shown in Figure 24. This is the step where the LCD is has been successfully configured and tested by a simple program without the interference of the ultrasonic sensor.

31

Figure 25: The output display on LCD screen

The interfacing of HC-SR04 Ultrasonic sensor with PIC16F877A has successfully displaying measurement of an object. The measurement displayed on the LCD is a little bit different from the measurement obtained by using ruler.

Figure 26: Object at a distance of 18 cm from the HC-SR04 Ultrasonic sensor.

32

Figure 27: Top view of an object at a distance of 18 cm from the HC-SR04 Ultrasonic sensor

Figure 28: Measurement LCD-display

Measurement displayed on the LCD when an object is at 18.5 cm of distance away from the HC-SR04 Ultrasonic sensor as shown in Figure 27. The distance displayed is changed sometimes to 18.0 cm, 19.0 cm and more when a little disturbance applied on the measured object. Uncertainty of +- 5 cm of measurement displayed are obtained when the object being measured. Lastly, the circuit is being assembly on the prototype that has been build up to show the function of the project itself. The ultrasonic sensor will be placed at the bottom of the water container‟s cover like shown in Figure 28. The cover will be placed on the prototype later on. From Figure 29 the connection from the breadboard to the ultrasonic sensor can be seen. As the prototype is placed and functioning the result of the output as in Figure 30 will be displayed on the LCD. 33

Figure 29: Ultrasonic sensor

Figure 30: Circuit connection

34

Figure 31: LCD Display

35

CHAPTER 5

COST EVALUATION

5.1

BILLS OF MATERIALS AND COMPONENTS

Power Supply No. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

Items Quantity IC 7805 Voltage Regulator 1 Ceramic Capacitor 100 µF 2 Ceramic Capacitor 0.01 µF 2 Resistor 220 Ω 1 1N4007 1 Light Emitting Diode (LED) 1 2 Pin Terminal Block 2 DC Jack 1 DC Power Adapter (Variable) 1 Printed Circuit Board 1 Overall Price (RM) *Components/materials are obtained from laboratory

Price for Each Unit (RM) 2.00 0.65 0.15 0.05 0.20 0.40 1.20 2.00 18.00 *

Total Price (RM) 2.00 1.30 0.30 0.05 0.20 0.40 2.40 2.00 18.00 * 26.65

Table 2: Bills of materials and components for 5V power supply circuit

Main Circuit No. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

Items Quantity 16X2A LCD 1 Potentiometer 5k Ω 1 PIC16F877A 1 Jumpers 1 4 MHz Crystal Oscillator 1 22 pF Ceramic Capacitor 2 40-Pin IC Socket 1 Straight 2mm Female Header 1x40 Ways 2 HC-SR04 Ultrasonic Sensor 1 Printed Circuit Board 1 Overall Price (RM) *Components/materials are obtained from laboratory

Price of Each Unit (RM) 18.00 1.20 17.00 12.00 2.00 0.15 0.70 1.20 39.00 *

Total Price (RM) 18.00 1.20 17.00 12.00 2.00 0.30 0.70 2.40 39.00 * 92.60

Table 3: Bills of materials and components for main circuit

36

Prototype No. 1. 2. 3. 4.

Items Plastic Board Polystyrene Blocks Water Flask Small Screws

Quantity 1 1 1 8 Overall Price (RM) *Components/materials are obtained unused items

Price of Each Unit (RM) 4.00 * 4.00 0.05

Total Price (RM) 4.00 * 4.00 0.40 8.40

Table 4: Bills of materials and components for prototype . 5.2

OVERALL PROTOTYPE PRICE

The overall price for the whole prototype is the sum total price for power supply circuit, main circuit and prototype. The calculation of the product‟s price are shown in the calculation below:

37

CHAPTER 6

CONCLUSION As a conclusion, a prototype of „Digital fuel tank detector‟ is successfully developed. This prototype used an ultrasonic sensor as it input and the output will be displayed at LCD display. Throughout this project, the LCD display is managed to display the output where the percentage of the fuel tank is being calculated and the ultrasonic sensor is able to detect the obstacle that is in it range. Most important is that, the PIC is successfully configured and all the error is fixed in order to achieve all the objectives and to come out with a fully working prototype.

38

6.1

RECOMMENDATION

Although this project has been successfully build with its application. There is still space to improve this project. This recommendation is made up based on the suitability for this product to be marketed in the future. This idea can be manipulated to produce a product that can be commercialized in order to improve the lifestyle of human being in this moderntechnologies world. These are some of the recommendation that is suggested for further improvement:

1. Modified the application.

Besides fuel tank, this project can be modified to use in other environment, such as a detector to alert the user if the water tank is almost run out of water. This is quite useful as the main water tank is at the rooftop. It is difficult if the user need to check the water tank regularly especially to some places than undergoes water restriction. This will ease the user to be in a standby mode if the water ran out.

2. Use M-Series Fuel Level Sensors from Gill Sensors.

Figure 32: M-Series fuel level sensor

M-Series fuel level sensors are custom designed using capacitive technology; the sensors have no moving parts and are extremely accurate. They can be designed to fit within the tightest of space envelopes and withstand the harshest of environments. 39

This type of sensors has a few additional characteristic make it the best sensor to replace the ultrasonic sensor for the application regarding fuel.

These sensors are compatible with all petroleum/gasoline fuels and are offered with totally configurable outputs and onboard multiple fuel calibration functions. The additional characteristics are:

i. Fully immersible ii. Custom designed to specific requirements iii. Super –lightweight versions available

40

REFERENCES [1] http://www.labcenter.com/products/pcb/pcb_intro.cfm. Retrieved on 19th May 2014. [2] http://www.labcenter.com/products/pcb/schematic_intro.cfm. Retrieved on 19th May 2014. [3] http://www.element14.com/community/docs/DOC-39318/l/microchip-mplabintegrated-development-environment-ide-overview. 11th November 2011 by Ankur Tomar. Retrieved on 18th May 2014. [4] http://tutorial.cytron.com.my/2012/02/04/lcd-interfacing-with-pic-microcontrollerspart-1/ . Retrieved on 20/3/2014. [5] http://tutorial.cytron.com.my/2012/03/14/lcd-interfacing-with-pic-microcontrollerspart-2/ .Retrieved on 20/3/ 2014. [6] http://www.pyroelectro.com/tutorials/pic_lcd/software.html (retrieved on 21/3/2014). [7] http://www.datasheetarchive.com/lcd%20162A-datasheet.html (retrieved on 21/3/2014). [8] http://www.circuitstoday.com/interfacing-16x2-lcd-with-8051 (retrieved on 21/3/2014). [9] Azosensor, 200-2014, Retrieved at http://www.azosensors.com/equipmentdetails.aspx?EquipID=271 [10]

Sapcon Instrument, FLY ASH Level Detection in ESP Hoppers, 2013.

Retrieved at http://www.sapconinstruments.com/articles. [11]

Datasheet, Retrieved at http://www.datasheetarchive.com/lcd%20162A-

datasheet.html [12]

Interfacing LCD, Retrieved at http://www.circuitstoday.com/interfacing-16x2-

lcd-with-8051

41

APPENDICES LCD INTERFACE ;######################################################################## LIST P=16F877A INCLUDE "P16F877A.INC" ERRORLEVEL __CONFIG

0,-302

0X3F32

;######################################################################## CBLOCK

0X20

LCOUNT HCOUNT Timer1 ENDC ;######################################################################## ORG

00h

GOTO

MAIN

ORG

; Started at address 0 ; Jumps to MAIN 5

;########################################################################

M1: MOVLW

'S'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'A'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'L'

MOVWF

PORTD 42

CALL

ENVIA

MOVLW

'A'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'M'

MOVWF

PORTD

CALL

ENVIA

RETURN

M2: MOVLW

'D'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'R'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'.'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'S'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'H'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'A'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'M' 43

MOVWF

PORTD

CALL

ENVIA

MOVLW

'I'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'A'

MOVWF

PORTD

CALL

ENVIA

MOVLW

'N'

MOVWF

PORTD

CALL

ENVIA

RETURN

Onems MOVLW

D'249'

MOVWF

Timer1

Loop1 DECFSZ

Timer1,F

GOTO

Loop1

RETURN

INITIAL_LCD: BCF

PORTB,6

; Set RS=0

MOVLW

0x01

MOVWF

PORTD

; Therefore it clears screen

CALL

COMMAND

; Jumps to COMMAND

MOVLW

0x0C

MOVWF

PORTD

; Set D0=1, the command control code is '00000001'

;

44

CALL

COMMAND

MOVLW

0x3C

MOVWF

PORTD

CALL

COMMAND

BSF

PORTB,6

; ;

; ;

RETURN

COMMAND: BSF

PORTB,7

; Enable pin is set

CALL

DELAY

CALL

DELAY

BCF

PORTB,7

CALL

DELAY

; Jumps to DELAY

BSF

PORTB,6

;

CALL

COMMAND

;

; Jumps to DELAY ; Jumps to DELAY ; Enable pin is clear

RETURN

ENVIA:

RETURN

LINEA2: BCF

PORTB, 6

; RS=0

MOVLW

0xC0

MOVWF

PORTD

CALL

COMMAND

;

; Jumps to COMANDO

RETURN

DELAY: MOVLW

0xFF 45

MOVWF

LCOUNT

MOVLW

0xFF

MOVWF

HCOUNT

DELAY_LOOP: DECFSZ

LCOUNT,1

GOTO

DELAY_LOOP

DECFSZ

HCOUNT,1

GOTO

DELAY_LOOP

RETURN

MAIN: BSF

STATUS,RP0

BCF

STATUS,RP1

CLRF

TRISB

CLRF

TRISD

BCF

STATUS,RP0 CLRF PORTB CLRF PORTD

START_LCD: CALL

INITIAL_LCD

CALL

M1

CALL

LINEA2

CALL

M2

NOP GOTO

$-1

END

46

THE FULL PROTOTYPE SOURCE CODE

LIST P=16f877a INCLUDE "P16F877A.INC" ERRORLEVEL __CONFIG

0,-302

0X3F32

;**************************************************************** CBLOCK

0X20

; Start of general purpose

registers LCOUNT HCOUNT TIME1 TIME2 ONE TEN HUNDRED TIMES VALUE DEC_POINT COUNTER STORE ENDC ;**************************************************************** ORG 0X00 GOTO MAIN ;**************************************************************** DELAY

MOVLW

0XAF

MOVWF

LCOUNT

MOVWF

HCOUNT 47

DELAY_LOOP

DECFSZ

LCOUNT,F

GOTO DELAY_LOOP MOVLW

0XAF

MOVWF

LCOUNT

DECFSZ

HCOUNT,F

GOTO DELAY_LOOP RETURN ;**************************************************************** SHORT_DELAY

DELAY_LOOP2

MOVLW

0X02

MOVWF

LCOUNT

MOVWF

HCOUNT

DECFSZ

LCOUNT,F

GOTO DELAY_LOOP2 MOVLW

0X02

MOVWF

LCOUNT

DECFSZ

HCOUNT,F

GOTO DELAY_LOOP2 RETURN ;**************************************************************** LCD

MACRO

DATA1

MOVLW

DATA1

MOVWF

PORTD

BSF

PORTD, 7

CALL DELAY BCF

PORTD, 7

CALL DELAY ENDM ;**************************************************************** LCD2

MOVWF

PORTD 48

BSF

PORTD, 7

CALL DELAY BCF

PORTD, 7

CALL DELAY RETURN ;**************************************************************** MOVLF

MACRO

DATA2,FILE1

MOVLW

DATA2

MOVWF

FILE1

ENDM ;**************************************************************** MOVFF

MACRO

FILE2,FILE3

MOVF FILE2, W MOVWF

FILE3

ENDM ;**************************************************************** SUB1

MACRO

VALUE1,FILE4

MOVLW

VALUE1

SUBWF

FILE4, W

ENDM ;**************************************************************** TABLE

ADDWF

PCL

RETLW

'0'

RETLW

'1'

RETLW

'2'

RETLW

'3'

RETLW

'4'

RETLW

'5'

RETLW

'6' 49

RETLW

'7'

RETLW

'8'

RETLW

'9'

;**************************************************************** STAY

MOVLW

D'10'

MOVWF LOOP

COUNTER

CALL DELAY DECFSZ

COUNTER, F

GOTO LOOP RETURN ;**************************************************************** DISPLAY

MOVFF TEN, STORE

SUB1 0X03, TEN BTFSC

STATUS, 0

GOTO LINE1_A MOVFF

STORE, TEN

BTFSC

STATUS, 0

SUB1 0X02, TEN

GOTO LINE1_D MOVFF

STORE, TEN

BTFSC

STATUS, 0

GOTO

LINE1_B

SUB1 0X01, TEN

GOTO LINE1_C ;***************************************************************** LINE1_A

BSF

PORTD, 6 50

LCD

'E'

LCD

'S'

LCD

'T'

LCD

':'

LCD

''

LCD

'2'

LCD

'5'

LCD

'%'

BCF

PORTD, 6

LCD

0XC0

BSF

PORTD, 6

LCD

'F'

LCD

'U'

LCD

'E'

LCD

'L'

LCD

''

LCD

'W'

LCD

'A'

LCD

'R'

LCD

'N'

LCD

'I'

LCD

'N'

LCD

'G'

LCD

''

LCD

'!'

MOVLF

B'00000001', PORTE

CALL STAY GOTO

START

;***************************************************************** 51

LINE1_B

BSF

PORTD, 6

LCD

'E'

LCD

'S'

LCD

'T'

LCD

':'

LCD

''

LCD

'5'

LCD

'0'

LCD

'%'

BCF

PORTD, 6

LCD

0XC0

BSF

PORTD, 6

LCD

'B'

LCD

'E'

LCD

'W'

LCD

'A'

LCD

'R'

LCD

'E'

LCD

'!'

LCD

'!'

LCD

''

CALL LINE2 MOVLF

B'00000010', PORTE

CALL STAY GOTO

START

;********************************************************************* LINE1_C

BSF

PORTD, 6

LCD

'E'

LCD

'S' 52

LCD

'T'

LCD

':'

LCD

'1'

LCD

'0'

LCD

'0'

LCD

'%'

BCF

PORTD, 6

LCD

0XC0

BSF

PORTD, 6

LCD

'F'

LCD

'U'

LCD

'E'

LCD

'L'

LCD

''

LCD

'M'

LCD

'A'

LCD

'X'

LCD

'E'

LCD

'D'

CALL LINE2 MOVLF

B'00000100', PORTE ; Red LED "ON"

CALL STAY GOTO

START

;********************************************************************* LINE1_D

BSF

PORTD, 6

LCD

'E'

LCD

'S'

LCD

'T'

LCD

':' 53

LCD

''

LCD

'7'

LCD

'5'

LCD

'%'

BCF

PORTD, 6

LCD

0XC0

BSF

PORTD, 6

LCD

'F'

LCD

'U'

LCD

'E'

LCD

'L'

LCD

''

LCD

'A'

LCD

'T'

LCD

''

LCD

'B'

LCD

'E'

LCD

'S'

LCD

'T'

LCD

'.'

LCD

'.'

MOVLF

B'00000001', PORTE ; Green LED "ON"

CALL STAY GOTO

START

LINE2 NEXT

; Display the distance MOVF TEN, W XORWF

0X00, W

BTFSC

STATUS, 2

GOTO

NEXT2

; TEN=0? ; Yes, no display

tens unit 54

WORD2

MOVF TEN, W

; No, display tens unit

CALL TABLE CALL LCD2 NEXT2

MOVF ONE, W

; Display ones unit

CALL TABLE CALL LCD2 LCD

'.'

; No, display '.'

and decimal point MOVF DEC_POINT, W CALL TABLE CALL LCD2 LCD

'c'

LCD

'm'

; Display "cm"

RETURN ;**************************************************************** MAIN

BSF

STATUS, RP0

; Bank 1

CLRF TRISB

; Set PORTB as the output (LCD

CLRF TRISD

; Set PORTD as the output (LCD

CLRF TRISE

; Set PORTE as the output (LED)

command) data)

MOVLF

B'00000100', TRISC ; Set RC2 as input (Echo of

ultrasonic) ; Set RC1 as output (Trigger of ultrasonic)

START every rising edge

BCF

STATUS, RP0

; Bank 0

MOVLF

0X05, CCP1CON

; Set Capture mode in

MOVLF

0X11, T1CON

; Enables Timer 1

CLRF PORTC LCD_SETTING receiving command

BCF

PORTD, 6

; Set RS=0 for LCD

55

LCD code='00000001' for clear screen

0X01

; LCD command

LCD mode and 5x10 dot format

0X3C

; Set 8 bit interface,2 line

LCD

0X0C

; Display ON and no

cursor CLEAR_FILES

CLRF DEC_POINT

; Clear all the files

CLRF ONE CLRF TEN CLRF HUNDRED CLRF TIME1 CLRF TIME2

HC_SR04 emitted sonar pulse

BSF

PORTC, 6

; Trigger pin is high to

CALL SHORT_DELAY

; at least 10us for emitting

BCF

; Stop emitted pulse

sonar pulse

AGAIN

PORTC, 6

CLRF TMR1H

; Clear Timer 1

CLRF TMR1L

ECHO_HIGH BTFSS PIR1, CCP1IF

; Is it ECHO raising? (ECHO=1)

GOTO

AGAIN

BCF

PIR1, CCP1IF

BCF

CCP1CON, 0

; No, clear Timer

1 ; Yes, clear the CCP1 flag ; Set Capture mode in

every falling edge

ECHO_LOW BTFSS PIR1, CCP1IF GOTO ECHO_LOW

; Is it ECHO falling? (ECHO=0) ; No, increase the content in

Timer 1

56

MOVFF

TMR1L, TIME1

; Store period of ECHO=1

MOVFF

TMR1H, TIME2

; Store period of ECHO=1

BCF

PIR1, CCP1IF

into TIME1 into TIME2

DIVISION1

SUB1 D'58', TIME1

; Clear the CCP1 flag

; Start the division TIME1/58 using subtraction

BTFSS STATUS, 0

; Is TIME1 > 58?

GOTO CHECK

; No, check TIME2=0 or

MOVWF

; Yes, result of (TIME1-

not? TIME1

58) stored in TIME1 INCF ONE, F operation (TIME-58) will

; The times of the ; stored in

temporary file, ONE GOTO DIVISION1 CHECK

MOVLW

0X00

XORWF

TIME2, W

; Subtraction again

; Compare TIME2 and

zero BTFSS STATUS, 2 GOTO ADDITIONAL because TIME2 has value GOTO DIVISION2

; TIME2=0? ; No, goto ADDITIONAL ; Yes, goto DIVISION2 ; to assign result in

hundreds, tens and ones unit ADDITIONAL DECF TIME2, F TIME1=255, TIME2-1 until TIME2=0

; TIME2=1 is same as

MOVLW

0X04

; 255/58=4.39, so taking 4

ADDWF

ONE, F

MOVLW

D'24'

; 4x58=232, 256-232=24

ADDWF

TIME1, F

; remaining values (23)

; Add 4 into the

result

stored in TIME1

57

GOTO DIVISION1

DIVISION2 MOVLF 10 times (TIME1x10)

D'10', TIMES

; Subtraction again

; TIMES=10 used for addition of TIME1

MOVFF TIME1 stored in VALUE

TIME1, VALUE

; Remaining value in

CHECK2 DECFSZ TIMES and then TIME1=0?

TIMES, F

; Decrement of 1 in

GOTO

AGAIN1

; No, subtraction

again GOTO SEPARATION1

AGAIN1

MOVF VALUE, W ADDWF

; Yes, separate result

; W=VALUE

TIME1, F

SUB1 D'58', TIME1 BTFSS STATUS, 0 GOTO

CHECK2

MOVWF

TIME1

; TIME1+VALUE ; TIME1-58 ; TIME1 > 58? ; Check the

TIMES=0 or not? ; Result (TIME1-58) store

in TIME1 INCF DEC_POINT, F *DEC_POINT=1 means 0.1*

; Increment of 1 in decimal point

GOTO CHECK2

SEPARATION1 unit (ONE-100)

SUB1 D'100', ONE

; Start seperate result in hundreds

BTFSS STATUS, 0

; ONE > 100?

GOTO SEPARATION2

; No, for separate result in

tens unit MOVWF (ONE-100) stored in ONE

ONE

INCF HUNDRED, F *HUNDRED=1 means 100*

; Yes, result ; Inceament of 1 in hundreds unit

58

GOTO SEPARATION1

; Separate result in

hundreds unit again

SEPARATION2 (ONE-10)

SUB1 D'10', ONE

; Start separate result in tens unit

BTFSS STATUS, 0

; ONE > 10?

GOTO FINISH_CALC

; No, goto

FINIFH_CALC MOVWF (ONE-10) stored in ONE

ONE

INCF TEN, F unit *TEN=6 means 60* GOTO SEPARATION2

; Yes, result ; Increment of 1 in tens ; Separate result in tens

unit again FINISH_CALC GOTO

DISPLAY

; Display result

END

59

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF