Download PROJECT REPORT On WIRELESS MONITOR AND CONTROL

Document related concepts

Flip-flop (electronics) wikipedia , lookup

Control system wikipedia , lookup

Resistive opto-isolator wikipedia , lookup

Rectiverter wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
PROJECT REPORT
On
WIRELESS MONITOR AND CONTROL SYSTEM FOR ENVIRONMENTAL
PARAMETERS IN GREENHOUSE
Submitted in partial fulfillment for the award of the degree
Of
BACHELOR OF TECHNOLOGY
in
ELECTRONICS AND COMMUNICATION ENGINEERING
By
M.PARANDHAMAN
10407537
M.PRAMODH KUMAR 10407541
NILABH RANJAN
10407627
Under the guidance of
Mr.S.M.SAKTHIVEL, M.Tech.,
(Assistant Professor(O.G), School of Electronics and Communication Engineering)
FACULTY OF ENGINEERING AND TECHNOLOGY
SRM UNIVERSITY, RAMAPURAM CAMPUS.
(Under section 3 of UGC Act, 1956)
Chennai – 89.
April, 2011
ii
BONAFIDE CERTIFICATE
Certified that this project report titled WIRELESS MONITORING AND
CONTROL
SYSTEM
GREENHOUSE
is the
FOR
ENVIRONMENTAL
bonafide
work
of
PARAMETERS
IN
M.PARANDHAMAN (10407537),
M.PRAMODH KUMAR (10407541) and NILABH RANJAN(10407627) who carried
out the project under my supervision.
H.O.D
Internal Guide
Date:
Internal Examiner-I
Internal Examiner-II
iii
ABSTRACT
Now a days Monitoring and control of greenhouse environment play an important
role in greenhouse production and management with automatic.
To
monitor
the
greenhouse environment parameters effectively, control design of wireless sensor
network system based on radio frequency (RF) transceiver for greenhouse, which
consists of some sensor nodes placed in the greenhouse and a master node connected
to data from in the monitoring center.
The sensor nodes collect signals of greenhouse temperature, humidity, and
light, control the actuators, and transmit the data at a constant interval and sends this
information over a wireless network to the parent node through peer-to-peer wireless
networking protocol based on IEEE.802.15.4 standard running at 2.4 GHz. The parent
node stores this information for later analysis and it should forward the data to the
monitoring station on via Greenhouse places.
A system such as this requires permanent energy source. The solution is to use
Energy Harvesting technology. An energy harvesting module is designed such that it
captures solar energy which is the only energy source available on sun. MiWi P2P wireless
networking protocol is used to form the green house. Nanowatt XLP PIC Microcontrollers
are involved in controlling the wireless motes for this project.
iv
ACKNOWLEDGEMENT
We place on regard our deep sense of gratitude to our beloved Chancellor to
Dr.T.R.PACHAMUTHU, for providing us with the requisite infrastructure throughout the
course.
We take the opportunity to extend our hearty thanks to our Pro-Vice Chancellor,
Mr.R.SHIVAKUMAR, for his constant encouragement.
We convey our sincere thanks to our Vice Principal Dr.L.ANTONY MICHAEL
RAJ, for his interest and support.
We take the privilege to extend our hearty thanks to the Head of the Department,
Mrs.R.BALARANI, for her suggestions, support and encouragement towards the
completion of the project with perfection.
We
thank
our
Project
Coordinator
and
Internal
Guide
Mrs.K.SANKARAPANDIAMMAL, Mr.S.M.SAKTHIVEL, for his timely help and
guidance throughout the overall process of the project.
We would like to express our sincere thanks to all of our staff members of the
Department of Electronics and Communication who gave many suggestions from time to
time that made our project work better and well finished.
v
TABLE OF CONTENTS
CHAPTER NO.
1
2
3
TITLE
PAGE
BONAFIDE CERTIFICATE
ii
ABSTRACT
iii
ACKNOWLEDGEMENT
iv
TABLE OF CONTENTS
v
LIST OF FIGURES
vii
LIST OF TABLES
viii
PROJECT DESCRIPTON
1
1.1 INTRODUCTION
1
1.2 MICROCONTROLLER
1
1.3 TRANSCEIVER
2
1.4 MA3232
2
1.5 HARDWARE
3
1.6 SOFTWARE
3
MICROCONTROLLER
4
2.1 GENERAL
4
2.2 ARCHITECTURE OF PIC18F45J11
5
2.3 OVERVIEW
6
2.4 MSSP MODULE
18
2.5 EUSART
19
2.6 10 BIT A/D CONVERTER
20
2.7 ELECTRICAL CHARACTERISTICS
21
2.8 MICROCONTROLLER FEATURES
22
MRF24J40MA RF TRANSCEIVER
25
3.1 FEATURES
25
3.2 PIN CONFIGURATIONS
27
vi
4
5
6
MICROCHIP MiWi™ P2P WIRELESS
PROTOCOL
29
4.1 INTRODUCTION
29
4.2 PROTOCOL OVERVIEW
29
4.3PROTOCOL FEATURES
30
4.4 PEER-TO-PEER TOPOLOGY
30
4.5 NETWORK TOPOLOGY
31
4.6 NETWORK ADDRESSING
31
4.7 MESSAGE FORMAT
32
4.8 UNIQUE FEATURES
32
CIRCUITDIAGRAM AND BOARD
PERIPHERALS
33
5.1 CIRCUIT DIAGRAM
33
5.2 BOARD PERIPHERALS
34
5.2.1 MAX 3232
34
5.2.2 L293D- DRIVER
35
5.3 SENSORS
36
5.3.1 LDR
36
5.3.2 HIH5030
37
5.3.3 LM35
38
SOFTWARE
40
6.1 GENERAL
40
6.2 MPLAB
40
6.3 HYPERTERMINAL
41
7
APPENDIX
43
8
CONCLUSION
57
REFERENCES
58
vii
LIST OF FIGURES
FIGURE NO.
1.1
FIGURE TITLE
PAGE
WIRELESS MONITOR AND CONTROL SYSTEM
FOR ENVIRONMENTAL PARAMETERS IN
GREENHOUSE
2
2.1
ARCHITECTURE OF PIC18F45J11
5
2.2
PIC18F45J11
6
2.3
MEMORY IN PIC18F45J11
8
2.4
I/O PORTS
10
2.5
A/D CONVERTER
20
3.1
BLOCK DIAGRAM
26
3.2
MRF24J40MA RF TRANSCEIVER
27
3.3
TRANCEIVER MODULE
28
4.1
P2P TOPOLOGY
30
4.2
FRAME FORMAT OF THE TRANSCEIVER
32
5.1
CIRCUIT DIAGRAM (MONITORINIG)
33
5.2
CIRCUIT DIAGRAM (CONTROL)
33
5.3
PIN DIAGRAM OF MAX 3232
34
5.4
PIN DIAGRAM OF L293D
35
6.1
LDR SENSOR
36
6.2
HUMIDITY SENSOR
38
6.3
TEMPERATURE SENSOR
39
7.1
“MOTE-0” CODE
55
7.2
“MOTE-1” CODE
55
7.3
“MOTE-2” CODE
56
7.4
BURNING TO MICROCONTROLLER
56
viii
LIST OF TABLES
TABLE NO.
TABLE NAME
PAGE
2.1
INPUT SPECIFICATIONS
11
2.2
DRIVE CAPABILITIES
11
2.3
TIMER RESOURCE
17
2.4
ELECTRICAL SPECIFICATIONS 21
5.1
RS232 CONVERSION
34
1
CHAPTER 1
INTRODUCTION
1.1 PROJECT DESCRIPTION
For the large rural distract, the greenhouse production has become a way of
being rich. The growth of crop in greenhouse depends on temperature, humility and other
parameters in greenhouse. So it is important to real-timely and properly measure and adjust
the temperature, humility and other parameters in the greenhouse. With the continued
expansion of production scale, the disadvantages of traditional wire monitoring system are
more and more prominent, such as complicated arrangement, difficult maintenance and so
on. Then the wireless monitoring system is developed, which based on wireless
communication
Technology, does not need cables, adds or reduces configuration at random, possess simple
system construction. Moreover, it is characterized by its low power consumption, simple
net construction. The project consists of a microcontroller, a transceiver section and
software through which the parameters are modified and the data is analyzed.
1.2 MICROCONTROLLER
The PIC18F45J11 microcontroller is used here to process the data sensed,
communicate with the PC and to actuate the drivers. The PIC is a “slave” device which is
effectively transparent to the normal operation of the system. It is capable of assuming
specific sequential control function is disclosed. The PIC is an enhanced version of
Microcontroller. It is an embedded controller. It performs Boolean and logic arithmetic on
the data. It comprises input, output and scratch pad random access memories for storing the
data.
2
1.3 TRANSCIEVER
The MRF24J40MA is a 2.4 GHz IEEE Std. 802.15.4™ compliant, surface mount module
with integrated crystal, internal voltage regulator, matching circuitry and PCB antenna.
The MRF24J40MA module operates in the non-licensed 2.4 GHz frequency band.
Figure 1.1-WIRELESS MONITOR AND CONTROL SYSTEM FOR
ENVIRONMENTAL PARAMETERS IN GREENHOUSE
1.4 MAX3232
The MAX3232 transceivers have a proprietary low-dropout transmitter output
stage enabling true RS-232 performance from a 3.0V to 5.5V supply with a dual charge
pump. The devices require only four small 0.1μF external charge pump capacitors. The
MAX3232 is guaranteed to run at data rates of 120kbps while maintaining RS-232 output
levels. It is an integrated circuit that converts signal from an RS-232 serial port to signal
suitable for use in TTL compatible digital logic circuits.
3
1.5 HARDWARE
1. MICROCONTROLLER
2.
RF TRANSCIEVER
3. RS 232
4. SENSORS- LM35,LDR,HIH5030
5. PC
1.6 SOFTWARE
1. MPLAB Integrated Development Environment.
2. PIC C 18 Compiler.
3. PICkit 2.
4
CHAPTER 2
MICROCONTROLLER
2.1 GENERAL
The PIC is a “slave” device which is effectively transparent to the normal
operation of the system. It is capable of assuming specific sequential control function is
disclosed. The PIC is an enhanced version of Microcontroller. It is an embedded controller.
It performs Boolean and logic arithmetic on the data. It comprises input, output and scratch
pad random access memories for storing the data.
PIC has three families:

Low end family
: 33 instructions
(Eg: PIC12 XXX)

Mid-range family : 35 instructions
(Eg: PIC16XXX)

High end family
: 77 instructions
(Eg: PIC17 XXX &PIC18XXX)
Microcontrollers are used in automatically controlled products and devices,
such as automobile engine control systems, implantable medical devices, remote controls,
office machines, appliances, power tools, and toys. By reducing the size and cost compared
to a design that uses a separate microprocessor, memory, and input/output devices,
microcontrollers make it economical to digitally control even more devices and processes.
Mixed signal microcontrollers are common, integrating analog components needed to
control non-digital electronic systems.
5
2.2 ARCHITECTURE OF PIC18F45J11
Figure 2.1-ARCHITECTURE OF PIC18F45J11
6
2.3 OVERVIEW
This family provides low power and high performance 8-bit MCU with
peripheral flexibility in a small package for cost sensitive applications in the PIC18 Jseries. New features include Deep sleep mode for low power applications, Peripheral Pin
Select for design flexibility for mapping peripherals to I/O pins and a CTMU module for
easy capacitive touch user interfaces. The PIC18F45J11 family is ideal for applications
requiring cost-effective, low-power solutions with a robust peripheral set in a small
package.
2.3.1 PIN CONFIGURATIONS
Figure 2.2-PIC18F45J11
7
2.3.2 LOW-POWER MODES
The PIC18F45J11 family devices can manage power consumption through
clocking to the CPU and the peripherals. In general, reducing the clock frequency and the
amount of circuitry being clocked reduces power consumption.
For managing power in an application, the primary
modes of operation are:
1. Run Mode
2. Idle Mode
3. Sleep Mode
4. Deep Sleep Mode
Additionally, there is an Ultra Low-Power Wake-up (ULPWU) mode for generating an
interrupt-on-change on RA0.

The Run and Idle modes can use any of the three available clock sources (primary,
secondary or internal oscillator blocks). The Sleep mode does not use a clock
source.
2.3.3 RESET
The PIC18F45J11 family of devices differentiates among various kinds of
Reset:
a) Power-on Reset (POR)
b) MCLR Reset during normal operation
c) MCLR Reset during power-managed modes
d) Watchdog Timer (WDT) Reset (during execution)
e) Configuration Mismatch (CM)
f) Brown-out Reset (BOR)
g) RESET Instruction
h) Stack Full Reset
i) Stack Underflow Reset
j) Deep Sleep Reset
8
2.3.4 MEMORY ORGANIZATION
There are two types of memory in PIC18 Flash microcontrollers:

Program Memory

