Вы находитесь на странице: 1из 57

DESIGN AND CONSTRUCTION OF DIGITAL COUNTER

BY

OWOEYE AKINTAYO DAMILOLA


030403079

PROJECT REPORT SUBMITTED TO THE DEPARTMENT OF ELECTRICAL/ELECTRONICS ENGINEERING IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE AWARD OF
BACHELOR OF SCIENCE (HONOURS) DEGREE IN

ELECTRICAL/ELECTRONICS ENGINEERING

Project Supervisor: Engr. O.D OSUNDE

NOVEMBER 2009

CERTIFICATION

This is to certify that OWOEYE DAMILOLA AKINTAYO carried out the design and construction of a DIGITAL COUNTER, as partial fulfillment of the requirements for the award of the degree of Bachelor of Science (Honours) in Electrical/Electronic Engineering, University of Lagos.

______________________________ OWOEYE DAMILOLA 030403079

______________________________ ENGINEER 0.D OSUNDE PROJECT SUPERVISOR

_______________________________ Dr. A.A AYORINDE PROJECT COORDINATOR

______________________________ Dr. F.N OKAFOR H.O.D ELECT /ELECT ENGR

ii

DEDICATION
I dedicate my soul, my life, my health, my education and finally this project work; To the Lord of Creation - My creation and that of many others; To the Owner of Judgment Day - My judgment and that of many others; To the Master of Death - My death and that of many others; To the Source of Peace, Love and Compassion - My peace and that of many others; To you my Lord, the ALL-KNOWING, the ALL-SEEING

In addition, my dedication goes to my mum and family, for always giving me the best.

Finally, I dedicate this project to all those that always expect the best from me, to true Christians and anyone who cares to read this page.

iii

ACKNOWLEDGEMENT
All appreciation goes to the Maker of all that is in the Heavens and on the Earth. My warmth and sincere acknowledgement goes to my dearest mum Mami; Mrs. Monisola Vicoria Awoyinfa, for her love, care and discipline since pregnancy until date. I know cannot pay you back, but I am sure GOD will bountifully, reward you graciously in this world and in the Hereafter. My gratitude goes totally to all those that aroused my interest in the field electrical/electronic/computer engineering and information technology, especially Tunde Lawal, Joseph Areghan for accommodating me, and always putting me on the right track. I also acknowledge my friends for always being friends. The list is countless, but I will always remember the following people; Ayodele Ajayi, Efe Omoruyi Steven, Israel Gbose, Komolafe Akinyemi, Kinsley Akwe, Stanley Opara, and to all those in EGRAD 09. I thank them for making my final year, a challenging and interesting year. Finally, I say Thank you sir, ENGR O.D OSUNDE, for his high-level of knowledge and discipline and commitment towards the development of young minds.

iv

TABLE OF CONTENT

Certification Dedication Acknowledgement Table of Content List of Figures

ii iii iiv vi vii

Abstract Chapter One: Introduction 1.1 Background 1.2 Objectives of Project 1.3 Relevance of Project 1 2 2 3 4

Chapter Two: Literature Review 2.1 Power Supply 2.2 Liquid Crystal Display (PCD 8544) 2.3 Microcontroller (PIC micro) 6 7 10

Chapter Three: Design Methodology 3.1 Design Specification 3.2 Block Diagram 3.3 Design Analysis 3.4 Circuit Diagram 3.5 Circuit Analysis 3.6 Program Code Analysis
v

14 15 16 17 18 20

Chapter Four: Design Construction 4.1 PCB Layout 4.2 Software Burning 4.3 Hardware Troubleshooting and debugging 4.4 Simulation/Testing

23 24 25 26 27

Chapter Five: Conclusion 5.1 Discussion of result 5.2 Conclusion 5.2 Recommendation

29 29 29 29

References Appendix I Appendix II Appendix III

30 31 46 47

vi

LIST OF FIGURES

Figure 1.1 Typical door

Figure 2.1: Power Supply Units

Figure 2.2: Liquid Crystal Display (PCD 8544):

Figure 2.3: Mid-range PIC Memory (Harvard architecture) Figure 2.4: USB PIC micro Programmer Figure 2.5: PIC 16F874A and PIC16F877 pin diagrams

10 11 12

Figure 2.6: Program memory map and stack for high-performance microcontroller Figure 3.1: Block Diagram of system

13 15

Figure 3.2: Circuit Diagram of a Digital Counter

16

Figure 4.3: PCB Layout of Main Circuit Figure 3.3: A Typical PIC16f877A Figure 4.1: Circuit Diagram of the Power Supply Figure 4.2 : WinPic800 USB Programmer software

17 18 24 26

vii

ABSTRACT
The clamor for the need to stop Nigeria as a dumping ground for all electronic devices, and the development of the talented Nigerian engineers, has gingered this sincere research. Bearing in mind that, the field of microelectronics and embedded systems is very large, only control and security systems have gained interest, and has prompted the design and construction of a Digital Counter. A digital counter is a device used for counting the occurrence of an event. The main purpose of designing and constructing this device is to provide an alternative to and perhaps a more effective way of counting the occurrence of an event. The device is able to detect occurrence of an event as long as the line sight between transmitter and receiver and is broken. Physical counting is important because of the need to know how much in order to cater for how many. This report presents a very simple, interactive, secured and low-cost design. The design uses a PIC16f877A microcontroller chip. The chip is in a family of high performance microcontrollers with ICSP (In-Circuit Serial Programming). The microcontroller is interfaced with a LCD display PCD8544.Finally, the design and construction was professionally done, with industry standard software and tools. The microcontroller was programmed using Microchips MPLAB v8.30, while the design and simulation of the project circuits were accomplished using Labcenters Proteus Professional 7.5. In addition, the final construction was done on a PCB (printed circuit board), with model board packaging.

