Anda di halaman 1dari 97

AUTOMATIC GARBAGE TRAP

FARAH HAYATI BINTI OTHMAN

UNIVERSITI KUALA LUMPUR JANUARY 2011

AUTOMATIC GARBAGE TRAP

FARAH HAYATI BINTI OTHMAN 51210207052

Report Submitted to Fulfill the Partial Requirements for the Bachelor of Engineering Technology (Hons) in Electrical Universiti Kuala Lumpur British Malaysian Institute

JANUARY 2011

DECLARATION

I declare that this report entitle Automatic Garbage Trap is the results of my own research excepts as cited in the references. The report has not been accepted for any degree and is not concurrently submitted in candidature of any other degree.

Signature : ............................................. Name ID No Date : Farah Hayati Binti Othman : 51210207052 :

APPROVAL PAGE

We have examined this report and verify that it meets the program and Universiti requirements for the Bachelor of Engineering Technology ( Hons ) in Electrical.

Date :

Signature

: ............................................

Supervisors Name : En.Azman Bin Abd. Aziz Official Stamp :

Date :

Signature

: ..........................................

Co Supervisors Name : Official Stamp :

ACKNOWLEDGEMENT

In the name of Allah S.W.T the most compassionate and merciful, I would like to express my gratitude for Allah S.W.T blessing and guidance through preparing this project and report until done. I also would like to acknowledge my supervisor, En.Azman Bin Abd. Aziz for his useful guidance, information, motivative critics and valuable advice throughout the two semester upon the completion of the final year project. I also would like to give my special dedication to my father, my mother and family for their understanding and supports throughout my studies. Last but not least, is to all my friends and colleagues for their suggestion that had opened my mind to handle and complete this project.

ABSTRACT

Automatic Garbage Trap is a project that emphasizes environmental cleanliness. Measures to deal with environmental pollution, particularly in the area of the river have given some ideas to invent this kind of system. This project requires the system to let the sensors and software monitored the operations. Sound alarm notification ensured the unsafe environment so an immediate action can be taken. Automatic Garbage Trap consists of two parts: the transmitter base and the receiver base. This project was implemented using PIC16F877A microcontrollers and RF module allowed wireless communication operated at 433MHz. The transmitter base consists of a sensor to sense any materials surround it, DC motor roles in movement for some parts, processed, and transfer the data to receiver. Then receiver will capture the signal, process, and finally display data on LCD panel with alert system consists of LED and buzzer. Several steps have been taken in order to implement this project from understanding all the basic theory involved, designing and simulating the design specifications, fabrication and lastly, testing to ensure that the project works correctly as needed

TABLE OF CONTENTS

CONTENTS TITLE PAGE DECLARATION APPROVAL PAGE ACKNOWLEDGEMENTS ABSTRACT TABLE OF CONTENTS LIST OF FIGURES LIST OF TABLES LIST OF ABBREVIATIONS

PAGE I II III IV V VI IX XI XIII

CHAPTER I: INTRODUCTION 1.1 Introduction 1.2 Project Background 1.3 Project Statement 1.4 Objectives 1.5 Scope of Project 1.6 Summary 1 1 2 2 3 3

CHAPTER II: LITERATURE REVIEW 2.1 History 2.1.1 Previous Work 2.1.1.1 Research 1 2.1.1.2 Research 2 2.1.1.3 Research 3 2.1.2 Present Work 2.2 Review of History 2.3 Summary 4 5 5 6 7 8 8 8

CHAPTER III: METHODOLOGY 3.1 Introduction 3.2 Project Development Block Diagram 3.2.1 Description of the Block Diagram 3.3 Hardware Development 3.3.1 Microcontroller Unit 3.3.2 RF Modules 3.3.3 Voltage Regulator 3.3.4 Dual Full-Bridge Driver 3.3.5 Infrared Sensor 3.3.6 LED 3.3.7 Buzzer 3.3.8 LCD 3.4 Software Development 3.4.1 Assembly Language 3.4.2 Description of Programming Flowchart 3.4.3 Software Tools 3.4.3.1 MPLAB IDE 3.4.3.2 Proteus Professional 3.4.3.3 Protel 99se 3.4.3.4 PICkit 2 3.4.3.5 PCB Fabrication 3.4.3.6 Project Development Tools Required 3.5 Summary 9 12 13 14 17 18 20 21 21 22 22 22 23 23 26 27 27 29 30 31 32 33 33

CHAPTER IV: RESULT AND ANALYSIS 4.1 Introduction 4.2 PCB and Circuitry 4.3 Software Simulation 4.4 Summary 34 34 37 41

CHAPTER V: CONCLUSION AND RECOMMENDATION 5.1 Conclusion 5.2 Recommendation 42 43

REFERENCES

44

APPENDICES APPENDIX A: TRANSMITTER AND RECEIVER SOURCE CODES APPENDIX B: DATASHEETS 45 79

LIST OF FIGURES

TITLE

PAGES

Figure 2.1: Floating Boom, collecting garbage trapped, and loaded into truck Figure 2.2: A state of the art litter trap to collect debris floating along rivers Figure 2.3: Debris is directed via collection booms through a patented one way flap or gate to capture floating litter and debris Figure 3.1: System Design flowchart Figure 3.2: System Design flowchart (continue) Figure 3.3: Basic block operation of PIC Figure 3.4: Transmitter Base schematic Figure 3.5: Receiver Base schematic Figure 3.6: Voltage Regulator schematic Figure 3.7: IR sensor schematic Figure 3.8: Motor Driver schematic Figure 3.9: PIC16F877A Microcontroller Chip Figure 3.10: Pin Diagram of PIC16F877A Figure 3.11: RF Transmitter (433MHz) Figure 3.12: RF Receiver (433MHz) Figure 3.13: 5V regulator LM7805 Figure 3.14: L298N motor driver Figure 3.15: Transmitter Base Program flowchart Figure 3.16: Receiver Base Program flowchart Figure 4.1: RX Base Components Layout Figure 4.2: RX Base PCB Layout Figure 4.3: RX Base Board Figure 4.4: Motor Driver Components

5 6 7

10 11 12 12 12 16 16 16 17 17 18 19 20 21 24 25 34 34 34 35

Figure 4.5: Motor Driver PCB Layout Figure 4.6: Motor Driver Board Figure 4.7: IR Components Layout Figure 4.8: IR PCB Layout Figure 4.9: IR Board Figure 4.10: TX Base Components Layout Figure 4.11: TX Base PCB Layout Figure 4.12: TX Base Board (front view) Figure 4.13: TX Base Board (back view) Figure 4.14: Simulation in Initial condition Figure 4.15: LCD display from Initial condition Figure 4.16: Simulation in Normal condition Figure 4.17: LCD display from Normal condition Figure 4.18: Simulation in Warning condition Figure 4.19: LCD display from Warning condition

35 35 35 35 35 36 36 36 36 38 38 39 39 40 40

LIST OF TABLES

TABLE NO. Table 3.1: Table 3.2: Table 4.1:

TITLE The Specifications of RF Transmitter The Specifications of RF Receiver System Operation

PAGE 19 20 37

LIST OF ABBREVIATIONS

A/D ADC ADCON ADRESL AM BOR CCP CM CPU Dec EEPROM HEX LSB MCLR MCU MHz MSB PWM RAM RF SAW UART -

Analog to Digital Converter Analog to Digital Converter Analog Digital Control Analog Digital Amplitude Modulation Brown Out Reset Capture/Compare/PWM Centralized Monitoring Centre Programmable Unit Decimal Electrically Erasable Programmable Read Only Memory Hexadecimal Lowest Significant Bit Master Clear Micro Controller Unit Mega Hertz Most Significant Bit Pulse Width M Random Access Memory Radio Frequency Surface Acoustic Wave Universal A Receiver Transmitter

USART VSM PCB FM FYP IC LCD LED IR -

Universal Synchronous Asynchronous Receiver Transmitter Virtual System Modelling Printed Circuit Board Frequency Modulation Final Year Project Integrated Circuit Liquid Crystal Display Light Entry Diode Infrared

CHAPTER I

INTRODUCTION 1.1 Introduction Wireless communication is expected to be a key technology for remote sensing system, especially in remote monitoring multiple devices. The use of RF-signal is extremely desirable due to the ability to penetrate walls and ceilings. The purpose of a remote monitoring system is to collect data at a place that is inconvenient and to relay the data to a point where the data may be evaluated. The project deal with the design of DC motor driver and limit switch system that monitors the motion and load and will be display it on a LCD screen panel by using RF as a remote communication medium. The focus of this project is to design and build a wireless monitoring retrieval communication system that effectively communicates between the transmitter and receiver bases. The rationale behind this is to provide the user with the information regarding the load condition that allows a smart monitoring method.

1.2 Project Background This project consists of two major components, the transmitter base (contain sensor devices) and the receiving base (collection and display devices). The wireless monitoring system was designed as a stand-alone system. The transmitter base consists of a microcontroller and IR sensors mounted approximate to the base to detect materials in surrounding condition. The information which is the load of materials then encoded using a microcontroller and sent through a transmitter at 433MHz. While at receiver base, another microcontroller is used to decode the received data and its parameter display on LCD panel. The LCD will indicate the data received in two different signals. In high load (overload), LED and buzzer provide as alarm notification. The details of hardware and software design are explained in the next section.