Data RAM
As Harvard architecture devices, the data and program memories use separate busses; this
allows for concurrent access of the two memory spaces.
Figure 2.3 -MEMORY IN PIC18F45J11
2.3.5 FLASH PROGRAM MEMORY
The Flash program memory is readable, writable and erasable during normal
operation over the entire VDD range. A read from program memory is executed on 1 byte
at a time. A write to program memory is executed on blocks of 64 bytes at a time or 2
bytes at a time. Program memory is erased in blocks of 1024 bytes at a time. A bulk erase
9
operation may not be issued from user code. Writing or erasing program memory will
cease instruction fetches until the operation is complete.
The program memory cannot be accessed during the write or erase, therefore,
code cannot execute. An internal programming timer terminates program memory writes
and erases. A value written to program memory does not need to be a valid instruction.
Executing a program memory location that forms an invalid instruction results in a NOP.
2.3.6 INTERRUPTS
Devices of the PIC18F45J11 family have multiple interrupt sources and an
interrupt priority feature that allows most interrupt sources to be assigned a high-priority
level or a low-priority level. The high-priority interrupt vector is at 0008h and the lowpriority interrupt vector
is at 0018h. High-priority interrupt events will interrupt any low-priority interrupts that
may be in progress.
There are 13 registers, which are used to control interrupt operation. These registers are:
•
RCON
•
INTCON
•
INTCON2
•
INTCON3
•
PIR1, PIR2, PIR3
•
PIE1, PIE2, PIE3
•
IPR1, IPR2, IPR3
It is recommended that the Microchip header files supplied with MPLAB® IDE be used
for the symbolic bit names in these registers. This allows the assembler/compiler to
automatically take care of the placement of these bits within the specified register. In
general, interrupt sources have three bits to control their operation. They are:
•
Flag bit to indicate that an interrupt event occurred.
•
Enable bit that allows program execution to branch to the interrupt vector
address when the flag bit is set.
•
Priority bit to select high priority or low priority.
10
2.3.7 I/O PORTS
Depending on the device selected and features enabled, there are up to five
ports available. Some pins of the I/O ports are multiplexed with an alternate function from
the peripheral features on the device. In general, when a peripheral is enabled, that pin may
not be used as a general purpose I/O pin. Each port has three registers for its operation.
These registers are:
•
TRIS register (Data Direction register)
•
PORT register (reads the levels on the pins of the device)
•
LAT register (Data Latch)
The Data Latch (LAT register) is useful for read-modify write operations on the value that
the I/O pins are driving
Figure2.4-I/O PORTS
11
Table 2.1-INPUT SPECIFICATIONS
Table 2.2-DRIVE CAPABILITIES
2.3.7.1 PORTA, TRISA AND LATA REGISTERS
PORTA is a 7-bit wide, bidirectional port. It may function as a 5-bit port,
depending on the oscillator mode selected. Setting a TRISA bit (= 1) will make the
corresponding PORTA pin an input (i.e., put the corresponding output driver in a highimpedance mode). Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an
output (i.e., put the contents of the output latch on the selected pin). Reading the PORTA
register reads the status of the pins, whereas writing to it, will write to the port latch.
Read-modify-write operations on the LATA register read and write the latched
output value for PORTA. The other PORTA pins are multiplexed with analog inputs, the
analog VREF+ and VREF- inputs and the comparator voltage reference output. The
operation of pins, RA<3:0> and RA5, as A/D converter inputs is selected by clearing or
setting the control bits in the ADCON1 register (A/D Control Register 1). Pins, RA0 and
RA3, may also be used as comparator inputs and by setting the appropriate bits in the
CMCON register. To use RA<3:0> as digital inputs, it is also necessary to turn off the
comparators.
12
2.3.7.2 PORTB, TRISB AND LATB REGISTERS
PORTB is an 8-bit wide, bidirectional port. The corresponding Data Direction
register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an
input (i.e., put the corresponding output driver in a high-impedance mode). Clearing a
TRISB bit (= 0) will make the corresponding PORTB pin an output (i.e., put the contents
of the output latch on the selected pin). The Data Latch register (LATB) is also memory
mapped. Read-modify-write operations on the LATB register read and write the latched
output value for PORTB.
2.3.7.3 PORTC, TRISC AND LATC REGISTERS
PORTC is an 8-bit wide, bidirectional port. The corresponding Data Direction
register is TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an
input (i.e., put the corresponding output driver in a high-impedance mode). Clearing a
TRISC bit (= 0) will make the corresponding PORTC pin an output (i.e., put the contents
of the output latch on the selected pin). The Data Latch register (LATC) is also memory
mapped. Read-modify-write operations on the LATC register read and write the latched
output value for PORTC.
PORTC is multiplexed with several peripheral functions (see Table ). The pins
have Schmitt Trigger input buffers. When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORTC pin. Some peripherals override the TRIS bit
to make a pin an output, while other peripherals override the TRIS bit to make a pin an
input. The user should refer to the corresponding peripheral section for additional
information. Unlike other PORTC pins, RC4 and RC5 do not have TRISC bits associated
with them. As digital ports, they can only function as digital inputs. If an external
transceiver is used, RC4 and RC5 always function as inputs from the transceiver. If the onchip transceiver is used, the data direction is determined by the operation being performed
by the module at that time.
13
2.3.7.4 PORTD, TRISD AND LATD REGISTERS
PORTD is an 8-bit wide, bidirectional port. The corresponding Data Direction
register is TRISD. Setting a TRISD bit (= 1) will make the corresponding PORTDpin an
input (i.e., put the corresponding output driver in a high-impedance mode). Clearing a
TRISD bit (= 0) will make the corresponding PORTD pin an output (i.e., put the contents
of the output latch on the selected pin). The Data Latch register (LATD) is also memory
mapped. Read-modify-write operations on the LATD register read and write the latched
output value for PORTD.
All pins on PORTD are implemented with Schmitt Trigger input buffers. Each pin is
individually configurable as an input or output.
2.3.7.5 PORTE, TRISE AND LATE REGISTERS
Depending on the particular PIC18F45J11 family device selected, PORTE is
implemented in two different ways. For 44-pin devices, PORTE is a 3-bit wide port. Three
pins (RE0/AN5/PMRD, RE1/AN6/PMWR and RE2/AN7/PMCS) are individually
configurable as inputs or outputs. These pins have Schmitt Trigger input buffers. When
selected as analog inputs, these pins will read as ‘0’s. The corresponding Data Direction
register is TRISE. Setting a TRISE bit (= 1) will make the corresponding PORTE pin an
input (i.e., put the corresponding output driver in a high-impedance mode). Clearing a
TRISE bit (= 0) will make the corresponding PORTE pin an output (i.e., put the contents
of the output latch on the selected pin). TRISE controls the direction of the RE pins, even
when they are being used as analog inputs. The user must make sure to keep the pins
configured as inputs when using them as analog inputs.
2.3.8 OSCILLATOR
2.3.8.1 CONFIGURATIONS
Devices in the PIC18F45J11 family incorporate a different oscillator and
microcontroller clock system than general purpose PIC18F devices. The PIC18F45J11
family has additional prescalers and postscalers, which have been added to accommodate a
wide range of oscillator frequencies. Figure 2-1 provides an overview of the oscillator
structure. Other oscillator features used in PIC18 enhanced microcontrollers, such as the
14
internal oscillator block and clock switching, remain the same. They are discussed later in
this chapter.
2.3.8.2 OSCILLATOR CONTROL
The operation of the oscillator in PIC18F45J11 family devices is controlled
through three Configuration registers and two control registers. Configuration registers,
CONFIG1L, CONFIG1H and CONFIG2L, select the oscillator mode, PLL prescaler and
CPU divider options. As Configuration bits, these are set when the device is programmed
and left in that configuration until the device is reprogrammed. The OSCCON register
(Register 2-2) selects the Active Clock mode; it is primarily used in controlling clock
switching in power-managed modes. The OSCTUNE register (Register 2-1) is used to trim
the INTOSC frequency source and select the low-frequency clock source that drives
several special features. The OSCTUNE register is also used to activate or disable the
Phase Locked Loop (PLL).
2.3.8.3 OSCILLATOR TYPES
PIC18F45J11 family devices can be operated in eight distinct oscillator modes.
Users can program the FOSC<2:0> Configuration bits to select one of the modes listed in
Table 2-1. For oscillator modes which produce a clock output (CLKO) on pin RA6, the
output frequency will be one fourth of the peripheral clock frequency. The clock output
stops when in Sleep mode, but will continue during Idle mode.
2.3.9 PERIPHERAL PIN SELECT (PPS)
A major challenge in general purpose devices is providing the largest possible
set of peripheral features while minimizing the conflict of features on I/O pins. The
challenge is even greater on low pin count devices similar to the PIC18F45J11 family. In
an application that needs to use more than one peripheral multiplexed on single pin,
inconvenient workarounds in application code or a complete redesign may be the only
option. The Peripheral Pin Select (PPS) feature provides an alternative to these choices by
enabling the user’s peripheral set selection and their placement on a wide range of I/O pins.
By increasing the pinout options available on a particular device, users can better tailor the
microcontroller to their entire application, rather than trimming the application to fit the
15
device. Users may independently map the input and/or output of any one of the many
digital peripherals to any one of these I/O pins. PPS is performed in software and generally
does not require the device to be reprogrammed. Hardware safeguards are included that
prevent accidental or spurious changes to the peripheral mapping once it has been
established.
2.3.10 AVAILABLE PINS
The PPS feature is used with a range of up to 22 pins; the number of available
pins is dependent on the particular device and its pin count. Pins that support the PPS
feature include the designation “RPn” in their full pin designation, where “RP” designates
a remappable peripheral and “n” is the remappable pin number. See Table 1-2 for pinout
options in each package offering.
2.3.11 TIMERS
2.3.11.1 TIMER0 MODULE
The Timer0 module incorporates the following features:
• Software selectable operation as a timer or counter in both 8-bit or 16-bit modes
• Readable and writable registers
• Dedicated 8-bit, software programmable prescaler
• Selectable clock source (internal or external)
• Edge select for external clock
• Interrupt-on-overflow
2.3.11.2 TIMER1 MODULE
The Timer1 timer/counter module incorporates these features:
• Software selectable operation as a 16-bit timer or counter
• Readable and writable 8-bit registers (TMR1H and TMR1L)
• Selectable clock source (internal or external) with device clock or Timer1 oscillator
internal options
• Interrupt-on-overflow
• Reset on ECCP Special Event Trigger
• Device clock status flag (T1RUN)
16
• Timer with gated control
2.3.11.3 TIMER2 MODULE
The Timer2 module incorporates the following features:
• 8-bit Timer and Period registers (TMR2 and PR2, respectively)
• Readable and writable (both registers)
• Software programmable prescaler (1:1, 1:4 and 1:16)
• Software programmable postscaler (1:1 through 1:16)
• Interrupt on TMR2 to PR2 match
• Optional use as the shift clock for the MSSP modules
2.3.11.4 TIMER3 MODULE
The Timer3 timer/counter module incorporates these features:
• Software selectable operation as a 16-bit timer or counter
• Readable and writable 8-bit registers (TMR3H and TMR3L)
• Selectable clock source (internal or external) with device clock or Timer1 oscillator
internal options.
• Interrupt-on-overflow
• Module Reset on ECCP Special Event Trigger
2.3.11.5 TIMER4 MODULE
The Timer4 timer module has the following features:
• 8-Bit Timer register (TMR4)
• 8-Bit Period register (PR4)
• Readable and writable (both registers)
• Software programmable prescaler (1:1, 1:4, 1:16)
• Software programmable postscaler (1:1 to 1:16)
• Interrupt on TMR4 match of PR4
17
2.3.12 ENHANCED CAPTURE/COMPARE/PWM (ECCP) MODULE
PIC18F45J11 family devices have two Enhanced Capture/Compare/PWM
(ECCP) modules: ECCP1 and ECCP2. These modules contain a 16-bit register, which can
operate as a 16-bit Capture register, a 16-bit Compare register or a PWM Master/Slave
Duty Cycle register. These ECCP modules are upward compatible with CCP.
2.3.13 ECCP MODE – TIMER
2.3.13.1 RESOURCE
Table 2.3-TIMER RESOURCE
2.3.13.2 PWM MODE
In Pulse-Width Modulation (PWM) mode, the CCPx pin produces up to a 10bit resolution PWM output. A PWM output has a time base (period) and a time that the
output stays high (duty cycle). The frequency of the PWM is the inverse of the period
(1/period).
2.3.13.3 PWM PERIOD
The PWM period is specified by writing to the PR2 (PR4) register. PWM
frequency is defined as 1/[PWM period]. When TMR2 (TMR4) is equal to PR2 (PR4), the
following three events occur on the next increment cycle:
• TMR2 (TMR4) is cleared
• The CCPx pin is set (exception: if PWM duty cycle = 0%, the CCPx pin will not be set)
• The PWM duty cycle is latched from CCPRxL into CCPRxH.
2.3.13.4 PWM DUTY CYCLE
The PWM duty cycle is specified by writing to the CCPRxL register and to the
CCPxCON<5:4> bits. Up to 10-bit resolution is available. The CCPRxL contains the eight
MSbs and the CCPxCON<5:4> contains the two LSbs. This 10-bit value is represented by
18
CCPRxL:CCPxCON<5:4>. CCPRxL and CCPxCON<5:4> can be written to at any time,
but the duty cycle value is not latched into CCPRxH until after a match between PR2
(PR4) and
TMR2 (TMR4) occurs (i.e., the period is complete). In PWM mode, CCPRxH is a readonly register.
2.4 MASTER SSP (MSSP) MODULE
2.4.1 OVERVIEW
The MSSP module can operate in one of two modes:
• Serial Peripheral Interface (SPI)
• Inter-Integrated Circuit (I2C™)
- Full Master mode
- Slave mode (with general address call)
The I2C interface supports the following modes in hardware:
• Master mode
• Multi-Master mode
• Slave mode with 5-bit and 7-bit address masking (with address masking for both 10-bit
and 7-bit addressing)
All members of the PIC18F45J11 family have two MSSP modules, designated as MSSP1
and MSSP2.
The modules operate independently:
• PIC18F4XJ11 devices – Both modules can be configured for either I2C or SPI
communication.
• PIC18F2XJ11 devices:
- MSSP1 can be used for either I2C or SPI communication
- MSSP2 can be used only for SPI Communication
All of the MSSP1 module-related SPI and I2C I/O functions are hard-mapped to specific
I/O pins.
For MSSP2 functions:
• SPI I/O functions (SDO2, SDI2, SCK2 and SS2) are all routed through the Peripheral Pin
Select (PPS) module.
19
2.4.2 REGISTERS
Each MSSP module has four registers for SPI mode operation. These are:
• MSSPx Control Register 1 (SSPxCON1)
• MSSPx Status Register (SSPxSTAT)
• Serial Receive/Transmit Buffer Register (SSPxBUF)
• MSSPx Shift Register (SSPxSR) – Not directly accessible
2.5 ENHANCED UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER
TRANSMITTER (EUSART)
The Enhanced Universal Synchronous Asynchronous Receiver Transmitter
(EUSART) module is one of two serial I/O modules. (Generically, the EUSART is also
known as a Serial Communications Interface or SCI.) The EUSART can be configured as a
full-duplex asynchronous system that can communicate with peripheral devices, such as
CRT terminals and personal computers. It can also be configured as a half-duplex
synchronous system that can communicate with peripheral devices, such as A/D or D/A
integrated circuits, serial EEPROMs and so on. The Enhanced USART module implements
additional features, including automatic baud rate detection and calibration, automatic
wake-up on Sync Break reception and 12-bit Break character transmit. These make it
ideally suited for use in Local Interconnect Network bus (LIN bus) systems. All members
of the PIC18F45J11 family are equipped with two independent EUSART modules,
referred to as EUSART1 and EUSART2. They can be configured in the following modes:
• Asynchronous (full-duplex) with:
- Auto-wake-up on character reception
- Auto-baud calibration
- 12-bit Break character transmission
• Synchronous – Master (half-duplex) with selectable clock polarity
• Synchronous – Slave (half-duplex) with selectable clock polarity
20
2.6 10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE
The Analog-to-Digital (A/D) Converter module has 10 inputs for the 28-pin
devices and 13 for the 44-pin devices. Additionally, two internal channels are available for
sampling the VDDCORE and VBG absolute reference voltage. This module allows
conversion of an analog input signal to a corresponding 10-bit digital number.
The module has six registers:
• A/D Control Register 0 (ADCON0)
• A/D Control Register 1 (ADCON1)
• A/D Port Configuration Register 2 (ANCON0)
• A/D Port Configuration Register 1 (ANCON1)
• A/D Result Registers (ADRESH and ADRESL)
Figure 2.5-A/D CONVERTER
21
2.7 ELECTRICAL CHARACTERISTICS
2.7.1ABSOLUTE MAXIMUM RATINGS
Ambient temperature under bias
40°C to +125°C
Storage temperature
-65°C to +150°C
Voltage on any digital only I/O pin or MCLR with respect to VSS -0.3V to 6.0V
(except VDD)
Voltage on any combined digital and analog pin with respect to VSS -0.3V to (VDD +
(except VDD)
0.3V)
Voltage on VDDCORE with respect to VSS
-0.3V to 2.75V
Voltage on VDD with respect to VSS
-0.3V to 4.0V
Total power dissipation
1.0W
Maximum current out of VSS pin
300 mA
Maximum current into VDD pin
250 mA
Maximum output current sunk by any PORTB, PORTC and RA6 I/O 25 mA
pin
Maximum output current sunk by any PORTA (except RA6), PORTD 4 mA
and PORTE I/O pin
Maximum output current sourced by any PORTB, PORTC and RA6 25 mA
I/O pin
Maximum output current sourced by any PORTA (except RA6), 4 mA
PORTD and PORTE I/O pin
Table 2.4-ELECTRICAL SPECIFICATIONS
22
2.8 MICROCONTROLLER PIC18F45J11 FEATURES
•Deep Sleep mode: CPU off, Peripherals off, Currents Down to 13 nA and 850 nA with
RTCC
•Able to wake-up on external triggers, programmable WDT or RTCC alarm
•Ultra Low-Power Wake-up (ULPWU)
•Sleep mode: CPU off, Peripherals off, SRAM on, Fast Wake-up, Currents Down to
105na.
•Idle: CPU off, Peripherals on, Currents Down to 2.3 µA Typical
•Run: CPU on, Peripherals on, Currents Down to 6.2 µA Typical
•Timer1 Oscillator/w RTCC: 1 µA, 32 kHz Typical
•Watchdog Timer: 2.2 µA, 2V Typical
2.8.1 SPECIAL MICROCONTROLLER FEATURES
• 5.5V Tolerant Inputs (digital only pins)
• Low-Power, High-Speed CMOS Flash Technology
• C Compiler Optimized Architecture for Re-Entrant Code
• Priority Levels for Interrupts
• Self-Programmable under Software Control
• 8 x 8 Single-Cycle Hardware Multiplier
• Extended Watchdog Timer (WDT):
- Programmable period from 4 ms to 131s
• Single-Supply In-Circuit Serial Programming™ (ICSP™) via Two Pins
• In-Circuit Debug (ICD) with Three Breakpoints via Two Pins
• Operating Voltage Range of 2.0V to 3.6V
• On-Chip 2.5V Regulator
• Flash Program Memory of 10,000 Erase/Write Cycles Minimum and 20-Year Data
Retention.
23
2.8.2 PERIPHERAL HIGHLIGHTS
• Peripheral Pin Select:
- Allows independent I/O mapping of many peripherals
- Continuous hardware integrity checking and safety interlocks prevent unintentional
configuration changes
• Hardware Real-Time Clock and Calendar (RTCC):
- Provides clock, calendar and alarm functions
• High-Current Sink/Source 25 mA/25 mA (PORTB and PORTC)
• Four Programmable External Interrupts
• Four Input Change Interrupts
• Two Enhanced Capture/Compare/PWM (ECCP) modules:
- One, two or four PWM outputs
- Selectable polarity
- Programmable dead time
- Auto-shutdown and auto-restart
- Pulse steering control
• Two Master Synchronous Serial Port (MSSP) modules featuring:
- 3-wire SPI (all 4 modes)
- 1024-byte SPI Direct Memory Access (DMA) channel
- I2C™ Master and Slave modes
• 8-Bit Parallel Master Port/Enhanced Parallel Slave Port
• Two-Rail – Rail Analog Comparators with Input Multiplexing
• 10-Bit, up to 13-Channel Analog-to-Digital (A/D) Converter module:
- Auto-acquisition capability
- Conversion available during Sleep
- Self-Calibration
• High/Low-Voltage Detect module
• Charge Time Measurement Unit (CTMU):
- Supports capacitive touch sensing for touch screens and capacitive switches
- Provides a Precise Resolution Time Measurement for Both Flow Measurement and
Simple Temperature Sensing
• Two Enhanced USART modules:
- Supports RS-485, RS-232 and LIN/J2602
24
- Auto-wake-up on Start bit
• Auto-Baud Detect
2.8.3 FLEXIBLE OSCILLATOR STRUCTURE
• 1% Accurate High-Precision Internal Oscillator
• Two External Clock modes, up to 48 MHz (12 MIPS)
• Internal 31 kHz Oscillator, Internal Oscillators Tunable at 31 kHz and 8 MHz or 48 MHz
with PLL.
• Secondary Oscillator using Timer1 @ 32 kHz
25
CHAPTER 3
MRF24J40MA RF TRENSCIEVER
The MRF24J40MA is a complete 2.4 GHz IEEE Std. 802.15.4™ compliant
surface mount module with integrated crystal, internal voltage regulator, matching circuitry
and PCB antenna. The MRF24J40MA module interfaces to many popular Microchip PIC
microcontrollers via a 4-wire serial SPI interface, interrupt, wake, Reset, power and
ground.
3.1 FEATURES
• IEEE Std. 802.15.4™ Compliant RF Transceiver
• Supports ZigBee®, MiWi™, MiWi™ P2P and Proprietary Wireless Networking
Protocols
• Small Size: 0.7” x 1.1” (17.8 mm x 27.9 mm), Surface Mountable
• Integrated Crystal, Internal Voltage Regulator, Matching Circuitry and PCB Antenna
• Easy Integration into Final Product – Minimize Product Development, Quicker Time to
Market
• Radio Regulation Certification for United States (FCC), Canada (IC) and Europe (ETSI)
• Compatible with Microchip Microcontroller Families (PIC16F, PIC18F, PIC24F/H,
dsPIC33
and PIC32)
• Up to 400 ft. Range
The MRF24J40 is an IEEE 802.15.4™ Standard compliant 2.4 GHz RF transceiver. It
integrates the PHY and MAC functionality in a single chip solution. The MRF24J40
creates a low-cost, low-power, low data rate (250 or 625 kbps) Wireless Personal Area
Network (WPAN) device. The MRF24J40 interfaces to many popular Microchip PIC®
microcontrollers via a 4-wire serial SPI interface, interrupt, wake and Reset.
26
The MRF24J40 provides hardware support for:
• Energy Detection
• Carrier Sense
• Three CCA Modes
• CSMA-CA Algorithm
• Automatic Packet Retransmission
• Automatic Acknowledgment
• Independent Transmit, Beacon and GTS FIFO Buffers
• Security Engine supports Encryption and Decryption for MAC Sublayer and Upper Layer
These features reduce the processing load, allowing the use of low-cost 8-bit
microcontrollers.
The MRF24J40 is compatible with Microchip's ZigBee®, MiWi™ and MiWi P2P
software stacks.
Figure 3.1-BLOCK DIAGRAM
27
3.2 PIN CONFIGURATIONS
Figure 3.2-MRF24J40MA RF TRANSCEIVER
3.2.1 Reset (RESET) Pin
An external hardware Reset can be performed by asserting the RESET pin 13 low. The
MRF24J40 will be released from Reset approximately 250 µs after the RESET pin is
released. The RESET pin has an internal weak pull-up resistor.
3.2.2 Interrupt (INT) Pin
The Interrupt (INT) pin 16 provides an interrupt signal to the host microcontroller from the
MRF24J40. The polarity is configured via the INTEDGE bit in the SLPCON0 (0x211<1>)
register. Interrupts have to be enabled and unmasked before the INT pin is active.
28
3.2.3 Power and Ground Pins
VDD pins 1 and 31 require two bypass capacitors to ensure sufficient bypass decoupling.
Minimize trace length from the VDD pin to the bypass capacitors and make them as short
as possible.
3.2.4 Phase Lock Loop
The Phase Lock Loop (PLL) circuitry requires one external capacitor connected to pin 40
(LCAP). The recommended value is 100 pF. The PCB layout around the capacitor and pin
40 should be designed carefully such as to minimize interference to the PLL.
3.2.5 Wake (WAKE) Pin
The Wake (WAKE) pin 15 provides an external wake-up signal to the MRF24J40 from the
host microcontroller. It is used in conjunction with the Sleep modes of the MRF24J40. The
WAKE pin is disabled by default.
Figure 3.3-TRANSCIVER MODULE
29
CHAPTER-4
MICROCHIP MiWi™ P2P WIRELESS PROTOCOL
4.1 INTRODUCTION
The demand is growing for more and more applications to move to wireless
communication. The benefits are reduced costs and ease implementation. Since the IEEE
released the Wireless Personal Area Network (WPAN) specification (IEEE 802.15.4™) in
2003, it has become the real industry standard for lowrate WPANs (LR-WPAN). The
specification applies to low data rate applications with low-power and low-cost
requirements.
Microchip MiWi™ P2P Wireless Protocol is one of the wireless protocols that
are supported in MiWi Development Environment (DE). It is a variation of IEEE 802.15.4,
using Microchip’s IEEE 802.15.4 compliant and other proprietary RF transceivers, which
are controlled by Microchip 8, 16 or 32-bit microcontroller with a Serial Peripheral
Interface (SPI). Microchip MiWi P2P protocol stack is now expanded beyond IEEE
802.15.4 specification to support Microchip proprietary transceivers (MRF49XA,
MRF89XA and future proprietary transceivers from Microchip), while using IEEE
802.15.4 Media Access
Control (MAC) layer design as the reference.
The protocol provides reliable direct wireless communication through an user
friendly programming interface. It has a rich feature set that can be compiled in and out of
the stack to meet a wide range of customer needs, while minimizing the stack footprint.
This application note describes the MiWi P2P Protocol and its differences from IEEE
802.15.4. The document details the supported features and how to implement.
4.2 PROTOCOL OVERVIEW
The MiWi P2P protocol modifies the IEEE 802.15.4 specification’s Media
Access Control (MAC) layer by adding commands that simplify the handshaking process.
It simplifies link disconnection and channel hopping by providing supplementary MAC
commands.
30
4.3 PROTOCOL FEATURES
The MiWi P2P Wireless Protocol has the following features:
• Operates on Microchip PIC18, PIC24, dsPIC33 and PIC32 platforms
• Supports Microchip C18, C30 and C32 compilers
• Functions as a state machine (not RTOS-dependent)
• Supports a sleeping device at the end of the communication
• Enables Energy Detect (ED) scanning to operate on the least-noisy channel
• Provides active scan for detecting existing connections
• Enables frequency agility (channel hopping)
4.4 PEER-TO-PEER (P2P) TOPOLOGY
From a device role perspective, this topology also has one PAN coordinator
that starts communication from the end devices. When joining the network, however, end
devices do not have to establish their connection with the PAN coordinator. As to
functional types, the PAN coordinator is an FFD and the end devices can be FFDs or
RFDs. In this topology, however, end devices that are FFDs can have multiple
connections. Each of the end device RFDs, however, can connect to only one FFD and
cannot connect to another RFD.
Figure 4.1-P2P TOPOLOGY
31
4.5 NETWORK TOPOLOGY
The IEEE 802.15.4 specification has two types of networks: beacon and nonbeacon. In a beacon network, devices can transmit data only during their assigned time
slot. The PAN coordinator assigns the time slots periodically by sending a superframe
(beacon frame). All devices are supposed to synchronize with the beacon frame and
transmit data only during their assigned time slot. In a non-beacon network, any device can
transmit data at any time when the energy level (noise) is below the predefined level.
Beacon networks reduce all devices’ power consumption because all of the
devices turn off their radios periodically. Non-beacon networks increase the power
consumption by FFD devices because they must have their radios on all the time. These
networks reduce the power consumption of RFD devices, however, because the RFDs do
not have to perform the frequent synchronizations. The MiWi P2P protocol supports only
non-beacon networks.
4.6 NETWORK ADDRESSING
The IEEE 802.15.4 specification defines two kinds of addressing mechanisms:
• Extended Organizationally Unique Identifier (EUI) or long address: An eight-byte
address that is unique for each device, worldwide. The upper three bytes are purchased
from IEEE by the company that releases the product. The lower five bytes are assigned by
the device manufacturer as long as each device’s EUI is unique.
• Short Address: A two-byte address that is assigned to the device by its parent when it
joins the network. The short address must be unique within the network. The MiWi P2P
protocol supports only one-hop communication; hence it transmits messages through EUI
or long address. Short addressing is used only when the stack transmits a broadcast
message.
32
4.7
MESSAGE
FORMAT
FOR
IEEE
802.15.4
COMPLIANT
TRANSCEIVER
The message format of the MiWi P2P protocol is a subset of the IEEE
802.15.4 specification’s message format.
Figure 4.2-FRAME FORMAT OF THE TRANSCEIVER
4.8 MiWi™ P2P WIRELESS PROTOCOL’S UNIQUE FEATURES
The MiWi P2P protocol supports a reduced functionality, point-to-point, direct
connection and a rich set of features. All features can be enabled or disabled and compiled
in and out of the stack, according to the needs of the wireless application. This section
describes the unique features of the MiWi P2P protocol. These include:
• Small programming size
• Support for Idle devices to turn off radio
• Indirect messaging
• Special security features
• Active scan for finding existing PANs on different channels
• Energy scans for finding the channel with the least noise
• Frequency agility (channel hopping)
33
CHAPTER-5
CIRCUIT DIAGRAM AND BOARD PERIPHERALS
5.1 CIRCUIT DIAGRAM
5.1.1CENTRAL MONITORING MOTE
Figure 5.1-CIRCUIT DIAGRAM (MONITORING)
5.1.2SENSOR MOTE
Figure 5.2-CIRCUIT DIAGRAM (CONTROL)
34
5.2BOARD PERIPHERALS
5.2.1 MAX 3232
Figure 5.3-PIN DIAGRAM
The MAX232 is an integrated circuit that converts signals from an RS232 serial port to signals suitable for use in TTL compatible digital logic circuits. The
MAX232 is a dual driver/receiver and typically converts the RX, TX, CTS and RTS
signals.
Table 5.1- RS232 CONVERSION
35
5.2.2 L293D- DRIVER:
•
This device is suitable for use in switching applications at frequencies up to 5 kHz
•
monolithic integrated high voltage, high current four channel driver
•
Accepts standard DTL or TTL logic levels and drive inductive loads (such as relays
solenoides, DC and stepping motors) .
•
PWM output from the microcontroller is the source for driving the loads.
•
duty cycle is altered acc. to the sensor outputs and this value drives the load
Figure 5.4-PIN DIAGRAM OF L293D
36
5.3 SENSORS
5.3.1 LDR (LIGHT SENSOR)
A photoresistor is made of a high resistance semiconductor. If light falling on
the device 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.
LDRs or Light Dependent Resistors are very useful especially in light/dark
sensor circuits. Normally the resistance of an LDR is very high, sometimes as high as 1000
000 ohms, but when they are illuminated with light resistance drops dramatically.
When the light level is low the resistance of the LDR is high. This prevents
current from flowing to the base of the transistors. Consequently the LED does not light.
However, when light shines onto the LDR its resistance falls and current flows into the
base of the first transistor and then the second transistor. The pre-set resistor can be turned
up or down to increase or decrease resistance, in this way it can make the circuit more or
less sensitive.
5.3.1.1APPLICATIONS
1. Photoresistors come in many different types. Inexpensive cadmium sulfide cells
can be found in many consumer items such as camera light meters, street lights,
clock radios, alarms, and outdoor clocks.
2. They are also used in some dynamic compressors together with a
small incandescent lamp or light emitting diode to control gain reduction.
Figure 6.1-LDR SENSOR
37
5.3.2 HIH 5030 (HUMIDITY SENSOR)
The HIH-5030/5031 Series Low Voltage Humidity Sensors operate down to
2.7 Vdc, often ideal in battery-powered systems where the supply is a nominal 3 Vdc. The
HIH 5030/5031 complements our existing line of 5 Vdc SMD (Surface Mount Device)
humidity sensors. HIH-5030 is a covered integrated circuit humidity sensoruses a laser
trimmed, thermoset polymer capacitive sensing element with on-chip integrated signal
conditioning.
The sensing element's multilayer construction provides excellent resistance to most
application hazards such as condensation, dust, dirt, oils and common environmental
chemicals.
5.3.2.1 FEATURES
1.
Operates down to 2.7 Vdc, often ideal in battery-powered systems where the
supply is a nominal 3 Vdc.
2.
Tape and reel packaging allows for use in high volume pick and place
manufacturing (1,000 units per tape and reel)
3.
Molded thermoset plastic housing
4.
Near linear voltage output vs %RH
5.
Laser trimmed interchangeability
6.
Low power design
7.
Enhanced accuracy
8.
Fast response time
5.3.2.2 POTENTIAL APPLICATIONS
1. Air compressors
2. Battery-powered systems
3. Drying equipment
4. HVAC (includes air conditioning, air movement, thermostats, humidifiers,
de-humidifiers, humidistats, enthalpy sensing)
5. OEM assemblies
6. Office automation equipment
38
7. Process equipment
8. Refrigeration (includes bulk and transport systems)
9. Telecommunications cabinets
Figure 6.2-HUMIDITY SENSOR
5.3.3 LM35 (TEMPERATURE SENSOR)
The LM35 sensor series are precision integrated-circuit temperature sensors,
whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The
LM35 series are precision integrated-circuit LM35 temperature sensors, whose output
voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 sensor
thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is
not required to subtract a large constant voltage from its output to obtain convenient
Centigrade scaling.
5.3.3.1 SPECIFICATIONS
The LM35 sensor does not require any external calibration or trimming to
provide typical accuracies of ±¼°C at room temperature and ±¾°C over a full -55 to
+150°C temperature range. Low cost is assured by trimming and calibration at the wafer
level.
It can be used with single power supplies, or with plus and minus supplies. As it draws
only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air.
39
1.
The LM35 is rated to operate over a -55° to +150°C temperature range, while the
LM35C sensor is rated for a -40° to +110°C range (-10° with improved accuracy).
2. The LM35 series is available packaged in hermetic TO-46 transistor packages,
while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92
transistor package.
3. The LM35D sensor is also available in an 8-lead surface mount small outline
package and a plastic TO-220 package.
5.3.3.2 FEATURES
1. Calibrated directly in ° Celsius (Centigrade).
2. Linear + 10.0 mV/°C scale factor.
3. 0.5°C accuracy guarantee able (at +25°C).
4. Rated for full -55° to +150°C range.
5. Suitable for remote applications.
6. Low cost due to wafer-level trimming.
7. Operates from 4 to 30 volts.
8. Less than 60 µA current drain.
9. Low self-heating, 0.08°C in still air.
10. Nonlinearity only ±¼°C typical.
11. Low impedance output, 0.1 Ohm for 1 mA load.
Figure 6.3-TEMPERATURE SENSOR (LM35)
40
CHAPTER-6
SOFTWARE
6.1 GENERAL
The chapter deals with the software section which gives life to the hardware.
The software used to program the PIC microcontroller to perform the certain operations is
MPLAB. The software used to control the robot from the PC is HyperTerminal and the XCTU software is used to configure the Zigbee modem.
6.2 MPLAB
MPLAB Integrated Development Environment (IDE) is a free, integrated
toolset for the development of embedded applications employing Microchip's PIC
microcontrollers. MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use
and includes a host of free software components for fast application development and
super-charged debugging. MPLAB IDE also serves as a single, unified graphical user
interface for additional Microchip and third party software and hardware development
tools. Moving between tools is a snap, and upgrading from the free software simulator to
hardware debug and programming tools is done in a flash because MPLAB IDE has the
same user interface for all tools.
Both Assembly and C programming languages can be used with MPLAB. Others may be
supported through the use of third party programs.
MPLAB IDE runs on a PC and contains all the components needed to design and deploy
embedded systems applications.
The typical tasks for developing an embedded controller application are:

Create the high level design. From the features and performance desired, decide
which PIC microcontroller is best suited to the application, then design the
associated hardware circuitry. After determining which peripherals and pins control
the hardware, write the firmware – the software that will control the hardware
aspects of the embedded application. A language tool such as an assembler, which
41
is directly translatable into machine code, or a compiler that allows a more natural
language for creating programs, should be used to write and edit code. Assemblers
and compilers help make the code understandable, allowing function labels to
identify code routines with variables that have names associated with their use, and
with constructs that help organize the code in a maintainable structure.

Compile, assemble and link the software using the assembler and/or compiler and
linker to convert your code into “ones and zeroes” – machine code for the PIC
microcontroller. This machine code will eventually become the firmware (the code
programmed into the microcontroller).

Test your code. Usually a complex program does not work exactly the way
imagined, and “bugs” need to be removed from the design to get proper results. The
debugger allows you to see the “ones and zeroes” execute, related to the source
code you wrote, with the symbols and function names from your program.
Debugging allows you to experiment with your code to see the value of variables at
various points in the program, and to do “what if” checks, changing variable values
and stepping through routines.

“Burn” the code into a microcontroller and verify that it executes correctly in the
finished application. Of course, each of these steps can be quite complex. The
important thing is to concentrate on the details of your own design, while relying
upon MPLAB IDE and its components to get through each step without
continuously encountering new learning curves.
6.3 HYPERTERMINAL
HyperTerminal is communications software used to connect to other
computers over modems, RS-232 serial connections, or telnet. In order to use
HyperTerminal, the user will have to know details about the computer they wish to connect
to, such as the number to dial or the IP address.
HyperTerminal can be accessed by:

Clicking Start on the desktop

Going to All Programs

Clicking Accessories

Then Communications
42

Next clicking HyperTerminal to start the program
For first time users, a window will open asking you to insert "Location Information". This
will include information such as your country, area code, the way you would like to
connect (modem/TCP) or if your phone uses tone or pulse dialing. Then click OK.
A "New Connection" window opens up, allowing you to choose a name and an icon for
your HyperTerminal session. After this information has been filled out, use the "telephone"
icons on the HyperTerminal toolbar to connect or disconnect a call to another computer.
Other than connecting to other computers, HyperTerminal can be used to monitor the
status of your modem. The details of any connection made using HyperTerminal are
recorded in a log file. Reviewing this file can be one way to troubleshoot modem issues.
43
CHAPTER-7
APPENDIX
Green_House Mote 0
MCU
:
PIC18F45J11
Description
:
PC Interface Display Mote
#include <p18cxxx.h>
#include "delay.h"
#include "miwi_p2p.h"
#include "uart_driver.c"
#include "hyperterminal.c"
BYTE myChannel = CHANNEL_18;
#define BUZZER
LATAbits.LATA3
void pc_disp_title(void);
void main(void) {
OSCCON = 0b01100000;
// 4 MHz internal oscillator
OSCTUNEbits.PLLEN = 1;
// PLL enabled (16 MHz)
MiWiP2PInit();
ANCON0bits.PCFG3 = 1;
// RA3 is digital
BUZZER = 0;
TRISAbits.TRISA3 = 0;
// acts as Buzzer output
uart_init(416);
pc_disp_title();
while(1) {
if( ReceivedPacket() ) {
if(RxMoteID == 1) {
LED ^= 1;
next_line();
goto_start(); tab(1);
44
uart_putn(RxData);
goto_start(); tab(2);
uart_putn(RxData1);
goto_start(); tab(3);
uart_putn(RxData2);
}
else if(RxMoteID == 2) {
LED ^= 1;
next_line();
goto_start();tab(6);
uart_putn(RxData);
goto_start(); tab(7);
uart_putn(RxData1);
goto_start(); tab(8);
uart_putn(RxData2);
}
DiscardPacket();
}
}
}
void pc_disp_title(void) {
INT8 i;
next_line();next_line();
for(i=1; i<=80; i++)
uart_putc('*');
next_line();tab(4);
uart_puts("GREEN HOUSE MONITORING ");
uart_putc(0x0a);
// Line Feed
next_line();next_line();
for(i=1; i<=80; i++)
uart_putc('*');
next_line();next_line();
goto_start();tab(2);
45
uart_puts(" MOTE 1");
goto_start();tab(7);
uart_puts(" MOTE 2");
next_line();
next_line();
goto_start();
goto_start();tab(1);
uart_puts("HUM");
goto_start();tab(2);
uart_puts("TEMP");
goto_start();tab(3);
uart_puts("LIGHT");
goto_start();tab(5);
goto_start();tab(6);
uart_puts("HUM");
goto_start();tab(7);
uart_puts("TEMP");
goto_start();tab(8);
uart_puts("LIGHT");
next_line();next_line();
next_line();next_line();
}
46
Green_House Mote 1
MCU
:
PIC18F45J11
Sensors
:
Humidity, Temperature, Light
Control
:
Fan, Light
#include <p18cxxx.h>
#include "delay.h"
#include "miwi_p2p.h"
#include "adc_driver.c"
#include "pwm_driver.c"
BYTE myChannel = CHANNEL_18;
#define FAN_MAX
200
#define FAN_MIN
35
#define LIGHT_MAX
100
#define LIGHT_MIN
25
#define PWM_THRO
25
#define LOOP_CNT_MAX
20
#define SAMPLE_SLOW
1
#define SAMPLE_FAST
0
INT16 adc_result_average(void);
void sensor_ref_update(void);
void LongDelay(void);
void SendSensorData(void);
INT16 humidity_sensor_val, temp_sensor_val, light_sensor_val;
INT8 pwm,temp_sensor_ref;
void main(){
INT16 loop_cnt;
float light_sensor_val_factor = 100.0/(LIGHT_MAX - LIGHT_MIN);
OSCCON = 0b01100000;
// 4 MHz internal oscillator
OSCTUNEbits.PLLEN = 1;
// PLL enabled (16 MHz)
MiWiP2PInit();
47
adc_init();
DelayMs(30);
PWMInit();
loop_cnt = 0;
while(1) {
loop_cnt++;
DelayMs(30);
adc_channel(2);
humidity_sensor_val = adc_result() >> 3;
DelayMs(30);
adc_channel(0);
light_sensor_val = (INT8)(adc_result_average() >> 3);
DelayMs(30);
adc_channel(1);
temp_sensor_val = adc_result() / 3;
if(temp_sensor_val == 30 || temp_sensor_val == 45)
{
pwm = FAN_MIN;
SetDC1(pwm);
}
else if(temp_sensor_val == 46 || temp_sensor_val == 65)
{
pwm = FAN_MIN + PWM_THRO;
SetDC1(pwm);
}
else if(temp_sensor_val == 65 || temp_sensor_val == 80)
{
pwm = FAN_MAX;
SetDC1(pwm);
}
else if (temp_sensor_val <= 30)
{
pwm = 0;
48
SetDC1(pwm);
}
if(light_sensor_val < LIGHT_MIN)
{
pwm = LIGHT_MAX;
SetDC0(pwm);
}
else if ((light_sensor_val <=LIGHT_MIN) && (light_sensor_val >= LIGHT_MAX))
{
pwm = (int8)((light_sensor_val - LIGHT_MIN) * light_sensor_val_factor);
SetDC0(pwm);
}
else if(light_sensor_val < 80)
{
pwm = LIGHT_MIN;
SetDC0(pwm);
}
else if (light_sensor_val < 96 )
{
pwm = 0;
SetDC0(pwm);
}
if(loop_cnt > LOOP_CNT_MAX)
{
LED = 1;
SendSensorData();
loop_cnt = 0;
LED = 0;
}
}
}
49
INT16 adc_result_average(void)
{
INT8 i;
INT16 ave;
ave = 0;
for (i = 1; i <= 8; i++)
{
DelayMs(5);
ave += adc_result();
}
ave >>= 3;
return ave;
}
void LongDelay(void) {
INT8 i;
for(i = 1; i <= 8; i++)
{
DelayMs(250);
}
}
void SendSensorData(void)
{
LED ^= 1;
FlushTx();
WriteData(humidity_sensor_val);
WriteData(temp_sensor_val);
WriteData(light_sensor_val);
BroadcastPacket();
LED ^= 1;
}
50
Green House Mote 2
MCU
:
PIC18F45J11
Sensors
:
Humidity, Temperature, Light
Control
:
Fan, Light
#include <p18cxxx.h>
#include "delay.h"
#include "miwi_p2p.h"
#include "adc_driver.c"
#include "pwm_driver.c"
BYTE myChannel = CHANNEL_18;
#define LIGHT_MAX
100
#define LIGHT_MIN
25
#define FAN_MAX
200
#define FAN_MIN
35
#define PWM_THRO
25
#define LOOP_CNT_MAX
20
#define SAMPLE_SLOW
1
#define SAMPLE_FAST
0
INT16 adc_result_average(void);
void sensor_ref_update(void);
void LongDelay(void);
void SendSensorData(void);
INT16 humidity_sensor_val, temp_sensor_val, light_sensor_val;
INT8 pwm;
51
void main()
{
INT8 txflag;
float light_sensor_val_factor = 100.0/(LIGHT_MAX - LIGHT_MIN);
OSCCON = 0b01100000;
// 4 MHz internal oscillator
OSCTUNEbits.PLLEN = 1;
// PLL enabled (16 MHz)
MiWiP2PInit();
adc_init();
DelayMs(30);
PWMInit();
while(1)
{
DelayMs(20);
adc_channel(2);
humidity_sensor_val = adc_result() >> 3;
DelayMs(20);
adc_channel(1);
temp_sensor_val = adc_result() / 3;
DelayMs(20);
adc_channel(0);
light_sensor_val = (INT8)(adc_result_average() >> 3);
if(temp_sensor_val == 30 || temp_sensor_val == 45)
{
pwm = FAN_MIN;
SetDC1(pwm);
}
else if(temp_sensor_val == 46 || temp_sensor_val == 65)
{
pwm = FAN_MIN + PWM_THRO;
SetDC1(pwm);
}
52
else if(temp_sensor_val == 65 || temp_sensor_val == 80)
{
pwm = FAN_MAX;
SetDC1(pwm);
}
else if (temp_sensor_val <= 33)
{
pwm = 0;
SetDC1(pwm);
}
if(light_sensor_val < LIGHT_MIN)
{
pwm = LIGHT_MAX;
SetDC0(pwm);
}
else if ((light_sensor_val <=LIGHT_MIN) && (light_sensor_val >= LIGHT_MAX))
{
pwm = (int8)((light_sensor_val - LIGHT_MIN) * light_sensor_val_factor);
SetDC0(pwm);
}
else if(light_sensor_val < 80)
{
pwm = LIGHT_MIN;
SetDC0(pwm);
}
else if (light_sensor_val < 96 )
{
pwm = 0;
SetDC0(pwm);
}
if( ReceivedPacket() ) {
if(RxMoteID == 1) {
53
DiscardPacket();
DelayMs(100);
LED = 1;
SendSensorData();
LED = 0;
}
}
}
}
INT16 adc_result_average(void)
{
INT8 i;
INT16 ave;
ave = 0;
for (i = 1; i <= 8; i++)
{
DelayMs(5);
ave += adc_result();
}
ave >>= 3;
return ave;
}
void LongDelay(void)
{
INT8 i;
for(i = 1; i <= 8; i++)
{
DelayMs(250);
}
}
54
void SendSensorData(void)
{
LED ^= 1;
FlushTx();
WriteData(humidity_sensor_val);
WriteData(temp_sensor_val);
WriteData(light_sensor_val);
UnicastPacket(0);
LED ^= 1;
}
55
SCREENSHOTS
Figure 7.1-"MOTE-0"CODE
Figure 7.2-"MOTE-1" CODE
56
Figure 7.3-"MOTE-2" CODE
Figure 7.4-BURNING TO MICROCONTROLLER
57
CONCLUSION
The measurement and control system for environment parameters in
greenhouse based on wireless communication technology is developed and initially
experimented.
It can be kept long distance, real time monitoring for parameter of
greenhouse and the information can be obtained of greenhouse at any time.
It has the advantages of not needing cables, low power consumption, cheap
cost, good robustness, flexible extension, convenient installing over the traditional
measurement and control system. The future scope is that we can make use of sprinkler to
control the humidity and thus one of the three essential parameters also can be controlled
on larger scale in the green house environment can be maintained efficiently.
58
REFERENCES
1. Othman Sidek, Muhammad Qayum Omar, Hashim Edin, Khairu Anuar Mohamed
Zain and Muhamad Azman Miskam “Preliminary Infrastructure Development for
Greenhouse Accounting of Malaysian Rainforest Using Wireless Sensor Network”
ISSN 1450-216X Vol.33 No.2 (2009), pp.249-260 © EuroJournals Publishing, Inc.
2009.
2. Andrzej Pawlowski , Jose Luis Guzman , Francisco Rodríguez , Manuel Berenguel
, José Sánchez and Sebastián Dormido “Simulation of Greenhouse Climate
Monitoring and Control with Wireless Sensor Network and Event-Based Control”
2Sensors 2009, 9, 232-252; doi:10.3390/s90100232.
3. Leong Boon Tik
Chan Toong Khuan Sellappan Palaniappan “Monitoring of an
Aeroponic Greenhouse with a Sensor Network” International Journal of Computer
Science and Network Security, VOL.9 No.3, March 2009.
4. Teemu Ahonen, Reino Virrankoski and Mohammed Elmusrati “Greenhouse
Monitoring with Wireless Sensor Network” University of Vaasa Department of
Computer Science
5. Telecommunication Engineering Group. Yang Shulian, Zhang Yu “Wireless
Measurement and Control System for Environmental Parameters in Greenhouse”
Shandong University of Technology 2010 International Conference on Measuring
Technology and Mechatronics Automation.
WEBSITES
1. www.embedded.com
2. www.howstuffworks.com
3. http://en.wikipedia.org/wiki/RS232
4. http://standards.ieee.org/getieee802/download/802.15.4-2003.pdf.
5. http://grouper.ieee.org/groups/802/15/pub/2003/Tutorial.ppt
6. ww1.microchip.com/downloads/en/devicedocww1.microchip.com/downloads/en/d
evicedoc/39932c.pd/39932c.pdf
7. http://ww1.microchip.com/downloads/en/AppNotes/AN1066%20%20MiWi%20App%20Note.pdf