SlideShare a Scribd company logo
1 of 79
RESTRICTED
i
RESTRICTED
Homework Help
https://www.homeworkping.com/
Research Paper help
https://www.homeworkping.com/
Online Tutoring
https://www.homeworkping.com/
click here for freelancing tutoring sites
DESIGN AND FABRICATION OF MICROCONTROLLER
BASED FOUR CHANNEL DATA LOGGER
By
PLT OFF FARHAN HASEEB (16062)
ADVISOR
WG CDR MUHAMMAD AJMAL
CO ADVISOR
ASST PROF SHAFQAT-UL-MULK
REPORT SUBMITTED IN PARTIAL FULFILLMENT OF
THE REQUIREMENTS FOR THE DEGREE OF BE
RESTRICTED
ii
RESTRICTED
COLLEGE OF AERONAUTICAL ENGINEERING
PAF ACADEMYRISALPUR
August, 2012
ACKNOWLEDGEMENT
RESTRICTED
iii
RESTRICTED
First of all I would like to thanks ALLAH, the Almighty for the successful
completion of my final semester project and report. Also Iam extremely grateful to my
advisorWing Commander MuhammadAjmal Khan and co-advisor Assistant Professor
Shafqat-ul-Mulk for theircontinuous help and guidance. In addition to that, I am also
grateful to Flying Officer Ali RazaGhumman from No. 606 R&D Wing for the support and
help they provided to me.Without theiraffectionate guidance at every step this would not
have been possible.
RESTRICTED
iv
RESTRICTED
DEDICATION
I would like to dedicate my report to my parents as theyhave always been a
source of guidance and motivation to me. Without their prayers this would not have
been possible.
RESTRICTED
v
RESTRICTED
ABSTRACT
This document provides final semester project reportof a microcontroller based
four channel data logger. It provides detailed definition and explanation of the
designed data logger, which was fabricated successfully. This document presents a
brief summary of different softwares and components that were used during the
project and finally the hardware part. It will also comprise of a detailed summary of
the specifications and applications of the data logger.
RESTRICTED
6
RESTRICTED
TITLE…………………............................................................................................... ii
ACKNOWLEDGEMENT ...................................................................................... iii
DEDICATION...………………………………………………………………………………………………….ii
v
ABSTRACT………... ...............................................................................................v
CHAPTER01: INTRODUCTION ......................................................................... 10
Project Title..................................................................................................................................10
Proposal Statement………………..…………………………………………….……………………………………………………….10
Background And Overview............................................................................................................10
Selection Of PIC 16F877A ..............................................................................................................13
Features Of PIC 16F877A ...............................................................................................................13
CHAPTER02: PHASES AND SOFTWARES......................................................... 15
Phases..........................................................................................................................................15
Phase 1 and 2................................................................................................................................15
Ccs C Compiler..............................................................................................................................16
Ic Writer.......................................................................................................................................16
Proteus.........................................................................................................................................17
CHAPTER03:COMPONENTS.............................................................................. 19
External Eeprom...........................................................................................................................19
Real Time Clock.............................................................................................................................20
I2C Connection..............................................................................................................................20
LCD...............................................................................................................................................21
4X3 Keypad...................................................................................................................................21
MAX 232.......................................................................................................................................22
RESTRICTED
7
RESTRICTED
IC-7805 .........................................................................................................................................22
CHAPTER04: ADVANCE FEATURESAND MEMORY ALLOCATION.................. 2024
Advance Features..........................................................................................................................24
Variable Time Interval...................................................................................................................24
Present And Finish Date And Time.................................................................................................25
Variable No Of Channels................................................................................................................25
Graphical Trend Analysis...............................................................................................................25
No Of Sample................................................................................................................................25
Resolution....................................................................................................................................26
Battery .........................................................................................................................................26
Frequency.....................................................................................................................................27
Memory Allocation.......................................................................................................................28
First 14 Bytes Dedicated................................................................................................................28
CHAPTER05: SERIAL INTERFACINGAND GRAPHICAL TREND ANALYSIS............ 29
Serial Communication...................................................................................................................29
USART ..........................................................................................................................................30
Max 232 Level Conversion.............................................................................................................30
RS 232 To Usb Convertor...............................................................................................................30
Baud Rate .....................................................................................................................................31
Serial Terminal..............................................................................................................................31
Hercules.......................................................................................................................................31
Advantages...................................................................................................................................32
Method........................................................................................................................................32
Graphical Trend Analysis...............................................................................................................33
RESTRICTED
8
RESTRICTED
CHAPTER06: HARDWARE IMPLEMENTATION................................................ 35
PCB...............................................................................................................................................35
PCB Design Software.....................................................................................................................35
Final product.................................................................................................................................36
Sensors.........................................................................................................................................38
LM 35 Temperature Sensor...........................................................................................................38
Light Dependent Resistor..............................................................................................................39
MQ 2 Smoke Sensor......................................................................................................................39
Variable Resistor...........................................................................................................................40
Sinewave From FunctionGenerator...............................................................................................40
CHAPTER 07: CONCLUSION ............................................................................ 41
Project DeliverablesFor 8th
Semester.............................................................................................41
Project Monstration Of 8th
Semester..............................................................................................41
Additional Tasks............................................................................................................................42
REFERENCES……............................................................................................... 44
APPENDICES……............................................................................................... 45
Appendix A...................................................................................................................................46
Appendix B...................................................................................................................................63
Appendix C...................................................................................................................................70
Appendix D...................................................................................................................................73
RESTRICTED
9
RESTRICTED
LIST OF FIGURES
Figure 1.1: Data Logger..................................................................................................................11
Figure 1.2: Modern Data Logger……………………………………………………………………………………………………..11
Figure 1.3: Data Logger Block Diagram...........................................................................................12
Figure 1.4: Elements Of A Digital Controller...................................................................................13
Figure 1.5: Pin Configuration Diagram Of Pic 16f877a.....................................................................14
Figure 2.1: Patch Board Picture Of Circuit.......................................................................................15
Figure 2.1: Serial Circuit Diagram...................................................................................................15
Figure 2.2: CCS C Compiler.............................................................................................................16
Figure 2.3: IC Writer......................................................................................................................17
Figure 2.4: Proteus........................................................................................................................17
Figure 2.5: Complete Simulation Diagram......................................................................................18
Figure 3.1: Atmel 24C256...............................................................................................................19
Figure 3.2: Pin Configuration Diagram Of AT24C256 .......................................................................19
Figure 3.3: Pin Configuration Diagram Of DS-1307..........................................................................20
Figure 3.4: Basic Form Of The I2c Connection.................................................................................20
Figure 3.5: I2C Signals....................................................................................................................21
Figure 3.6: 16x2 LCD......................................................................................................................21
Figure 3.7: IC-7805 ........................................................................................................................22
Figure 3.8: Picture Of Max 232.......................................................................................................22
Figure 3.9: Max 232 Along With Capacitors Attached .....................................................................23
RESTRICTED
10
RESTRICTED
Figure 4.1: LCD Showing The Entered Time Interval In Sec..............................................................28
Figure 4.2: LCD Showing The Entered Finish Date...........................................................................25
Figure 4.3: Picture Of Sample No Along With Date And Time..........................................................25
Figure 4.4: Rechargeable Battery...................................................................................................26
Figure 4.5: Memory Allocation......................................................................................................27
Figure 4.6: 247 (8 Bit No) Saved At First Memory Location..............................................................28
Figure 4.7: 283 (16 Bit No) Saved At First Two Memory Locations...................................................28
Figure 5.1: Female Part Of Standard Serial Db9 Connector..............................................................29
Figure 5.2: RS232 To Usb Converter...............................................................................................31
Figure 5.3: Hercules Terminal ........................................................................................................31
Figure 5.4: Com 9 Is Usb To Serial Communication Port..................................................................32
Figure 5.5: Matlab Command Window...........................................................................................33
Figure 5.6: Input simulated wave...................................................................................................33
Figure 5.7: Reconstructed wave in MATLAB...................................................................................34
Figure 6.1: PCB File Designed In Proteus ........................................................................................35
Figure 6.3: Final Pcb Design In Orcade Software.............................................................................36
Figure 6.4: Finaly Encased Data Logger...........................................................................................37
Figure 6.4: Side and Back View of Data Logger ...............................................................................37
Figure 6.4: Lm-35 Temperature Sensor...........................................................................................38
Figure 6.5: Different Types Of Light Dependent Resistors ...............................................................39
Figure 6.6: MQ-2 Sensor................................................................................................................39
Figure 6.7: Variable Resistor..........................................................................................................40
RESTRICTED
11
RESTRICTED
CHAPTER01
INTRODUCTION
Project Title
1. Design and fabrication of microcontroller based four channel data logger.
Proposal Statement
2. This project is aimed at designing and fabrication of microcontroller based data
logger which is able to simultaneously store values from four different sensors that are
attached to its four input analog channels. The data is to be stored and can
subsequently be transferred to a PC using serial port.
Background and Overview
3. Data logger, also called data recorder is an electronic device that is able to
record data over time with help of external sensors. It is portable, battery powered, and
standalone device with a built-in memory and an interface for data transfer with a
personal computer.
4. Data logging has become the most common, useful and easy way of storing data
values taken from different sensors,without the requirementof user on the apparatus.
Data logger can record values from the sensor automatically. User can attach any
sensor whose output voltage is within the allowed voltage range for data logger input.
Data logger samplesthe inputs at user defined intervals and savesthe sample digital
values in external memory. Figures 1.1 and 1.2 show two of the commercial data
loggers available in market.
RESTRICTED
12
RESTRICTED
Figure 1.1: Data logger[1]
Figure 1.2: Modern data logger[2]
5. There are many different possible approaches to the design of data logger. For
example by using data acquisition card and recording data values from inputs of DAQ
card, which is further connected to PC in which data can be was acquired by some
software like LAB VIEW. However, the main drawback of this technique is the
mandatory requirement of a PC as the DAQ card can’t be used independently. Hence it
is not portable and economical. The main idea of this project was to design a
microcontroller based data logger that is independent of PC and is portable. Data
values should be recorded in some memory from where they can be transferred to PC
RESTRICTED
13
RESTRICTED
whenever required for subsequent analysis. Once in PC, appropriate software can be
used to see graphical trend of the data values.
6. The concept block diagram of data logger is shown in figure 1.3 below:-
Figure 1.3: Data logger block diagram
7. The microcontroller unit (MCU) is big revolution in electronics. It is one of the
most significant developments in electronics which has highly contributed in
miniaturization of electronic hardware.Microcontroller has three main elements i.e. I/O
pins, processor and a memory. I/O stands for input or output devices, which
communicate with the outside world. The function of processor is to make calculations
and handle data operations to provide results. The purpose of memory is to store
program and data. The microcontroller contains all these elements shown in figure 1.4
below, in one chip and is not like PC which has separate chips integrated to perform
these functions.
RESTRICTED
14
RESTRICTED
Figure 1.4: Elements of a Digital Controller[3]
8. Selection of PIC 16F877A. The main manufacturers of microcontrollers
are Intel, Atmel and Microchip. The Intel’s microcontroller taught and commonly used in
CAE is Intel 8051, and that of Microchip is PIC 16F877A. There are many differences in
both like inbuilt ADC channels in PIC 16F877A, total number of ports in both are
different and many other. After studying in detail about microcontrollers, the selected
microcontroller used in this project was PIC 16F877A due to its many additional
features over other compared microcontrollers. Some of thereasons for selection were:-
a) PIC 16F877A has inbuilt capability of analogtodigitalconversion (ADC) at
its eight pins iefrom AD0 to AD7.For a four channel data logger four input ADC
pins were required.
b) Two options are available for selecting the resolution of ADC ie 8 or 10 bit.
Due to less requirement of storage capacity, 8 bit ADC would be used.
9. Features of PIC 16F877A. Features of PIC 16F877A are:-
a) The A suffix in PIC 16F877A indicates that the chip can have maximum
clock speed of 20 MHz which is the main upgrade from the original 16F877
device.
RESTRICTED
15
RESTRICTED
c) The chip has 8K (8096 x14 bits) of flash ROM program memory. The
microcontroller stores its program in ROM (read only memory). It has 256 bytes
internal EEPROM.
d) The operating voltage range is 2-6 Volts. The maximum current that can
flow through any pin is 25mA at 5V. It has total five ports ie A, B, C, D and E and
has total of 33 I/O pins
10. Pin configuration diagram of PIC 16F877A is shown in figure 1.5 below:-
Figure 1.5: Pinconfiguration diagram of PIC 16F877A[4]
RESTRICTED
16
RESTRICTED
CHAPTER 02
PHASES AND SOFTWARES
PHASES
1. The project has two main phases which are required to be completed:-
a) Phase one is interfacing external components with microcontroller.
b) In second phase PC is to be interfaced withmicrocontroller.
2. Phase 1. In phase 1 was completed by interfacing the components that are
explained later in the report. Figure 2.1 shows the patch board picture of the hardware
components patched. All these components and methods would be explained later in
the report.
Figure 2.1 Patch board picture of circuit
3. Phase 2. In phase two PC was interfaced with the circuit and the figure 2.2
below shows the circuit.
Figure 2.2: Serial circuit
RESTRICTED
17
RESTRICTED
Software
4. CCS C Compiler. The microcontroller would be programmed to perform certain
task andthis can be done in either machine language or C language. Machine language
is not user friendly relatively to C language. Then C code would be compiled in some
suitable software to convertit into machine code. Many compilers like CCS compiler,
Mickro C compiler High Tec Care used. CCS C Compiler was selected and the source
code written is provided in appendix A at the end. CCS is shown in figure 2.2 below:-
Figure 2.2: CCS C compiler
5. IC Writer. It is the software that is supplied by the vendor with IC burner
which is used to burn the HEX file into the microcontroller. Microchip is to be selected
for PIC microcontrollers and it is shown in figure 2.3 below:-
Figure 2.3: IC writer
RESTRICTED
18
RESTRICTED
6. MATLAB. MATLAB would be used for analyzing the data in the form of
plots which would be explained later in the report. Figure 2.4 shows the matlab window
picture below:-
Figure 2.4: MATLAB window
7. Proteus User can simulate the program involving different components and
ICs in Proteus. The circuit is to be patched as it is in physical hardware and theHEX file,
the output file of CCS compiler, is given to the microcontroller along with the oscillating
frequency. The Proteus window is shown in figure 2.5 below:-
Figure 2.5: Proteus
8. The complete simulation diagram of Proteus is shown in figure 2.6 below.
RESTRICTED
19
RESTRICTED
Figure 2.6: Complete simulation diagram
RESTRICTED
20
RESTRICTED
CHAPTER03
COMPONENTS
1. The data logger would sample input values after the defined time interval and
along with time stamp theywould be saved in external memorytill either the memory is
full or the predefined time. Initially the internal EEPROM of the microcontroller was used
for the saving of data but it wasonly 256 bytes and large no of values can’t be saved. It
could only save 240 samples which is too less for an effective data logger. For
savinglarge number of observations an external EEPROM was used.
Components
2. External EEPROM. The selected external EEPROM chip Atmel 24C256 is a
serial memory chip and has storage capacity of 256K bits or 32K byteswith three
external address pins that are A0, A1, and A2. These three chips can be connected to
increase thestorage capacityto 96K bytes. The figure 3.1 shows the picture of Atmel
24C256. The pin configuration diagram of at24c256 is shown in figure 3.2 below:-
Figure 3.1: Atmel 24C256[5]
Figure 3.2: Pin configuration diagram of AT24c256[6]
RESTRICTED
21
RESTRICTED
3. Real Time Clock. External real time clock DS 1307 was used instead of
internal clock of microcontroller, to prevent it from intense load. It is an 8 pin IC including
SDA and SCL pin. The driver code for this RTC written in C language is provided at the
end of report in appendix C. A crystal of32.768 KHz is connected between pin 1 and 2.
Itcan also bepowered up from a backup battery.Figure 3.3 shows its pin configuration
diagram below:-
Figure 3.3: configuration diagram of DS-1307[7]
I2C Connection
4. At24c256 and DS-1307 are connected through I2C connection with PIC. The I2C
stands for interintegrated circuit bus which is used for short-range communication
between different chips and microcontroller. Chip used in thistype of connection is either
master or slave. Slave chip is attached to a two-wire bus andis pulled up to logic 1 when
idle. The basic form of the I2C connection is shown in figure 3.4 below:-
Figure 3.4: Basic form of the I2C connection[8]
5. The master chip first sends a control code to set up the transfer, then the 8-bit or
10-bit address code, and finally the data. Each byte has a start and acknowledge bit. To
RESTRICTED
22
RESTRICTED
improve reliabilityeach byte must be acknowledgedbefore sending the next byte. The
sequence to read a single byte requires a total of 5 bytes to complete the process, 3 to
set the address, and 2 to return the data. I2C signals are shown in figure 3.5 below:-
Figure 3.5: I2C signals[9]
6. LCD. 20x4 LCD has total 16 pins including enable, RS, RW, VCC, ground
and seven data pins. Enable pin of LCD would be connected to PIN_D0 of PIC,
similarly RS pin with PIN_D1 and RW pin with PIN_D2. Rest pins of D port except
PIN_D3 would be connected to data pins of the LCD. Initially 16x2 LCD was used for
display which was upgraded to 20x4. Driver code for this LCD written in C language is
provided in appendix B at the end of report. Its pin configuration is same as 20x4 LCD.
Figure 3.6 below shows20x4 LCD.
Figure 3.6: 16x2 LCD[10]
7. Keypad. 4x3Keypadwas used so that the user can interact with the
device. It’s * button would be used as OK button for selection of any feature.
RESTRICTED
23
RESTRICTED
8. IC 7805. Above 5V the voltage should be down converted to 5V to prevent
PIC from any damage. 6.5 volts rechargeable battery was used as DC source in circuit.
IC-7805 was used for converting 6.5 volts to exact 5 volts. It has three pins for input,
ground and output respectively.The output can vary from 4.8-5.2 volts andthe maximum
current allowed through it is 1 Amp. IC 7805 is shown in figure 3.7 below:-
Figure 3.7: IC-7805[11]
8. MAX 232. MAX 232 would be used for serial interface between the data
logger and PC. Transmit pin of MAX 232 will be connected to receive pin and vice
versa. Selected baud rate was 9600. The main function of MAX-232 is to convert the
level of PIC signals from 5 volts to 12 volts for PC. Figure 3.8 below shows picture of
MAX 232. Figure 3.9 below shows pin configuration diagram along with attached
capacitors of MAX 232.
Figure 3.8:Picture of MAX 232[12]
RESTRICTED
24
RESTRICTED
Figure 3.9: MAX 232 along with capacitors attached[13]
RESTRICTED
25
RESTRICTED
CHAPTER04
ADVANCE FEATURESAND MEMORY ALLOCATION
1. Conventional data loggers have some features which wererequired to be
amended and incorporate those in the required data logger. In this chapter all those
advance features would be explained and they would be compared with conventional
data loggers.
Advance Features
2. Conventional data loggers take input values after some fix time interval. The date
and time is already fed in its clock and it can only be changed from the code. Cheaply
available data loggers in the market are either single or dual channel.In the designed
data logger,memory is divided into number of parts equal to total number of channels
that have been used.
3. Variable Time interval. Designed data logger hasuser defined variable time
interval and is entered in the start of logging process whichcan be different for different
logging processes. The complete range for the time interval is from a minimum of one
second to a maximum of 255 minutes. Seconds are used for fast varying processes and
minutes are used for slow varying processes. Figure 4.1 below shows the picture of
LCD showing the entered time interval in seconds.
Figure 4.1: LCD showing the entered time interval in sec
RESTRICTED
26
RESTRICTED
4. Present and finish date and time. In conventional data loggers the date
and time can only be changed from the source code butthe designed data logger has
the capability of user defined present and finish date and time. Logging process will
automatically stop at predefined time. Figure 4.2below shows the picture LCD showing
the entered finish date. Similarly present date and time would be entered.
Figure 4.2: LCD showing the entered finish date
5. Variable no of Input Channels. Designed data logger has variable no of
channels. They could be different for different logging processes. Minimum no of
channels to be selected is one and a maximum of four can be selected.
6. Graphical trend analysis. The logged data would be analyzed in MATLAB
in form of graphs that would be plotted automatically after reception of data by Matlab
over serial interface.This would be explained later in the report.
7. No of Samples. The total no of samples takenwould be displayed on LCD.
Figure 4.3 below shows the picture of the sample no, date and time taken during the
execution of the program.
Figure 4.3: Picture of sample no along with date and time
RESTRICTED
27
RESTRICTED
8. Resolution. Resolution of the ADC channel that would be used is 8 bit.
Sensors would have output voltage from 0-5V. This means that a 9.6 mV change in
voltage would change the ADC level.8 bit means that ADC level assigned to each
voltage level would be within 0 to 255. The formula applied to specify ADC level to the
voltage is given below:-
ADC level value= (ADC value at channel / 255.0) * 5.0
9. Battery. A rechargeable battery was connected with the circuit to eliminate
its dependence on AC input power supply. It is a 4.5 Amp Hour battery, which means it
can supply 4.5 Amperes of current for one hour. The designed circuit draws current of
70mA, so it can survive over 2.5 days with this current requirement. Figure 4.4 shows
the picture of the rechargeable battery which was used.
Figure 4.4: Rechargeable battery
10. Frequency. Basically the data logger was designed for sensing slow varying
factors like temperature, humidity, light intensity etc. The minimum frequency of the
input sensor should be less than 0.25 Hz. It was tested after providing it with a sine
wave of frequency of 0.2 Hz. It recorded 5 values in every cycle and was able to draw
graph of the wave. This part would be explained later in the report.
RESTRICTED
28
RESTRICTED
Memory Allocation
11. Each sampled value is 8 bit soit requires one byte memory space for saving. The
basic idea of memory allocation is that if one channel is used the complete memory
would be dedicated for that sensor. If two channels are used the complete memory
would be divided into two parts. Similarly for three and four channels, memory would be
divided into three and four parts.
12. First 14 bytes dedicated. Data entered by the user in the startis saved on
first 14 bytes of the memory.The first byteis a number (123) that is for checking the
correct transfer of data over serial interface and its reception by the serial terminal. The
next five bytes are for the current date and time. The next five are for the finish date and
time. 12th byte saves no of used channels. 14th byte is the interval between two
consecutive readings. If previous value is 1 and 14th byte shows 5 as shown in figure, it
means that the interval is of 5 seconds. Rest all locations are for the data.
Figure 4.5: Memory allocation [14]
RESTRICTED
29
RESTRICTED
13. AT24C256 cannot be reset at start of every program execution as it is a
permanent memory. First two bytes of internal EEPROM of PIC would be used to store
the 16 bit number. Due to this, the ability to only transfer the values of the recent logging
process would be achieved. We need to reset this variable so that the new data logging
process can be started otherwise there is much chance garbagedata. Figure 4.7 shows
16 bit no saved at first two memory locations. A 16 bit no is required to cover all
memory locations. As only 8 bit no can be saved internal EEPROM‘s one memory
location, so we require two memory locations to save one 16 bit no.
Figure 4.6 : 247 (8 bit no) saved at first memory location
Figure 4.7 : 283 (16 bit no) saved at first two memory locations
RESTRICTED
30
RESTRICTED
CHAPTER 05
SERIAL INTERFACING ANDGRAPHICAL TREND ANALYSIS
1. The recordeddata is to be transferred to PC after the completion of logging
process for observing the trend. There could have been different approaches for
interfacing data logger with PC like wireless connection through antennas, wired serial
connection etc. The method selected for connection between PC and data logger was
serial connection using wires. There was a requirement that this data logger could be
connected to any PC easily without the need of any extra components which was the
most important reason for selection of this method. It was achieved by using the
standard DB-9 connector which is shown in figure 5.1. Nowadays serial DB-9 port is not
available in new PCs so serial to USB convertor was used for connection. The data
logger would utilize only one USB port.
Figure 5.1 Female part of standard serial DB9 connector[15]
Serial communication
2. Serial communication is a way enables different equipment to communicate with
outside world. It is called serial because the data bits will be sent in a serial way over a
single lineand transmission or reception of data one bit at a time would occur. A
personal computer has a serial port known as communication port or COM Port used to
connect a modem or any other device. Serial ports are controlled by a special chip
RESTRICTED
31
RESTRICTED
called UART (Universal Asynchronous Receiver Transmitter). Different applications use
different pins on the serial port and this basically depend of the functions required.
3. USART. The universal synchronous/asynchronous receive transmit
(USART) device is typicallyused in asynchronous mode to implement off-board, one-to-
one connections. The termasynchronousmeans that no separate clock signal is needed
to time the data reception, soonly a data send, data receive, and ground wires are
needed. It is quick and simple toimplement if a limited data bandwidth is acceptable.The
USART link can send data up to 100meters by converting the signal to higher-voltage
levels (typically 12 V). The digitalsignal is inverted and shifted to become bipolar
(symmetrical about 0 V, line negativewhen inactive) for transmission.PIC has a
dedicated hardware RS232 port, but CCS C allows any pin to beset up as an RS232
port, providing functions to generate the signals in software. Thebasic form of the signal
has 8 data bits, a stop and start bit. The bit period is set bythe baud rate whose typical
value is 9600 which is about 10 k bits per second.
4. MAX 232 level conversion. In order to connect a microcontroller to a serial
port on a PC computer, we need to adjust the level of the signals so communicating can
take place. The signal level on a PC is -10V for logic zero, and +10V for logic one. Since
the signal level on the microcontroller is +5V for logic one and 0V for logic zero, we
need an intermediary stage that will convert the levels. One chip specially designed for
this task is MAX232. This chip receives signals from -10 to +10V and converts them into
0 and 5V.
5. RS232 to USB converter. ModernPCs have USB ports instead of serial
ports. For utilization of USB port instead of serial port we will use RS 232 to USB
converter. It is a port-powered, bi-directional USB to RS232 adapter / USB to RS232
converter that can be used to convert any standard RS232 port into a USB port and vice
versa.Figure 5.2 below shows a RS232 to USB converter.
RESTRICTED
32
RESTRICTED
Figure 5.2: RS232 to USB converter[16]
6. Baud Rate. In telecommunication and electronics, baud is synonymous to
symbols per second or pulses per second. It is the unit of symbol rate, also known as
baud rate or modulation rate. The number of distinct symbol changes (signaling events)
made to the transmission medium per second in a digitally modulated signal or a line
code.
Serial Terminal
7. Serial terminals are used for reception of data transferred from microcontroller
and transferring data that can be received by microcontroller.Serial terminalused in
serial interfacing was Hercules.
8. Hercules. Hercules SETUP utility is useful serial port terminal which was
created for HW group internal use only, but today it's includes many functions in one
utility.Figure 5.3shows a Hercules terminal below:-
Figure 5.3: Hercules terminal
RESTRICTED
33
RESTRICTED
11. There are many properties that should be known for accurate serial
communication of data. The first and most important is baud rate. The second
characteristic is parity. The parity characteristic can be even, odd, mark, space, or none.
If even parity, then the last data bit transmitted will be a logical 1 if the data transmitted
had an even amount of 0 bits. If odd parity, then the last data bit transmitted will be a
logical 1 if the data transmitted had an odd amount of 0 bits.
13. Advantages. Serial communication has some advantages over the
parallel communication. One of the advantages is transmission distance. Serial link can
send data to a remote device, more far then parallel link. The cable connection of serial
link is simpler then parallel link and uses lessnumber of wires.
Method
14. Initially the RS 232 to USB conversion cable would be connected to any USB
port and the driver for this cable is installed. This driver is freely available on internet. A
COM port would be generated in the device manager. This port is noted and fed in the
serial terminal for serial connection. Figure 5.4 below shows COM port generated and
shown in device manger on connecting the cable in USB port.
Figure 5.4: COM 9 is USB to serial communication port
RESTRICTED
34
RESTRICTED
Graphical Trend Analysis in MATLAB
15. Analysis of therecordeddata would bedone in MATLAB.The code written in
MATLAB is provided in appendix D at the end. MATLAB would receive the data that is
sent at serial port of PC at specified baud rate. All the data entered in the start would be
displayed in the command window. Figure 5.5 below shows this data displayed in the
command window.
16. MATLAB automatically plots the graphs equal to the number sensors used. They
would be differentiated by plotting them by different colors and shapes. Figure 5.6below
shows the input wavesimulated in Proteus. This input wave was generated by charging
and discharging of capacitor through a resistor. Figure 5.7 below shows the
reconstructed wave in MATLAB.
Figure 5.5: Matlab command window
Figure 5.6: Input wavesimulated in Proteus
RESTRICTED
35
RESTRICTED
Figure 5.7: Reconstructed wave in MATLAB
RESTRICTED
36
RESTRICTED
CHAPTER 06
HARDWARE IMPLEMENTATION AND FINAL PRODUCT
Printed Circuit Board
1. The project was aimedat fabricating the data logger in a final product form so
itcould be properly packed in some casing. PCB is very necessary for a product to be in
its presentable form. First of all the PCB design wasto be made in some software and
then fabricate it on the PCB machine.
PCB Design Software
2. The machine available in CAE is compatible with Advance design system (ADS)
and Proteus. Initially PCB was designedin Proteus butdue to some fault, the PC was not
fabricating the Proteus design. Figure 6.1 shows the PCB file designed in Proteus
below:-
Figure 6.1: PCB file designed in Proteus
RESTRICTED
37
RESTRICTED
3. Orcad. Due to non-compatibility of PCB machine with Proteus, the PCB
was redesigned in Orcad software and finally fabricated from No 606 R&D Wing with
the help and guidance of Flying Officer Ali RazaGhumman.Figure 6.3 shows the final
PCB design ofOrcad software.All the green connections are showing ground signal. All
connections in red correspond to bottom layer and blue color corresponds to top layer.
Figure 6.3: Final PCB design in Orcad software
Final product
3. Data logger was given a final product form by encasing it, which was fabricated
by the help of IE workshop. Plastic sheet was used which was painted with silver color
to improve its aesthetics. Terminals for connection of sensors and the power button
were provided on the front side. LCD and keypad were provided on the inclined surface
for the ease of the user’s view. Buttons for transfer of data serially were provided at one
side along with the serial port. Battery charger input was given at the back side. Figure
6.4 below shows the finally encased data logger. Figure 6.5 provides the side and back
view of the data logger.
RESTRICTED
38
RESTRICTED
Figure 6.4: Finally encased data logger
Figure 6.5: Side and back view of data logger.
Sensors
4. The aim was not to attach complex sensors and design their difficult complex
driver circuits. Simple sensors were used during the testing of project which are:-
a) LM-35 temperature sensor
b) Light dependent resistor
c) MQ-2 smoke sensor
RESTRICTED
39
RESTRICTED
d) Variable resistor
e) Sine wave from function generator
5. LM-35 temperature sensor. LM35 is an integrated circuit sensor that can
be used to measure temperature with an electrical output proportional to the
temperature (in oC). This temperature sensor is an easy to use, cost-effective and has
decent accuracy of 0.5oC. It has three pins i.e. Vcc, Vout, and ground respectivelyOutput
is taken across a resistor of 10 k ohm that is connected between pin no 2 and ground.
The output voltage is between 0 and 1 volt. Figure 6.6 below shows the pin
configuration diagram of LM-35.Figure 6.7 shows the circuit diagram of LM-35.
Following conversion factor is used to convert voltage into temperature.
Temperature in degrees = Output voltage * 100
Figure 6.6: LM-35 temperature sensor[17]
Figure 6.7: Circuit diagram of LM-35[18]
RESTRICTED
40
RESTRICTED
6. Light dependent resistor. A light dependent resistor (LDR) is a resistor
whose resistance decreases with increasing incident light intensity. A photoresistor is
made of a high resistance semiconductor. If light falling on it is of high enough
frequency, photons absorbed by the semiconductor give bound electrons enough
energy to jump into the conduction band. The resulting free electron (and its hole
partner) conduct electricity, thereby lowering resistance. Figure 6.8 shows different
types of light dependent resistors below:-
Figure 6.8:Different types of light dependent resistors[19]
7. MQ-2 smoke sensor. MQ-2 is a simple smoke sensor which is used in gas
leakage detecting equipment in family and industry. They are suitable for detection of
LPG, i-butane, propane, methane, alcohol, Hydrogen and smoke. It has many
advantages over other smoke sensors which include wide detecting scope, fast
response and high sensitivity. Figure 6.9 below shows the picture of MQ-2 sensor.
Figure 6.9: MQ-2 sensor[20]
RESTRICTED
41
RESTRICTED
8. Variable resistor. It is aresistor whose value can be varied from 0 to
maximum. A knob is provided at the top of it to change the value of resistance. Variable
resistor of 50 K Ohm was used in the circuit. It has three pins similar to any other three
pin IC. Pin 1, 2 and 3 are for input voltage, ground and output voltage respectively. 5V
input voltage would be applied at input pin and the resistance was varied from 0-50 K
Ohm to get output voltage from 5-0 volts. The response of the variable resistor is
known, so the circuit can be checked for the exact response. The diagram of variable
resistor is shown in figure 6.10 below:-
Figure 6.10:Variable resistor[21]
9. Charging and Discharging of Capacitor. Capacitor was charged and
discharged through a resistorto check the response of MATLAB code. Graph plotted in
MATLAB was approximately exact as it was expected. The amplitude of this wave was
4.5 volts and had DC offset of approximately 2 volts. This offset was required to shift the
complete sine wave above zero value so that the microcontroller takes the accurate
values from ADC ports. Frequency of this wave is 0.2 Hz, so the time period is 5
seconds.
RESTRICTED
42
RESTRICTED
CHAPTERNO7
CONCLUSION
1. This chapter summarizes various tasks completed in this project. These were as
following:-
a) Understanding overall project and carrying out literature survey about
available data loggers
b) Studying different microcontrollers and understanding PIC16F877A
c) Understanding PIC C programming, IC writer, Proteus and Orcade
d) Compiling C program for keypad, DS1307 and external memory and
interfacing them with microcontroller
e) Transfer of logged data through serial port to PC
f) Graphical trend analysis of data in MATLAB
g) Design and fabrication of PCB
Project Deliverables for 8th Semester
2. The project deliverables for 8th semester are as following:-
a) Design and fabrication of data logger circuit with user interface.
b) Design and fabrication of data logger interface with PC.
c) Demonstration of maximum capacity of data logging capability with
suitable sensor.
d) Project documentation in form of project report.
RESTRICTED
43
RESTRICTED
Final Demonstration for 8th semester
3. Data logger can receive analog inputs from multiple sensors and then sample /
store these values as per user defined time interval. After the completion of logging
process, the logged data can be transferred to PC over a serial interface for subsequent
data analysis.
Additional Tasks
4. Additional tasks for the project were:-
a) Provide USB capability with the designed data logger.
b) Attach rechargeable battery along with the ac input source.
5. Rechargeable battery was attached with circuit successfully. It is 6.5 volts, 3.5
amp hour battery. So IC 7805 was used to provide exactly 5 volt to microcontroller. USB
capability cannot be added with PIC 16F877A. MMC/SD card is addressed in blocks of
512 bytes. PIC 16F877A has very less RAM i.e. 368 bytes. USB requires even more
RAM
6. The project was successfully completed and all the milestones were achieved
within the specifiedtime. Data Logger can form independent measurement and storage
system by hooking it up with suitable sensor. Measurement parameters could be:-
a) Humidity
b) Wind speed
c) Temperature
d) Voltage
RESTRICTED
44
RESTRICTED
REFERENCES
Ref [1],[2] www.dataloggerinc.com
Ref [3],[4],[8],[9] Programming-8BIT-PIC-MicroController
Ref [5],[6] www.microchip.com
Ref [7],[12] www.maxim.com
Ref [10],[19] www.extreme-electronics.com
Ref [10],[11] www.extreme-electronics.com
Ref [14] www.sodoityourself.com
Ref [15] Proteus software picture
Ref [16] www.romux.com
Ref [17] www.usbconvertors.com
Ref [18] www.engineersgarage.com
Ref [20] www.electronics-table.com
Ref [21] www.hwsensor.com
RESTRICTED
45
RESTRICTED
Appendices
Appendix A: C source code for data logger
Appendix B: Driver code for 4 line LCD
Appendix C: Driver code for DS-1307 real time clock
Appendix D: Matlab code for graphical trend analysis
RESTRICTED
46
RESTRICTED
Appendix A
C source code for data logger
#include <16F877A.h> //PIC 16F877A selected
#device adc=8 //8 or 10 bit can be selected. 8 bit resolution of ADC is selected
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (>4mhz)
#FUSES NOPUT //No Power Up Timer
#use delay(clock=20000000) //clock speed
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //Baud rate, transmit
//and recieve pin selected
#include <lcd44.c> //driver for 20x4 LCD
#include <ds1307.c> //driver for ds-1307 RTC
#define EEPROM_SDA PIN_C1 //SDA(serial data) pin selected
#define EEPROM_SCL PIN_C2 //SCL(serial clock) pin selected
#include <24256.c> //Driver for AT24c256 EEprom
int sec,mins,hrs,day,month,year,dow,x,numofdigs,channel,Fhrs,Fmin,hunsdig=0,tensdig=0,onesdig=0,
thoudig=0, Fday,Fmonth,m_Adc_Value,Fyear,yy,number;
void value(); //If the function is defined after main program
//then its prototype should be defined in start.
//prototype function named value defined.It would be explained later in the program.
int16pata,xx,zz=0,interval; //16 bit values defined
floatm_inp;
// getkey is a function for keypad. Whichever key would be pressed its value would be returned.
*key//would act as OK key.
intgetkey()
RESTRICTED
47
RESTRICTED
{
int i;
while(1)
{
//Checking Row 1
output_low(PIN_B4); //output logic 0 at pin B4
output_high(PIN_B5); //output logic 1 at pin B5
output_high(PIN_B6);
output_high(PIN_B7);
i=0;
while(i<10)
{
if(!input(PIN_B0))
{
while(!input(PIN_B0));
return x=1; //Return value of x as 1
break; //Leave the loop
}
else if(!input(PIN_B1))
{
while(!input(PIN_B1));
return x=2;
break;
}
else if(!input(PIN_B2))
{
while(!input(PIN_B2));
return x=3;
break;
}
i=i+1;
delay_ms(5);
RESTRICTED
48
RESTRICTED
}
//Checking Row 2
output_high(PIN_B4);
output_low(PIN_B5);
output_high(PIN_B6);
output_high(PIN_B7);
i=0;
while(i<10)
{
if(!input(PIN_B0))
{
while(!input(PIN_B0));
return x=4;
break;
}
else if(!input(PIN_B1))
{
while(!input(PIN_B1));
return x=5;
break;
}
else if(!input(PIN_B2))
{
while(!input(PIN_B2));
return x=6;
break;
}
i=i+1;
delay_ms(5);
}
//Checking Row 3
output_high(PIN_B4);
output_high(PIN_B5);
RESTRICTED
49
RESTRICTED
output_low(PIN_B6);
output_high(PIN_B7);
i=0;
while(i<10)
{
if(!input(PIN_B0))
{
while(!input(PIN_B0));
return x=7;
break;
}
else if(!input(PIN_B1))
{
while(!input(PIN_B1));
return x=8;
break;
}
else if(!input(PIN_B2))
{
while(!input(PIN_B2));
return x=9;
break;
}
i=i+1;
delay_ms(5);
}
//Checking Row 4
output_high(PIN_B4);
output_high(PIN_B5);
output_high(PIN_B6);
output_low(PIN_B7);
i=0;
while(i<10)
{
RESTRICTED
50
RESTRICTED
if(!input(PIN_B0))
{
while(!input(PIN_B0));//printf(lcd_putc,"f"); //star key breaks the function and
// acts as ok key
return x=100;
break;
}
else if(!input(PIN_B1))
{
while(!input(PIN_B1));
return x=0;
break;
}
else if(!input(PIN_B2))
{
while(!input(PIN_B2));
return x=200;
break;
}
i=i+1;
delay_ms(5);
}
}
}
// Pause function is for giving delay or pause between acquirement of two consecutive input values.The
//pause should be equal to the time interval entered in start of data logging process that is either in
//second or minutes. During the pause the time and date would be shown on LCD.
void pause(void)
{
ints,t;
zz++;
ds1307_get_date(day,month,year,dow); //get date from DS-1307
RESTRICTED
51
RESTRICTED
ds1307_get_time(hrs,mins,sec); //get time from DS-1307
printf(lcd_putc,"fTime : %02u:%02u:%02u",hrs,mins,sec); //Display time on LCD
lcd_gotoxy(1,2);
printf(lcd_putc,"Date : %02u:%02u:%02u",day,month,year); //Display date on LCD
lcd_gotoxy(1,3);
printf(lcd_putc,"Waiting for input.");
lcd_gotoxy(1,4);
printf(lcd_putc,"Sample # %lu",zz); //No of acquired samples would be shown
if(number==1){ //Pause loop for 1 second
for(t=0;t<(interval);t++)
{
delay_ms(900);
}
}
if(number==2){ //Pause loop for 1 minute
for(t=0;t<(interval);t++)
{
for(s=0;s<60;s++)
{
delay_ms(950);
}
}
}
}
//checkchannel is a function for selecting the no of channels by data logger and switching the ADC pins
//equal to the channels entered.
voidcheck_channel(void)
{
floatm_inp;
if(channel==1)
{
set_adc_channel(0); //set to read ADC channel 0
RESTRICTED
52
RESTRICTED
delay_ms(10);
m_Adc_Value=read_adc(); //get 8 bit readig for channel 0
delay_ms(10);
m_inp=(m_Adc_Value/255.0)* 5; //Conversion factor
printf(lcd_putc,"fvoltage1=%3.3f",m_inp); //Print voltage value at LCD
write_ext_eeprom(pata,m_Adc_Value); //Write to external EEPROM at location variable that is pata
delay_ms(10);
pata++; //increment in pata for next value to be saved at next location
delay_ms(1500);
}
else if(channel==2)
{
set_adc_channel(0);
delay_ms(20);
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
printf(lcd_putc,"fvoltage1=%3.3f",m_inp);
set_adc_channel(1); //ADC Channel 1
delay_ms(20); //Donot remove delay
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
lcd_gotoxy(1,2); //Goto 2nd line of LCD
printf(lcd_putc,"voltage2=%3.3f",m_inp);
delay_ms(1500);
}
else if(channel==3)
{
RESTRICTED
53
RESTRICTED
set_adc_channel(0); //ADC Channel 0
delay_ms(10); //Donot remove delay
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
printf(lcd_putc,"fvoltage1=%3.3f",m_inp);
set_adc_channel(1); //ADC Channel 1
delay_ms(10);
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
lcd_gotoxy(1,2);
printf(lcd_putc,"voltage2=%3.3f",m_inp);
set_adc_channel(2); //ADC Channel 1
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
lcd_gotoxy(1,3); //Goto 3rd line of LCD
printf(lcd_putc,"voltage3=%3.3f",m_inp);
delay_ms(2000);
}
else if(channel==4)
{
set_adc_channel(0); //ADC Channel 0
delay_ms(20);
m_Adc_Value=read_adc();
delay_ms(10);
RESTRICTED
54
RESTRICTED
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
printf(lcd_putc,"fvoltage1=%3.3f",m_inp);
set_adc_channel(1); //ADC Channel 1
delay_ms(20); //Donot remove delay
m_Adc_Value=read_adc();
delay_ms(10); //ADC needs some time for reading input so Donot remove this delay
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
lcd_gotoxy(1,2);
printf(lcd_putc,"voltage2=%3.3f",m_inp);
set_adc_channel(2); //ADC Channel 1
delay_ms(10);
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
lcd_gotoxy(1,3);
printf(lcd_putc,"voltage3=%3.3f",m_inp);
set_adc_channel(3); //ADC Channel 1
delay_ms(10);
m_Adc_Value=read_adc();
delay_ms(10);
write_ext_eeprom(pata,m_Adc_Value);
delay_ms(10);
pata++;
m_inp=(m_Adc_Value/255.0)*5.0;
delay_ms(10);
lcd_gotoxy(1,4);
printf(lcd_putc,"voltage4=%3.3f",m_inp);
delay_ms(2000);
RESTRICTED
55
RESTRICTED
}
}
// makenum is a function due to which we don’t have to define an array of number entered by
keypad.this//function automatically makes number even if is 2 or 3 digit
voidmakenum()
{
numofdigs++;
if(numofdigs==4)
{
thoudig=hunsdig;hunsdig = tensdig; tensdig = onesdig; onesdig = x;
}
if(numofdigs==3)
{
hunsdig = tensdig; tensdig = onesdig; onesdig = x;
}
if(numofdigs==2)
{
tensdig=onesdig; onesdig = x;
}
if(numofdigs==1)
onesdig = x;
}
//Loop for printing no pressed on keypad on the LCD.
void again(void)
{
do
{
x=getkey();
if(x==100)
break;
else
RESTRICTED
56
RESTRICTED
{
printf(lcd_putc,"%u",x);delay_ms(250);
if((x>=0)&&(x<=9))
makenum();
}
}while((x>=0)&&(x<=9)) //execute this loop until entered no is between 1 to 9
}
void start(void)
{
write_ext_eeprom(0,11); //Write 11 on location 0 of EEPROM
delay_ms(15);
write_ext_eeprom(1,22);
delay_ms(15);
printf(lcd_putc,"fEnter complete date");
lcd_gotoxy(1,2); //Goto 2nd line of LCD
printf(lcd_putc,"and time.Enter day");
lcd_gotoxy(1,3);
printf(lcd_putc,"Day : ");
again();
delay_ms(15);
day=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); //Forming the no of
//value entered by keypad
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,day);
pata++;
delay_ms(20);
lcd_gotoxy(1,4);
printf(lcd_putc,"Enter Month : ");
again();
month=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata, month);
pata++;
delay_ms(20);
RESTRICTED
57
RESTRICTED
printf(lcd_putc,"fEnter year : ");
again();
year=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
write_ext_eeprom(pata,year);
pata++;
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
delay_ms(20);
lcd_gotoxy(1,2);
printf(lcd_putc,"Enter current time");
lcd_gotoxy(1,3);
printf(lcd_putc,"Enter Hours : ");
again();
hrs=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
write_ext_eeprom(pata,hrs);
pata++;
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
delay_ms(20);
lcd_gotoxy(1,4);
printf(lcd_putc,"Enter Mins : ");
again();
mins=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,mins);
pata++;
delay_ms(20);
printf(lcd_putc,"fEnter finish date ");
lcd_gotoxy(1,2);
printf(lcd_putc,"and time.Enter time");
lcd_gotoxy(1,3);
printf(lcd_putc,"Enter hours : ");
again();
Fhrs=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
RESTRICTED
58
RESTRICTED
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,Fhrs);
pata++;
delay_ms(20);
lcd_gotoxy(1,4);
printf(lcd_putc,"Enter min : ");
again();
Fmin=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
delay_ms(10);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,Fmin);
pata++;
delay_ms(20);
printf(lcd_putc,"fEnter Finish Date");
lcd_gotoxy(1,2);
printf(lcd_putc,"Enter Day : ");
again();
Fday=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,Fday);
pata++;
delay_ms(20);
lcd_gotoxy(1,3);
printf(lcd_putc,"Enter Month : ");
again();
Fmonth=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,Fmonth);
pata++;
delay_ms(20);
lcd_gotoxy(1,4);
printf(lcd_putc,"Enter Year : ");
again();
RESTRICTED
59
RESTRICTED
Fyear=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,Fyear);
pata++;
delay_ms(20);
printf(lcd_putc,"fEnter no of channels");
lcd_gotoxy(1,2);
printf(lcd_putc,"to be used.");
lcd_gotoxy(1,3);
printf(lcd_putc,"Channels: ");
again();
channel=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,channel);
pata++;
delay_ms(20);
printf(lcd_putc,"fEnter gap b/w input");
lcd_gotoxy(1,2);
printf(lcd_putc,"values.Press 1 for");
lcd_gotoxy(1,3);
printf(lcd_putc,"seconds.Press 2 for");
lcd_gotoxy(1,4);
printf(lcd_putc,"minutes : ");
again();
number=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
write_ext_eeprom(pata,number);
delay_ms(20);
pata++;
printf(lcd_putc,"fEnter Interval : ");
again();
interval=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
RESTRICTED
60
RESTRICTED
write_ext_eeprom(pata,interval);
delay_ms(20);
pata++;
}
//Checktime is a function which compares the start time and date with finish time and date in every loop.
//when they are same or when start time and date
//match with finish time and date.
voidchecktime(void)
{
if((Fhrs==hrs)&&(Fmin==mins)&&(Fday==day)&&(Fmonth=month)&&(Fyear==year))
{
output_high(PIN_A5);
while(1)
{
lcd_putc("fFinish time reached");
delay_ms(1000);
}
}
}
void main() //Main function
{
pata=2;
lcd_init(); //Initialize LCD
delay_ms(10);
init_ext_eeprom(); //Initialize external EEPROM
delay_ms(10);
ds1307_init(); //Initialize DS-1307
delay_ms(10);
if(input(PIN_C0)) //push button at PIN_C0
{
printf(lcd_putc,"fSending saved data");
RESTRICTED
61
RESTRICTED
xx=read_int16_eeprom(0); //read location 0 of internal
EEPROM of PIC
yy = read_ext_eeprom(0);
delay_ms(10);
printf("%unr",yy); //send value of variable
printf("%lunr",xx);
delay_ms(10);
value();
}
if(input(PIN_B3))
{
write_int16_eeprom(0,0); //write on internal EEPROM of PIC at
location 0
write_int16_eeprom(1,0);
}
start();
ds1307_set_date_time(day,month,year,3,hrs,mins,50); //Set date and time of DS-1307
delay_ms(10);
setup_adc(ADC_CLOCK_INTERNAL); // ADC clock
setup_adc_ports(ALL_ANALOG);
delay_ms(20);
while(1) //Infinite loop
{
check_channel();
xx=pata; //last memory location saved
write_int16_eeprom(0,xx);
delay_ms(10);
checktime();
pause();
}
RESTRICTED
62
RESTRICTED
}
//value is the function for transfering all data values from external memory to PC serially
void value()
{
pata=1;
while(pata<15) //first 14 dedicated bytes
{
yy = read_ext_eeprom(pata);
delay_ms(10);
printf("%unr",yy);
delay_ms(10);
pata++;
}
pata=15;
delay_ms(10);
while(pata<xx) //Loop for sendng all data values saved to PC serially
{
m_inp=(read_ext_eeprom(pata)/255.0)*5;
delay_ms(10);
printf("%3.3fnr",m_inp);
delay_ms(10);
pata++;
}
pata=xx;
}
RESTRICTED
63
RESTRICTED
Appendix B
Driver code for 20x4 LCD
// Flex_LCD420.c
// These pins are for my Microchip PicDem2-Plus board,
// which I used to test this driver.
// An external 20x4 LCD is connected to these pins.
// Change these pins to match your own board's connections.
#define LCD_DB4 PIN_D4
#define LCD_DB5 PIN_D5
#define LCD_DB6 PIN_D6
#define LCD_DB7 PIN_D7
#define LCD_RS PIN_D1
#define LCD_RW PIN_D2
#define LCD_E PIN_D0
// If you want only a 6-pin interface to your LCD, then connect the R/W pin on the LCD to ground, and
//comment out the following line. Doing so will save one PIC pin, but at the cost of losing the ability to
//read from the LCD. It also makes the write time a little longer because a static delay must be used,
//instead of pollingthe LCD's busy bit. Normally a 6-pin interface is onlyused if you are running out of
//PIC pins, and you need to use as few as possible for the LCD.
#define USE_RW_PIN 1
// These are the line addresses for most 4x20 LCDs.
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54
//========================================
RESTRICTED
64
RESTRICTED
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines(or more)
int8 lcd_line;
int8const LCD_INIT_STRING[4] =
{
0x20 | (lcd_type<< 2), // Set mode: 4-bit, 2+ lines, 5x8 dots
0xc, // Display on
1, // Clear display
6 // Increment cursor
};
//-------------------------------------
voidlcd_send_nibble(int8 nibble)
{
// Note: !!converts an integer expression to a boolean (1 or 0).
output_bit(LCD_DB4, !!(nibble& 1));
output_bit(LCD_DB5, !!(nibble& 2));
output_bit(LCD_DB6, !!(nibble& 4));
output_bit(LCD_DB7, !!(nibble& 8));
delay_cycles(1);
output_high(LCD_E);
delay_us(2);
output_low(LCD_E);
}
// This sub-routine is only called by lcd_read_byte().It's not a stand-alone routine. For example, the
// R/W signal is set high by lcd_read_byte() before this routine is called.
#ifdef USE_RW_PIN
int8 lcd_read_nibble(void)
{
int8retval;
// Create bit variables so that we can easily setindividual bits in the retval variable.
#bit retval_0 = retval.0
#bit retval_1 = retval.1
RESTRICTED
65
RESTRICTED
#bit retval_2 = retval.2
#bit retval_3 = retval.3
retval = 0;
output_high(LCD_E);
delay_us(1);
retval_0 = input(LCD_DB4);
retval_1 = input(LCD_DB5);
retval_2 = input(LCD_DB6);
retval_3 = input(LCD_DB7);
output_low(LCD_E);
delay_us(1);
return(retval);
}
#endif
// Read a byte from the LCD and return it.
#ifdef USE_RW_PIN
int8 lcd_read_byte(void)
{
int8 low;
int8 high;
output_high(LCD_RW);
delay_cycles(1);
high = lcd_read_nibble();
low = lcd_read_nibble();
return( (high<<4) | low);
}
RESTRICTED
66
RESTRICTED
#endif
//----------------------------------------
// Send a byte to the LCD.
voidlcd_send_byte(int8 address, int8 n)
{
output_low(LCD_RS);
#ifdef USE_RW_PIN
while(bit_test(lcd_read_byte(),7)) ;
#else
delay_us(60);
#endif
if(address)
output_high(LCD_RS);
else
output_low(LCD_RS);
delay_cycles(1);
#ifdef USE_RW_PIN
output_low(LCD_RW);
delay_cycles(1);
#endif
output_low(LCD_E);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
//----------------------------
voidlcd_init(void)
{
int8 i;
RESTRICTED
67
RESTRICTED
lcd_line = 1;
output_low(LCD_RS);
#ifdef USE_RW_PIN
output_low(LCD_RW);
#endif
output_low(LCD_E);
// Some LCDs require 15 ms minimum delay afterpower-up. Others require 30 ms.
// To set it to 35 ms, so it should work withall of them.
delay_ms(35);
for(i=0 ;i < 3; i++)
{
lcd_send_nibble(0x03);
delay_ms(5);
}
lcd_send_nibble(0x02);
for(i=0; i <sizeof(LCD_INIT_STRING); i++)
{
lcd_send_byte(0, LCD_INIT_STRING[i]);
// If the R/W signal is not used, thenthe busy bit can't be polled. One ofthe init commands takes longer
//thanthe hard-coded delay of 50 us, so inthat case, lets just do a 5 ms delay after all four of them.
#ifndef USE_RW_PIN
delay_ms(5);
#endif
}
}
//----------------------------
RESTRICTED
68
RESTRICTED
voidlcd_gotoxy(int8 x, int8 y)
{
int8 address;
switch(y)
{
case 1:
address = LCD_LINE_1_ADDRESS;
break;
case 2:
address = LCD_LINE_2_ADDRESS;
break;
case 3:
address = LCD_LINE_3_ADDRESS;
break;
case 4:
address = LCD_LINE_4_ADDRESS;
break;
default:
address = LCD_LINE_1_ADDRESS;
break;
}
address += x-1;
lcd_send_byte(0, 0x80 | address);
}
//-----------------------------
voidlcd_putc(char c)
{
RESTRICTED
69
RESTRICTED
switch(c)
{
case 'f':
lcd_send_byte(0,1);
lcd_line = 1;
delay_ms(2);
break;
case 'n':
lcd_gotoxy(1, ++lcd_line);
break;
case 'b':
lcd_send_byte(0,0x10);
break;
default:
lcd_send_byte(1,c);
break;
}
}
#ifdef USE_RW_PIN
charlcd_getc(int8 x, int8 y)
{
char value;
lcd_gotoxy(x,y);
// Wait until busy flag is low.
while(bit_test(lcd_read_byte(),7));
output_high(LCD_RS);
value = lcd_read_byte();
output_low(LCD_RS);
return(value);
}
#endif
RESTRICTED
70
RESTRICTED
Appendix C
Driver code for DS-1307
//ds1307_init() - Enable oscillator without clearing the seconds register used when PIC loses power and
//DS1307 run from 3V BAT
// ds1307_set_date_time(day,mth,year,dow,hour,min,sec) Set the date/time
// ds1307_get_date(day,mth,year,dow) Get the date
// ds1307_get_time(hr,min,sec) Get the time
#define RTC_SDA PIN_C4
#define RTC_SCL PIN_C3
#use i2c(master, sda=RTC_SDA, scl=RTC_SCL)
BYTE bcd2bin(BYTE bcd_value);
BYTE bin2bcd(BYTE binary_value)
{
BYTE temp;
BYTE retval;
temp = binary_value;
retval = 0;
while(1)
{
// Get the tens digit by doing multiple subtractionof 10 from the binary value.
if(temp >= 10)
{
temp -= 10;
retval += 0x10;
}
else // Get the ones digit by adding the remainder.
{
retval += temp;
break;
RESTRICTED
71
RESTRICTED
}
}
return(retval);
}
// Input range - 00 to 99.
BYTE bcd2bin(BYTE bcd_value)
{
BYTE temp;
temp = bcd_value;
// Shifting upper digit right by 1 is same as multiplying by 8.
temp>>= 1;
// Isolate the bits for the upper digit.
temp&= 0x78;
// Now return: (Tens * 8) + (Tens * 2) + Ones
return(temp + (temp >> 2) + (bcd_value& 0x0f));
}
void ds1307_init(void)
{
BYTE seconds = 0;
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_start();
i2c_write(0xD1); // RD from RTC
seconds = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
i2c_stop();
seconds&= 0x7F;
delay_us(3);
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_write(bin2bcd(seconds)); // Start oscillator with current "seconds value
RESTRICTED
72
RESTRICTED
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x07); // Control Register
i2c_write(0x80); // Disable squarewave output pin
i2c_stop();
}
void ds1307_set_date_time(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE
sec)
{
sec&= 0x7F;
hr&= 0x3F;
i2c_start();
i2c_write(0xD0); // I2C write address
i2c_write(0x00); // Start at REG 0 - Seconds
i2c_write(bin2bcd(sec)); // REG 0
i2c_write(bin2bcd(min)); // REG 1
i2c_write(bin2bcd(hr)); // REG 2
i2c_write(bin2bcd(dow)); // REG 3
i2c_write(bin2bcd(day)); // REG 4
i2c_write(bin2bcd(mth)); // REG 5
i2c_write(bin2bcd(year)); // REG 6
i2c_write(0x80); // REG 7 - Disable squarewave output pin
i2c_stop();
}
void ds1307_get_date(BYTE &day, BYTE &mth, BYTE &year, BYTE &dow)
{
i2c_start();
i2c_write(0xD0);
i2c_write(0x03); // Start at REG 3 - Day of week
i2c_start();
i2c_write(0xD1);
dow = bcd2bin(i2c_read() & 0x7f); // REG 3
day = bcd2bin(i2c_read() & 0x3f); // REG 4
RESTRICTED
73
RESTRICTED
mth = bcd2bin(i2c_read() & 0x1f); // REG 5
year = bcd2bin(i2c_read(0)); // REG 6
i2c_stop();
}
void ds1307_get_time(BYTE &hr, BYTE &min, BYTE &sec)
{
i2c_start();
i2c_write(0xD0);
i2c_write(0x00); // Start at REG 0 - Seconds
i2c_start();
i2c_write(0xD1);
sec = bcd2bin(i2c_read() & 0x7f);
min = bcd2bin(i2c_read() & 0x7f);
hr = bcd2bin(i2c_read(0) & 0x3f);
i2c_stop();
}
RESTRICTED
74
RESTRICTED
Appendix D
MATLAB code for Graphical trend analysis
delete(instrfindall); % Delete all previous COM ports
clear all
clc % Clear screen
s=serial('COM9', 'BaudRate', 9600); % Change to required COM
fopen(s); % Open the serial port for r/w
hold on
n=1;
while (n<4)
Vp = fscanf(s); % Read Data back from serial port
Vp=str2double(Vp); % String to double conversion
E(n) = Vp;
n=n+1;
end
x=1;
while (x<=E(2))
Vt = fscanf(s);
Vt=str2double(Vt);
C(x) = Vt;
x=x+1;
end
fclose(s); % Close the serial port
delete(s); % Delete the serial port
day=C(1); % Assign values to variables
month=C(2);
year=C(3);
hours=C(4);
mins=C(5);
Fhours=C(6);
Fmins=C(7);
RESTRICTED
75
RESTRICTED
Fday=C(8);
Fmonth=C(9);
Fyear=C(10);
channel=C(11);
number=C(12);
interval=C(13);
for i=14:length(C)
j=i-13;
voltage(j)=C(i);
end
disp(['No. of channels used were: ', num2str(C(11))]) %Display no of channels in command window
disp(['Start time was ', num2str(C(4)),':',num2str(C(5)),':50'])
disp(['Start date was ', num2str(C(1)),'/',num2str(C(2)),'/',num2str(C(3))])
disp(['Finish time was ', num2str(C(6)),':',num2str(C(7))])
disp(['Finish date was ', num2str(C(8)),'/',num2str(C(9)),'/',num2str(C(10))])
if C(12)==1
disp(['Interval used between two sampled input values was: ', num2str(C(13)),' seconds'])
elseif C(12)==2
disp(['Interval used between two sampled input values was: ', num2str(C(13)),' minutes'])
end
hold on;
title('Data Logger Sensor#1 values'); %title of figure
ylabel('Voltage value axis'); % Label of Y axix of figure
xlabel('Reading# axis'); % Label of X axix of figure
ylim([25 45]);
if C(11)==1
Channel_1=C(14:length(C));
Channel_1=Channel_1*100;
RESTRICTED
76
RESTRICTED
disp(['Number of reading from each sensor are ',num2str(length(Channel_1))])
plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5)
% Characteristics of graph
h = legend('Channel#1',1); % Legend for figure
set(h,'Interpreter','none')
elseif C(11)==2
Channel_1=C(14:2:length(C));
Channel_1=Channel_1*100;
Channel_2=C(14:2:length(C));
disp(['Number of reading from each sensor are ',num2str(length(Channel_2))])
plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5)
h = legend('Channel#1',1);
figure(2); % Plot second figure
plot(Channel_2,'--b*','LineWidth',1,'MarkerEdgeColor','m','MarkerFaceColor','g','MarkerSize',5)
title('Data Logger Sensor#2 values');
ylabel('Voltage value axis');
xlabel('Reading# axis');
ylim([0 5]);
h = legend('Channel#2',1);
set(h,'Interpreter','none')
elseif C(11)==3
Channel_1=C(17:3:length(C));
Channel_1=Channel_1*100;
Channel_2=C(18:3:length(C));
Channel_3=C(19:3:length(C));
disp(['Number of reading from each sensor are ',num2str(length(Channel_2))])
figure(1);
plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5)
h = legend('Channel#1',1);
figure(2);
plot(Channel_2,'--b*','LineWidth',1,'MarkerEdgeColor','m','MarkerFaceColor','g','MarkerSize',5)
title('Data Logger Sensor#2 values');
ylabel('Voltage value axis');
xlabel('Reading# axis');
RESTRICTED
77
RESTRICTED
ylim([0 5]);
h = legend('Channel#2',1);
figure(3);
plot(Channel_3,'--ms','LineWidth',1,'MarkerEdgeColor','r','MarkerFaceColor','y','MarkerSize',5)
title('Data Logger Sensor#3 values');
ylabel('Voltage value axis');
xlabel('Reading# axis');
ylim([0 5]);
h = legend('Channel#3',1);
set(h,'Interpreter','none')
elseif C(11)==4
Channel_1=C(17:4:length(C));
Channel_1=Channel_1*100;
Channel_2=C(18:4:length(C));
Channel_3=C(19:4:length(C));
Channel_4=C(20:4:length(C));
disp(['Number of reading from each sensor are ',num2str(length(Channel_2))])
plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5)
h = legend('Channel#1',1);
figure(2);
plot(Channel_2,'--b*','LineWidth',1,'MarkerEdgeColor','m','MarkerFaceColor','g','MarkerSize',5)
title('Data Logger Sensor#2 values');
ylabel('Voltage value axis');
xlabel('Reading# axis');
ylim([0 5]);
h = legend('Channel#2',1);
figure(3);
plot(Channel_3,'--ms','LineWidth',1,'MarkerEdgeColor','r','MarkerFaceColor','y','MarkerSize',5)
title('Data Logger Sensor#3 values');
ylabel('Voltage value axis');
xlabel('Reading# axis');
RESTRICTED
78
RESTRICTED
ylim([0 5]);
h = legend('Channel#3',1);
figure(4);
plot(Channel_4,'--go','LineWidth',1,'MarkerEdgeColor','y','MarkerFaceColor','r','MarkerSize',5)
title('Data Logger Sensor#4 values');
ylabel('Voltage value axis');
xlabel('Reading# axis');
ylim([0 5]);
h = legend('Channel#4',1);
set(h,'Interpreter','none')
end
Homework Help
https://www.homeworkping.com/
Math homework help
https://www.homeworkping.com/
Research Paper help
https://www.homeworkping.com/
Algebra Help
https://www.homeworkping.com/
Calculus Help
https://www.homeworkping.com/
Accounting help
https://www.homeworkping.com/
Paper Help
https://www.homeworkping.com/
RESTRICTED
79
RESTRICTED
Writing Help
https://www.homeworkping.com/
Online Tutor
https://www.homeworkping.com/
Online Tutoring
https://www.homeworkping.com/