CHAPTER ONE
INTRODUCTION
Background
Counting has a very useful application in monitoring visitors circulation and in security related issues. By visitor circulation we mean the number of INS and OUT of people (visitors) in a place and over a particular period of time. In area of security the device can be used as an object counter for example, if you have 10 items and one goes missing. Also has application in parking lot where there are limited spaces for cars. With a counter it is easily known where the allocated number of spaces for the cars in the parking lot is exceeded. Previously this exercise has been done manually which leads to errors, and sometimes disorganization but with a counter these errors and disorganization can be avoided. This device can also be used in Airports, Stadium, Churches, Mosques, Parking lots and even in lecture rooms where attendance taking is very important. A digital counter has a variety of application but for the purpose of this project we are going to concentrate on two areas which are the areas of visitors circulation and security which most of the time go hand in hand. In visitors circulation, if a place exists, it is imperative for the managers of the place to know the exact INS and OUT so as to be able to know when to provide properly for other services that would encourage more visitors to come to the place. It is not until people start standing in a place they should be sitting that one should know when to provide extra seats. This is applicable in airports, museums etc where there is constant flow of people. Another application of digital object counters is stadium where visitors circulation and security is important. Stadiums usually have existing capacities. Organizers of some events in
2

such places most times sell more tickets than the allotted capacity. With a digital counter, the stadium manager can ensure that the stadiums capacity is not exceeded during such an event. This will ensure that manager has control over the crowd coming for such an event. In museums, a digital counter can also be very useful because many people come into and out of a museum with a counter when the average number of people increases, the managers of the museum will be able to provide customers related servi ces better.

Figure 1.1 Typical door

Objectives of the Project


Accurate counting is very important. As mentioned earlier to cater for how much you have to know how many. It is not that this cant be done manually but usually, it is very difficult especially when the objects to be counted are much. Mistakes are often made or an object or an object may be counted twice. Method of design I have used can be later on is this report. I have used this mode of design because of it is not too difficult to understand. It can be designed by anybody that has a good background of digital electronics .The unique part of my design is the programming of the micro controller chip to realize the necessary logic The system is to implement a low power consuming, cost effective, and secured design. The design is flexible, interactive and sophisticated to suit any application.

Relevance of the Project


This project finds application where added security measure is to be put in place to minimize the entry of unauthorized personnel into any restricted area such as in entrances, safety vestibules, corridors inmate housing and administrative areas. The project is ideally suited for the following: y y y y y y y y High Security Applications Dormitories Assisted Living Facilities Hospitals Retail Buildings Meeting Rooms Office complexes, Banks Stairwell doors, et.c

The design is extensible to any security barrier or remote keyless entry system4.

Comment [A1]: Reference: Chuck Simmers, Microchip Technology Inc, Remote Keyless Entry and Convenience Center Reference Design with LIN Bus Interface

CH

TER T

a e er z, re

LITER TURE RE IE

a t

rizi

tem . T e reticall , t e a re i t r ,

tem i i

e ice

ca acit r ,

e,

micr c T e

tr ller .

il i c

l c

ft i

r ject ma e e i

e f t e e e ice a il i l c

ei

i erati

. T e t e rie

t e

P
ta

er
ar l i t e

l :
ic circ it re e f ire er l fa t . e i le rce f t e e r m re atterie c i ec ti ecte i erie . t a relia le rce i t e

                               %           %                      10! % ") ('&   "!             %     $         "!     # "!           

rectifie T

lta e t at ill r fr m t e

tai +

al

i i

er tra f rmer a e rectifier.

erti

fr m alter ati all

ri

t i

filter (

l ati

irect c rre t t

irect c rre t.

lta e re t

ta t

lta e, i ca e f ariati t e ta e i

i l a

ri

T e l c

ia ram

l e i a

Rect f c t

terat

Reg at

re . :

er

it

8 @B DE

8 @B

DBC

8 @B 7 B B

 5  4 3 &  2

8 @B 7A6 @ 98 76

ac T input

                
a ic electrical a m t r, electr ic a tra i t r , itc e ma m re, it effecti e ; ft i r ject are a f ll l . ire cali ft e lta e c rre t t l ati e irect c rre t, c a ca acit r) i t ert t e e re lat r i i c r rate t lta e. l er it.
dc output

T e tec

                                                      
l f a i ital ter a ee i e i te ce, i ce t e a e t f

i ital

Liquid Crystal Display (PCD 8544):


As is the case with input devices, electronic systems must provide data output in a human readable form to increase interactivity. One of the numerous output technologies is the liquid crystal display. A liquid crystal display (LCD) is a pixilated output device capable of displaying ASCII characters and dot-based graphics. LCDs can be color or monochrome according to their construction. One of the advantages of LCD display when compared to other output device such as seven-segment LED is the very low power consumption, making it suitable for battery-powered devices. Hitachi LCD displays also have a standard ASCII set of characters plus Japanese, Greek and mathematical symbols. In operation, the liquid crystal display consists of two pieces of polarized glass with perpendicular axes of polarity. The PCD8544 is a low power CMOS LCD controller/driver, designed to drive a graphic display of 48 rows and 84 columns. All necessary functions for the display are pro vided in a single chip, including on-chip generation of LCD supply and bias voltages, resulting in a minimum of external components and low power consumption. The PCD8544 interfaces to microcontrollers through a serial bus interface. The PCD8544 is manufactured in n-well CMOS technology.

Figure 2.2: Liquid Crystal Display (PCD 8544):

Features Single chip LCD controller/driver 48 row, 84 column outputs Display data RAM 48 x 84 bits

On-chip: Generation of LCD supply voltage (external supply also possible) Generation of intermediate LCD bias voltages Oscillator requires no external components (external clock also possible). External RES (reset) input pin Serial interface maximum 4.0 Mbits/s CMOS compatible inputs Mux rate: 48 Logic supply voltage range VDD to VSS : 2.7 to 3.3 V Display supply voltage range VLCD to VSS 6.0 to 8.5 V with LCD voltage internally generated (voltage generator enabled) 6.0 to 9.0 V with LCD voltage externally supplied (voltage generator switched-off). Low power consumption, suitable for battery operated systems Temperature compensation of VLCD Temperature range: -25 to +70 C.