1.3 Project Statement In conjunction with the rapid growth in technology and economy development, a great effort has been made to create a system that can reduce the percentage of various type of pollution especially in Malaysia. Automatic Garbage Trap is designed to overcome any risk problem involved inconvenient surrounding especially in waters such as river. There are a lot of advantages that can be achieved when applying this project in the real environmental situation, especially on water which is basic need in daily life for human to survive.

This prototype is using a wireless system offering a high reliability service at a low cost. It is vital that circuits design have been made properly to provide a better sensitivity, selectivity and stability while simplifying the circuit design to minimize the components count and board space, reducing the cost, and lowering the power consumption.

1.4 Objectives The prime objective is to to develop a suitable mechanism for garbage trap on river. Secondly is to find out the most effective way to help create a more stable environment. Any critical situation happen can be taken immediately according to the data displayed. Thirdly is to apply wireless monitoring system that utilizes of RF transmitter and receiver, microcontrollers and the use of small antenna to allow wireless data transfer to operate via RF signal.

1.5 Scope of Project This project is divided into two main parts: transmitter base (sensor devices) and the receiver base (collection and display devices). The transmitter and receiver are implemented by preliminary studies on relevant subject regarding environment monitoring fundamentals, knowledge on Assembler Language and compiler, circuit design and program loader, software tool, microcontroller etc. Then a voltage regulator LM7805, microcontroller PIC16F877A, RF Transmitter 433MHz (baud rate 4800, data rate 4.8kbit/sec), five limit switch, two IR sensors and two DC motor are developed for transmission part. Receiving part is developed by microcontroller PIC16F877A, RF Receiver 433MHz, LCD display panel, LED and a sound buzzer (alarm). The load data result is displayed on LCD panel.

Programming works is conducted including ADC, Serial Data Communication and processing part. Then circuit is designed and implemented on board.

1.6 Summary The overall of this project is to study and explore the application of microcontroller as a brain which can control application including transmitting and receiving RF signal and function according to the commands written in the programming source code.

CHAPTER II

LITERATURE REVIEW 2.1 History Water pollution has become increasingly troubling in the last few decades. Even though many new laws have been enacted to try to protect the water sources there is still much work to be done to keep the water systems of the world clean and pollution free. Once a source of drinking water, many rivers in Malaysia have become dumping grounds for various types of hazardous wastes. Of all natural resources, water is the most severely threatened by pollution in this country. Generally, water pollution in Malaysia is caused by point and non- point sources. Point sources comprise sewage treatment plants, manufacturing and agro-based industries as well as animal farms. Nonpoint sources are made up of diffused sources such as agricultural activities and surface runoffs. There are many ethnic aboriginal groups that still exist in Malaysia and the people depend on the rivers and streams to survive. They depend on the river for food, water supply for drinking, bathing and for their crops. The river happens to be the main centre of their livelihood and without the rivers the whole tribes cannot survive as their ancestors had done generations before them, all of them depending on the rivers.

2.1.1 Previous Work This project generally involves comprehensive knowledge on an Automatic Garbage Trap control and movement aspect. To develop autonomous garbage trap system, the information and data have been collected based on the review of journals, thesis and internet sources to make that the project developing successfully. The purpose of collected information and data is to get some idea how to design and develop the Automatic Garbage Trap system.

2.1.1.1 Research 1 Reference: Thesis Title: Analysis of Floating Refuse Along Gombak River Year: 1987 Author: Yong Eu Fan and Tan Ka Kheng, Universiti Pertanian Malaysia, Serdang.

Figure 2.1: Floating Boom, collecting garbage trapped, and loaded into truck

The floating lock boom was made from empty drums strung together across the river and anchored to both banks. The boom floats with the rise and fall of the water level. Floating refuse was trapped by a floating boom tied across the width of the river, which was built by Jabatan Parit dan Taliair Selangor on an experimental basis. The refuse was

retrieved and collected by a team of workers from city Hall on a daily basis. The refuse collected was then hauled away by a truck to a disposal site.

2.1.1.2 Research 2 Reference: Article Title: River Darwen Litter Trap Project, Blackburn, UK Year: 2007 Author: David Gibbs

Figure 2.2: A state of the art litter trap to collect debris floating along rivers

The litter trap consists of a floating boom, which deflects floating litter and debris into a steel cage that can be lifted out from the river to be emptied. The trap is designed to cope with all but the largest items of waterborne waste. The litter trap has been installed at Witton Country Park (Blackburn) in the River Darwen, just downstream of its confluence with the River Blakewater, which is mainly culverted beneath Blackburn. Most of the floating litter comes from the River Blakewater, which is why the litter trap has been installed where it meets the main River Darwen.

2.1.1.3 Research 3 Reference: Article Title: Bandalong Litter Trap, Hobart Rivulet, Australia Year: 1993 Author: James Wood

Figure 2.3: Debris is directed via collection booms through a patented one way flap or gate to capture floating litter and debris.

The Bandalong Litter Trap floats on waterways, given buoyancy by exceptionally strong and durable polyethylene pipes. The unit is held in place by galvanized chains attached to ground anchors or fitted to rider poles for canal installations. Outspread collection booms direct floating litter through a one-way mesh gate into the trap where it is retained ready for removal. Re-entrainment is prevented by a system of counterweights and paddles that close the entry gate when the water flow ceases or there is a change in flow direction due to tide or wind. A 150mm polyethylene side skirt beneath the waterline prevents debris from escaping from under the main floats

2.1.2 Present Work Automatic Garbage Trap is a prototype which has been designed similar with the Boom concept but it used 100 percent mechanical part including electronic hardware and software programming. The Boom is replaced by a net that made by zinc, which controlled by DC motor with forward and reverse motion. Obviously, the major difference between Automatic Garbage Trap and typical Boom system is automatically operate and capable to transmit and receive data. This technology gives a lot of advantage to mankind and nature as well. This project is specially recommended to other party who is interested to take some ideas in developing the same concept and objectives due to this project.

2.2 Review of History Manual controlling and data collection methods are still in wide use today. Such methods usually involve more than one person to do such job. Manually control and collecting data in this method has some obvious advantages: there is minimal equipment to purchase, there are next to nothing to maintain and service, and everything is very quick and easy to set up. Manual systems, though, can be very expensive to operate and are often unreliable. In this cases, to pay the salary for each worker due to the unstable economic condition, hiring new worker, monitoring every work done, are totally counted. All these system need to properly organized and always be ready to face any risk in future. For the above reasons, many facility managers can easily cost-justify a move from manual methods to some sort of automated systems.

2.2 Summary Normally, pollution is caused by human itself. Low in mentality, morality and culture are the reasons to nature disaster. Because of no enforcement in law applied to river or lake area, it will be our responsibility and awareness to protect our nature. In fact, 70 percent of earth contains water and all living creatures need water to survive.

CHAPTER III

METHODOLOGY

3.1 Introduction Automatic Garbage Trap is developed into two part that are transmitting base part and receiving base part contains hardware and software design. Hardware design is developed to build a smart material detector that can sense, transmit, receive and display data while software design consist program to control the whole process of microcontroller regarding analysis, and communication between devices. However this project will be implemented in five stages. First thing is conducted preliminary studies on relevant subject regarding to the project such as telemetry system fundamentals, knowledge on Assembly Language and compiler and circuit design. Upon completing this stage, the second stage is interfaced the hardware. Circuits are designed and simulated using PROTEUS- ISIS to ensure they are all free of error. Next stage is all about programming woks using MPLAB. There are a few important steps in programming. Each time a segment of a new code is completed, it is to be simulated to check for any error.

The fourth stage is integrated both software and hardware together to test the whole system. Test system is done on software by using PROTEUS-ISIS before implemented into hardware. Debugging work is implemented to identify and solve problem. Next stage is to embed the software (programme) into PIC microcontroller using PICKit2 software and circuit design is implemented into PCB board. Then calibration works is done to match the actual data and the obtain data. Finally the whole system is implemented into board. The overall project flow is shown in figure 3.1 and figure 3.2 as below.

START

Literature Review

Design schematic circuit on Proteus ISIS (source from internet and datasheet)
Yes No

Success? Permasala han Write program (Assembly Language) for PIC16F877A using MPLAB

Redesign circuit

Run Program
Yes No

Success?? Permasala han A

Revise the source code

Figure 3.1: System Design flowchart

Combine program and schematic design (attach .HEX in PIC)

Simulate
Yes No

Success?? Permasal ahan Download program (.HEX) in PIC using PICKit 2


Yes No

Debug (troubleshoot or recheck program)

Success?? Permasal ahan Proceed to hardware

Read data downloaded at program memory

END

Figure 3.2: System Design flowchart (continue)

3.2

Project Development Block Diagram

Motor Driver Circuit

12V DC supply

LCD display

IR Sensor (1,2) 5V Regulator Limit Switch (1,2,3,4,5) PIC RX 16F877A 5V Regulator Buzzer PIC RX 16F877A

LED

TX Module

Transmitting RF Signal

Receiving RX Module

Figure 3.3: Basic block operation of PIC