More Related Content

Viewers also liked

172970484 case-sulit
172970484 case-sulit172970484 case-sulit
172970484 case-sulithomeworkping8
 
210236505 nephrotic-case-study
210236505 nephrotic-case-study210236505 nephrotic-case-study
210236505 nephrotic-case-studyhomeworkping8
 
127385992 case-diare
127385992 case-diare127385992 case-diare
127385992 case-diarehomeworkping8
 
Information google apps
Information google appsInformation google apps
Information google appsinovallee
 
CMSday 2013 - Doper votre audience en optimisant votre référencement ?
CMSday 2013 - Doper votre audience en optimisant votre référencement ?CMSday 2013 - Doper votre audience en optimisant votre référencement ?
CMSday 2013 - Doper votre audience en optimisant votre référencement ?Smile I.T is open
 

Viewers also liked (6)

172970484 case-sulit
172970484 case-sulit172970484 case-sulit
172970484 case-sulit
 
210236505 nephrotic-case-study
210236505 nephrotic-case-study210236505 nephrotic-case-study
210236505 nephrotic-case-study
 
127385992 case-diare
127385992 case-diare127385992 case-diare
127385992 case-diare
 
Information google apps
Information google appsInformation google apps
Information google apps
 
CMSday 2013 - Doper votre audience en optimisant votre référencement ?
CMSday 2013 - Doper votre audience en optimisant votre référencement ?CMSday 2013 - Doper votre audience en optimisant votre référencement ?
CMSday 2013 - Doper votre audience en optimisant votre référencement ?
 