Microcontroller (PICmicro):
A microcontroller is a type of microprocessor furnished in a single integrated circuit to serve as an intelligent core for specialized dedicated systems. Microcontrollers are embedded in many control, monitoring, and processing systems. A microcontroller usually includes a central processor, input and output ports, memory for program and data storage, an internal clock, and one or more peripheral devices such as timers, counters, analog-to-digital converters, serial communication facilities, and watchdog circuits 1. Among the various manufacturers of microcontrollers are Intel (such as the 8051 and the Pentium), Zilog (derivatives of Z-80 microprocessor), Motorola (such as the 68HC05), Atmel (the AVR), Parallax (the BASIC Stamp)1, and Microchip. PICmicro is a family of microcontrollers made by Microchip Technology. PIC (Programmable IC / Programmable Interface Controller)1 microcontrollers, do not use the conventional Von Neumann architecture, instead they use the Harvard architecture . That is, the microcontroller can read and write instructions and data to and from memory at the same time.
1 Comment [YUN3]: Pg129 .Microcontroller Programming book Comment [YUN4]: Pg 142 ..micro book Comment [YUN2]: Pg129 Microcontroller Programming book

Figure 2.3: Mid-range PIC Memory (Harvard architecture) PICs use an instruction set that varies in length from about 33 instructions for the low-end PICs to more than 70 for the high-end devices. PIC does not implement the CISC (Complete Instruction Set Computer) design, but uses the RISC1 (Reduced Instruction Set Computer) design because fewer instructions are required to perform basic operations. The PICs are programmable in their native Assembly Language. Programming the PIC microcontroller requires the following tools and components:
1 Comment [YUN5]: Pg143 micro book

10

1. An Assembler or high-level language compiler. The software package usually includes a debugger, simulator, and other support programs. 2. A computer (usually a PC) in which to run the development software such as MPLAB. 3. A hardware device called a programmer that connects to the computer through the serial, parallel, or USB line. The PIC is inserted in the programmer and blown by downloading the executable code generated by the development system. The hardware programmer usually includes the driver or support software. 4. A cable or connector for connecting the programmer to the computer. 5. A PIC microcontroller.

Figure 2.4: USB PICmicro Programmer Microchip as a company has classified the PICmicro architecture into three groups; namely the baseline, mid-range, and high-performance. y Baseline family: These are low-cost, low power, 8-bit

flash/EEPROM/EPROM/ROM-based CMOS microcontrollers. They use RISC architecture and have 33 single - word, single-cycle instructions. This group includes members of the PIC10, PIC12, and PIC14 families. They have 12-bit program words and have 6- to 28-pin packages. Popular features and peripherals common to this family are 4-20MHz clock frequency, Timer module, Wake-up from SLEEP, 8-bit A/D converter, In-Circuit Serial Programming, Interrupt, Internal Pull-Up and EEPROM data memory. y Mid-range family: This is by far the most extensive family. These are microcontrollers with 14-bit program words, with either flash or OTP program memory. This group includes members of the PIC12, and PIC16 families. Some members of the mid-range group have 4-40MHz clock frequency, USB1, I2C, LCD,
11
Comment [YUN6]: Pg 138 microcontroller book ..programming

and USART in addition to features in the baseline family. Implementations range from 8- to 64- pin packages. y High-Performance family: These PICs belong to the PIC18 group. They have 16-bit program words, flash program memory, a linear memory space of up to 2MB, and protocol-based communications facilities. They all support internal and external interrupts and have a much larger instruction set than members of the baseline and mid-range families have. They have 32-level of stacks, integrated A/D converter, 8by-8 hardware multiplier, up to 48MHz clock frequency, over 79 instructions set and are shipped in 18 to 80 pin packages.

Figure 2.5: PIC 16F874A and PIC16F877 pin diagrams

12

The pin diagrams for some mid-range microcontrollers are as shown in figure 2.10 above. In addition, figure 2.11 is a pin diagram of high-performance microcontroller PIC18F2620. The instruction set and data sheet for the microcontroller used for this project is as shown in appendix. Some commonly used commands in the instruction set are MOVLW, ADDLW, RETLW, BCF, CALL, DECFSZ, ANDLW, INCF, CLRF, BTFSS, GOTO, NOP, and END. The program memory map and stack for a typical microcontroller is as shown in figure 2.11 below. The diagram shows the addressing scheme and memory space available to microcontrollers.

Figure 2.6: Program memory map and stack for high-performance microcontroller

13

CHAPTER THREE
DESIGN METHODLOGY
The design generally requires basic understanding of the project, its objectives and mode of operation of the units in the circuit to achieve the desired aim. In doing this, some fundamental factors need to be taken into consideration for effective realization of the objectives. This includes; Accuracy and Reliability Flexibility and sophistication Cost Size and weight Availability of components

y y y y y

These factors if not properly taken care of may impair the operation of the circuit, taking note that, there has to be a trade-off between complementary specifications.

Design Specification:
The general specifications for the project are included in the objective; which means, the use of Switches (Sensors) to increment and decrement the counting register. Using the standard door as the reference for this project, Switch 1 is placed at the entry door and Switch 2 is placed at the exit door Identifying that the general specifications are hardware based. It is noted that the level of security, sophistication and interactivity is software based. Therefore, software specifications include:

14

y y y

Ability to increment the counting register Ability to decrement the counting register Ability to display input and authentication processes

In implementation of these specifications, consideration of high level of accuracy and speed is of utmost importance.