3.2.1 Description of the Block Diagram Automatic Garbage Trap system is actually using two units of MCU which are both PIC16F877A model that powered by 12V DC supply using adapter and has been step down to 5V DC by voltage regulator which is used by almost all the components in the system. PIC TX is referring to the transmitter base microcontroller unit (MCU) while PIC RX is referring to receiver base MCU. Each MCU operates with different roles. PIC TX consists of motor driver, two units IR sensor, 5 units limit switch, and also transmitter module. Briefly, there are two DC motors connected at PIC TX. Every single DC motor has two limit switches and one IR sensor and they have a same function which is to detect, to move forward and reverse while limit switch has a relay that could stop the motor movement if it is touched. Transmitter and receiver modules are linked with Radio Frequency (RF) signal. They must have the same frequency, otherwise they cannot communicate to each other and thus the data will not be successfully received. In addition, RF modulation is transmitting and receiving data with a straight wave signal. So that, it must not have any obstacles between these two modules in order to prevent transmission disturbances. LCD, LED and buzzer at PIC RX are functions as an output to the data received. LCD will display all the bytes that have been sent via transmitter. But the data must be read by PIC RX before it gives command to all output. Other than same frequency used, the programming should be excellent in order to connect transmitter and receiver signals. These serial communication commands must be in proper order due to the two units of MCU used in the system.

3.3 Hardware Development

The transmitter base unit in figure 3.4 is the main part of this project. A microcontroller chip used to process the gathered data, which is then encoded into appropriate data packets and sent via the radio wave (RF) wireless transmitter at 433MHz. Transmitter base also contains of two motors at port B which are RB7, RB6, RB5 and RB4. IR sensors which are connected at port A pin RA0 and RA1 and limit switches are connected at port C pin RC1 and RC2. RF Transmitter has 3 pins (Vcc, GND and Data). In this project, Vcc pin is connected to 5V and GND pin is connected to GND of circuit board. The data pin is connected to pin 25 (RC6/TX/CK).

While at the receiver base unit showed in figure 3.5, the receiver at the same frequency 433MHz as transmitter, is expected to receive the data sent and decoded using another same microcontroller. There are 4 pins for the receiver (Vcc, GND and Data pin). Same as transmitter, 5V is given to Vcc pin and GND pin is connected to GND of circuit board. The data (output) pin is connected to pin 26 (RC7/RX/DT). The actual data gathered then will be displayed on LCD panel which is connected at port B (RB0-RB7) and pin E, RW and RS are connected to pin RD7, RD6 and RD5. LED and buzzer as the output as well are connected at pin RD0 and RD1.

Figure 3.6 shows the voltage regulator circuit, a LM7805 with 9V input and 5V output is connected to VDD pin of microcontroller. Maximum input voltage is 12V and 5V is a standard voltage that usually used for sensor, relay driver, and other parts in circuit. IN4007 diode allows electricity to flow in only one direction and resistor is function as a load which allows small current flow through it and to switch on the LED. The capacitors functioned as a filter to produce clean DC operating voltage.

Figure 3.4: Transmitter Base schematic

Figure 3.5: Receiver Base schematic

Figure 3.6: Voltage Regulator schematic

Figure 3.7: IR sensor schematic

Figure 3.8: Motor Driver schematic

3.3.1 Microcontroller Unit

Figure 3.9: PIC16F877A Microcontroller Chip

Figure 3.10: Pin diagram of PIC16F877A

The microcontrollers might look a bit difficult at first thought. The reason is that there are lots of microcontrollers to choose from, each with its own instruction set, architecture and programming tools. The PIC16F877A is a better choice to develop transmitting and receiving data system because of the low cost and its special features.

Special Features of Microcontroller PIC 16F877A is a low power, high speed FLASH/EEPROM using CMOS technology. It also has 100,000 erase or write cycle enhanced FLASH program memory and has 1,000,000 erase or write cycle data EEPROM memory typical. The PIC 16F877A provides the following features: i. Wide operating voltage rage (2.OV-S.SV). ii. Programmable code protection. iii. Power saving sleep mode

iv. Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation. v. Self-reprogrammable under software control. vi. Single supply 5V in-circuit serial programming. vii. Up to 8K x 14 words of FLASH program memory. viii. Up to 368 x 8 bytes of data memory (RAM). ix. Up to 256 x 8 bytes of EEPROM data memory. x. Only 35 single word instruction. xi. Timer 0: 8-bit timer/counter with 8-bit prescaler. xii. Timer 1: 16-bit timer/counter with prescaler, can be increment during SLEEP via external crystal or clock.

3.3.2 RF Modules

Figure 3.11: RF Transmitter (433MHz)

This low cost RF transmitter can be used to transmit signal up to 100 meters (the antenna design, working environment and supply voltage will seriously impact the effective distance). It is good for short distance, battery power device development.

It has benefits of: Wide input supply (2.5V-12V) Easy to integrate (Data, Vcc and GND) Device in deep sleep mode when Data pin is grounded Very small dimension No. 1. 2. 3. 4. 5. 6. 7. 8. 9. Specifications Operating Voltage Operating Current Oscillator Frequency Frequency error Modulation Transfer Rate Transmitting power Antenna Length RF Transmitter Module 3V to 12 V Max 40mA (12V), Min 9mA (3V) SAW (Surface Acoustic Wave) oscillator 315MHz433.92MHz 150kHz(max) ASK/OOK 10Kbps 25mW (315MHz@12V) 24cm (315MHz), 18cm (433.92MHz)

Table 3.1: The Specifications of RF Transmitter

Figure 3.12: RF Receiver (433MHz)

This low cost RF Receiver can be used to receive RF signal from any 315MHz transmitter. Super regeneration design ensure sensitive to weak signal. It has benefits of:

Low power consumption (4mA) Easy to integrate (Vcc, GND and Data) Super regeneration design Very small dimension No. 1. 2. 3. 4. 5. 6. Specifications Operating Voltage Operating Current Operating Principle Modulation Frequency Bandwidth RF Receiver Module 5.0V 0.5V 5.5mA @5.0V Monolithic super heterodyne receiving OOK/ASK 315MHz, 433.92MHz 2MHz

7. 8. 9. 10.

Sensitivity Rate Data Output Antenna Length

-100dBm 9.6Kbps (315MHz @-95dBm) TTL 24cm (315MHz), 18cm (433.92MHz)

Table 3.2: The Specifications of RF Receiver

3.3.3 Voltage Regulator

Figure 3.13 : 5V regulator LM7805

The voltage regulator module is used to protect PIC and other connected sensors or actuators from over voltage. This is because PIC and all other connected sensors, actuators all support 5V DC only. Over voltage will cause any of the module burn. LM7805 is used to regulate voltage in the system and output 5V DC (max current: 1000mA). It supports input voltage from 7V DC to 18V DC.

3.3.4 Dual Full-Bridge Driver

Figure 3.14 : L298N motor driver

The L298N is an integrated monolithic circuit in a 15-lead Multiwatt Vertical package. It is a high voltage, high current dual full-bridge driver designed to accept standard TTL logic levels and drive inductive loads such as relays, solenoids, DC and stepping motors. Two enable inputs are provided to enable or disable the device independently of the input signals. The emitters of the lower transistors of each bridge are connected together and the corresponding external terminal can be used for the connection of an external sensing resistor. An additional supply input is provided so that the logic works at a lower voltage.

3.3.5 Infrared Sensor An infrared sensor is an electronic device that emits and/or detects infrared radiation in order to sense some aspect of its surroundings. Infrared sensors can measure the heat of an object, as well as detect motion. If an object is moving, the sensor receives different microwaves than the ones it sent out, signifying movement and setting off the alarm. These types of motion sensor systems cover a larger area than infrared sensors, they are capable of penetrating walls, and they are more reliable over longer distances.

3.3.6 LED A normal LED use 5V and 5mA to operate. And through LED the current status of the system can be known. A 1KR resistor is connected series with the LED to limit the current pass through LED is 5mA. This is calculated using V=IR. Where V=5VDC, R=1KR. The LED will light on when the power is go through the circuit to alert system.

3.3.7 Buzzer

In alarm system, buzzer is another way to fast notification of unneeded condition happened to our system environment. In this project a sound buzzer conducts as a warning action that temperature condition is in alert and danger situation.

3.3.8 LCD The Serial LCD provides a very functional, low-cost LCD that can be easily controlled by a microcontroller. The LCD display is two lines by 16 characters and provides basic text wrapping so that your text looks right on the display. In addition, the Serial LCD also provides you with full control over all of its advanced LCD features, allowing you to move the cursor anywhere on the display with a single instruction and turn the display on and off in any configuration.

3.4 Software Development

3.4.1 Assembly Language