Communiqué de presse 2017
Communiqué de presse 2017Communiqué de presse 2017
Communiqué de presse 2017
 

Similar to 125692800 data-logger

Dual-Band Mobile Phone Jammer
Dual-Band Mobile Phone JammerDual-Band Mobile Phone Jammer
Dual-Band Mobile Phone JammerMohamed Atef
 
ALMAULY_WALEED_LINKREPORT
ALMAULY_WALEED_LINKREPORTALMAULY_WALEED_LINKREPORT
ALMAULY_WALEED_LINKREPORTWaleed Almauly
 
Project final report
Project final reportProject final report
Project final reportALIN BABU
 
LPG Booking System [ bookmylpg.com ] Report
LPG Booking System [ bookmylpg.com ] ReportLPG Booking System [ bookmylpg.com ] Report
LPG Booking System [ bookmylpg.com ] ReportNandu B Rajan
 
Front of V D report pdf
Front of V D report pdfFront of V D report pdf
Front of V D report pdfShiva Nand
 
Highway wind turbine report
Highway wind turbine reportHighway wind turbine report
Highway wind turbine reportAli Rehman
 
Training_report23155.ppt
Training_report23155.pptTraining_report23155.ppt
Training_report23155.pptsatyam537911
 
Proceso de Diseño de Líneas de Transmisión
Proceso de Diseño de Líneas de TransmisiónProceso de Diseño de Líneas de Transmisión
Proceso de Diseño de Líneas de Transmisiónssuser2bab32
 