Block Diagram:
With the aid of the specifications, the integrated system is divided into Three (3) different sub-systems. Figure 3.1 shows the block diagram of the subsystems contained in the complete system.

SENSOR

MICRO controller

LCD DISPLAY

Figure 3.1: Block Diagram of system

15

Design Analysis:
The power supply circuit provides power to the system at all time and the keypad circuit scans for input, while the display of all the operations will be on the LCD display simultaneously. The microcontroller coordinates all the operations of the system. Therefore, the program on the microcontroller must take input from the sensors (switches), while displaying it on the LCD, processes such as incrementing and decrementing and storage are been done smoothly without break in power. The power section must also smoothly switch between the a.c mains and the circuit without any distortion in operation of the main system.

16

Circuit diagram
Figure 3.2 shows the complete circuit diagram excluding the power section. The circuit was designed and simulated using Proteus 7.5 professional software

PIC16F877 5V +V U2
MCLR VCC GND OSC1 U1 OSC2 RB0 RB1 RB2 RB3 RB4 RB5 RB6 RB7 RC0 RC1 RC2 RC3 RC4 RC5 RD0 RD1 RD2 RD3 RD4 RD5 RD6 RD7 RE0 RE1 RE2

4MHZ R11 1k S1 R13 R12 1k 1k

LCD3310

3V R1 R2 R3 R4 R5 R7 + C1 4.7uF R6 R8 R9 R10

S2

Figure 3.2: Circuit Diagram of a Digital Counter

17

1 2 3 4 5 6 7 8

Circuit Analysis:
The four (3) sub-systems; microcontroller, Sensor, and LCD display make up the main circuit. Microcontroller: The heart of the digital counter is a microcontroller PIC16f877A; it is interfaced with a LCD display PCD8544.The microcontroller was selected because of its memory size, low power consumption and flexibility. PIC16F877A is a High performance RISC CPU with Only 35 single word instructions to learn which operates at a speed between DC - 20 MHz clock input with single cycle instructions except for program branches which are two cycle Operating at DC - 200ns instruction cycle time, it has 8K x 14 words of FLASH Program Memory,368 x 8 bytes of Data Memory (RAM) and 256 x 8 bytes of EEPROM Data Memory, has a Pin out compatible to the PIC16C73B/74B/76/77 with the following features

Figure 3.3: A Typical PIC16f877A

Interrupt capability (up to 14 sources) Eight level deep hardware stack Direct, indirect and relative addressing modes Power-on Reset (POR)

18

Power-up Timer (PWRT) and Oscillator Start-up Timer (OST) Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation Programmable code protection Power saving SLEEP mode Selectable oscillator options Low power, high speed CMOS FLASH/EEPROM technology Fully static design In-Circuit Serial Programming (ICSP) via two pins

Single 5V In-Circuit Serial Programming capability In-Circuit Debugging via two pins Processor read/write access to program memory Wide operating voltage range: 2.0V to 5.5V High Sink/Source Current: 25mA Commercial, Industrial and Extended temperature ranges Low-power consumption: - < 0.6mA typical @ 3V, 4 MHz - 20 A typical @ 3V, 32 kHz- < 1 A typical standby current.

19

Program Code Analysis:


As earlier stated, that the core of this integrated system, is based on the program in the microcontroller. Appendix I show over a thousand (1000) lines of program code written in Assembler Language with the MPLAB IDE v8.30 software. The major divisions in the program are macros, functions, subroutines, configurations, and variable and constant declarations. The program is modularized, to implement the blocks in the flowchart, following the sequence of programming in Assembler Language. Description of Program The program starts with the declaration of the processor used with the list command, followed by the #include command indicating the processor file imported (Lines 234 and 235 also imported lcd_routine and keypad_routine files). Lines 6-10 define the configuration bits; most bits are OFF, except PWRT (Power-up Timer), and OSC (oscillator) is set INTIO67, to set up internal oscillator of the microcontroller chip. The cblock from lines 14-75 is used to declare the variables used. Lines 80 -106 define all the registers used by the application. Lines 108-113 and lines 115-119 are two macros, one to set address of LCD and the other to send characters to LCD. The main program starts at line 121 with the org 0xf00000 statement, indicating the RAM pointer locator for accessing the EEPROM memory, and lines 123-169 are declarations of EEPROM data addresses using the de command. Noting that the idea behind this system is the fast detection of interruption of normal operations, many timers and interrupt handlers are set. Lines 172-180 set up interrupt vector address and flag test. Lines 188-222 sets timer interrupt to handle first time use (that is, key not yet pressed) by displaying initial message on screen.

20

The org0x0000 and goto statements are the actual start point for the program, setting the pointer address to 0x0000. The goto statement branches to lines 226-230 the takeoff labeled point, by initializing internal oscillator to 4MHz and enabling PLL mode. Lines 240-274 set both timers and delay subroutines for different time durations that is need for the system. While lines 275-346, does quick processing on the processor such as; clearing of registers, pointing to EEPROM data memory, delaying time for key debounce of the keypad, turning the backlight of LCD display ON, turning OFF of interrupt timer, and resetting all other timers. Lines 348-374 initialize the pins of the microcontroller as inputs and output. Lines 378-398 initialize the LCD display with the lcd_init call command, and enable a global interrupt for any kind of interruption in the system. With the processor setup and ready for operation, the processor will change from one state to another; the idle state, PIN-change state, unlock state, error state, process state, and save states. The idle state is also the reset state. This state is always waiting key press. Any process state will also return to the idle state when the escape key is pressed. Lines 401-465 is the code section for the idle state. While the clear is not pressed, lines 467-538, are at PINchange state, with a branch to lines 717-855 to save the changes. To unlock, after entering the PIN, the # button is key pressed, so lines 540-558 handles unlocking state. Before unlocking, authentication is required, and this is at the process state. In order for the microcontroller to authenticate effectively, all interrupt sources are disabled. The program searches for existing/old PINs in the EEPROM. During the authentication process, there is transfer of error or success to related states to handle. The authentication process state is at lines 560-593. The actual unlocking and display of access message is at lines 595-650. This line of code is a branch from the process state. The line displays access message, turns the