An assembly language is a computer-oriented language with instruction that is in one-to-one correspondence with machine instruction. In assembly language a symbol is used for each machine instruction, which is subsequently translated into machine language. An assembly program is written using a simple text editor. Each assembler has specific syntax rules regarding the structure of the source file and the names that are used to represent assembler directives, opcodes, and operands. There are also syntax rules regarding comments in the file. In the assembly process, in order to create source file the text editor has to be save in (.asm). Then execute commands from a DOS prompt to assemble text file and create an output hex file with a (.hex) extension. Executable hex-code can be run without errors when every program line may consist of a maximum of 255 characters; every program line to be compiled, must start with a symbol, label, mnemonics or directive; text following the mark ; in a program line represents a comment ignored (not compiled) by the assembler; and all the elements of one program line (labels, instructions etc.) must be separated by at least one space character. For the sake of better clearness, a push button TAB on a keyboard is commonly used instead of it, so that it is easy to delimit columns with labels, directives etc. in a program. But, if the errors still occur during assembly, edit the source file to correct the syntax error. A listing file (.lst) can be used what error the assembler encountered. Once assembler execute without error, load the (.hex) file into the simulator or into target hardware. Execute code and continue the debugging process.

START

Define variables

Initialize I/O ports

Test routine during startup (checking motor function)

Read IR r DC motor operation


No Do forever

Send data TXnormal via transmitter

Overload?
Yes Permasalah

an Send data TXwarning via transmitter

Delay 250ms

Figure 3.15: Transmitter Base Program flowchart

START

Define variables

Initialize I/O ports; Initialize LCD

Check data received in RXd


No

Data= 3; Data= 4? Permasalah Yes an Display WARNING on LCD Display NORMAL on LCD

LED & Buzzer ON in alert condition

DONE

Figure 3.16: Receiver Base Program flowchart

3.4.2 Description of Programming Flowchart

The software development for the Transmitter and Receiver Base is relatively simple since it involves in gathering the data, processing, transmitting and receiving. PIC16F877A is able to be program in Assembly Language and makes it easy to design and develop.

As all the variables and ports have been initialized, the program begins with the main operation process in every related port. At pin RA0, IR sensor 1 is started to operate when it detects any materials that pass through it. Motor at pins RB6 and RB5 will then move forward until it touched limit switch at pin RA2. IR sensor 2 at pin RA1 is now started to operate when materials from IR sensor 1 move towards it. It is capable to detect any material with a certain range. The motor at pins RB6 and RB5 will automatically reverse until it touched limit switch at pin RA3. In a short time, motor at pins RB4 and RB3 then will move forward until it touched limit switch at pin RA5. The delay will be about 250ms and motor at pins RB4 and RB3 will reverse until it touched limit switch at pin RA4.

In normal condition, limit switch at pin RE0 will always be untouched. For that case, transmitter program will call TXNormal to send data 3 to receiver in order to display NORMAL on LCD. Otherwise, if the limit switch is touched, the transmitter will call TXWarning to send data 4 to receiver and the data will be stored at RXd. The receiver program will start to check any data received at RXd. LCD pins RD5, RD6 and RD7 are now will be busy in reading all data received and display every bytes at port B, LCD pins.

3.4.3 Software Tools

3.4.3.1 MPLAB IDE Features and Installing MPLAB IDE: MPLAB IDE is a Windows Operating System (OS) based Integrated Development Environment for the PIC MCU families and the dsPIC Digital Signal Controllers. The MPLAB IDE provides the ability to:

Create and edit source code using the built-in editor. Assemble, compile and link source code. Debug the executable logic by watching program flow with the built-in simulator or in real time with in-circuit emulators or in-circuit debuggers. Make timing measurements with the simulator or emulator. View variables in Watch windows. Program firmware into devices with device programmers If installing from a CD-ROM, place the disk into a CD drive. Follow the on-screen menu to install MPLAB IDE. If no on-screen menu appears, use Windows Explorer to find and execute the CD-ROM menu, menu.exe.

If downloading MPLAB IDE from the Microchip web site (www.microchip.com), locate the download (.zip) file, select the file and save it to the PC. Unzip the file and execute the resulting setup.exe file to install.

Step of use MPLAB IDE: Select Device The capabilities of MPLAB IDE vary according to which device is selected. Device selection should be completed before starting a project.

Create Project MPLAB IDE Project Wizard will be used to create a Project.

Select Language Tools In the Project Wizard the language tools will be selected. For this tutorial, the built-in assembler and linker will be used. For other projects, one of the Microchip compilers or other third party tools might be selected.

Put Files in Project Two files will be put into the project, a template file and a linker script. Both of these files exist in sub folders within the MPLAB IDE folder. It is easy to get started using these two files.

Create Code Some code will be added to the template file to send an incrementing value out an I/O port.

Build Project The project will be built causing the source files to be assembled and linked into machine code that can run on the selected PIC MCU.

Test Code with Simulator Finally, the code will be tested with the simulator.

3.4.3.2 Proteus professional Installing Proteus: Insert Proteus CD into CD tray. Use Window Explorer/My Computer to search for Proteus 9 Professional folder in the CD. Click Proteus.exe to start install Proteus. Click OK to complete the installation.

Step of use Proteus: Create new design (Click file > select new design > select Landscape A4 > click OK. Edit design properties Click Design > select Edit Design Properties > Edit Title > Edit Doc No. > Edit Revision > Edit author > Click OK > click file > select Save Design As) Picking component into the schematic (Click library > select Pick Device/Symbol > Click on P button > right click the mouse on an empty area of the schematic and select Place Component From libraries > select component > click OK or Double Click Component > then the component will be appear at devices Colum) Placing the components onto the schematic (Select component > click cursor at circuit layout or right click at circuit layout > select component > select device) Convert from Schematic Circuit to PCB layout (Click tool > select netlist to ARES)

3.4.3.3 Protel 99se The circuit has been designed using Protel 99se. The schematic diagram was designed based on block diagram. The advantages of this software; it can automatically convert schematic file to PCB and design PCB Drawing.

Starting a New Design Database: 1. Click Menu file > new design. 2. Named the file design in Database File Name. Otherwise, the file will be saving as MyDesign.ddb. 3. Determine the file location in Database location for easy finding.

Schematic Circuit Design: 1. Right click on folder, it will display a menu. 2. Click New, a New Document window will be displayed. Then, select Schematic Document on the same window. 3. A new schematic will display on window. 4. Choose desired file name. Right click on the file Sheet1.sch and click rename file.

3.4.3.4 PICkit 2 PICkit 2 has been used to download program into PIC with import .hex file which generate by MPLAB IDE.

Steps to Use PICkit 2: 1. Connect PIC programmer to computer via serial port / USB port. 2. Insert PIC into the programmer socket. 3. Open the .hex file which you want to export into PIC. 4. Click for Read -> Read Program from the export file or from the PIC. 5. Click for Write -> Write abc.hex to the PIC. 6. Click for Verify -> Verify the programming in the PIC. 7. Click for Erase -> Erase the existence programming in the PIC.

3.4.3.5 PCB fabrication:

PCB drawing is designed using Proteus Professional 9, this software can automatically convert schematic file to PCB automatically After PCB file is generated, use laser printer to print it on transparency. Cut photo PCB size according to the film size. Expose the photo PCB in photo etching kit for 8 to 10 minutes. Wash the PCB using PCB developer (white powder) for 5 minutes After PCB is developed, put it in Ferric Chloride liquid. Add in hot water and shake the water until you see unused part is washed and left only the tracks. It takes about 30 minutes for this process.

Wash the PCB with alcohol to get rid of the green coating. This process takes about 1 minute. Drill PCB after alcohol washing, use drill bit 0.8mm, 1.0mm and 2.0mm. Place all the components on the PCB, use tape to stick all components tightly on the PCB and the solder the components using soldering iron and lead.

3.4.3.6 Project Development Tools Required 1. Computer: The computer used to draw schematic for simulation and PCB for the system. Computer can be used to compile and download program into PIC through C-compiler and downloader software.

2. Laser printer: The laser printer was used to print the PCB drawing for PCB fabrication.

3. PCB development tools: a. Blade: to cut suitable size for PCB. b. Fluorescence light: to do photo etching for PCB. c. PCB developer, etching powder and thinner: to develop track from PCB.

4. PCB assembly tools: a. Cutter: used to cut wire and components legs. b. Pliers: used to bend component legs and place components on PCB. c. Soldering iron: used to solder components on PCB. d. Mini drill: used to drill holes on PCB to place components.

3.5 Summary In this chapter, it showed that the methodology process for hardware and software development are important on being the main purpose to make this project successfully accomplish. The hardware development is focusing on circuitry of the transceiver module, while the software development is more focus on creating programming software that will transfer data and load into PIC microcontroller. It is clearly explained the steps which has start with project block diagram and followed by flow chart of programming descriptions.

CHAPTER IV

RESULTS AND ANALYSIS

4.1

Introduction

This chapter will explain about the results and analysis of project detailed with circuitry on PCB board and simulations of Automatic Garbage Trap system.

4.2

PCB and Circuitry

Figure 4.1 : RX Base Components Layout

Figure 4.2 : RX Base PCB Layout

Figure 4.3 : RX Base Board

Figure 4.4: Motor Driver Components Layout

Figure 4.5: Motor Driver PCB Layout

Figure 4.6: Motor Driver Board

Figure 4.7: IR Components Layout

Figure 4.8: IR PCB Layout

Figure 4.9: IR Board

Figure 4.10: TX Base Components Layout

Figure 4.11: TX Base PCB Layout

Figure 4.12: TX Base Board (front view)

Figure 4.13: TX Base Board (back view)