D7.1 project management handbook
D7.1 project management handbookD7.1 project management handbook
D7.1 project management handbookBabak Sorkhpour
 
BRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdf
BRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdfBRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdf
BRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdfJaco Voorspuij
 
21020-BAB-04101-HS-PR-0005_C1 FINAL
21020-BAB-04101-HS-PR-0005_C1 FINAL21020-BAB-04101-HS-PR-0005_C1 FINAL
21020-BAB-04101-HS-PR-0005_C1 FINALGeorge Ralph
 
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...DavidCarlosXaveriusP
 
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...DavidCarlosXaveriusP
 
Ip aiim anuj rawat
Ip aiim anuj rawatIp aiim anuj rawat
Ip aiim anuj rawatAnuj Rawat
 
Ip aiim anuj rawat
Ip aiim anuj rawatIp aiim anuj rawat
Ip aiim anuj rawatAnuj Rawat
 
sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...
sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...
sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...lamluanvan.net Viết thuê luận văn
 
Stojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_Only
Stojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_OnlyStojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_Only
Stojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_OnlyDaniel Stojanovski
 

Similar to 125692800 data-logger (20)

Dual-Band Mobile Phone Jammer
Dual-Band Mobile Phone JammerDual-Band Mobile Phone Jammer
Dual-Band Mobile Phone Jammer
 