Comment [YUN7]: Branch statement..check appendix

21

motor, delay for some seconds, and then returns the motor to the original position. These lines also return the system back to the idle state. To accommodate for mistakes and error from either the user or system instability, lines 653715 handles the error state. The error state is usually a branch from anywhere in the program, so the error handling lines has display error messages, set-up of the alarm (intruder alert), delay in time, turn-off of the LCD display, and restore back to the idle state. Key scanning is through lines 856- 1088, by checking if any of the number 0-9 is pressed. The save state is required to save new PIN. After a new PIN is entered, and the save button is pressed, lines 1091-1128, handles the saving process, by saving to EEPROM, at the correct address and displaying the action as PIN SAVED on the LCD..

22

CHAPTER FOUR
DESIGN CONSTRUCTION
In this chapter, we shall take a look at the design and analysis of the circuit for constructing the frequency counter. The project is constructed in three modules

control system (Micro-controller) and lastly the counter/display system (LCD display PCD8544). The sensor is used to detect what to be counted, when used as a visitor counter the sensor will be connected to a foot mat or to an infrared which sends a clock to the microcontroller when someone steps on the foot mat, the microcontroller counts the number of clocks the sensor sends then converts it and send it to the LCD display The sensor is a switch, when pressed sends a high logic to the microcontroller and when released it sends a low logic, the transition from low to high and back to low logic is called a clock so for every clock the microcontroller increase its count register by 1 and the counts are converted from binary to decimal before being displayed on the LCD.

MICROCONTROLLER
The microcontroller operates on 5v DC supply and the LCD operate on a maximum 3.3v DC so in other to interface the 5v output of the microcontroller to the 3.3v input of the LCD a voltage divider is used, R1-R10 are used to divide the 5v output of the microcontroller to 2.5v which is within the operating range of the LCD S1 and S2 are push button switches which are used as sensors, S1 is used to count visitor coming in while S2 people going out, when S1 is open a low logic flows from ground through resistor R12 to RB1 of the microcontroller, the diode blocks the flow of the low logic to RB0, the logic at RB0 is low logic because it is pulled to ground by R11. When
23

the power supply, the

S1 is pressed a high logic flows to the RB1 pin, it also flow to RB0 pin through the diode. The RB0 pin is the interrupt input of the microcontroller so when the high logic is received, an interrupt occurs and the microcontroller goes to the counting routine, it checks if its S1 or S2 that send the logic by checking the logic state of RB1 and RB2 since S1 was pressed and the high logic also flowed to RB1 therefore the microcontroller increases the COUNT IN register. If S2 was pressed the high logic will flow to RB0 and RB2 so the microcontroller will increase the COUNT OUT register

POWER ANALYSIS

3V 5V U3 78L05
IN OUT

U4 LM317
IN OUT

AC PLUG 220V - 12V D3

1000uF C2

9V R19

Figure 4.1: Circuit Diagram of the Power Supply

To power the circuit, the 220v input is stepped down to 12v AC and converted to 12v DC using a bridge rectifier D3, C2 filters the voltage and U3 is used to regulate the voltage to 5v, U4 regulates the 5v to 3.2v which is used to power the LCD, capacitor C3,C4 filters out the ripples while R19 andR18 are used to preset the 3.2v of U4.
24

COM

C3 COM 1uF

R18 180

C4 1uF

CALCULATION FOR VOLTAGE RECTIFICATION


Vin(min) is the minimum input voltage Vp is the peak input voltage = 12v Vr is the ripple voltage =? Vin(min) = Vp Vr = Vp 2*0.7 2*0.7

Vr

Vin(min)

Vr = 12v-1.4-10 = 0.6v Filter capacitor C = Vp/(2*f*Vr*R). Vp = 12 f= 50Hz R= 200 Vr =0.6v from above C = 12/(100*0.6*200) = 0.001F = 1000uf

let it be = 10v

25

Software Burning:
After compilation, into hex file, the machine code is burnt into the chip, using a WinPic800 USB programmer. The PIC is first erased, and the code is downloaded into it. Verification of the downloaded content and memory allocation is ensured to provent improper execution.

Figure 4.2 : WinPic800 USB Programmer software After initial burning, subsequent burning of modifications to the code was achieved using the ICSP (In-Circuit Serial Programming) feature of the microcontroller.

Hardware Troubleshooting and debugging:


While programming the code, a lot of errors and problems were encountered, as result of ingeniuity. Also, during construction, a lot of troubleshooting and trial and error activities was so much involved. But all problems were successfully resolved.

Simulation/Testing:
The program after compilation, was simulated using both MPLAB v8.30, and Proteus Professional 7.5. The program worked perfectly, but some software parameters were not physical, limiting the real situation. Such parameters include board resistance, environmental temperature changes, component tolerance. The final system was tested, after construction and also worked well, Figure 4.6 shows the real keypad outline as simulated.
26

PCB Layout:
The PCB layout was generated by Proteus Professional 7.5 package, after the circuit design. The 3D visualization, made construction easier. The PCB layouts for the main circuit are shown in figure 4 below.

Figure 4.3: PCB Layout of Main Circuit

Hardware Troubleshooting and debugging:


While programming the code, a lot of errors and problems were encountered, as result of ingeniuity. Also, during construction, a lot of troubleshooting and trial and error activities was so much involved. But all problems were successfully resolved.

27

Simulation/Testing:
The program after compilation, was simulated using both MPLAB v8.30, and Proteus Professional 7.5. The program worked perfectly, but some software parameters were not physical, limiting the real situation. Such parameters include board resistance, environmental temperature changes, component tolerance. The final system was tested, after construction and also worked well