The troubleshooting is done in order to change the components port at PIC pins and to add up the number of components unit. Some ports might not suitable for some components based on both characteristic. Besides, the pins number for certain port is not enough for additional components. So, these situations are forced to reorganize the component positions. Resistors are used to jump from original pin to new pin. Resistor could control the current limitation and produce a voltage drop.

4.3

Software Simulations

Proteus professional is used as a method for simulations. It is very important to ensure that the circuit design and simulation are successfully developed before a real prototype is invented. These simulations have been rebuild and slightly different from its original schematic because of the changes in components unit and troubleshooting process.

Pin IR 1 (RA0) Motor 1 (RB5, RB6) IR 2 (RA1) Motor 2 (RB3, RB4) RA2 RA3 RA5 RA4 RE0

Component Limit switch 1 Limit switch 2 Limit switch 3 Limit switch 4 Limit switch 5

Function (ON Mode) gate open gate close basket up basket down container overload

Table 4.1: System operation

Figure 4.14: Simulation in Initial condition

Off Mode: The initial condition is actually the condition when circuits have been given 12V DC supply before the system starts to function. All units of IR sensor and limit switch at Port A and pin RE0 remain in the off mode for a while.

Figure 4.15: LCD display from Initial condition

Figure 4.16: Simulation in Normal condition

On Mode: After IR 2 (RA1) started to function, the gate will close (RA3) and basket moves up (RA5). Delay with 250ms, basket moves down (RA4) to its initial place. In normal condition, the container is empty or the load is not over the limit yet. Then, the transmitter will keep sending the same data to receiver to display it on LCD.

Figure 4.17: LCD display from Normal condition

Figure 4.18: Simulation in Warning condition

On Mode: The system will keep working until the container is heavy enough with materials (garbage) and the container automatically will touch the limit switch (RE0) beneath it. Thus, the warning will be send to receiver as a precaution for further actions.

Figure 4.19: LCD display from Warning condition

4.4

Summary There were a few problems occurred while doing software and hardware task. For

problems solving, some researches through internet, discussion and idea exchanging with colleagues and supervisor are the best way to get solutions. There are various ideas that can be taken as an outcome from doing an experiment and troubleshooting until the desired result is successfully achieved.

CHAPTER V

CONCLUSION AND RECOMMENDATION

5.1

Conclusion

Development of Automatic Garbage Trap has a well function system. The system is not complicated as it requires the most of basic and familiar components for overall project. The errors that occurred in the system are normally not difficult to identify due to the well organized in circuit implementation. The application of this project can be categorized as a simple, safe and easy to understand.

The project conclusion can be assessed using successful and unsuccessful outcomes according to the original requirements that were expected from the finished system. In this report, the development of Automatic Garbage Trap for both transmitter and receiver has been presented. The wireless connection between the transmitter base and receiver base, processing and display the data received have been successfully developed. The source code for all the system was written in Assembly Language and compiled using MPLAB which are easy tools to provide an easy environment and reliability for PIC microcontroller in designing system. Finally, the objectives of this project are successfully achieved.

5.2

Recommendation

There are several steps that than be taken or avoided in order to ensure the successfulness of this project during the future research. Simulations using Proteus can be very confusing and hard because of the software limitations. The real components used for project sometimes are not listed in Proteus Library. Try to find other software which is capable of simulating RF applications more efficiently. The movement of forward-reverse DC motor is not practical enough. It can be upgraded to other types of DC motor, which is operate without depending on limit switch to stop the motor movement. Basically, this project is counted as a low cost project. Most of the components used in this project are so familiar and easy to find. But, in order to apply in the real world, Infra Red sensor can be replaced with level or weight sensor which is more effective to be use under water and could give an accurate measurement to data transfer.

It is strongly recommended to Dewan Bandaraya Kuala Lumpur (DBKL), to use this kind of project for their own benefits, such as can reduce the numbers of worker and make their job a lot easier as well.

REFERENCES

1. Pekka Eskelinen (2004). Introduction to RF Equipment and System Design. Canton Street, Norwood: Artech Wood Inc. 2. W. Alan Davis (2001). Radio Frequency Circuit Design. John Wiley & Sons Ltd 3. Paramasivan Pillai Tharusingam (2006). AM & FM Transmitter and Receiver. Universiti Teknologi Malaysia: Bachelor Thesis. 4. Yong Eu Fan and Tan Ka Kheng (1987). Analysis of Floating Refuse Along Gombak River. Universiti Pertanian Malaysia: Bachelor Thesis. 5. Siti Zahamimiah Binti Kasim@Mansor (2007). Temperature Monitoring System. Universiti Teknologi Malaysia: Bachelor Thesis. 6. Muhammad Al Farabi Bin Muhammad Iqbal (2009). Radio Frequency Transceiver For Amateur Radio. Universiti Teknologi Malaysia: Bachelor Thesis. 7. Zaidah Binti Zulkifli (2007). Wireless Audio Transmission (Transmitter). Universiti Teknikal Malaysia Melaka: Bachelor Thesis. 8. Microchip Technology Inc (2001). PIC16F877A Data Sheet. Web Site, URL: http://www.microchip.com. 9. Bruce Reynolds (2002). PicBasic Experiment With The PIC16F877A. Reynolds Electronics Web Site, URL: http://www.rentron.com/PICX.html. 10. David Gibbs (2007). River Darwen Litter Trap Project, Blackburn, UK. Web Site, URL: http://merseybasin.typepad.co.uk/my_weblog/darwen_litter_trap/ 11. James Wood (1993). Bandalong Litter Trap, Hobart Rivulet, Australia. Web Site, URL: http://www.bandalong.com.au/products.htm 12. Achong Tanjong (2010). New Trap to Collect Rubbish at Brunei River. Web Site, URL: http://news.brunei.fm/2010/03/03/new-trap-to-collect-rubbish-at-brunei-river/

APPENDIX A TRANSMITTER AND RECEIVER SOURCE CODES

TRANSMITTER BASE SOURCE CODE

;Variable declaration

;#define TXINV ;invert TX output so inactive is HIGH? packet_len EQU 2 ;packet length 1 + 1 address byte

;TX pin is portc, 4 #ifndef #define #define #else #define #define #endif TXINV TXLOW TXHIGH TXLOW TXHIGH

BCF BSF BSF BCF

PORTC, 6 PORTC, 6 PORTC, 6 PORTC, 6

;***** CONSTANT VALUES EXPIRE_TIMER EQU 0x12 LATCH_MASK EQU 0xff VALID_BIT EQU 4 hdrcntmin EQU 0x0c ; minimum number of header bits to receive hdrcntmax EQU 0x10 ; maximum number of header bits to receive ; decoder time tolerances are set at : 0.5T, 1.5T, 2.5T ; measured in 9xinstr.time (9usec) counts T EQU .39 ; half frame 350 usec (= T * 9 usec) T/2 ; half frame (T) minimum time 3*T/2 ; half frame (T) maximum time and full frame (2T) 5*T/2 ; full frame (2T) maximum time

min_t EQU min_2t EQU minimum time max_2t EQU

packet_len EQU 2 ; packet length, check var. alloc! mrx_packet_len EQU 2 ; packet length, check var. alloc!

;--------------------------------------------------------------------------------------;assign user variable in the PIC memory

;***** VARIABLE DEFINITIONS cblock 0x20 ;RECEIVER bitcnt tmrval ; timer value ; receive byte buffer ; decode logic status ; byte counter ;start of general purpose registers

flags btcnt rxtime1 rxtime2 mrx_buffer ; receive address buffer mrx_buffer1 ; receive packet buffer mrx_bsum ; receive buffer, checksum count ;used in looping routines tmp1 ;temporary storage tmp2 Xmit_Byte ;holds byte to xmit Rcv_Byte ;holds received byte Bit_Cntr ;bit counter for RS232 Delay_Count ;delay loop counter TREADY count1a ;used in delay routine count2a N1 N ITEM_T counta1 ;used in delay routine countb1 ;used in delay routine F1a DMA DMB FMA FMB D0 DIGIT D1 D2 D3 D4 D5 D6 D7 MyTable N2 FIXDELAY

T1 T2 countc item i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 Ditem Fitem RXd ncnt bt sum mtx_buffer mtx_buffer1 mtx_delay visdelay dataL count1 count2 counta countb HEADERx endc org 0x0000

; half_frame delay

;used in delay routine ;used in delay routine ;used in delay routine

;-----------------------------------------------------------------------------;Initialize IO

main bsf STATUS, movlw 0x00 movlw b'00000000' movwf TRISB MOVLW 0x06 MOVWF ADCON1 movlw b'00111111' movwf TRISA movlw b'00101111' movwf TRISE movlw b'00000111' movwf TRISC movlw b'00000000' movwf TRISD bcf STATUS, RP0 ;select bank 1

;CONFIGURED ALL PIN AS DIGITAL I/O

RP0

;select bank 0

call start

mtx_init

;Initialize tx

bcf PORTB,4 bcf PORTB,3 bcf PORTB,6 bcf PORTB,5 call SECOND_1 call SECOND_1 call SECOND_1