ALMAULY_WALEED_LINKREPORT
ALMAULY_WALEED_LINKREPORTALMAULY_WALEED_LINKREPORT
ALMAULY_WALEED_LINKREPORT
 
Project final report
Project final reportProject final report
Project final report
 
BOUDY -SALM A FINAL
BOUDY -SALM A FINAL  BOUDY -SALM A FINAL
BOUDY -SALM A FINAL
 
LPG Booking System [ bookmylpg.com ] Report
LPG Booking System [ bookmylpg.com ] ReportLPG Booking System [ bookmylpg.com ] Report
LPG Booking System [ bookmylpg.com ] Report
 
Front of V D report pdf
Front of V D report pdfFront of V D report pdf
Front of V D report pdf
 
Highway wind turbine report
Highway wind turbine reportHighway wind turbine report
Highway wind turbine report
 
Training_report23155.ppt
Training_report23155.pptTraining_report23155.ppt
Training_report23155.ppt
 
thesis
thesisthesis
thesis
 
thesis
thesisthesis
thesis
 
Proceso de Diseño de Líneas de Transmisión
Proceso de Diseño de Líneas de TransmisiónProceso de Diseño de Líneas de Transmisión
Proceso de Diseño de Líneas de Transmisión
 
D7.1 project management handbook
D7.1 project management handbookD7.1 project management handbook
D7.1 project management handbook
 
BRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdf
BRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdfBRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdf
BRS-IntegratedTrackandTraceforMulti-ModalTransportationv0.1-Final.pdf
 
21020-BAB-04101-HS-PR-0005_C1 FINAL
21020-BAB-04101-HS-PR-0005_C1 FINAL21020-BAB-04101-HS-PR-0005_C1 FINAL
21020-BAB-04101-HS-PR-0005_C1 FINAL
 
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
 
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
Major Assignment AE3140 - Analisis Regulasi Pembuatan Part pada Pesawat Terba...
 
Ip aiim anuj rawat
Ip aiim anuj rawatIp aiim anuj rawat
Ip aiim anuj rawat
 
Ip aiim anuj rawat
Ip aiim anuj rawatIp aiim anuj rawat
Ip aiim anuj rawat
 
sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...
sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...
sưu tầm ENHANCING INFORMATION TECHNOLOGY APPLICATION AND DIGITAL TRANSFORMATI...
 
Stojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_Only
Stojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_OnlyStojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_Only
Stojanovski-Daniel_MECH4841B_2014_Aero-Cooling-Business_Appendix_Only
 

Recently uploaded

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