28

CHAPTER FIVE
CONCLUSION/RECOMMENDATION

Discussion of Result
The result observed so far indicate the accuracy of the program code and hardware construction. A fair pre-assessment to the final system (that is, after final packaging) also indicates that the system will work perfectly, if maintained and handled with care.

Conclusion
Indeed, securing restricted locations can become more secured and flexible without the use of complete mechanical locking devices. This project has designed and constructed a portable electronically controlled lock, with features that are expansible. The project has also accounted for power failure in many premises that utilize electronic locks. The design is also adaptable to other input mechanisms such as iris, retinal, and fingerprint, by just designing adapter hardware capable of generating 4-digit code OR adjusting the code for longer digit codes and using the same microcontroller design.

Recommendations
A more elaborate system or access control system can be built that can store several PIN codes of different devices at different locations in a protected zone, to a central server for coordination, surveillance, and crime detection purposes. Advancement in power usage and back-up system, can implement piezo power supply. Research in RFID (Radio Frequency ID) and SMS (Short message service) as other mean s of activating the lock should also be favoured.

29

REFERENCES
Chuck Simmers, Microchip Technology Inc, Remote Keyless Entry and Convenience Center Reference Design with LIN Bus Interface L298 datasheet by Sgs. Thomson Microelectronics, 1998, Pg 1-4 CSC Cherry Semi - conductor. Power Conversion IC Data Book . 1992 Damle, P and Dubey, G.K. (1976). Software Burning on Micro Chip . IEEE Trans. VOL. 31. NO. 8. Pp.1724-1735. Dewan S.B. (1981). Optimum input and output filters for single phase rectifiers power supply .IEEE Trans Industry Applications, vol. IA17, No3, 282-288. Dixon J.W, Venegas G. and Moran L. (1997). A Series Active Power Filter based on a Sinusodial Current Controlled Voltage- Source Inverter. IEEE Transactions on Industrial Electronics, Vol. 44, NO . 5. 612-620 Gbadebo S(2002) project report on digital frequency counter Electrical/Electronic Engineering Department University of Lagos . Pg 23-40 Jacob Millman, (1979) Microelectronic Digital and Analog Circuits and Systems, McGraw-Hill Book Company, New York, ISBN 1979 0-07- 02327-X. Pg 53, 145-148 James Buchanan (1970) CMOS/TTL digital systems John Wiley and Sons LA 1970.Pg 2932. Julio Sanchez and Maria Canton (2002) Microcontroller programming .The Microchip PIC by Canton pg 120, 129, 140, 142, 143 PIC18F2525/2620/4525/4620 Datasheet by Microchip Technology Inc. 2004 PIC 16F877A datasheet by Microchip Technology Inc. pg3-8

Paul Horowitz and Winfield Hill, (1989) The Art of Electronics 2nd Ed Cambridge University Press, Cambridge, 1989 ISBN 0-521-37095-7. Pg 76. William Klietz (1975) Digital Electronics a practical application 5 th Edition. Cambridge University press. Cambridge, 1975 ISBN 0-521-37095-7. Pg 100-109

30

APPENDIX I
Main Program Code
;************************************************************************** ; Filename: access.asm ; Author: OWOEYE DAMILOLA AKINTAYO ; Date: July 19, 2009 ; Processor: PIC18F2620 ; Reference Circuit: Figure 3.2 ; Description: Software program of a Digital counter ; ;************************************************************************** * * * * * *

list p=16F877, f=INHX8M include "P16f877.inc" include "set1A.inc" __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _WRT_ENABLE_OFF & _LVP_OFF

;Set up general purpose registers cblock d'32'

WTEMP WTEMP1 WTEMP2 WTEMP3 WTEMP4 WTEMP5 WTEMP6 WTEMP7 WTEMP8 WTEMP9 WTEMP10 MODE XTEST INT_W_STORE STATUS_TEMP PCLATH_TEMP WTEMP_ISR_STORE WTEMP_BUF COUNT_IN_L COUNT_IN_H COUNT_OUT_L

;General use variables ; ; ;General use variables ;

31

COUNT_OUT_H COUNTX_IN_L COUNTX_IN_H CAR_L CAR_H SETX SETY NUMBER NUM NUMHI NUMLO D4 D3 D2 D1 D0

COUNTx COUNT0x COUNT1x COUNT COUNT1 COUNT2 COUNT3 ADDR ADDR1 NUM_LEN endc

;------------------------------------------------------------------------------------------------------------; Origin code ;------------------------------------------------------------------------------------------------------------ORG 0x000 before it. nop nop goto INIT ;Start here. Programmer puts bootloader code

;Go to your main application start point

32

ORG 5 goto ISR

;Interrupt Vector

org 0x01FF ;------------------------------------------------------------------------------------------------------------;Initialise ports ;----------------------------------------------------------------------------- -------------------------------;------------------------------------------------------------------------------------------------------------;Initialise ports ;--------------------------------------------------------------------------------------------- ---------------;--------------------------------------------------------------------------------------------------;-------------------------------------------------------------------------------------------------------------

;---------------------------------------------------------------------------------------------START ;----------------------------------------------------------------------------------------------movlw D'100' goto START

;---------------------------------------------------------------------------------------------;---------------------------------------------------------------------------------------------SEND_DATA bcf STATUS,6 bcf STATUS,5 movwf SSPBUF BANKSEL SSPSTAT Char1 btfss SSPSTAT,BF goto Char1 BANKSEL SSPBUF movf SSPBUF,W ; return

; put in SSPBUF ; BANK 1 ; Data transfer complete? (Buffer Full?) ; if not, check again ; BANK0 ; Get Data from SSPBUF ; Throw it away

;----------------------------------------------------------------------------------------------

33

;---------------------------------------------------------------------------------------------DELAY movlw D'200' movwf WTEMP LOOP decfsz WTEMP goto LOOP return ;-----------------------------------------------------------------------------------------------