;Clear motor

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;INITIALIZE PROGRAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; TEST ROUTINES DURING STARTUP call TXInit MAIN bsf PORTB,6 ;On Motor Open Gate Direction bcf PORTB,5 btfsc PORTA,2 ;Check Open Limit goto MAIN bcf PORTB,6 ;OFF Motor Open Gate bcf PORTB,5 call SECOND_1 call SECOND_1 LOpen bcf PORTB,6 ;On Motor Close Gate Direction

bsf PORTB,5 btfsc PORTA,3 goto LOpen bcf PORTB,6 bcf PORTB,5 call SECOND_1 call SECOND_1

;Check Close Limit ;OFF Motor Close Gate

BasketUp bsf PORTB,4 bcf PORTB,3 btfsc PORTA,5 goto BasketUp bcf PORTB,4 bcf PORTB,3 call SECOND_1 call SECOND_1 BasketDown bcf PORTB,4 bsf PORTB,3 btfsc PORTA,4 goto BasketDown bcf PORTB,4 bcf PORTB,3 call SECOND_1 call SECOND_1 call TXRun ;On Motor Close Gate Direction ;Check Close Limit ;OFF Motor Close Gate ;On Motor Open Gate Direction ;Check Open Limit ;OFF Motor Open Gate

;--------------------MAINLOOP - CONTINOUSLY----------------------------MAINLOOP btfsc PORTA,0 call GateOpen btfsc PORTA,1 goto Warn goto Norm ;Check IR gate ;Detect any? then goto GateOpen ;Check IR2 for warning alarm

Continue btfss PORTE,0 goto ClearAll call SECOND_1 call SECOND_1 ;Overload

goto MAINLOOP Warn call TXWarning call SECOND_1 goto Continue Norm call TXNormal call SECOND_1 goto Continue ClearAll call GateClose call BaskUp call SECOND_1 call SECOND_1 call BaskDown call SECOND_1 goto MAINLOOP

goto GateOpen

MAINLOOP

; just display the bytes

bsf PORTB,6 bcf PORTB,5 btfsc PORTA,2 goto GateOpen bcf PORTB,6 bcf PORTB,5 return

;On Motor Open Gate Direction ;Check Open Limit ;OFF Motor Open Gate

GateClose bcf PORTB,6 bsf PORTB,5 btfsc PORTA,3 goto GateClose bcf PORTB,6 bcf PORTB,5 return BaskUp bsf PORTB,4 bcf PORTB,3 btfsc PORTA,5 ;On Motor Open Gate Direction ;Check Open Limit ;On Motor Close Gate Direction ;Check Close Limit ;OFF Motor Close Gate

goto BaskUp bcf PORTB,4 bcf PORTB,3 return BaskDown

;OFF Motor Open Gate

bcf PORTB,4 ;On Motor Close Gate Direction bsf PORTB,3 btfsc PORTA,4 ;Check Close Limit goto BaskDown bcf PORTB,4 ;OFF Motor Close Gate bcf PORTB,3 return ;---------------------END OF MAIN PROGRAM-----------------

;---------------------SEND RF DATA----------------------TXInit movlw 0xAA ;set packet address byte to 0xAA movwf mtx_buffer movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '1' movwf mtx_buffer1 call mtx_send call Delay20 movlw 0xAA movwf mtx_buffer movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '1' movwf mtx_buffer1 call mtx_send call Delay20 return TXRun ;set packet address byte to 0xAA

movlw 0xAA movwf

;set packet address byte to 0xAA mtx_buffer

movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '2' movwf mtx_buffer1 call mtx_send call Delay20 movlw 0xAA movwf mtx_buffer movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '2' movwf mtx_buffer1 call mtx_send call Delay20 return TXNormal ;set packet address byte to 0xAA

movlw 0xAA movwf mtx_buffer movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '3' movwf mtx_buffer1 call mtx_send call Delay20 movlw 0xAA

;set packet address byte to 0xAA

;set packet address byte to 0xAA

movwf

mtx_buffer

movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '3' movwf mtx_buffer1 call mtx_send call Delay20 return TXWarning

movlw 0xAA movwf mtx_buffer movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '4' movwf mtx_buffer1 call mtx_send call Delay20 movlw 0xAA movwf mtx_buffer movlw A'A' movwf mtx_buffer1 call mtx_send call Delay20 movlw '4' movwf mtx_buffer1 call mtx_send call Delay20 return

;set packet address byte to 0xAA

;set packet address byte to 0xAA

;---------------------------DELAY ROUTINES----------------------SECOND_1 movlw d'4' movwf N2 more call Delay_T DECFSZ N2,1 goto more return

Delay_T d1

movlw d'245' movwf countc movlw 0xC7 movwf counta movlw 0x01 movwf countb decfsz goto decfsz goto counta, f $+2 countb, f Delay_0

;delay 250 ms (4 MHz clock)

Delay_0

decfsz countc ,f goto d1 retlw 0x00

;delay routines Delay255 Delay100 Delay50 Delay20 Delay5 d0 d1x movlw 0xff goto d0 movlw d'100' goto d0 movlw d'50' goto d0 movlw d'20' goto d0 movlw 0x05 movwf count1 movlw 0xC7 movwf counta movlw 0x01 movwf countb decfsz counta, f ;delay 255 mS ;delay 100mS ;delay 50mS ;delay 20mS ;delay 5.000 ms (4 MHz clock) ;delay 1mS

Delay_0x

goto $+2 decfsz countb, f goto Delay_0x decfsz count1 ,f goto d1x retlw 0x00

;"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" ;TRANSMITTER subroutines ;""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" mtx_init movlw movwf return ; .115 mtx_delay ; 350 usec

mtx_send outbuf header head0 movlw 0x14 ; send out buffer ; 20xbit1, 1xbit0

movwf count2 call bit1 decfsz count2,F goto head0 call bit0 movlw mtx_buffer movwf FSR movlw packet_len movwf count1 movlw 0xff movwf sum ; movf INDF,W call update_sum movf INDF,W call outbyte incf FSR,F decfsz count1,F goto outbu0 movf sum,W call outbyte ; buffer is sent return

outbu0

update_sum

; fast CRC-8 algorithm with poly x^8+x^5+x^4+1 ; executes in 23 cycles per update xorwf sum,f clrw btfsc sum,7 xorlw 0x7a btfsc sum,6 xorlw 0x3d btfsc sum,5 xorlw 0x86 btfsc sum,4 xorlw 0x43 btfsc sum,3 xorlw 0xb9 btfsc sum,2 xorlw 0xc4 btfsc sum,1 xorlw 0x62 btfsc sum,0 xorlw 0x31 movwf sum return

outbyte

outby0

outby1 outby2

movwf bt movlw 8 movwf count2 rlf bt,F btfsc STATUS,C goto outby1 call bit0 goto outby2 call bit1 decfsz count2,F goto outby0 ; call bit1 ; and bit0 - falls through to bit0 subroutine

;send a bit0 bit0 TXHIGH ; HIGH

call

mtx_bitdel

; bit time delay

TXLOW call mtx_bitdel return ;send a bit1 bit1 TXLOW call mtx_bitdel

; to LOW transition ; bit time delay

; LOW ; bit time delay ; to HIGH transition ; bit time delay

TXHIGH call mtx_bitdel return ; bit delay modified by NG mtx_bitdel

movf mtx_delay, W movwf ncnt ndelaya1 decfsz ncnt, F goto ndelaya1 return ;-----------------------------------------------------------------------------------------------------------------------

Delay_T2 d1a2

movlw d'100' movwf count1a movlw 0xC7 movwf counta1 movlw 0x01 movwf countb1 decfsz goto decfsz goto counta1, f $+2 countb1, f Delay_0a2 ,f

;delay 250 ms (4 MHz clock)

Delay_0a2

decfsz count1a goto d1a2 retlw 0x00

end RECEIVER BASE SOURCE CODE

;Variable declaration

packet_len EQU 2 ; packet length, check var. alloc! mrx_packet_len EQU 2 ; packet length, check var. alloc!

; input port bit #define RXBIT ; normal decoder logic input #define SKL btfsc #define SKH btfss ; inverse decoder logic input ;#define SKL btfss ;#define SKH btfsc

PORTC, 7

;***** FLAGS #define IF_SHORT flags, 0 #define FIRST_HALF flags, 1 #define HEADER flags, 2 #define VALID flags, 7 if_short_val EQU first_half_val EQU 1 ; bit value of IF_SHORT flag 2 ; bit value of FIRST_HALF flag

;***** VARIABLE DEFINITIONS cblock 0x20 ;RECEIVER bitcnt tmrval min_t flags btcnt rxtime1 rxtime2 mrx_buffer mrx_buffer1 mrx_bsum count ; timer value ; receive byte buffer ; decode logic status ; byte counter ;start of general purpose registers

; receive address buffer ; receive packet buffer ; receive buffer, checksum ;used in looping routines

tmp1 ;temporary storage tmp2 Xmit_Byte ;holds byte to xmit Rcv_Byte ;holds received byte Bit_Cntr ;bit counter for RS232 Delay_Count ;delay loop counter TREADY count1a ;used in delay routine count2a min_2t N1 N hdrcntmin ITEM_T counta1 ;used in delay routine countb1 ;used in delay routine F1a DMA DMB FMA FMB D0 DIGIT D1 D2 D3 D4 D5 D6 D7 max_2t N2 FIXDELAY T1 T2 countc item i1 i2 i3 i4 i5 i6 i7 i8 i9