125692800 data-logger

  • 1. RESTRICTED i RESTRICTED Homework Help https://www.homeworkping.com/ Research Paper help https://www.homeworkping.com/ Online Tutoring https://www.homeworkping.com/ click here for freelancing tutoring sites DESIGN AND FABRICATION OF MICROCONTROLLER BASED FOUR CHANNEL DATA LOGGER By PLT OFF FARHAN HASEEB (16062) ADVISOR WG CDR MUHAMMAD AJMAL CO ADVISOR ASST PROF SHAFQAT-UL-MULK REPORT SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF BE
  • 2. RESTRICTED ii RESTRICTED COLLEGE OF AERONAUTICAL ENGINEERING PAF ACADEMYRISALPUR August, 2012 ACKNOWLEDGEMENT
  • 3. RESTRICTED iii RESTRICTED First of all I would like to thanks ALLAH, the Almighty for the successful completion of my final semester project and report. Also Iam extremely grateful to my advisorWing Commander MuhammadAjmal Khan and co-advisor Assistant Professor Shafqat-ul-Mulk for theircontinuous help and guidance. In addition to that, I am also grateful to Flying Officer Ali RazaGhumman from No. 606 R&D Wing for the support and help they provided to me.Without theiraffectionate guidance at every step this would not have been possible.
  • 4. RESTRICTED iv RESTRICTED DEDICATION I would like to dedicate my report to my parents as theyhave always been a source of guidance and motivation to me. Without their prayers this would not have been possible.
  • 5. RESTRICTED v RESTRICTED ABSTRACT This document provides final semester project reportof a microcontroller based four channel data logger. It provides detailed definition and explanation of the designed data logger, which was fabricated successfully. This document presents a brief summary of different softwares and components that were used during the project and finally the hardware part. It will also comprise of a detailed summary of the specifications and applications of the data logger.
  • 6. RESTRICTED 6 RESTRICTED TITLE…………………............................................................................................... ii ACKNOWLEDGEMENT ...................................................................................... iii DEDICATION...………………………………………………………………………………………………….ii v ABSTRACT………... ...............................................................................................v CHAPTER01: INTRODUCTION ......................................................................... 10 Project Title..................................................................................................................................10 Proposal Statement………………..…………………………………………….……………………………………………………….10 Background And Overview............................................................................................................10 Selection Of PIC 16F877A ..............................................................................................................13 Features Of PIC 16F877A ...............................................................................................................13 CHAPTER02: PHASES AND SOFTWARES......................................................... 15 Phases..........................................................................................................................................15 Phase 1 and 2................................................................................................................................15 Ccs C Compiler..............................................................................................................................16 Ic Writer.......................................................................................................................................16 Proteus.........................................................................................................................................17 CHAPTER03:COMPONENTS.............................................................................. 19 External Eeprom...........................................................................................................................19 Real Time Clock.............................................................................................................................20 I2C Connection..............................................................................................................................20 LCD...............................................................................................................................................21 4X3 Keypad...................................................................................................................................21 MAX 232.......................................................................................................................................22
  • 7. RESTRICTED 7 RESTRICTED IC-7805 .........................................................................................................................................22 CHAPTER04: ADVANCE FEATURESAND MEMORY ALLOCATION.................. 2024 Advance Features..........................................................................................................................24 Variable Time Interval...................................................................................................................24 Present And Finish Date And Time.................................................................................................25 Variable No Of Channels................................................................................................................25 Graphical Trend Analysis...............................................................................................................25 No Of Sample................................................................................................................................25 Resolution....................................................................................................................................26 Battery .........................................................................................................................................26 Frequency.....................................................................................................................................27 Memory Allocation.......................................................................................................................28 First 14 Bytes Dedicated................................................................................................................28 CHAPTER05: SERIAL INTERFACINGAND GRAPHICAL TREND ANALYSIS............ 29 Serial Communication...................................................................................................................29 USART ..........................................................................................................................................30 Max 232 Level Conversion.............................................................................................................30 RS 232 To Usb Convertor...............................................................................................................30 Baud Rate .....................................................................................................................................31 Serial Terminal..............................................................................................................................31 Hercules.......................................................................................................................................31 Advantages...................................................................................................................................32 Method........................................................................................................................................32 Graphical Trend Analysis...............................................................................................................33
  • 8. RESTRICTED 8 RESTRICTED CHAPTER06: HARDWARE IMPLEMENTATION................................................ 35 PCB...............................................................................................................................................35 PCB Design Software.....................................................................................................................35 Final product.................................................................................................................................36 Sensors.........................................................................................................................................38 LM 35 Temperature Sensor...........................................................................................................38 Light Dependent Resistor..............................................................................................................39 MQ 2 Smoke Sensor......................................................................................................................39 Variable Resistor...........................................................................................................................40 Sinewave From FunctionGenerator...............................................................................................40 CHAPTER 07: CONCLUSION ............................................................................ 41 Project DeliverablesFor 8th Semester.............................................................................................41 Project Monstration Of 8th Semester..............................................................................................41 Additional Tasks............................................................................................................................42 REFERENCES……............................................................................................... 44 APPENDICES……............................................................................................... 45 Appendix A...................................................................................................................................46 Appendix B...................................................................................................................................63 Appendix C...................................................................................................................................70 Appendix D...................................................................................................................................73
  • 9. RESTRICTED 9 RESTRICTED LIST OF FIGURES Figure 1.1: Data Logger..................................................................................................................11 Figure 1.2: Modern Data Logger……………………………………………………………………………………………………..11 Figure 1.3: Data Logger Block Diagram...........................................................................................12 Figure 1.4: Elements Of A Digital Controller...................................................................................13 Figure 1.5: Pin Configuration Diagram Of Pic 16f877a.....................................................................14 Figure 2.1: Patch Board Picture Of Circuit.......................................................................................15 Figure 2.1: Serial Circuit Diagram...................................................................................................15 Figure 2.2: CCS C Compiler.............................................................................................................16 Figure 2.3: IC Writer......................................................................................................................17 Figure 2.4: Proteus........................................................................................................................17 Figure 2.5: Complete Simulation Diagram......................................................................................18 Figure 3.1: Atmel 24C256...............................................................................................................19 Figure 3.2: Pin Configuration Diagram Of AT24C256 .......................................................................19 Figure 3.3: Pin Configuration Diagram Of DS-1307..........................................................................20 Figure 3.4: Basic Form Of The I2c Connection.................................................................................20 Figure 3.5: I2C Signals....................................................................................................................21 Figure 3.6: 16x2 LCD......................................................................................................................21 Figure 3.7: IC-7805 ........................................................................................................................22 Figure 3.8: Picture Of Max 232.......................................................................................................22 Figure 3.9: Max 232 Along With Capacitors Attached .....................................................................23
  • 10. RESTRICTED 10 RESTRICTED Figure 4.1: LCD Showing The Entered Time Interval In Sec..............................................................28 Figure 4.2: LCD Showing The Entered Finish Date...........................................................................25 Figure 4.3: Picture Of Sample No Along With Date And Time..........................................................25 Figure 4.4: Rechargeable Battery...................................................................................................26 Figure 4.5: Memory Allocation......................................................................................................27 Figure 4.6: 247 (8 Bit No) Saved At First Memory Location..............................................................28 Figure 4.7: 283 (16 Bit No) Saved At First Two Memory Locations...................................................28 Figure 5.1: Female Part Of Standard Serial Db9 Connector..............................................................29 Figure 5.2: RS232 To Usb Converter...............................................................................................31 Figure 5.3: Hercules Terminal ........................................................................................................31 Figure 5.4: Com 9 Is Usb To Serial Communication Port..................................................................32 Figure 5.5: Matlab Command Window...........................................................................................33 Figure 5.6: Input simulated wave...................................................................................................33 Figure 5.7: Reconstructed wave in MATLAB...................................................................................34 Figure 6.1: PCB File Designed In Proteus ........................................................................................35 Figure 6.3: Final Pcb Design In Orcade Software.............................................................................36 Figure 6.4: Finaly Encased Data Logger...........................................................................................37 Figure 6.4: Side and Back View of Data Logger ...............................................................................37 Figure 6.4: Lm-35 Temperature Sensor...........................................................................................38 Figure 6.5: Different Types Of Light Dependent Resistors ...............................................................39 Figure 6.6: MQ-2 Sensor................................................................................................................39 Figure 6.7: Variable Resistor..........................................................................................................40
  • 11. RESTRICTED 11 RESTRICTED CHAPTER01 INTRODUCTION Project Title 1. Design and fabrication of microcontroller based four channel data logger. Proposal Statement 2. This project is aimed at designing and fabrication of microcontroller based data logger which is able to simultaneously store values from four different sensors that are attached to its four input analog channels. The data is to be stored and can subsequently be transferred to a PC using serial port. Background and Overview 3. Data logger, also called data recorder is an electronic device that is able to record data over time with help of external sensors. It is portable, battery powered, and standalone device with a built-in memory and an interface for data transfer with a personal computer. 4. Data logging has become the most common, useful and easy way of storing data values taken from different sensors,without the requirementof user on the apparatus. Data logger can record values from the sensor automatically. User can attach any sensor whose output voltage is within the allowed voltage range for data logger input. Data logger samplesthe inputs at user defined intervals and savesthe sample digital values in external memory. Figures 1.1 and 1.2 show two of the commercial data loggers available in market.
  • 12. RESTRICTED 12 RESTRICTED Figure 1.1: Data logger[1] Figure 1.2: Modern data logger[2] 5. There are many different possible approaches to the design of data logger. For example by using data acquisition card and recording data values from inputs of DAQ card, which is further connected to PC in which data can be was acquired by some software like LAB VIEW. However, the main drawback of this technique is the mandatory requirement of a PC as the DAQ card can’t be used independently. Hence it is not portable and economical. The main idea of this project was to design a microcontroller based data logger that is independent of PC and is portable. Data values should be recorded in some memory from where they can be transferred to PC
  • 13. RESTRICTED 13 RESTRICTED whenever required for subsequent analysis. Once in PC, appropriate software can be used to see graphical trend of the data values. 6. The concept block diagram of data logger is shown in figure 1.3 below:- Figure 1.3: Data logger block diagram 7. The microcontroller unit (MCU) is big revolution in electronics. It is one of the most significant developments in electronics which has highly contributed in miniaturization of electronic hardware.Microcontroller has three main elements i.e. I/O pins, processor and a memory. I/O stands for input or output devices, which communicate with the outside world. The function of processor is to make calculations and handle data operations to provide results. The purpose of memory is to store program and data. The microcontroller contains all these elements shown in figure 1.4 below, in one chip and is not like PC which has separate chips integrated to perform these functions.
  • 14. RESTRICTED 14 RESTRICTED Figure 1.4: Elements of a Digital Controller[3] 8. Selection of PIC 16F877A. The main manufacturers of microcontrollers are Intel, Atmel and Microchip. The Intel’s microcontroller taught and commonly used in CAE is Intel 8051, and that of Microchip is PIC 16F877A. There are many differences in both like inbuilt ADC channels in PIC 16F877A, total number of ports in both are different and many other. After studying in detail about microcontrollers, the selected microcontroller used in this project was PIC 16F877A due to its many additional features over other compared microcontrollers. Some of thereasons for selection were:- a) PIC 16F877A has inbuilt capability of analogtodigitalconversion (ADC) at its eight pins iefrom AD0 to AD7.For a four channel data logger four input ADC pins were required. b) Two options are available for selecting the resolution of ADC ie 8 or 10 bit. Due to less requirement of storage capacity, 8 bit ADC would be used. 9. Features of PIC 16F877A. Features of PIC 16F877A are:- a) The A suffix in PIC 16F877A indicates that the chip can have maximum clock speed of 20 MHz which is the main upgrade from the original 16F877 device.
  • 15. RESTRICTED 15 RESTRICTED c) The chip has 8K (8096 x14 bits) of flash ROM program memory. The microcontroller stores its program in ROM (read only memory). It has 256 bytes internal EEPROM. d) The operating voltage range is 2-6 Volts. The maximum current that can flow through any pin is 25mA at 5V. It has total five ports ie A, B, C, D and E and has total of 33 I/O pins 10. Pin configuration diagram of PIC 16F877A is shown in figure 1.5 below:- Figure 1.5: Pinconfiguration diagram of PIC 16F877A[4]
  • 16. RESTRICTED 16 RESTRICTED CHAPTER 02 PHASES AND SOFTWARES PHASES 1. The project has two main phases which are required to be completed:- a) Phase one is interfacing external components with microcontroller. b) In second phase PC is to be interfaced withmicrocontroller. 2. Phase 1. In phase 1 was completed by interfacing the components that are explained later in the report. Figure 2.1 shows the patch board picture of the hardware components patched. All these components and methods would be explained later in the report. Figure 2.1 Patch board picture of circuit 3. Phase 2. In phase two PC was interfaced with the circuit and the figure 2.2 below shows the circuit. Figure 2.2: Serial circuit
  • 17. RESTRICTED 17 RESTRICTED Software 4. CCS C Compiler. The microcontroller would be programmed to perform certain task andthis can be done in either machine language or C language. Machine language is not user friendly relatively to C language. Then C code would be compiled in some suitable software to convertit into machine code. Many compilers like CCS compiler, Mickro C compiler High Tec Care used. CCS C Compiler was selected and the source code written is provided in appendix A at the end. CCS is shown in figure 2.2 below:- Figure 2.2: CCS C compiler 5. IC Writer. It is the software that is supplied by the vendor with IC burner which is used to burn the HEX file into the microcontroller. Microchip is to be selected for PIC microcontrollers and it is shown in figure 2.3 below:- Figure 2.3: IC writer
  • 18. RESTRICTED 18 RESTRICTED 6. MATLAB. MATLAB would be used for analyzing the data in the form of plots which would be explained later in the report. Figure 2.4 shows the matlab window picture below:- Figure 2.4: MATLAB window 7. Proteus User can simulate the program involving different components and ICs in Proteus. The circuit is to be patched as it is in physical hardware and theHEX file, the output file of CCS compiler, is given to the microcontroller along with the oscillating frequency. The Proteus window is shown in figure 2.5 below:- Figure 2.5: Proteus 8. The complete simulation diagram of Proteus is shown in figure 2.6 below.
  • 20. RESTRICTED 20 RESTRICTED CHAPTER03 COMPONENTS 1. The data logger would sample input values after the defined time interval and along with time stamp theywould be saved in external memorytill either the memory is full or the predefined time. Initially the internal EEPROM of the microcontroller was used for the saving of data but it wasonly 256 bytes and large no of values can’t be saved. It could only save 240 samples which is too less for an effective data logger. For savinglarge number of observations an external EEPROM was used. Components 2. External EEPROM. The selected external EEPROM chip Atmel 24C256 is a serial memory chip and has storage capacity of 256K bits or 32K byteswith three external address pins that are A0, A1, and A2. These three chips can be connected to increase thestorage capacityto 96K bytes. The figure 3.1 shows the picture of Atmel 24C256. The pin configuration diagram of at24c256 is shown in figure 3.2 below:- Figure 3.1: Atmel 24C256[5] Figure 3.2: Pin configuration diagram of AT24c256[6]
  • 21. RESTRICTED 21 RESTRICTED 3. Real Time Clock. External real time clock DS 1307 was used instead of internal clock of microcontroller, to prevent it from intense load. It is an 8 pin IC including SDA and SCL pin. The driver code for this RTC written in C language is provided at the end of report in appendix C. A crystal of32.768 KHz is connected between pin 1 and 2. Itcan also bepowered up from a backup battery.Figure 3.3 shows its pin configuration diagram below:- Figure 3.3: configuration diagram of DS-1307[7] I2C Connection 4. At24c256 and DS-1307 are connected through I2C connection with PIC. The I2C stands for interintegrated circuit bus which is used for short-range communication between different chips and microcontroller. Chip used in thistype of connection is either master or slave. Slave chip is attached to a two-wire bus andis pulled up to logic 1 when idle. The basic form of the I2C connection is shown in figure 3.4 below:- Figure 3.4: Basic form of the I2C connection[8] 5. The master chip first sends a control code to set up the transfer, then the 8-bit or 10-bit address code, and finally the data. Each byte has a start and acknowledge bit. To
  • 22. RESTRICTED 22 RESTRICTED improve reliabilityeach byte must be acknowledgedbefore sending the next byte. The sequence to read a single byte requires a total of 5 bytes to complete the process, 3 to set the address, and 2 to return the data. I2C signals are shown in figure 3.5 below:- Figure 3.5: I2C signals[9] 6. LCD. 20x4 LCD has total 16 pins including enable, RS, RW, VCC, ground and seven data pins. Enable pin of LCD would be connected to PIN_D0 of PIC, similarly RS pin with PIN_D1 and RW pin with PIN_D2. Rest pins of D port except PIN_D3 would be connected to data pins of the LCD. Initially 16x2 LCD was used for display which was upgraded to 20x4. Driver code for this LCD written in C language is provided in appendix B at the end of report. Its pin configuration is same as 20x4 LCD. Figure 3.6 below shows20x4 LCD. Figure 3.6: 16x2 LCD[10] 7. Keypad. 4x3Keypadwas used so that the user can interact with the device. It’s * button would be used as OK button for selection of any feature.
  • 23. RESTRICTED 23 RESTRICTED 8. IC 7805. Above 5V the voltage should be down converted to 5V to prevent PIC from any damage. 6.5 volts rechargeable battery was used as DC source in circuit. IC-7805 was used for converting 6.5 volts to exact 5 volts. It has three pins for input, ground and output respectively.The output can vary from 4.8-5.2 volts andthe maximum current allowed through it is 1 Amp. IC 7805 is shown in figure 3.7 below:- Figure 3.7: IC-7805[11] 8. MAX 232. MAX 232 would be used for serial interface between the data logger and PC. Transmit pin of MAX 232 will be connected to receive pin and vice versa. Selected baud rate was 9600. The main function of MAX-232 is to convert the level of PIC signals from 5 volts to 12 volts for PC. Figure 3.8 below shows picture of MAX 232. Figure 3.9 below shows pin configuration diagram along with attached capacitors of MAX 232. Figure 3.8:Picture of MAX 232[12]
  • 24. RESTRICTED 24 RESTRICTED Figure 3.9: MAX 232 along with capacitors attached[13]
  • 25. RESTRICTED 25 RESTRICTED CHAPTER04 ADVANCE FEATURESAND MEMORY ALLOCATION 1. Conventional data loggers have some features which wererequired to be amended and incorporate those in the required data logger. In this chapter all those advance features would be explained and they would be compared with conventional data loggers. Advance Features 2. Conventional data loggers take input values after some fix time interval. The date and time is already fed in its clock and it can only be changed from the code. Cheaply available data loggers in the market are either single or dual channel.In the designed data logger,memory is divided into number of parts equal to total number of channels that have been used. 3. Variable Time interval. Designed data logger hasuser defined variable time interval and is entered in the start of logging process whichcan be different for different logging processes. The complete range for the time interval is from a minimum of one second to a maximum of 255 minutes. Seconds are used for fast varying processes and minutes are used for slow varying processes. Figure 4.1 below shows the picture of LCD showing the entered time interval in seconds. Figure 4.1: LCD showing the entered time interval in sec
  • 26. RESTRICTED 26 RESTRICTED 4. Present and finish date and time. In conventional data loggers the date and time can only be changed from the source code butthe designed data logger has the capability of user defined present and finish date and time. Logging process will automatically stop at predefined time. Figure 4.2below shows the picture LCD showing the entered finish date. Similarly present date and time would be entered. Figure 4.2: LCD showing the entered finish date 5. Variable no of Input Channels. Designed data logger has variable no of channels. They could be different for different logging processes. Minimum no of channels to be selected is one and a maximum of four can be selected. 6. Graphical trend analysis. The logged data would be analyzed in MATLAB in form of graphs that would be plotted automatically after reception of data by Matlab over serial interface.This would be explained later in the report. 7. No of Samples. The total no of samples takenwould be displayed on LCD. Figure 4.3 below shows the picture of the sample no, date and time taken during the execution of the program. Figure 4.3: Picture of sample no along with date and time
  • 27. RESTRICTED 27 RESTRICTED 8. Resolution. Resolution of the ADC channel that would be used is 8 bit. Sensors would have output voltage from 0-5V. This means that a 9.6 mV change in voltage would change the ADC level.8 bit means that ADC level assigned to each voltage level would be within 0 to 255. The formula applied to specify ADC level to the voltage is given below:- ADC level value= (ADC value at channel / 255.0) * 5.0 9. Battery. A rechargeable battery was connected with the circuit to eliminate its dependence on AC input power supply. It is a 4.5 Amp Hour battery, which means it can supply 4.5 Amperes of current for one hour. The designed circuit draws current of 70mA, so it can survive over 2.5 days with this current requirement. Figure 4.4 shows the picture of the rechargeable battery which was used. Figure 4.4: Rechargeable battery 10. Frequency. Basically the data logger was designed for sensing slow varying factors like temperature, humidity, light intensity etc. The minimum frequency of the input sensor should be less than 0.25 Hz. It was tested after providing it with a sine wave of frequency of 0.2 Hz. It recorded 5 values in every cycle and was able to draw graph of the wave. This part would be explained later in the report.
  • 28. RESTRICTED 28 RESTRICTED Memory Allocation 11. Each sampled value is 8 bit soit requires one byte memory space for saving. The basic idea of memory allocation is that if one channel is used the complete memory would be dedicated for that sensor. If two channels are used the complete memory would be divided into two parts. Similarly for three and four channels, memory would be divided into three and four parts. 12. First 14 bytes dedicated. Data entered by the user in the startis saved on first 14 bytes of the memory.The first byteis a number (123) that is for checking the correct transfer of data over serial interface and its reception by the serial terminal. The next five bytes are for the current date and time. The next five are for the finish date and time. 12th byte saves no of used channels. 14th byte is the interval between two consecutive readings. If previous value is 1 and 14th byte shows 5 as shown in figure, it means that the interval is of 5 seconds. Rest all locations are for the data. Figure 4.5: Memory allocation [14]
  • 29. RESTRICTED 29 RESTRICTED 13. AT24C256 cannot be reset at start of every program execution as it is a permanent memory. First two bytes of internal EEPROM of PIC would be used to store the 16 bit number. Due to this, the ability to only transfer the values of the recent logging process would be achieved. We need to reset this variable so that the new data logging process can be started otherwise there is much chance garbagedata. Figure 4.7 shows 16 bit no saved at first two memory locations. A 16 bit no is required to cover all memory locations. As only 8 bit no can be saved internal EEPROM‘s one memory location, so we require two memory locations to save one 16 bit no. Figure 4.6 : 247 (8 bit no) saved at first memory location Figure 4.7 : 283 (16 bit no) saved at first two memory locations
  • 30. RESTRICTED 30 RESTRICTED CHAPTER 05 SERIAL INTERFACING ANDGRAPHICAL TREND ANALYSIS 1. The recordeddata is to be transferred to PC after the completion of logging process for observing the trend. There could have been different approaches for interfacing data logger with PC like wireless connection through antennas, wired serial connection etc. The method selected for connection between PC and data logger was serial connection using wires. There was a requirement that this data logger could be connected to any PC easily without the need of any extra components which was the most important reason for selection of this method. It was achieved by using the standard DB-9 connector which is shown in figure 5.1. Nowadays serial DB-9 port is not available in new PCs so serial to USB convertor was used for connection. The data logger would utilize only one USB port. Figure 5.1 Female part of standard serial DB9 connector[15] Serial communication 2. Serial communication is a way enables different equipment to communicate with outside world. It is called serial because the data bits will be sent in a serial way over a single lineand transmission or reception of data one bit at a time would occur. A personal computer has a serial port known as communication port or COM Port used to connect a modem or any other device. Serial ports are controlled by a special chip
  • 31. RESTRICTED 31 RESTRICTED called UART (Universal Asynchronous Receiver Transmitter). Different applications use different pins on the serial port and this basically depend of the functions required. 3. USART. The universal synchronous/asynchronous receive transmit (USART) device is typicallyused in asynchronous mode to implement off-board, one-to- one connections. The termasynchronousmeans that no separate clock signal is needed to time the data reception, soonly a data send, data receive, and ground wires are needed. It is quick and simple toimplement if a limited data bandwidth is acceptable.The USART link can send data up to 100meters by converting the signal to higher-voltage levels (typically 12 V). The digitalsignal is inverted and shifted to become bipolar (symmetrical about 0 V, line negativewhen inactive) for transmission.PIC has a dedicated hardware RS232 port, but CCS C allows any pin to beset up as an RS232 port, providing functions to generate the signals in software. Thebasic form of the signal has 8 data bits, a stop and start bit. The bit period is set bythe baud rate whose typical value is 9600 which is about 10 k bits per second. 4. MAX 232 level conversion. In order to connect a microcontroller to a serial port on a PC computer, we need to adjust the level of the signals so communicating can take place. The signal level on a PC is -10V for logic zero, and +10V for logic one. Since the signal level on the microcontroller is +5V for logic one and 0V for logic zero, we need an intermediary stage that will convert the levels. One chip specially designed for this task is MAX232. This chip receives signals from -10 to +10V and converts them into 0 and 5V. 5. RS232 to USB converter. ModernPCs have USB ports instead of serial ports. For utilization of USB port instead of serial port we will use RS 232 to USB converter. It is a port-powered, bi-directional USB to RS232 adapter / USB to RS232 converter that can be used to convert any standard RS232 port into a USB port and vice versa.Figure 5.2 below shows a RS232 to USB converter.
  • 32. RESTRICTED 32 RESTRICTED Figure 5.2: RS232 to USB converter[16] 6. Baud Rate. In telecommunication and electronics, baud is synonymous to symbols per second or pulses per second. It is the unit of symbol rate, also known as baud rate or modulation rate. The number of distinct symbol changes (signaling events) made to the transmission medium per second in a digitally modulated signal or a line code. Serial Terminal 7. Serial terminals are used for reception of data transferred from microcontroller and transferring data that can be received by microcontroller.Serial terminalused in serial interfacing was Hercules. 8. Hercules. Hercules SETUP utility is useful serial port terminal which was created for HW group internal use only, but today it's includes many functions in one utility.Figure 5.3shows a Hercules terminal below:- Figure 5.3: Hercules terminal
  • 33. RESTRICTED 33 RESTRICTED 11. There are many properties that should be known for accurate serial communication of data. The first and most important is baud rate. The second characteristic is parity. The parity characteristic can be even, odd, mark, space, or none. If even parity, then the last data bit transmitted will be a logical 1 if the data transmitted had an even amount of 0 bits. If odd parity, then the last data bit transmitted will be a logical 1 if the data transmitted had an odd amount of 0 bits. 13. Advantages. Serial communication has some advantages over the parallel communication. One of the advantages is transmission distance. Serial link can send data to a remote device, more far then parallel link. The cable connection of serial link is simpler then parallel link and uses lessnumber of wires. Method 14. Initially the RS 232 to USB conversion cable would be connected to any USB port and the driver for this cable is installed. This driver is freely available on internet. A COM port would be generated in the device manager. This port is noted and fed in the serial terminal for serial connection. Figure 5.4 below shows COM port generated and shown in device manger on connecting the cable in USB port. Figure 5.4: COM 9 is USB to serial communication port
  • 34. RESTRICTED 34 RESTRICTED Graphical Trend Analysis in MATLAB 15. Analysis of therecordeddata would bedone in MATLAB.The code written in MATLAB is provided in appendix D at the end. MATLAB would receive the data that is sent at serial port of PC at specified baud rate. All the data entered in the start would be displayed in the command window. Figure 5.5 below shows this data displayed in the command window. 16. MATLAB automatically plots the graphs equal to the number sensors used. They would be differentiated by plotting them by different colors and shapes. Figure 5.6below shows the input wavesimulated in Proteus. This input wave was generated by charging and discharging of capacitor through a resistor. Figure 5.7 below shows the reconstructed wave in MATLAB. Figure 5.5: Matlab command window Figure 5.6: Input wavesimulated in Proteus
  • 36. RESTRICTED 36 RESTRICTED CHAPTER 06 HARDWARE IMPLEMENTATION AND FINAL PRODUCT Printed Circuit Board 1. The project was aimedat fabricating the data logger in a final product form so itcould be properly packed in some casing. PCB is very necessary for a product to be in its presentable form. First of all the PCB design wasto be made in some software and then fabricate it on the PCB machine. PCB Design Software 2. The machine available in CAE is compatible with Advance design system (ADS) and Proteus. Initially PCB was designedin Proteus butdue to some fault, the PC was not fabricating the Proteus design. Figure 6.1 shows the PCB file designed in Proteus below:- Figure 6.1: PCB file designed in Proteus
  • 37. RESTRICTED 37 RESTRICTED 3. Orcad. Due to non-compatibility of PCB machine with Proteus, the PCB was redesigned in Orcad software and finally fabricated from No 606 R&D Wing with the help and guidance of Flying Officer Ali RazaGhumman.Figure 6.3 shows the final PCB design ofOrcad software.All the green connections are showing ground signal. All connections in red correspond to bottom layer and blue color corresponds to top layer. Figure 6.3: Final PCB design in Orcad software Final product 3. Data logger was given a final product form by encasing it, which was fabricated by the help of IE workshop. Plastic sheet was used which was painted with silver color to improve its aesthetics. Terminals for connection of sensors and the power button were provided on the front side. LCD and keypad were provided on the inclined surface for the ease of the user’s view. Buttons for transfer of data serially were provided at one side along with the serial port. Battery charger input was given at the back side. Figure 6.4 below shows the finally encased data logger. Figure 6.5 provides the side and back view of the data logger.
  • 38. RESTRICTED 38 RESTRICTED Figure 6.4: Finally encased data logger Figure 6.5: Side and back view of data logger. Sensors 4. The aim was not to attach complex sensors and design their difficult complex driver circuits. Simple sensors were used during the testing of project which are:- a) LM-35 temperature sensor b) Light dependent resistor c) MQ-2 smoke sensor
  • 39. RESTRICTED 39 RESTRICTED d) Variable resistor e) Sine wave from function generator 5. LM-35 temperature sensor. LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature (in oC). This temperature sensor is an easy to use, cost-effective and has decent accuracy of 0.5oC. It has three pins i.e. Vcc, Vout, and ground respectivelyOutput is taken across a resistor of 10 k ohm that is connected between pin no 2 and ground. The output voltage is between 0 and 1 volt. Figure 6.6 below shows the pin configuration diagram of LM-35.Figure 6.7 shows the circuit diagram of LM-35. Following conversion factor is used to convert voltage into temperature. Temperature in degrees = Output voltage * 100 Figure 6.6: LM-35 temperature sensor[17] Figure 6.7: Circuit diagram of LM-35[18]
  • 40. RESTRICTED 40 RESTRICTED 6. Light dependent resistor. A light dependent resistor (LDR) is a resistor whose resistance decreases with increasing incident light intensity. A photoresistor is made of a high resistance semiconductor. If light falling on it is of high enough frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electron (and its hole partner) conduct electricity, thereby lowering resistance. Figure 6.8 shows different types of light dependent resistors below:- Figure 6.8:Different types of light dependent resistors[19] 7. MQ-2 smoke sensor. MQ-2 is a simple smoke sensor which is used in gas leakage detecting equipment in family and industry. They are suitable for detection of LPG, i-butane, propane, methane, alcohol, Hydrogen and smoke. It has many advantages over other smoke sensors which include wide detecting scope, fast response and high sensitivity. Figure 6.9 below shows the picture of MQ-2 sensor. Figure 6.9: MQ-2 sensor[20]
  • 41. RESTRICTED 41 RESTRICTED 8. Variable resistor. It is aresistor whose value can be varied from 0 to maximum. A knob is provided at the top of it to change the value of resistance. Variable resistor of 50 K Ohm was used in the circuit. It has three pins similar to any other three pin IC. Pin 1, 2 and 3 are for input voltage, ground and output voltage respectively. 5V input voltage would be applied at input pin and the resistance was varied from 0-50 K Ohm to get output voltage from 5-0 volts. The response of the variable resistor is known, so the circuit can be checked for the exact response. The diagram of variable resistor is shown in figure 6.10 below:- Figure 6.10:Variable resistor[21] 9. Charging and Discharging of Capacitor. Capacitor was charged and discharged through a resistorto check the response of MATLAB code. Graph plotted in MATLAB was approximately exact as it was expected. The amplitude of this wave was 4.5 volts and had DC offset of approximately 2 volts. This offset was required to shift the complete sine wave above zero value so that the microcontroller takes the accurate values from ADC ports. Frequency of this wave is 0.2 Hz, so the time period is 5 seconds.
  • 42. RESTRICTED 42 RESTRICTED CHAPTERNO7 CONCLUSION 1. This chapter summarizes various tasks completed in this project. These were as following:- a) Understanding overall project and carrying out literature survey about available data loggers b) Studying different microcontrollers and understanding PIC16F877A c) Understanding PIC C programming, IC writer, Proteus and Orcade d) Compiling C program for keypad, DS1307 and external memory and interfacing them with microcontroller e) Transfer of logged data through serial port to PC f) Graphical trend analysis of data in MATLAB g) Design and fabrication of PCB Project Deliverables for 8th Semester 2. The project deliverables for 8th semester are as following:- a) Design and fabrication of data logger circuit with user interface. b) Design and fabrication of data logger interface with PC. c) Demonstration of maximum capacity of data logging capability with suitable sensor. d) Project documentation in form of project report.
  • 43. RESTRICTED 43 RESTRICTED Final Demonstration for 8th semester 3. Data logger can receive analog inputs from multiple sensors and then sample / store these values as per user defined time interval. After the completion of logging process, the logged data can be transferred to PC over a serial interface for subsequent data analysis. Additional Tasks 4. Additional tasks for the project were:- a) Provide USB capability with the designed data logger. b) Attach rechargeable battery along with the ac input source. 5. Rechargeable battery was attached with circuit successfully. It is 6.5 volts, 3.5 amp hour battery. So IC 7805 was used to provide exactly 5 volt to microcontroller. USB capability cannot be added with PIC 16F877A. MMC/SD card is addressed in blocks of 512 bytes. PIC 16F877A has very less RAM i.e. 368 bytes. USB requires even more RAM 6. The project was successfully completed and all the milestones were achieved within the specifiedtime. Data Logger can form independent measurement and storage system by hooking it up with suitable sensor. Measurement parameters could be:- a) Humidity b) Wind speed c) Temperature d) Voltage
  • 44. RESTRICTED 44 RESTRICTED REFERENCES Ref [1],[2] www.dataloggerinc.com Ref [3],[4],[8],[9] Programming-8BIT-PIC-MicroController Ref [5],[6] www.microchip.com Ref [7],[12] www.maxim.com Ref [10],[19] www.extreme-electronics.com Ref [10],[11] www.extreme-electronics.com Ref [14] www.sodoityourself.com Ref [15] Proteus software picture Ref [16] www.romux.com Ref [17] www.usbconvertors.com Ref [18] www.engineersgarage.com Ref [20] www.electronics-table.com Ref [21] www.hwsensor.com
  • 45. RESTRICTED 45 RESTRICTED Appendices Appendix A: C source code for data logger Appendix B: Driver code for 4 line LCD Appendix C: Driver code for DS-1307 real time clock Appendix D: Matlab code for graphical trend analysis
  • 46. RESTRICTED 46 RESTRICTED Appendix A C source code for data logger #include <16F877A.h> //PIC 16F877A selected #device adc=8 //8 or 10 bit can be selected. 8 bit resolution of ADC is selected #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (>4mhz) #FUSES NOPUT //No Power Up Timer #use delay(clock=20000000) //clock speed #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //Baud rate, transmit //and recieve pin selected #include <lcd44.c> //driver for 20x4 LCD #include <ds1307.c> //driver for ds-1307 RTC #define EEPROM_SDA PIN_C1 //SDA(serial data) pin selected #define EEPROM_SCL PIN_C2 //SCL(serial clock) pin selected #include <24256.c> //Driver for AT24c256 EEprom int sec,mins,hrs,day,month,year,dow,x,numofdigs,channel,Fhrs,Fmin,hunsdig=0,tensdig=0,onesdig=0, thoudig=0, Fday,Fmonth,m_Adc_Value,Fyear,yy,number; void value(); //If the function is defined after main program //then its prototype should be defined in start. //prototype function named value defined.It would be explained later in the program. int16pata,xx,zz=0,interval; //16 bit values defined floatm_inp; // getkey is a function for keypad. Whichever key would be pressed its value would be returned. *key//would act as OK key. intgetkey()
  • 47. RESTRICTED 47 RESTRICTED { int i; while(1) { //Checking Row 1 output_low(PIN_B4); //output logic 0 at pin B4 output_high(PIN_B5); //output logic 1 at pin B5 output_high(PIN_B6); output_high(PIN_B7); i=0; while(i<10) { if(!input(PIN_B0)) { while(!input(PIN_B0)); return x=1; //Return value of x as 1 break; //Leave the loop } else if(!input(PIN_B1)) { while(!input(PIN_B1)); return x=2; break; } else if(!input(PIN_B2)) { while(!input(PIN_B2)); return x=3; break; } i=i+1; delay_ms(5);
  • 48. RESTRICTED 48 RESTRICTED } //Checking Row 2 output_high(PIN_B4); output_low(PIN_B5); output_high(PIN_B6); output_high(PIN_B7); i=0; while(i<10) { if(!input(PIN_B0)) { while(!input(PIN_B0)); return x=4; break; } else if(!input(PIN_B1)) { while(!input(PIN_B1)); return x=5; break; } else if(!input(PIN_B2)) { while(!input(PIN_B2)); return x=6; break; } i=i+1; delay_ms(5); } //Checking Row 3 output_high(PIN_B4); output_high(PIN_B5);
  • 49. RESTRICTED 49 RESTRICTED output_low(PIN_B6); output_high(PIN_B7); i=0; while(i<10) { if(!input(PIN_B0)) { while(!input(PIN_B0)); return x=7; break; } else if(!input(PIN_B1)) { while(!input(PIN_B1)); return x=8; break; } else if(!input(PIN_B2)) { while(!input(PIN_B2)); return x=9; break; } i=i+1; delay_ms(5); } //Checking Row 4 output_high(PIN_B4); output_high(PIN_B5); output_high(PIN_B6); output_low(PIN_B7); i=0; while(i<10) {
  • 50. RESTRICTED 50 RESTRICTED if(!input(PIN_B0)) { while(!input(PIN_B0));//printf(lcd_putc,"f"); //star key breaks the function and // acts as ok key return x=100; break; } else if(!input(PIN_B1)) { while(!input(PIN_B1)); return x=0; break; } else if(!input(PIN_B2)) { while(!input(PIN_B2)); return x=200; break; } i=i+1; delay_ms(5); } } } // Pause function is for giving delay or pause between acquirement of two consecutive input values.The //pause should be equal to the time interval entered in start of data logging process that is either in //second or minutes. During the pause the time and date would be shown on LCD. void pause(void) { ints,t; zz++; ds1307_get_date(day,month,year,dow); //get date from DS-1307
  • 51. RESTRICTED 51 RESTRICTED ds1307_get_time(hrs,mins,sec); //get time from DS-1307 printf(lcd_putc,"fTime : %02u:%02u:%02u",hrs,mins,sec); //Display time on LCD lcd_gotoxy(1,2); printf(lcd_putc,"Date : %02u:%02u:%02u",day,month,year); //Display date on LCD lcd_gotoxy(1,3); printf(lcd_putc,"Waiting for input."); lcd_gotoxy(1,4); printf(lcd_putc,"Sample # %lu",zz); //No of acquired samples would be shown if(number==1){ //Pause loop for 1 second for(t=0;t<(interval);t++) { delay_ms(900); } } if(number==2){ //Pause loop for 1 minute for(t=0;t<(interval);t++) { for(s=0;s<60;s++) { delay_ms(950); } } } } //checkchannel is a function for selecting the no of channels by data logger and switching the ADC pins //equal to the channels entered. voidcheck_channel(void) { floatm_inp; if(channel==1) { set_adc_channel(0); //set to read ADC channel 0
  • 52. RESTRICTED 52 RESTRICTED delay_ms(10); m_Adc_Value=read_adc(); //get 8 bit readig for channel 0 delay_ms(10); m_inp=(m_Adc_Value/255.0)* 5; //Conversion factor printf(lcd_putc,"fvoltage1=%3.3f",m_inp); //Print voltage value at LCD write_ext_eeprom(pata,m_Adc_Value); //Write to external EEPROM at location variable that is pata delay_ms(10); pata++; //increment in pata for next value to be saved at next location delay_ms(1500); } else if(channel==2) { set_adc_channel(0); delay_ms(20); m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; printf(lcd_putc,"fvoltage1=%3.3f",m_inp); set_adc_channel(1); //ADC Channel 1 delay_ms(20); //Donot remove delay m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; lcd_gotoxy(1,2); //Goto 2nd line of LCD printf(lcd_putc,"voltage2=%3.3f",m_inp); delay_ms(1500); } else if(channel==3) {
  • 53. RESTRICTED 53 RESTRICTED set_adc_channel(0); //ADC Channel 0 delay_ms(10); //Donot remove delay m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; printf(lcd_putc,"fvoltage1=%3.3f",m_inp); set_adc_channel(1); //ADC Channel 1 delay_ms(10); m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; lcd_gotoxy(1,2); printf(lcd_putc,"voltage2=%3.3f",m_inp); set_adc_channel(2); //ADC Channel 1 m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; lcd_gotoxy(1,3); //Goto 3rd line of LCD printf(lcd_putc,"voltage3=%3.3f",m_inp); delay_ms(2000); } else if(channel==4) { set_adc_channel(0); //ADC Channel 0 delay_ms(20); m_Adc_Value=read_adc(); delay_ms(10);
  • 54. RESTRICTED 54 RESTRICTED write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; printf(lcd_putc,"fvoltage1=%3.3f",m_inp); set_adc_channel(1); //ADC Channel 1 delay_ms(20); //Donot remove delay m_Adc_Value=read_adc(); delay_ms(10); //ADC needs some time for reading input so Donot remove this delay write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; lcd_gotoxy(1,2); printf(lcd_putc,"voltage2=%3.3f",m_inp); set_adc_channel(2); //ADC Channel 1 delay_ms(10); m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; lcd_gotoxy(1,3); printf(lcd_putc,"voltage3=%3.3f",m_inp); set_adc_channel(3); //ADC Channel 1 delay_ms(10); m_Adc_Value=read_adc(); delay_ms(10); write_ext_eeprom(pata,m_Adc_Value); delay_ms(10); pata++; m_inp=(m_Adc_Value/255.0)*5.0; delay_ms(10); lcd_gotoxy(1,4); printf(lcd_putc,"voltage4=%3.3f",m_inp); delay_ms(2000);
  • 55. RESTRICTED 55 RESTRICTED } } // makenum is a function due to which we don’t have to define an array of number entered by keypad.this//function automatically makes number even if is 2 or 3 digit voidmakenum() { numofdigs++; if(numofdigs==4) { thoudig=hunsdig;hunsdig = tensdig; tensdig = onesdig; onesdig = x; } if(numofdigs==3) { hunsdig = tensdig; tensdig = onesdig; onesdig = x; } if(numofdigs==2) { tensdig=onesdig; onesdig = x; } if(numofdigs==1) onesdig = x; } //Loop for printing no pressed on keypad on the LCD. void again(void) { do { x=getkey(); if(x==100) break; else
  • 56. RESTRICTED 56 RESTRICTED { printf(lcd_putc,"%u",x);delay_ms(250); if((x>=0)&&(x<=9)) makenum(); } }while((x>=0)&&(x<=9)) //execute this loop until entered no is between 1 to 9 } void start(void) { write_ext_eeprom(0,11); //Write 11 on location 0 of EEPROM delay_ms(15); write_ext_eeprom(1,22); delay_ms(15); printf(lcd_putc,"fEnter complete date"); lcd_gotoxy(1,2); //Goto 2nd line of LCD printf(lcd_putc,"and time.Enter day"); lcd_gotoxy(1,3); printf(lcd_putc,"Day : "); again(); delay_ms(15); day=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); //Forming the no of //value entered by keypad numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,day); pata++; delay_ms(20); lcd_gotoxy(1,4); printf(lcd_putc,"Enter Month : "); again(); month=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata, month); pata++; delay_ms(20);
  • 57. RESTRICTED 57 RESTRICTED printf(lcd_putc,"fEnter year : "); again(); year=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); write_ext_eeprom(pata,year); pata++; numofdigs=thoudig=hunsdig=tensdig=onesdig=0; delay_ms(20); lcd_gotoxy(1,2); printf(lcd_putc,"Enter current time"); lcd_gotoxy(1,3); printf(lcd_putc,"Enter Hours : "); again(); hrs=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); write_ext_eeprom(pata,hrs); pata++; numofdigs=thoudig=hunsdig=tensdig=onesdig=0; delay_ms(20); lcd_gotoxy(1,4); printf(lcd_putc,"Enter Mins : "); again(); mins=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,mins); pata++; delay_ms(20); printf(lcd_putc,"fEnter finish date "); lcd_gotoxy(1,2); printf(lcd_putc,"and time.Enter time"); lcd_gotoxy(1,3); printf(lcd_putc,"Enter hours : "); again(); Fhrs=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000);
  • 58. RESTRICTED 58 RESTRICTED numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,Fhrs); pata++; delay_ms(20); lcd_gotoxy(1,4); printf(lcd_putc,"Enter min : "); again(); Fmin=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); delay_ms(10); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,Fmin); pata++; delay_ms(20); printf(lcd_putc,"fEnter Finish Date"); lcd_gotoxy(1,2); printf(lcd_putc,"Enter Day : "); again(); Fday=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,Fday); pata++; delay_ms(20); lcd_gotoxy(1,3); printf(lcd_putc,"Enter Month : "); again(); Fmonth=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,Fmonth); pata++; delay_ms(20); lcd_gotoxy(1,4); printf(lcd_putc,"Enter Year : "); again();
  • 59. RESTRICTED 59 RESTRICTED Fyear=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,Fyear); pata++; delay_ms(20); printf(lcd_putc,"fEnter no of channels"); lcd_gotoxy(1,2); printf(lcd_putc,"to be used."); lcd_gotoxy(1,3); printf(lcd_putc,"Channels: "); again(); channel=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,channel); pata++; delay_ms(20); printf(lcd_putc,"fEnter gap b/w input"); lcd_gotoxy(1,2); printf(lcd_putc,"values.Press 1 for"); lcd_gotoxy(1,3); printf(lcd_putc,"seconds.Press 2 for"); lcd_gotoxy(1,4); printf(lcd_putc,"minutes : "); again(); number=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0; write_ext_eeprom(pata,number); delay_ms(20); pata++; printf(lcd_putc,"fEnter Interval : "); again(); interval=onesdig+(tensdig*10)+(hunsdig*100)+(thoudig*1000); numofdigs=thoudig=hunsdig=tensdig=onesdig=0;
  • 60. RESTRICTED 60 RESTRICTED write_ext_eeprom(pata,interval); delay_ms(20); pata++; } //Checktime is a function which compares the start time and date with finish time and date in every loop. //when they are same or when start time and date //match with finish time and date. voidchecktime(void) { if((Fhrs==hrs)&&(Fmin==mins)&&(Fday==day)&&(Fmonth=month)&&(Fyear==year)) { output_high(PIN_A5); while(1) { lcd_putc("fFinish time reached"); delay_ms(1000); } } } void main() //Main function { pata=2; lcd_init(); //Initialize LCD delay_ms(10); init_ext_eeprom(); //Initialize external EEPROM delay_ms(10); ds1307_init(); //Initialize DS-1307 delay_ms(10); if(input(PIN_C0)) //push button at PIN_C0 { printf(lcd_putc,"fSending saved data");
  • 61. RESTRICTED 61 RESTRICTED xx=read_int16_eeprom(0); //read location 0 of internal EEPROM of PIC yy = read_ext_eeprom(0); delay_ms(10); printf("%unr",yy); //send value of variable printf("%lunr",xx); delay_ms(10); value(); } if(input(PIN_B3)) { write_int16_eeprom(0,0); //write on internal EEPROM of PIC at location 0 write_int16_eeprom(1,0); } start(); ds1307_set_date_time(day,month,year,3,hrs,mins,50); //Set date and time of DS-1307 delay_ms(10); setup_adc(ADC_CLOCK_INTERNAL); // ADC clock setup_adc_ports(ALL_ANALOG); delay_ms(20); while(1) //Infinite loop { check_channel(); xx=pata; //last memory location saved write_int16_eeprom(0,xx); delay_ms(10); checktime(); pause(); }
  • 62. RESTRICTED 62 RESTRICTED } //value is the function for transfering all data values from external memory to PC serially void value() { pata=1; while(pata<15) //first 14 dedicated bytes { yy = read_ext_eeprom(pata); delay_ms(10); printf("%unr",yy); delay_ms(10); pata++; } pata=15; delay_ms(10); while(pata<xx) //Loop for sendng all data values saved to PC serially { m_inp=(read_ext_eeprom(pata)/255.0)*5; delay_ms(10); printf("%3.3fnr",m_inp); delay_ms(10); pata++; } pata=xx; }
  • 63. RESTRICTED 63 RESTRICTED Appendix B Driver code for 20x4 LCD // Flex_LCD420.c // These pins are for my Microchip PicDem2-Plus board, // which I used to test this driver. // An external 20x4 LCD is connected to these pins. // Change these pins to match your own board's connections. #define LCD_DB4 PIN_D4 #define LCD_DB5 PIN_D5 #define LCD_DB6 PIN_D6 #define LCD_DB7 PIN_D7 #define LCD_RS PIN_D1 #define LCD_RW PIN_D2 #define LCD_E PIN_D0 // If you want only a 6-pin interface to your LCD, then connect the R/W pin on the LCD to ground, and //comment out the following line. Doing so will save one PIC pin, but at the cost of losing the ability to //read from the LCD. It also makes the write time a little longer because a static delay must be used, //instead of pollingthe LCD's busy bit. Normally a 6-pin interface is onlyused if you are running out of //PIC pins, and you need to use as few as possible for the LCD. #define USE_RW_PIN 1 // These are the line addresses for most 4x20 LCDs. #define LCD_LINE_1_ADDRESS 0x00 #define LCD_LINE_2_ADDRESS 0x40 #define LCD_LINE_3_ADDRESS 0x14 #define LCD_LINE_4_ADDRESS 0x54 //========================================
  • 64. RESTRICTED 64 RESTRICTED #define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines(or more) int8 lcd_line; int8const LCD_INIT_STRING[4] = { 0x20 | (lcd_type<< 2), // Set mode: 4-bit, 2+ lines, 5x8 dots 0xc, // Display on 1, // Clear display 6 // Increment cursor }; //------------------------------------- voidlcd_send_nibble(int8 nibble) { // Note: !!converts an integer expression to a boolean (1 or 0). output_bit(LCD_DB4, !!(nibble& 1)); output_bit(LCD_DB5, !!(nibble& 2)); output_bit(LCD_DB6, !!(nibble& 4)); output_bit(LCD_DB7, !!(nibble& 8)); delay_cycles(1); output_high(LCD_E); delay_us(2); output_low(LCD_E); } // This sub-routine is only called by lcd_read_byte().It's not a stand-alone routine. For example, the // R/W signal is set high by lcd_read_byte() before this routine is called. #ifdef USE_RW_PIN int8 lcd_read_nibble(void) { int8retval; // Create bit variables so that we can easily setindividual bits in the retval variable. #bit retval_0 = retval.0 #bit retval_1 = retval.1
  • 65. RESTRICTED 65 RESTRICTED #bit retval_2 = retval.2 #bit retval_3 = retval.3 retval = 0; output_high(LCD_E); delay_us(1); retval_0 = input(LCD_DB4); retval_1 = input(LCD_DB5); retval_2 = input(LCD_DB6); retval_3 = input(LCD_DB7); output_low(LCD_E); delay_us(1); return(retval); } #endif // Read a byte from the LCD and return it. #ifdef USE_RW_PIN int8 lcd_read_byte(void) { int8 low; int8 high; output_high(LCD_RW); delay_cycles(1); high = lcd_read_nibble(); low = lcd_read_nibble(); return( (high<<4) | low); }
  • 66. RESTRICTED 66 RESTRICTED #endif //---------------------------------------- // Send a byte to the LCD. voidlcd_send_byte(int8 address, int8 n) { output_low(LCD_RS); #ifdef USE_RW_PIN while(bit_test(lcd_read_byte(),7)) ; #else delay_us(60); #endif if(address) output_high(LCD_RS); else output_low(LCD_RS); delay_cycles(1); #ifdef USE_RW_PIN output_low(LCD_RW); delay_cycles(1); #endif output_low(LCD_E); lcd_send_nibble(n >> 4); lcd_send_nibble(n & 0xf); } //---------------------------- voidlcd_init(void) { int8 i;
  • 67. RESTRICTED 67 RESTRICTED lcd_line = 1; output_low(LCD_RS); #ifdef USE_RW_PIN output_low(LCD_RW); #endif output_low(LCD_E); // Some LCDs require 15 ms minimum delay afterpower-up. Others require 30 ms. // To set it to 35 ms, so it should work withall of them. delay_ms(35); for(i=0 ;i < 3; i++) { lcd_send_nibble(0x03); delay_ms(5); } lcd_send_nibble(0x02); for(i=0; i <sizeof(LCD_INIT_STRING); i++) { lcd_send_byte(0, LCD_INIT_STRING[i]); // If the R/W signal is not used, thenthe busy bit can't be polled. One ofthe init commands takes longer //thanthe hard-coded delay of 50 us, so inthat case, lets just do a 5 ms delay after all four of them. #ifndef USE_RW_PIN delay_ms(5); #endif } } //----------------------------
  • 68. RESTRICTED 68 RESTRICTED voidlcd_gotoxy(int8 x, int8 y) { int8 address; switch(y) { case 1: address = LCD_LINE_1_ADDRESS; break; case 2: address = LCD_LINE_2_ADDRESS; break; case 3: address = LCD_LINE_3_ADDRESS; break; case 4: address = LCD_LINE_4_ADDRESS; break; default: address = LCD_LINE_1_ADDRESS; break; } address += x-1; lcd_send_byte(0, 0x80 | address); } //----------------------------- voidlcd_putc(char c) {
  • 69. RESTRICTED 69 RESTRICTED switch(c) { case 'f': lcd_send_byte(0,1); lcd_line = 1; delay_ms(2); break; case 'n': lcd_gotoxy(1, ++lcd_line); break; case 'b': lcd_send_byte(0,0x10); break; default: lcd_send_byte(1,c); break; } } #ifdef USE_RW_PIN charlcd_getc(int8 x, int8 y) { char value; lcd_gotoxy(x,y); // Wait until busy flag is low. while(bit_test(lcd_read_byte(),7)); output_high(LCD_RS); value = lcd_read_byte(); output_low(LCD_RS); return(value); } #endif
  • 70. RESTRICTED 70 RESTRICTED Appendix C Driver code for DS-1307 //ds1307_init() - Enable oscillator without clearing the seconds register used when PIC loses power and //DS1307 run from 3V BAT // ds1307_set_date_time(day,mth,year,dow,hour,min,sec) Set the date/time // ds1307_get_date(day,mth,year,dow) Get the date // ds1307_get_time(hr,min,sec) Get the time #define RTC_SDA PIN_C4 #define RTC_SCL PIN_C3 #use i2c(master, sda=RTC_SDA, scl=RTC_SCL) BYTE bcd2bin(BYTE bcd_value); BYTE bin2bcd(BYTE binary_value) { BYTE temp; BYTE retval; temp = binary_value; retval = 0; while(1) { // Get the tens digit by doing multiple subtractionof 10 from the binary value. if(temp >= 10) { temp -= 10; retval += 0x10; } else // Get the ones digit by adding the remainder. { retval += temp; break;
  • 71. RESTRICTED 71 RESTRICTED } } return(retval); } // Input range - 00 to 99. BYTE bcd2bin(BYTE bcd_value) { BYTE temp; temp = bcd_value; // Shifting upper digit right by 1 is same as multiplying by 8. temp>>= 1; // Isolate the bits for the upper digit. temp&= 0x78; // Now return: (Tens * 8) + (Tens * 2) + Ones return(temp + (temp >> 2) + (bcd_value& 0x0f)); } void ds1307_init(void) { BYTE seconds = 0; i2c_start(); i2c_write(0xD0); // WR to RTC i2c_write(0x00); // REG 0 i2c_start(); i2c_write(0xD1); // RD from RTC seconds = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307 i2c_stop(); seconds&= 0x7F; delay_us(3); i2c_start(); i2c_write(0xD0); // WR to RTC i2c_write(0x00); // REG 0 i2c_write(bin2bcd(seconds)); // Start oscillator with current "seconds value
  • 72. RESTRICTED 72 RESTRICTED i2c_start(); i2c_write(0xD0); // WR to RTC i2c_write(0x07); // Control Register i2c_write(0x80); // Disable squarewave output pin i2c_stop(); } void ds1307_set_date_time(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min, BYTE sec) { sec&= 0x7F; hr&= 0x3F; i2c_start(); i2c_write(0xD0); // I2C write address i2c_write(0x00); // Start at REG 0 - Seconds i2c_write(bin2bcd(sec)); // REG 0 i2c_write(bin2bcd(min)); // REG 1 i2c_write(bin2bcd(hr)); // REG 2 i2c_write(bin2bcd(dow)); // REG 3 i2c_write(bin2bcd(day)); // REG 4 i2c_write(bin2bcd(mth)); // REG 5 i2c_write(bin2bcd(year)); // REG 6 i2c_write(0x80); // REG 7 - Disable squarewave output pin i2c_stop(); } void ds1307_get_date(BYTE &day, BYTE &mth, BYTE &year, BYTE &dow) { i2c_start(); i2c_write(0xD0); i2c_write(0x03); // Start at REG 3 - Day of week i2c_start(); i2c_write(0xD1); dow = bcd2bin(i2c_read() & 0x7f); // REG 3 day = bcd2bin(i2c_read() & 0x3f); // REG 4
  • 73. RESTRICTED 73 RESTRICTED mth = bcd2bin(i2c_read() & 0x1f); // REG 5 year = bcd2bin(i2c_read(0)); // REG 6 i2c_stop(); } void ds1307_get_time(BYTE &hr, BYTE &min, BYTE &sec) { i2c_start(); i2c_write(0xD0); i2c_write(0x00); // Start at REG 0 - Seconds i2c_start(); i2c_write(0xD1); sec = bcd2bin(i2c_read() & 0x7f); min = bcd2bin(i2c_read() & 0x7f); hr = bcd2bin(i2c_read(0) & 0x3f); i2c_stop(); }
  • 74. RESTRICTED 74 RESTRICTED Appendix D MATLAB code for Graphical trend analysis delete(instrfindall); % Delete all previous COM ports clear all clc % Clear screen s=serial('COM9', 'BaudRate', 9600); % Change to required COM fopen(s); % Open the serial port for r/w hold on n=1; while (n<4) Vp = fscanf(s); % Read Data back from serial port Vp=str2double(Vp); % String to double conversion E(n) = Vp; n=n+1; end x=1; while (x<=E(2)) Vt = fscanf(s); Vt=str2double(Vt); C(x) = Vt; x=x+1; end fclose(s); % Close the serial port delete(s); % Delete the serial port day=C(1); % Assign values to variables month=C(2); year=C(3); hours=C(4); mins=C(5); Fhours=C(6); Fmins=C(7);
  • 75. RESTRICTED 75 RESTRICTED Fday=C(8); Fmonth=C(9); Fyear=C(10); channel=C(11); number=C(12); interval=C(13); for i=14:length(C) j=i-13; voltage(j)=C(i); end disp(['No. of channels used were: ', num2str(C(11))]) %Display no of channels in command window disp(['Start time was ', num2str(C(4)),':',num2str(C(5)),':50']) disp(['Start date was ', num2str(C(1)),'/',num2str(C(2)),'/',num2str(C(3))]) disp(['Finish time was ', num2str(C(6)),':',num2str(C(7))]) disp(['Finish date was ', num2str(C(8)),'/',num2str(C(9)),'/',num2str(C(10))]) if C(12)==1 disp(['Interval used between two sampled input values was: ', num2str(C(13)),' seconds']) elseif C(12)==2 disp(['Interval used between two sampled input values was: ', num2str(C(13)),' minutes']) end hold on; title('Data Logger Sensor#1 values'); %title of figure ylabel('Voltage value axis'); % Label of Y axix of figure xlabel('Reading# axis'); % Label of X axix of figure ylim([25 45]); if C(11)==1 Channel_1=C(14:length(C)); Channel_1=Channel_1*100;
  • 76. RESTRICTED 76 RESTRICTED disp(['Number of reading from each sensor are ',num2str(length(Channel_1))]) plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5) % Characteristics of graph h = legend('Channel#1',1); % Legend for figure set(h,'Interpreter','none') elseif C(11)==2 Channel_1=C(14:2:length(C)); Channel_1=Channel_1*100; Channel_2=C(14:2:length(C)); disp(['Number of reading from each sensor are ',num2str(length(Channel_2))]) plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5) h = legend('Channel#1',1); figure(2); % Plot second figure plot(Channel_2,'--b*','LineWidth',1,'MarkerEdgeColor','m','MarkerFaceColor','g','MarkerSize',5) title('Data Logger Sensor#2 values'); ylabel('Voltage value axis'); xlabel('Reading# axis'); ylim([0 5]); h = legend('Channel#2',1); set(h,'Interpreter','none') elseif C(11)==3 Channel_1=C(17:3:length(C)); Channel_1=Channel_1*100; Channel_2=C(18:3:length(C)); Channel_3=C(19:3:length(C)); disp(['Number of reading from each sensor are ',num2str(length(Channel_2))]) figure(1); plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5) h = legend('Channel#1',1); figure(2); plot(Channel_2,'--b*','LineWidth',1,'MarkerEdgeColor','m','MarkerFaceColor','g','MarkerSize',5) title('Data Logger Sensor#2 values'); ylabel('Voltage value axis'); xlabel('Reading# axis');
  • 77. RESTRICTED 77 RESTRICTED ylim([0 5]); h = legend('Channel#2',1); figure(3); plot(Channel_3,'--ms','LineWidth',1,'MarkerEdgeColor','r','MarkerFaceColor','y','MarkerSize',5) title('Data Logger Sensor#3 values'); ylabel('Voltage value axis'); xlabel('Reading# axis'); ylim([0 5]); h = legend('Channel#3',1); set(h,'Interpreter','none') elseif C(11)==4 Channel_1=C(17:4:length(C)); Channel_1=Channel_1*100; Channel_2=C(18:4:length(C)); Channel_3=C(19:4:length(C)); Channel_4=C(20:4:length(C)); disp(['Number of reading from each sensor are ',num2str(length(Channel_2))]) plot(Channel_1,'--rs','LineWidth',1,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5) h = legend('Channel#1',1); figure(2); plot(Channel_2,'--b*','LineWidth',1,'MarkerEdgeColor','m','MarkerFaceColor','g','MarkerSize',5) title('Data Logger Sensor#2 values'); ylabel('Voltage value axis'); xlabel('Reading# axis'); ylim([0 5]); h = legend('Channel#2',1); figure(3); plot(Channel_3,'--ms','LineWidth',1,'MarkerEdgeColor','r','MarkerFaceColor','y','MarkerSize',5) title('Data Logger Sensor#3 values'); ylabel('Voltage value axis'); xlabel('Reading# axis');
  • 78. RESTRICTED 78 RESTRICTED ylim([0 5]); h = legend('Channel#3',1); figure(4); plot(Channel_4,'--go','LineWidth',1,'MarkerEdgeColor','y','MarkerFaceColor','r','MarkerSize',5) title('Data Logger Sensor#4 values'); ylabel('Voltage value axis'); xlabel('Reading# axis'); ylim([0 5]); h = legend('Channel#4',1); set(h,'Interpreter','none') end Homework Help https://www.homeworkping.com/ Math homework help https://www.homeworkping.com/ Research Paper help https://www.homeworkping.com/ Algebra Help https://www.homeworkping.com/ Calculus Help https://www.homeworkping.com/ Accounting help https://www.homeworkping.com/ Paper Help https://www.homeworkping.com/