;This routine will delay program operation from 0.7 to 200mS MSDELAY movlw d'1' DELAY_0 movwf WTEMP1 DELAY_1 movlw d'150' movwf WTEMP2 DELAY_2 movlw d'255' movwf WTEMP3 DELAY_3 decfsz WTEMP3,F goto DELAY_3 decfsz WTEMP2,F goto DELAY_2 decfsz WTEMP1,F goto DELAY_1 return ;------------------------------------------------------------------------------------------------BIN_TO_BCD ;10b binaey to BCD Bin2DecFast movf NUMHI,w iorlw 0xF0 ;w=H2-16 movwf D1 ;D1=H2-16 addwf D1,f ;D1=H2*2-32 addwf D1,f ;D1=H2*3-48 movwf D2 ;D2=H2 -16 addlw -D'5' ;w=H2-21 addwf D2,f ;D2=H2*2-37 Done! addlw D'41' ;w=H2 20 movwf D0 ;D0=H2 20 swapf NUMLO,w iorlw 0xF0 ;w=H1-16 addwf D1,f ;D1=H2*3 H1-64 addwf D0,f ;D0=H2 H1 4, C=1 rlf D0,f ;D0=(H2 H1)*2 9, C=0

I I I

34

comf D0,f ;D0= -(H2 H1)*2-10 rlf D0,f ;D0= -(H2 H1)*4-20 movf NUMLO,w andlw 0x0F ;w=H0 addwf D0,f ;D0=H0-(H2 H1)*4-20 Done! rlf D1,f ;C=0, D1=H2*6 H1*2-128 Done! movlw D'5' movwf D3 movlw D'10' mod0 addwf D0,f decf D1,f skpc goto mod0 mod1 addwf D1,f decf D2,f skpc goto mod1 mod2 addwf D2,f decf D3,f skpc goto mod2 return ISR ;Interrupt Service Routine ;This should be called every 1/100th of a second movwf INT_W_STORE ;Backup the W register swapf STATUS,W ;Backup STATUS clrf STATUS ;Forces correct page and bank IRP,RP0 and RP1 movwf STATUS_TEMP ; movf PCLATH, W ;Only required if using pages 1, 2 and/or 3 movwf PCLATH_TEMP ;Save PCLATH into W clrf PCLATH ;Page zero, regardless of current page movf WTEMP,W movwf WTEMP_ISR_STORE movf SSPBUF,0 movwf WTEMP_BUF btfss goto btfsc INTCON,INTF INT_EXIT PORTB,2
35

;D(X)=D(X)mod10 ;D(X 1 )=D(X 1 ) D(X)div10

P P

P P

goto btfsc goto call btfss goto call goto TESX call clrf goto

TESX MODE,0 CARPARK_FULL MSDELAY PORTB,1 INT_EXIT CAR_IN INT_EXIT

CAR_OUT MODE INT_EXIT

INT_EXIT ;--------------------------------------------------------------------------------------------; SET LCD DATA FOR IN bcf PORTC,0 ;WRITE COMMAND TO LCD ; move to line 2 of display Y=2 ; move to COLUNM 0 of display X=0

movlw H'42' call SEND_DATA movlw H'92' call SEND_DATA

bsf PORTC,0 ;WRITE DATA TO LCD ;---------------------------------------------------------------------------------------------;CONVERT COUNT IN TO DIGITS movf COUNT_IN_H,0 movwf NUMHI movf COUNT_IN_L,0 movwf NUMLO call BIN_TO_BCD IN_TENS movf D2,0 call TABLE_LOOKUP movwf WTEMP7 IN1 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto IN_ONES call SEND_DATA

;SELECTED_TENS FOR COUNT IN

;SELECTED_ONES FOR COUNT IN ; SEND W TO LCD


36

incf WTEMP7 goto IN1 IN_ONES movf D1,0 call TABLE_LOOKUP movwf WTEMP7 IN2 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto IN_DECI call SEND_DATA incf WTEMP7 goto IN2 IN_DECI movf D0,0 call TABLE_LOOKUP movwf WTEMP7 IN3 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto OUT_CONVERT1 call SEND_DATA incf WTEMP7 goto IN3 OUT_CONVERT1 movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00'

;SELECTED_ONES FOR COUNT IN

;SELECTED_DECIMAL FOR COUNT IN ; SEND W TO LCD

;SELECTED_DECIMAL FOR COUNT IN

;COUNT IN ; SEND W TO LCD

; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE
37

call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA

; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE

movlw D'30' movwf SETX N_A movlw H'00' call SEND_DATA ; clear display

incf SETX movlw D'75' movwf WTEMP movf SETX,0 subwf WTEMP,0 btfss STATUS,Z goto N_A ;-------------------------------------------------------------------------------------------;-------------------------------------------------------------------------------------------OUT_CONVERT ;----------------------------------------------------- ---------------------------------------bcf PORTC,0 ;WRITE COMMAND TO LCD ; move to line 3 of display Y=3 ; move to COLUNM 0 of display X=0

movlw H'43' call SEND_DATA movlw H'80' call SEND_DATA bsf ;OUT PORTC,0

;WRITE DATA TO LCD

38

movlw H'3E' call SEND_DATA movlw H'41' call SEND_DATA movlw H'41' call SEND_DATA movlw H'3E' call SEND_DATA movlw H'00' call SEND_DATA movlw H'3F' call SEND_DATA movlw H'40' call SEND_DATA movlw H'40' call SEND_DATA movlw H'3F' call SEND_DATA movlw H'00' call SEND_DATA movlw H'03' call SEND_DATA movlw H'03' call SEND_DATA movlw H'7F' call SEND_DATA movlw H'03' call SEND_DATA movlw H'03' call SEND_DATA movlw H'00' call SEND_DATA movlw H'08' call SEND_DATA movlw H'08' call SEND_DATA movlw H'08' call SEND_DATA movlw H'08' call SEND_DATA movlw H'00' call SEND_DATA