i10 i11 i12 i13 i14 i15 i16 i17 i18 i19 i20 Ditem Fitem RXd ncnt bt sum mtx_buffer mtx_buffer1 mtx_delay visdelay dataL count1 count2 counta countb HEADERx endc

; half_frame delay

;used in delay routine ;used in delay routine ;used in delay routine

;---------------------------------------------;Initialize IO org main 0x0000

; program starts here bsf STATUS, movlw 0x00 movlw b'00000000' movwf TRISB MOVLW 0x06 MOVWF ADCON1 movlw b'00000111' movwf TRISA movlw b'10101111'

RP0

;select bank 1

;CONFIGURED ALL PIN AS DIGITAL I/O

movwf TRISC movlw b'00000000' movwf TRISD bcf STATUS,

RP0

;select bank 0

call INITLCD call delay start call DisStart call visualdelay bcf PORTD,2 bcf PORTD,3 bsf PORTC,6 bsf PORTC,7 bcf PORTD,1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN PROGRAM ;ROUTINES MAIN bcf PORTD,0 call mrx_receive ; get packet andlw 0xff bnz call andlw bnz MAIN mrx_chk_buf 0xff MAIN ; reject if error code ; test the checksum value ; reject packet if checksum fails ; check that packet address is correct (0xAA) ; else reject packet

movlw 0xAA subwf (mrx_buffer), W bnz MAIN bsf PORTD,0 movf mrx_buffer+1, W movwf RXd movf RXd,w xorlw A'1' btfsc STATUS,Z goto SysInit movf RXd,w xorlw A'2' btfsc STATUS,Z goto SysRun movf RXd,w xorlw A'3'

;Store data receive in RXd ;Check Data RXd? for display purpose

btfsc STATUS,Z goto SysNorm movf RXd,w xorlw A'4' btfsc STATUS,Z goto SysWarn goto MAIN

; just display the bytes

;---------------------END OF MAIN PROGRAM-----------------

SysInit call DisInit goto MAIN call DisRun goto MAIN call DisNormal goto MAIN call DisWarning goto MAIN

SysRun

SysNorm SysWarn

;------------------------------------------------------------------------------------------------mrx_receive s3 s4 s5 ; receive a full manchester-encoded packet ; set flags: first_half=1, if_short=0 bsf FIRST_HALF bcf IF_SHORT ; init before the received packet ; set FSR to buffer start movlw mrx_buffer movwf FSR ; set byte counter movlw (packet_len+1) ; bytes / packet movwf btcnt ; set header receive mode bsf HEADER clrf bitcnt ; counting bit1-s in this mode s2 ; wait for a pulse SKH RXBIT

goto s6 s6_w

s2

; wait for end of (short) pulse up to min_2t clrf tmrval SKH RXBIT goto s7 ; goto s7 at end of pulse incf tmrval, F nop movlw min_2t subwf tmrval, W btfss STATUS, C goto s6_w ; timeout, exit retlw 1

; illegal startbit

s7

; start timer clrf tmrval ; if (if_short & rxbit) goto s9 ; if (!if_short & !rxbit) goto s9 ; goto s10 btfsc IF_SHORT ; if_short = 1 goto s8_ss1

s8

s8_ss0

; if_short = 0 SKL RXBIT goto s10

; rxbit = 1, goto s10

s9_ss0

; if (timer > max_2t) exit - else goto s8 movlw max_2t subwf tmrval, W btfsc STATUS, C retlw 2 ; signal too long incf goto tmrval, F s8_ss0

s8_ss1

; if_short = 1 SKH RXBIT goto s10 ; rxbit = 0, goto s10 ; if (timer > max_2t) exit - else goto s8

s9_ss1

movlw max_2t subwf tmrval, W btfsc STATUS, C retlw 2 ; signal too long incf goto s10 tmrval, F s8_ss1

; invert if_short movlw if_short_val xorwf flags, F ; if (timer < min_t) exit movlw min_t subwf tmrval, W btfss STATUS, C retlw 3 ; signal too short ; if (timer < min_2t) goto s14 movlw min_2t subwf tmrval, W btfss STATUS, C goto s14 ; if (first_half = 0) goto s16 - else exit btfss FIRST_HALF goto s16 retlw 4 ; no mid-frame transition/out of sync ; invert first_half movlw first_half_val xorwf flags, F ; if (first_half = 1) goto 7 btfsc FIRST_HALF goto s7 ; if_short is a decoded bit. Handle here btfss HEADER goto s16_not_header ; header receiving mode btfss IF_SHORT goto s16_header_end ; header bit is 1

s11

s12

s13

s14

s15

s16

btfss incf

bitcnt, 4 ; inc up to 16 bitcnt, F ; 16 is enough...

#ifdef NOMAXHDR ; test for max header length movlw hdrcntmax subwf bitcnt, W btfss STATUS, C #endif goto s7 ; loop back retlw 9 ; header too long s16_header_end bcf ; header ends indicated by a 0 HEADER

; test for min header length movlw hdrcntmin subwf bitcnt, W btfss STATUS, C retlw 0x0a ; header too short next_byte movlw 0x0a movwf bitcnt goto s7 ; loop back ; receiving bytes bitcnt, F s16_s4 ; if (bitcnt = 0) check for a byte-sep 1

s16_not_header decf bz

; if (bitcnt = 1) check for a byte-separator 0 movlw 1 xorwf bitcnt, W bnz s16_s2 ; test for a byte separator 1 btfsc IF_SHORT goto s7 retlw 7 ; byte-ending 1 not present s16_s2 ; bit is data rrf rlf goto s16_s4 flags, W bt, F s7

; check for a byte-separator 0

btfsc IF_SHORT retlw 8

; byte-ending 0 not present

; OK, received byte is sane, store in buffer movf bt, W movwf INDF incf FSR, F decfsz btcnt, F goto next_byte retlw 0 ; OK, buffer received

; buffer checking is not done automatically! ; if returned value is 0, call mrx_chk_buf to check ; mrx_chk_buf ; check buffer sanity by chksum movlw mrx_buffer movwf FSR movlw (packet_len+1) ; number of bytes with the chksum byte movwf btcnt movlw 0xff movwf bt ; used as sum register chk0 movf INDF, W ; fast CRC-8 algorithm with poly x^8+x^5+x^4+1 ; executes in 23 cycles per update xorwf bt,f clrw btfsc bt,7 xorlw 0x7a btfsc bt,6 xorlw 0x3d btfsc bt,5 xorlw 0x86 btfsc bt,4 xorlw 0x43 btfsc bt,3 xorlw 0xb9 btfsc bt,2 xorlw 0xc4 btfsc bt,1 xorlw 0x62 btfsc bt,0 xorlw 0x31

movwf bt incf FSR, F decfsz btcnt, F goto chk0 ; correct checksum must be zero movf bt, W bnz chk_err retlw 0 ; result is in Z retlw 0x0c ; checksum error return

chk_err mrx_init ;delay routines Delay255 Delay100 Delay50 Delay20 Delay5 d0 d1

movlw 0xff goto d0 movlw d'100' goto d0 movlw d'50' goto d0 movlw d'20' goto d0 movlw 0x05 movwf count1 movlw 0xC7 movwf counta movlw 0x01 movwf countb decfsz goto decfsz goto counta, f $+2 countb, f Delay_0

;delay 255 mS ;delay 100mS ;delay 50mS ;delay 20mS ;delay 5.000 ms (4 MHz clock) ;delay 1mS

Delay_0

decfsz count1 ,f goto d1 retlw 0x00 ;----------------------------------------------------------------------------------------------------------------------; Initialize the LCD. ;----------------------------------------------------------------------------------------------------------------------INITLCD

MOVLW 0xE6 CALL NDELAY BCF BCF MOVLW matrix MOVWF PORTB CALL ENABLEPULSE CALL DELAY50 CALL ENABLEPULSE CALL DELAY50 CALL ENABLEPULSE CALL DELAY50 completion PORTD, 5 PORTD, 6

; Call for 46ms delay ; Wait for VCC of the LCD to reach 5V ; Clear RS to select Instruction Reg. ; Clear R/W to write

B'00111011' ; Function Set to 8 bits, 2 lines and 5x7 dot

; Call 50us delay and wait for instruction

MOVLW B'00001000' ; Display OFF MOVWF PORTB CALL ENABLEPULSE CALL DELAY50 ; Call 50us delay and wait for instruction completion MOVLW B'00000001' ; Clear Display MOVWF PORTB CALL ENABLEPULSE MOVLW 0x09 ; Call 1.8ms delay and wait for instruction completion CALL NDELAY MOVLW B'00000010' ; Cursor Home MOVWF PORTB CALL ENABLEPULSE MOVLW 0x09 ; Call 1.8ms delay and wait for instruction completion CALL NDELAY MOVLW B'00001100' ; Display ON, Cursor OFF, Blinking OFF MOVWF PORTB CALL ENABLEPULSE CALL DELAY50 ; Call 50us delay and wait for instruction completion MOVLW shift MOVWF PORTB B'00000110' ; Entry Mode Set, Increment & No display

