You are on page 1of 63

( : 08197E)

(...: 503022)
(...: 503059)
:

2009



, , ,
... .

.
.
( )
,
( ).
24 .
,

.


1:
1-A:

. 4

1-: . 5
1-:

. 6

2:
2-A:

. 10

2-:

. 10

2-:

. 14

2-: PIC Microchip

. 15

2-: O PIC16F628

. 21

2-:

. 23

3: &
3-:

. 25

3-:

. 25

4: &

4-:

. 32

4-:

. 33

4-:

. 40

5:

. 55

. 57

1-A:

. ,
. ,
,

, ,
, ,
,
. ,
.

,
,
, .
, , . ,
,
,
.
,
. ,
.
,
.
,
,

.
4

, ,
, .
,
.


, ,
24
.

1-:

.

.

,
,


.
,
1-1:

. , ,
, .

:

5

: ( / )
,

1-:

.
- - ,
, .
,
,
.

, ,
. ,
. ,
6 12 Volt DC,

, - (keyswitch)
.

,
. ,
,
: ,
2A
.

,

, .
,
,
.

230/400 Volt AC
, .

( 1-2)

( ).

1-2:

16 (10 ,4 ,
* # )

E
,
.
/ :
.
,
.
7

,
(pressure mats) , PIR (Passive Infrared- ),
, ,
Interior Active Infrared .
( ),
. .

, ,

, .
,
, - .


. ,
.
,

.
/ 3.


, ,

.
:

( 1-3) : ,

:
.
,

1-3:

.
8

,
.O
110 db 125 db.

odem


( ,
, / ..).
, GSM
Modems
, SMS MMS.

: , (),
LEDs.

v
( ),
( & ) 24
, .

2-A:
'70.

().
, .

, , -,
,
.
, , ,
,
.
,

8bit 16bit 32bit.


o
/.

2-:
, ,
(computer on a chip).
VLSI ,

, Silicon Wafers.

2-1:

8051 Atmel

10


.

. E
,
.

,
, , ,
, . ,
,


, ,
.
,
.
,
.
,
, . ,
,
.
embedded systems.

, ;
, ,
.
. ',
/,
.
, , .

11

,
, .


(
).
, .
(
RAM), , flash
.

( milliwatt microwatt),
,
, .

,
.
, ,
, , .
, ,
, ,
-,
.

,
, , ,
, .
(embedded systems).

,
, ,
.

12

(relay), LED,

LCD,

,

, ,
, ...

2-2 /

,
.

.

. 8bit , 16-bit, 32-bit.


,

.
,
.
100 ,
.

,
.
(pins).
, ; ,
,
. ' , ,
.

13

, .
: CF (32-bit), ARM, MIPS (32-bit PIC32),
S08, AVR, PIC (8-bit PIC16, PIC18, 16-bit dsPIC33 / PIC24), V850, PowerPC ISE, PSoC
(Programmable System-on-Chip).

2-:

1 0.
, assembly,
.

, ,
C.
. ,
BASIC INTEL, BASIC FORTH Zilog Z8.

.
Assembly. Assembly
.


assemblers. , MOV,
ADD, LD, (, , ) assembler
0 1 .
, ,
.



.
.

14


, compiler ()
interpreter (). ,
.

, (hardware)
.

( compiler) .
,
.

2-: PIC Microchip


PIC Microchip Technology
Inc., .
.
,
.
PIC .
( )
.
20MHz 1 4 (Kb).
.
Harvard
Risk controller, (Redused instraction set
controller) (
)
.

35
.
2-3: PIC

15

PIC General Instruments.


, PIC (Peripheral Interface
Controller). '70 General Instruments
PIC 1650 1655. '
, ,
. RISC,
(Working) 30 .
PIC - , , .

' '90 PIC


, PIC
. , Microchip
, . ,
8-bit. ,
General Instruments,
.

PIC ,
. ,
, .
. ,
PIC , , 8-bit, Harvard,
RISC, (Working W), reset interrupt vectors.

, Microchip .
.

. `C` CMOS,
. `F`
flash ( CMOS
). `A`
.

16

, 16C84 .
16F84, flash. ,
16F84,
.

Microchip
. ,
, 16C5XX,
"baseline". ,
`16C'
`16F' "mid-range".
, `17C',
"high-end".

2-4: 16C84

,
, ,
.

PIC

PIC .
:

Harvard ( )

(accumulator) W,

RAM

(hardware stack)

( 256 byte),

Data Space (RAM)


PICs RAM
. data space.

17

,
PIC .
(move instructions)
. PIC (. Baseline MidRange),
accumulator W.

Code Space
PICs Harvard,
. PIC
EPROM, ROM, or flash.

Word Size
PIC . PIC
8-bit , 8- .
Baseline Mid-Range ,
( 12 14 bit ).
PIC18 8bit (byte), , 16-bit.

Stacks
PICs (call stack)
.
, PIC18,

.


PIC , 35 (
Baseline Mid-Range PIC), 80 high-end
PICs.
.

18

, PIC 5 :

accumulator W, ("literal"), 8-bit .


movlw (move literal to W) andlw (AND literal with W).

accumulator W .
W (. addwf reg,w).

X bit. ,
bit , 4
. "0" "1" bit,
bit "0" "1".

: 2, goto call

- (zero operand instructions),


sleep
.


O PIC :
* Sleep mode ( ).
* Watchdog timer.
* .

,
.

8/16 Bit

EEPROM Memory

/ USART

MSSP Peripheral IC SPI

Capture/Compare PWM modules

(~1.0 MHz)

19

USB, Ethernet, CA

PIC

Baseline
PIC (code memory) 12-bit,
(register file) 32-byte, call stack .
PIC10, PIC12
PIC16. Baseline 6 40 .
, 7-9 byte

, byte
RAM .
ROM 512
words (12 bit ),
2048 words.
O CALL GOTO

2-4: Baseline

9-bit .
.
"f", "k".
bit (0-7) "b". bit "d" : 0
W, 1
.

Mid-Range
PIC code memory 14-bit,
cal stack 8 .
Baseline, 128
2048 words . mid-range
PIC12 and PIC16.
32 bytes ,
96 bytes RAM .

20

PIC17 High End



PIC18. ,
.

16-bit ( ), call stack 16 .
40 68

PIC18 High End


H Microchip PIC18 High End 2002.
PIC18 ,
. ,
C.

PIC24 dsPIC 16-bit


H Microchip dsPIC 2001,
2004. 16-bit.
.

PIC32MX 32-bit
H Microchip PIC32MX, 32-bit
2007.
MIPS32 M4K Core.
PIC24.

2-: O PIC16F628
PIC16F628,
, , in-circuit
programming,
. , programmer
Microchip PICKIT 2.

21

PIC16F628 ( 2-5) 18 , ,
, CMOS, 8-bit. flash memory

RISC.

,
stack 8 ,

(interruptions).

,
2-5: PIC16F628A

(branches)
.

, 35 . PIC16F628
2:1 4:1 8-bit
.
, ,
.

PIC16F628 8 . RC
. LP , XT
, INTOSC , ,
. HS
(High-Speed crystals). EC .
Sleep (power-down) .
"" sleep
interrupts, interrupts resets.
Watchdog (Watchdog Timer),
RC, .
, ,
.

22

flash,
.
.

2-:

""

(programmers)

. PIC
Microchip , ICSP (In Circuit Serial
Programming)

LVP

(Low

Voltage

Programming),

.

2-6:
PIC16F628

ICSP , clock data,


12V ., v Vpp/MCLR.
(LVP), '

/, LVP.

PICkit

PIC.

PIC. PICkit 2
ICSP,
PIC ,
, ,
.
ICSP,
,
2-7:

PICkit 2

PICKIT2 Microchip

.
23

PICkit 2 USB, 6
. ICSP
5 :

Vpp - Programming Voltage: . ,


ICSPCLK PGC - Programming Clock

ICSPDAT or PGD Programming Data

VDD Power Supply positive voltage:

VSS Power Supply ground reference:

, .

. .
.

, ,
,
.
.

24

3-:
, ,

, .
, ,

3-:
( / )
,
.
.
, .
,

. ,

3-1:

,
.

.
-


3-2:

.
25

,
.
H
70,

.
, ,
.

PIR
PIR
. ,
,
, . ,
, .


, .
PIR ,
.
,
, . ,
,
.

microns.
3-3 PIR

7 14 microns.
PIR

.
,
.
,

26

. ,
,
, ,
.
,
.
,
, .
,
,
.
PIR ,
.

/
, , ,
.
""
, . ,
,
360 .


. O
PIR
,
.
PIR

3-4

PIR

,
PIR .
, , ,
.

27

,
, .
PIR,
,
.


.
, PIR
,
.
,


.

,
PIR
(
) .



,
. ,
. ,
.


, ,
,
.

28



, ,

,
. ,
. ,
.
-
: .

3-5:


.
( )
. ,
90%
75 milliseconds (
) .

,
. ,
, ,
. ,

. , ,
.
, ,
. ,
, .

.

, , . ,

.
29


,
. :
.

,
- -
, .

. ,
,
, PIR,
.

, . ,
,
,
,



,
.


,
.
.
, ,
.
.

30



,
.
(
) .
, .
, ,
,
.


,
.,
.
,
-
. ,
.
,
,
3-6:


A
.


.

31

4-:
,
. ,
, .
, , ,
. ,
.
.

Microchip, PIC16F628, , ,
in-circuit programming ( 2),
.
,
Assembly . PIC,
Microchip PICKIT 2.
, ,
, , , ...

:
, , PIR (Passive InfraRed)
.
.

: PIC16F628A
.

: LEDs,
.

32

4-:
, .
.



. ,
( 4-1).
. ,
...

4-1:

,
( 4-2),
, , ..
,
.

,
4-2:

CMOS 4001, R,
2 ( 4-3).

Cmos 4001 14 . 3 Volt


15 Volt. ,
.
.
9 Volt. 4001 4 R,
. 2
.
1 2 ,

4-3: CMOS 4001

3.
, ( High) (
Low) . ,
10 mA.

33

4-4:

( 4-4).
.
,
. ,
R2 C2 ( ,
3 5 ).
,
R1 (4,7M). ,
R1,
. 8 "Low"
C1 .

,
. C1 8
"High". , .

34

11, Q1
.
"High", C2
R2. , "High"
11 "Low".
, , ,
, 3 ,
,
( 4-5).

, CMOS
.
.
, C1
.
C3 .
,
R1 C1,

4-5:

( ).

(Infrared Beam Detector)


(Infrared Beam Detector) . .
,
.
,
,
.
( 4-6).
,
4-6

35

,
2 LED,
. .
.
( 4-7), ,
,
.

,
, . ,

.
, ,

4-7

, .


.
4 . 9 Volt.

.

.

.
( 4-8).
. ,
.

,
,

4-8:

, .

.
36

4-9:

( 4-9) BC547, 2
LED . 9 Volt.
LM324
( 4-10).
O LM324 , ,
. 3, 32
Volt,
.
11 .

( 4-11)
(L53P3C). To
.

4-10: LM324

, .
-
transistor.

37

4-11:

PIR (Passive InfraRed)


PIR ( 4-12
). , ,

38

, .

.
Normally Open Normally Closed
. 9 16 V, (
9Volt).
. ,
. , PIR
,
20 .
,
4-12:


PIR ,
. , PIR

. PIR
.
(. ,
) .
110
. 2.3
( 4-13),
, 12 .
,

4-13: PIR
()

( ).
.

O PIR ( 4-14): , 30
.

39

, .
, .
PIR,
,
20 . ,
.

, ,
, ,
PIR .


,
,

4-14: PIR

, .

4-:
.
, ,
.
, .
, ,
. 12 Volt,
(, ..) 12 Volt
.

,
. , :

, 5 Volt

40

, PIC16F628A

LEDs, () ( ,
)


(regulators) ,
7805, 7809. regulators
. To
7805, , , GND, OUT
( 4-15). , 7805
12V,
35V. To ,
, 5V,
.

4-15: regulator 7805

regulators,
.
, , .
regulator 7809, , 7805,
9V.
.

:

,
"1" ( 5 V)
"0" (0 Volt) ;

, ,
5 Volt.

4-16:
TLP 621

41

(photocoupler)
TLP 621 ( 4-16) , .

TLP 621 , ,
.
, .
, , .

TLP 621.
. 1 2
, 5 Volt,
.
. ,
. ,
. phototransistor , ,
5 Volt,
'high' 'low' (
10 . 4-19).
.

PIC16F628A
PIC16F628 ( 4-17) 18 ( 4-18)

PIC
6 15 /.
2kb (

2048

), 4MHz
37kHz. 4MHz
4-17: PIC16F628A

4 1uS
.

42

PIC16F628


PIC16F628

4MHz 48kHz.


(ICSP)

4-18: PIC16F628/

low speed clock mode,


programmable BOR, . /
25mA. , I/O
, .
PIC16F628, (RA5). PIC
I/O ,
( PIC16F84).
, 3 pin (RA4) ,
. (Port A) 7 / .

(Port B) 8 /,
, pins RB6 RB7
"1". 14 /,
,
. 2 pins (5) (0).

, 6 (PortB,0)
(interrupt). high, interrupt
.
, Port A . R0 (pin
17) , R1 (pin 18)
, RA2 (pin 1)
PIR . Port , R0
(pin 6), interrupt.
.
43

419:

44

R1 (pin 7), 330, LED,


Stand-by Mode ( 4-20). R2 (pin
7), LED, t o
ON mode.
RB4, RB5, RB6, LED

(PIR,
).
RB7,

,
1

4-20:

BD139,
.

Stand-by Mode

,
. SW1. O
SW2 FF,
.
E SW1, stand-by mode.
, , ,
(loop).
,
"1" RB1, LED "stand-by
mode". A SW2 ( ),
,
. .

45

stand-by
. 30
.

ON mode
, stand-by
SW2.
, interrupt, .
.
interrupt stand-by, 6 "low"
, "1" RB2.
"" -
high ( ). :

17 (PortA,0)
. "0", PORTB,6 PORTB,7 ( 12
& 13 ) "low".
LED
,
(
).
, pin 17 "high",
,
alarm ( 4-21).
alarm
, ,
delay,
,
nop,
.
,
, high

4-21:
alarm

. , ,
60 .
46

,
alarm.
,
18,
.


. 1 pin 18.
, LED
(pin 11) (pin 13).
, LED
11, alarm.
.
, PIR,
1. "1" (PORTA,2),
LED ( 10) PIR,
alarm.
"0" , PIR,
(pin 13).
,
. ,
mode.

, ,
interrupt,
SW2.
interrupt.
SW2 . ,
stand-by .
SW2 , ,
interrupt . ,
, interrupt ,
stand-by.
A ( 4-22)
47

4-22:

48

4-23: , ()
()

4-24: , () ()

4-25: PIR (), ()


49

4-26: breadboard

4-28: PIC16F628A

4-27: :

4-29: OFF

4-30: stand-by

50

4-31:

4-32:

4-33: ,

stand-by

stand-by

51

4-34:

4-35:

4-36: .

52

4-37: ,

4-38: PIR

4-39: ,

53

4-40:
PIR

4-41:

54

,

. , ,
(PIR,IR Beam ). ,
.


,

, (keypad) /
.

,
.
, ,
, ,
. ,
.

,
.

, ,
,
, .
55

, ,



.

.

56

Assembly
;************************************************************
; Processor: PIC16F628A at 4 MHz using internal RC oscillator

;************************************************************

LIST P=16F628A, R=DEC ; Use the PIC16F628 and decimal system

#include "P16F628A.INC" ; Include header file

__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF &


_PWRTE_ON & _BODEN_ON

CBLOCK 0x20

; Declare variable addresses starting at 0x20

Loop1,Loop2,Loop3
ENDC
;
; ----------; INITIALIZE
; ----------;
ORG 0x00

; Program starts at 0x000

goto Init
ORG 0x0004
Call Intrpt
retfie

Init CLRF PORTA


CLRF PORTB

BSF STATUS,RP0

; Initialize port A
; Initialize port B

; RAM bank 1

57

movlw 0xFF
movwf PORTA ;all inputs

movlw 0x01 ; all outputs except B0


movwf PORTB
BCF STATUS,RP0

; RAM bank 0

;
; -----------------------; FUNCTION OF PORT A PINS
; -----------------------;
MOVLW

MOVWF CMCON

; Comparators off, all pins digital I/O

;
BSF 0x0B,4
BSF 0x0B,7

Infinite

bsf PORTB,1
goto Infinite

;****************************************************************
;* Main
;****************************************************************

Intrpt

Start

First

bcf

PORTB,1

bsf

PORTB,2

btfss PORTA,0
goto

First

bsf

PORTB,6

call

alarm

goto

Second

bcf

PORTB,7
58

bcf

PORTB,6

goto

Second

Second

Third

btfss PORTA,1
goto

Third

bsf

PORTB,5

call

alarm

goto

Fourth

bcf

PORTB,7

bcf

PORTB,5

goto

Fourth

Fourth

Fifth

alarm

btfss PORTA,2
goto

Fifth

bsf

PORTB,4

call

alarm

goto

Check

bcf

PORTB,7

bcf

PORTB,4

goto

Check

bsf

PORTB,7

call

delay

return
return

Check

BCF 0x0B,1
btfss PORTB,0
goto

Init

goto

Intrpt

;
59

; --------------; DELAY 250 MSEC


; --------------;
delay MOVLW 255
MOVWF Loop1
Outer MOVLW 255
MOVWF Loop2
InOut MOVLW

200

MOVWF

Loop3

Inner NOP
NOP
DECFSZ Loop3,F
GOTO

Inner

; Inner loop = 5 usec.

DECFSZ Loop2,F
GOTO

InOut
DECFSZ Loop1,F

GOTO

Outer

RETURN

END

60


,
()
.
Microchip PIC16F628 .
. ,
(PIR) ( ).
,
,
,
.

Summary
The purpose of this project is the research, analysis and the installation of a security system
(alarm) in a private parking lot that will detect possible intrusions and inform the owner. The
system uses Microchips PIC16F628A microcontroller as the central process unit. It also
consists of three detectors as inputs. magnetic reed switch, a passive infrared motion
detector and an infrared barrier beam (transmitter and receiver). The microcontroller analyses
the electrical signals that the detectors produce, when motion or invasion is detected at its
input pins and gives an output signal. Each time the system gives an output, a flash-light
alarm and a siren that are connected at the microcontrollers output become active, and also,
an indicator that allows us to know which detector is activated at the moment.

61

Security Electronics-Circuits Manual, RM MARSTON

Electronic Protection&SecuritySystems, Gerard Honey

Security Manager -

Designing Embedded Systems with PIC Microcontrollers, Tim Wilmshurst

123 PIC MCU Experiments for the Evil Genius, Myke Predko

http://www.microchip.com

http://feelingsafe.net/

http://www.karakostas.gr/sf/sec/index-2.html

http://www.armaos.gr

http://jap.hu/electronic/

http://www.etoxtr.com/el/home/289.html

http://www.hellascams.gr/grc/wi_fi_calculators/knowledge_base/Passive_Infrare
d_Dedector.html

http://uk.geocities.com/ronj_1217/door.html

http://www.securitymagazine.com/

http://www.wikipedia.org

http://www.hobby-elec.org/e_pic.htm

http://www.talkingelectronics.com/

http://ftp.hlektronika.gr/

http://electronicsworld.tripod.com/

http://www.electronics-lab.com/projects/index.html

http://www.cyberpcb.com

http://www.winpicprog.co.uk/

http://www.rentron.com/PIC16F628.htm

http://www.oshonsoft.com/pic.html

62

http://www.datasheetcatalog.com/

http://www.kitsrus.com/

http://www.zen22142.zen.co.uk/

http://pic-in-greek.freewebpages.org/

http://stuff.nekhbet.ro/2006/06/18/how-to-build-a-5v-regulator-using-78l057805.html

63

You might also like