; letter O ; letter O ; letter O ; letter O ; letter O

; letter U ; letter U ; letter U ; letter U ; letter U

; letter T ; letter T ; letter T ; letter T ; letter T ; letter T

; letter ; letter ; letter ; letter ; letter -

;----------------------------------------------------------------------------------------------movf COUNT_OUT_H,0 movwf NUMHI


39

movf COUNT_OUT_L,0 movwf NUMLO call BIN_TO_BCD OUT_TENS movf D2,0 call TABLE_LOOKUP movwf WTEMP7 OUT1 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto OUT_ONES call SEND_DATA incf WTEMP7 goto OUT1 OUT_ONES movf D1,0 call TABLE_LOOKUP movwf WTEMP7 OUT2 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto OUT_DECI call SEND_DATA incf WTEMP7 goto OUT2 OUT_DECI movf D0,0 call TABLE_LOOKUP movwf WTEMP7 OUT3 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto STAFF1C call SEND_DATA incf WTEMP7 goto OUT3 STAFF1C movlw H'00' call SEND_DATA movlw H'00'

;SELECTED_TENS FOR OUT

;SELECTED_ONES FOR OUT ;SEND W TO LCD

;SELECTED_ONES FOR OUT

;SELECTED_DECIMAL FOR OUT ; SEND W TO LCD

;SELECTED_DECIMAL FOR OUT

; ; SEND W TO LCD

; letter SPACE ; letter SPACE


40

call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA

; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE

CAR_LEFT ;--------------------------------------------------------------------------------------------; SET LCD DATA FOR CAR_LEFT bcf PORTC,0 ;WRITE COMMAND TO LCD ; move to line 4 of display Y=4 ; move to COLUNM 0 of display X=0

movlw H'44' call SEND_DATA movlw H'8B' call SEND_DATA bsf PORTC,0

;WRITE DATA TO LCD

;----------------------------------------------------------------------------------------------movlw D'0'
41

movwf NUMHI movf COUNTX_IN_L,0 movwf NUMLO call BIN_TO_BCD CAR_TENS movf D2,0 call TABLE_LOOKUP movwf WTEMP7 CAR1 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto CAR_ONES call SEND_DATA incf WTEMP7 goto CAR1 CAR_ONES movf D1,0 call TABLE_LOOKUP movwf WTEMP7 CAR2 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto CAR_DECI call SEND_DATA incf WTEMP7 goto CAR2 CAR_DECI movf D0,0 call TABLE_LOOKUP movwf WTEMP7 CAR3 movf WTEMP7,0 call TABLE2 movwf WTEMP8 btfsc WTEMP8,7 goto STA1 call SEND_DATA incf WTEMP7 goto CAR3 STA1 movlw H'00' call SEND_DATA ; letter SPACE

;SELECTED_ONES FOR CAR ;SEND W TO LCD

;SELECTED_ONES FOR CAR

;SELECTED_DECIMAL FOR CAR ; SEND W TO LCD

;SELECTED_DECIMAL FOR IN

; ; SEND W TO LCD

42

movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw H'00' call SEND_DATA movlw D'30' movwf SETX N_AX movlw H'00' call SEND_DATA incf SETX movlw D'75' movwf WTEMP movf SETX,0 subwf WTEMP,0 btfss STATUS,Z goto N_AX ;;INT_EXIT

; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE ; letter SPACE

; clear display

43

movf WTEMP_BUF,0 movwf SSPBUF movf WTEMP_ISR_STORE,W movwf WTEMP movf PCLATH_TEMP, W movwf PCLATH swapf STATUS_TEMP,W movwf STATUS swapf INT_W_STORE,F STATUS swapf INT_W_STORE,W bcf INTCON,INTF retfie CARPARK_FULL call FULL bsf MODE,0 goto CAR_IN call call movf subwf btfsc goto incf incf btfss return clrf incf call return CAR_OUT call call call movf btfss decf incf btfss return clrf incf call INT_EXIT call WELCOME DELAYX CLEAR COUNTX_IN_L,0 XTEST,0 STATUS,Z CARPARK_FULL COUNTX_IN_L COUNT_IN_L STATUS,Z COUNT_IN_L COUNT_IN_H MSDELAY

;Restore PCLATH ;Move W into PCLATH ;Recall STATUS ;Recall the W register without affecting

BYE DELAYX CLEAR COUNTX_IN_L STATUS,Z COUNTX_IN_L COUNT_OUT_L STATUS,Z COUNT_OUT_L COUNT_OUT_H MSDELAY
44

return ;---------------------------------------------------------------------------------------------------------------DELAYX ; DELAYN for about 100 usec movlw D'2' ;DELAYN loop movwf COUNTx ;DELAYN loop udelayxy movlw D'255' movwf COUNT0x movlw D'255' COUNT1x ;DELAYN loop ;DELAYN loop ;delay loop ;delay loop ;delay loop ;delay loop ;delay loop ;delay loop ;delay loop

udelayx movwf udelay1x

decfsz COUNT1x, F goto udelay1x decfsz COUNT0x, F goto udelayx decfsz COUNTx, F goto udelayxy

return ; go back to program ;---------------------------------------------------------------------------------------------------------------DELAYN ; DELAYN for about 100 usec movlw D'255' ;DELAYN loop movwf COUNT ;DELAYN loop udelay0 movwf udelay1 goto movlw D'200' COUNT1 decfsz COUNT1, F udelay1 ;delay loop ;delay loop ;delay loop ;delay loop ;delay loop ;delay loop

decfsz COUNT, F goto udelay0 return END

45

APPENDIX II
PIC16F877A Datasheet

46

APPENDIX III: PICF8774 INSTRUCTION SET

47

48

49

50

Оценить