CALL ENABLEPULSE CALL DELAY50 completion BSF BCF RETURN ENABLEPULSE BCF PORTD, 7 Pulse and 2us LOW. NOP NOP BSF PORTD, 7 NOP NOP NOP BCF PORTD, 7 NOP NOP RETURN PORTD, 5 PORTD, 6

; Call 50us delay and wait for instruction

; Set RS to select Data Reg. ; Clear R/W to write

; 2us LOW followed by 3us HIGH Enable

NDELAY NOTOVER MOVWF N CALL DELAY200 DECFSZ N, 1 GOTO NOTOVER RETURN ; N is delay multiplier ; Call for 200us ; Decrease N by 1 ; The delay isn't done

DELAY200 MOVLW 0x42 MOVWF FIXDELAY DECFSZ FIXDELAY, 1 GOTO NOTDONE200 RETURN instruction. ; 66 LOOPS ; 200us fixed delay ; Decrement of FIXDELAY ; If 200us isn't up go back to ; If 200us is up then return to

NOTDONE200 NOTDONE200

DELAY50 MOVLW 0x10 ; 16 LOOPS MOVWF FIXDELAY ; 50us fixed delay NOTDONE50 DECFSZ FIXDELAY, 1 ; Decrement of FIXDELAY

GOTO NOTDONE50 RETURN instruction.

; If 50us isn't up go back to NOTDONE50 ; If 50us is up then return to

;----------------------------------------------------------------------------------------------------------------------; Visual delay subroutine. ;----------------------------------------------------------------------------------------------------------------------visualdelay movlw 0x20 movwf visdelay seetemp movlw 0x20 call NDELAY decfsz visdelay, 1 goto seetemp return ;FAST

visualdelay1 movlw 0x12 movwf visdelay seetemp2 movlw 0xAA call NDELAY decfsz visdelay, 1 goto seetemp2 return

PUTCHAR MOVWF PORTB CALL ENABLEPULSE CALL CHKBUSY RETURN CHKBUSY bcf bsf PORTD,5 PORTD,6 ; Clear RS to select Instruction Reg. ; Set R/W to read. ; Select Bank for TRISC. ; Define all PORTC Pins as Inputs.

banksel TRISB movlw 0xFF movwf TRISB banksel PORTD bsf PORTD,7 movf PORTB,w bcf PORTD,7

; Select Bank for PORTC.

andlw 0x80 btfss STATUS,Z goto CHKBUSY banksel TRISB movlw 0x00 movwf TRISB banksel PORTD bsf PORTD,5 bcf PORTD,6 return ;----------------------------------------------------------------------------------------------------------------------; Position Cursor to the next line. ;----------------------------------------------------------------------------------------------------------------------nextline banksel PORTD bcf PORTD, 5 ; Select Instructions Register. bcf PORTD, 6 ; Select Write. movlw b'11000000' on LCD. call PUTCHAR return nextline1 banksel PORTD bcf PORTD, 5 ; Select Instructions Register. bcf PORTD, 6 ; Select Write. movlw b'11000000' on LCD. call PUTCHAR return nextline2 banksel PORTD bcf PORTD, 5 ; Select Instructions Register. bcf PORTD, 6 ; Select Write. ; Shift cursor to second line at 0x40 RAM address ; Shift cursor to second line at 0x40 RAM address ; Select Bank for TRISB. ; Define all PORTC Pins as Outputs.

; Select Bank for PORTA, B, and C. ; Set RS to select Data Register. ; Clear R/W to write.

movlw b'01000000' on LCD. call PUTCHAR return

; Shift cursor to second line at 0x40 RAM address

;----------------------------------------------------------------------------------------------------------------------; Clear screen and Cursor home. ;----------------------------------------------------------------------------------------------------------------------clrscreen banksel PORTD bcf PORTD, 5 bcf PORTD, 6 ; Clear RS to select Instructions Register. ; Clear R/W to select Write.

banksel PORTB MOVLW B'00000001' call PUTCHAR return

; Clear Display

;----------------------------------------------------------------------------------------------------------------------; Position Cursor to home position. ;----------------------------------------------------------------------------------------------------------------------cursorhome banksel PORTD bcf PORTD, 5 ; Select Instructions Register. bcf PORTD, 6 ; Select Write. movlw b'00000010' call PUTCHAR ; Position cursor to home position.

return ;----------------------------------------------------------------------------------------------------------------------; Wait 20us for Acquisition time in order for holding capacitor to charge up. ;----------------------------------------------------------------------------------------------------------------------delay20

banksel FIXDELAY ; A loop to generate 20us delay. movlw 0x0A movwf FIXDELAY notdone20 decfsz FIXDELAY, 1 goto notdone20 return delay banksel dataL clrf dataL settle decfsz dataL, f goto settle ; The delay loop.

return ;-----------------------------------------------------------------------------------------------------------------------

Delay_T2 d1a2

movlw d'100' movwf count1a movlw 0xC7 movwf counta1 movlw 0x01 movwf countb1 decfsz goto decfsz goto counta1, f $+2 countb1, f Delay_0a2 ,f

;delay 250 ms (4 MHz clock)

Delay_0a2

decfsz count1a goto d1a2 retlw 0x00

;------------------Display LCD---------------

DisStart call clrscreen call cursorhome movlw A'A' call PUTCHAR call Delay_T

call Delay_T movlw A'u' call PUTCHAR call Delay_T call Delay_T movlw A't' call PUTCHAR call Delay_T call Delay_T movlw A'o' call PUTCHAR call Delay_T call Delay_T movlw A' ' call PUTCHAR call Delay_T call Delay_T movlw A'G' call PUTCHAR call Delay_T call Delay_T movlw A'a' call PUTCHAR call Delay_T call Delay_T movlw A'r' call PUTCHAR call Delay_T call Delay_T movlw A'b' call PUTCHAR call Delay_T call Delay_T movlw A'a' call PUTCHAR call Delay_T call Delay_T movlw A'g' call PUTCHAR call Delay_T call Delay_T movlw A'e' call PUTCHAR call Delay_T call Delay_T movlw A' '

call PUTCHAR call Delay_T call Delay_T movlw A'R' call PUTCHAR call Delay_T call Delay_T movlw A'X' call PUTCHAR call Delay_T call Delay_T movlw A' ' call PUTCHAR call Delay_T call Delay_T call visualdelay return DisRun call clrscreen call cursorhome movlw A'S' call PUTCHAR movlw A'y' call PUTCHAR movlw A's' call PUTCHAR movlw A't' call PUTCHAR movlw A'e' call PUTCHAR movlw A'm' call PUTCHAR movlw A' ' call PUTCHAR movlw A'R' call PUTCHAR movlw A'u' call PUTCHAR movlw A'n' call PUTCHAR movlw A'n' call PUTCHAR movlw A'i' call PUTCHAR

movlw A'n' call PUTCHAR movlw A'g' call PUTCHAR call visualdelay return DisReady call clrscreen call cursorhome movlw A'R' call PUTCHAR movlw A'e' call PUTCHAR movlw A'a' call PUTCHAR movlw A'd' call PUTCHAR movlw A'y' call PUTCHAR movlw A'.' call PUTCHAR movlw A'.' call PUTCHAR movlw A'.' call PUTCHAR call visualdelay return DisInit call clrscreen call cursorhome movlw A'I' call PUTCHAR movlw A'n' call PUTCHAR movlw A'i' call PUTCHAR movlw A't' call PUTCHAR movlw A'i' call PUTCHAR movlw A'a' call PUTCHAR movlw A'l'

call PUTCHAR movlw A'i' call PUTCHAR movlw A'z' call PUTCHAR movlw A'e' call PUTCHAR movlw A' ' call PUTCHAR movlw A'S' call PUTCHAR movlw A'y' call PUTCHAR movlw A's' call PUTCHAR movlw A't' call PUTCHAR movlw A'e' call PUTCHAR movlw A'm' call PUTCHAR call visualdelay return DisNormal call clrscreen call cursorhome movlw A'N' call PUTCHAR movlw A'o' call PUTCHAR movlw A'r' call PUTCHAR movlw A'm' call PUTCHAR movlw A'a' call PUTCHAR movlw A'l' call PUTCHAR call visualdelay return call clrscreen call cursorhome movlw A'W' call PUTCHAR

DisWarning

movlw A'a' call PUTCHAR movlw A'r' call PUTCHAR movlw A'n' call PUTCHAR movlw A'i' call PUTCHAR movlw A'n' call PUTCHAR movlw A'g' call PUTCHAR call visualdelay bsf PORTD,1 call SECOND_1 call SECOND_1 bcf PORTD,1 return SECOND_1 more movlw d'4' movwf N2 call Delay_T DECFSZ N2,1 goto more return

Delay_T d1x

movlw d'245' movwf countc movlw 0xC7 movwf counta movlw 0x01 movwf countb decfsz goto decfsz goto counta, f $+2 countb, f Delay_0x

;delay 250 ms (4 MHz clock)

Delay_0x

decfsz countc ,f goto d1x retlw 0x00 end

APPENDIX B DATASHEETS