Professional Documents
Culture Documents
.
AZ-EX 2013
2
AZ-EX Technical support Committee
eldaboly_2010@yahoo.com
y_m729@yahoo.com
anas-ebrahim@hotmail.com
anas_khalil@live.com
belal.eldiwany@hotmail.com
flying_ butterfly91@yahoo.com
soma_mostafa2020@hotmail.com
3
AZ-EX Technical support Committee
Table of contents:
4
AZ-EX Technical support Committee
Table of components:
1-PIC16F877a
2- RESISTORS WITH DIFFERENT VALUES
3-LM016 (LCD DISPLAY)
4-PUSH PUTTONS
5-TRANSISTORS (BC547 OR 548 & 2N2222 &BC337 & TIP122 & TIP127)
6-DIODES (1N4007 OR 1N4001)
7-LEDS WITH DIFFERENT COLOURS
8-VARIABLE RESISTOR
9-ICS (LM35 & ULN2803 & 4514<DECODER>)
10-LDR
11-BUZZER
12-RELAYS 5V
13-KEYPAD
14-SEVEN SEGMENT
15-PIN HEADER
16-REGULATOR (7805)
17-Capacitor 10F
18-Capacitor 20pF
19-Crystal 4MHz
20-MAX232
5
AZ-EX Technical support Committee
Chapter (1)
Introduction
6
AZ-EX Technical support Committee
Microcontroller
Microprocessor
IC
) (CPU
.
3 :
1_ ALU (arithmetic & logic unit):
processing
( / )... ( XOR
. )....
2_REGISTERS:
DATA LINES
ALU
. REGISTER
CPU
3 CPU :
: oscillator _1
CPU
oscillator
) (clock
Crystal )system clock).
: Memory _2
CPU :
7
AZ-EX Technical support Committee
: RAM (read & write memory) _A
MP
.
ROM MP
firmware ROM
.
: o/p ports _3
processor interface
. outputs
: timers _4
. processor
communication interface _5
: buses _6
Example:
:
8
AZ-EX Technical support Committee
set point ram X
T>X
T<X
:
_1 ANALOG digital
ADC analog .
_2
ports USB PORT SERIAL PORT serial port
microprocessor
parallel serial interface parallel
serial .
_3
parity check 00000011
zero
000000011 one
interface parity check
ones
parity check
interface . Ethernet
Components 10 ICS
Micro Controller:
9
AZ-EX Technical support Committee
MCU
IC
SINGLE CHIP
. SOFTWARE
Minicomputer CPU RAM
ROM (
)
) (Pins
, .
:
: Microcontroller
_1 .. Microcomputer
_2
_3
10
AZ-EX Technical support Committee
: microcomputer
microcomputer .
:
microprocessor
.
Microcontroller
11
AZ-EX Technical support Committee
8 bit
register 8 register
8 byte
3/2 3/1
bits .
Types of microcontroller
.
8 bite semiconductor :
ATMEL
INTEL MICRO CHIP RENESAS
EL
8051 AVR
PIC
PIC AVR
PIC stability .
12
AZ-EX Technical support Committee
plc !!!!!!!!!!!!!!
plc hardware
power plc
power plc power
power .
controller
.
PIC microcontroller
PIC 16
I/O
1K BIT I/O
Programming
Low level language High level language
C , C++ , PASCAL ,
Assembly BASIC
.
C MICRO C
C CODE Machine language . C compiler
13
AZ-EX Technical support Committee
PIC 16 microcontrollers Datasheet
IC data sheet
www.microchip.com PIC16F87XA X . 7 6 4 3
Data sheet .
PIC16F877A 40 pin
program memory
power
nonvolatile
PIC
erasable
programmable
Rom
access programmable electrically
Rom erasable 1000
programmable E^2 P
Rom ROM
chip
chip enhanced flash
chip 100
100
100
14
AZ-EX Technical support Committee
PIC
PIC :
: memory
268
.
: 40 pin 44
pic16f877a
. pin 40
interfaces
:
:
1_ 3 timers
15
AZ-EX Technical support Committee
:
100
range .
16
AZ-EX Technical support Committee
PIC
PDIP
20 20
IC hole
TQFP
Thin quad flat package
Surface mount
PCB
4
package standard NC
17
AZ-EX Technical support Committee
. pin 44
PIC
IC notch IC _ 1
. pin1 hole notch 1 pin
18
AZ-EX Technical support Committee
2_Oscillator 20MHZ
3_Currents 25mA
_3 25mA
relay interface .
4_ Pins description.
Pin1 :
MCLR MASTER
CLEAR reset PIC
reset
active low pin
low voltage
(0v ) VCC
5v pin1
reset VCC
19
AZ-EX Technical support Committee
push button
reset power
. VCC pin 1
33 I/O PINS
Individual PIN
......... A
PINS 7 PORTS
. (1/32/11/12/31/14/13)
. PORTB
. digital (PORTD,PORTC,PORTB)
PIN32/PIN 11
PIN12 /PIN31
VSS
20
AZ-EX Technical support Committee
VDD -0.3:7.5
POWER VDD
SUPPLY 4 5.5 3V
VDD IC .
POWER SUPPLY 12 11
adaptor
12 11 0.1uf noise
supply .. 32 31
adaptor . 9v
P=V* I
21
AZ-EX Technical support Committee
.
Pin 13 /pin14
OSC1&OSC2
PIC pic oscillator built in
.
OSCILLATOR
22
AZ-EX Technical support Committee
23
AZ-EX Technical support Committee
:
RC circuit
open door
stop watch crystal crystal
.
POWER adaptor
24
AZ-EX Technical support Committee
Chapter (2)
Mikro C
25
AZ-EX Technical support Committee
C Compiler
Software requirements:
1_ PROTEUS
SIMULATION
2_ MICROC
. PIC CODE
3_burner program
HARDWARE REQUIREMENTS:
1_COMPUTER
2_PROGRAMMER
3_COMPONENTS
Such as (pic16f877a/crystal
4MHZ/ LCD 2
16/LEDS/PUSH
BUTTONS/RESISTORS
(330/10K/1K)/DC MOTOR
12V/RELAY 12V/transistor
bc547/ Pin header
/sevensegment)
4_ POWER SUPPLY
26
AZ-EX Technical support Committee
HOW TO CHOOSE MICROCONTROLLER:
: parameters
2_ ANALOG INPUT
3_MEMORY SIZE
FLASH memory
micro c compile c compiler
memory size memory
. size
4_ Internal oscillator
5_ Interfaces
such as (ADC / serial port /timer.)
6_ Price
27
AZ-EX Technical support Committee
................
28
AZ-EX Technical support Committee
:
29
AZ-EX Technical support Committee
NEXT _ 2
30
AZ-EX Technical support Committee
31
AZ-EX Technical support Committee
compile build
. hex GENERATE
project linked successfully messages
32
AZ-EX Technical support Committee
build .
compile
project . open project
copy
file . open
33
AZ-EX Technical support Committee
:
_2 MICROC
PROJECT close project
new project .
_3 f1 help
libraries .
_4 VIEW .
34
AZ-EX Technical support Committee
C language tutorial
_1 include
>#include <.
_2 define
#define PI 3.14
3.14 . pi
_3 main
MAIN FUNCTION
code main
{ )( Void main
..
Data types _4
35
AZ-EX Technical support Committee
signed system
unsigned system
unsigned 255
Variable names
3_ variable name cannot be a reserved word such as (void, main, while... for)
5_ semi Column ;
:(int)
int x=10;
: (float )
float y;
: (char)
: (string )
: comments _5
.
//one line comment
. comment
/* long comment */
comment
36
AZ-EX Technical support Committee
function call _6
function
cube
{)Void cube(int x
;Return x*x*x
function input
;) cube (3
function cube x
3 3*3*3 .
sequence :
Variable scope:
1) Local
function function .
2) Global
37
AZ-EX Technical support Committee
global
variable global
RAM local
Operators:
1) Arithmetic
q=x/y;
q=x % y;
5/2= 2, 1/2
q=1 1
x++;
x=6
y--;
y=1
38
AZ-EX Technical support Committee
;Unsigned char x
;Unsigned int y
;y=100
;x=y
16 bit 8 bit 8
;If y=256
; x=y
x=0
LCD 8
bit .
2) Relational :
q=x==y
. Z=0
39
AZ-EX Technical support Committee
3) Logic operators
Ex:
1 nonzero value
q=x&&y;
q=1;
X=00000111
Y=00011011
q=x & y;
bit binary
q=00000011=3
q=3
Ex:
X=255;
Y= ~x;
40
AZ-EX Technical support Committee
X=11111111
Y=00000000
Y=0
Ex:
X=4
Y=x<<2
2 number of shift
x=00000100
y=00010000
y=16
Y=4*2*2=16
Statements
IF FOR WHILE
If:
If (expression) {
..
41
AZ-EX Technical support Committee
If (expression) {
..
Else {
If (expression) {
..
Else if {
Else if {
Else {
42
AZ-EX Technical support Committee
curl brackets if true false else if
expression curl brackets else iftrue
false else if
curl brackets . else
Else is optional .
if }{
}{
.
For:
}..
;Unsigned char I
}.
sequence I=0
loop condition 0<10 {}
1<10 increment {}
condition loop .
{);;( For
infinite loop
43
AZ-EX Technical support Committee
infinite loop main system
.
infinite loop
While:
{ )while (exp
Do while:
{ Do
}.
)While (condition
true or false
false true do statement
: MAIN
: input
. output
: .
infinite loop :
44
AZ-EX Technical support Committee
. power
I/O ports
Data direction
0 ____________ output
1 _____________ input
: C code
TRISX=Value;
VALUE :- it has one of two values [0 , 1 ] zero for make the pin output and one for
making the pin input .The value may binary or hexadecimal or decimal
TRISX.fN = 0 or 1;
TRISB.f3 = 0;
45
AZ-EX Technical support Committee
input pin input pin default
input high impedance float
PIN OUTPUT
. 5V 0V PIN
PORTX = Value;
46
AZ-EX Technical support Committee
PIN PINS PORT 5V / 0V :
;PORTX .fN =0 or 1
INPUT :
47
AZ-EX Technical support Committee
void main( )
{
unsigned char eng ; :
TRISA = 0b00011111 ;
TRISB = 0 ; OUTPUT PORTB
PORTB = 0 ; ENG ZERO
while(1)
{ ENG PORTA INPUT
eng = PORTA ; . PORTB
portb = eng ;
}
}
48
AZ-EX Technical support Committee
C
Array size too large
Bad file name format in include directive
Case outside of switch switch case
Compound statement missing} {
Conflicting type modifiers
Could not find file 'filename'
Declaration missing;
Declaration syntax error
Suspicious pointer conversion
Declaration terminated incorrectly
Default outside of switch switch Default
Default value missing
Division by zero
do statement must have while while do
do-while statement missing( ( do-while
do-while statement missing) () do-while
do-while statement missing; ; do-while
Duplicate case
expected( (
expected) )
expected,
expected{ }
expected} {
expected< <
Expression syntax
For statement missing( ( for
For statement missing) ) for
For statement missing; ; for
Function call missing) )
function' cannot return a value'
function' must be declared with no parameters'
function' must be declared with one parameter'
function' must be declared with two parameters'
If statement missing( (
If statement missing) ( if
Misplaced else ) if
Undefined symbol
Unable to open include file ' ' ) (
Statement massing ; ;
49
AZ-EX Technical support Committee
Chapter (3)
Input & output
devices
50
AZ-EX Technical support Committee
Input & output devices:
A) Push buttons
: push button
51
AZ-EX Technical support Committee
):(active low switch
VCC
low high pin
. reset
2) Limit switch
switch
switch
switch .
Push button
3) Proximity switch
sensor
.
metal
52
AZ-EX Technical support Committee
) Second type (capacitive
metal& nonmetal
high 24v DC
low 0V
5 24 24 clamping
:
sensor 24v
D1 is on
D2 is off 5 pin
S.C VCC PIN
19=5-24 .
D2
clamping
24 5
R= (24-5)/1mA=19K
P = I^2R = (1mA)^2*19K=19mW
53
AZ-EX Technical support Committee
4) Photocell
object sensor
reflector high
object low
SENSOR .
photocell proximity
object sensor
proximity
proximity
dust reflector
sensor high
reflector.
5) PIR sensor
PIR
sensor 5
.
54
AZ-EX Technical support Committee
PIR
. sensor
Input devices
Active
Dry contact
_ Switch _ Photocell
Output<=5v
(Low=o, high=5)
_PIR
55
AZ-EX Technical support Committee
Digital Output devices
1) Led:
R= (5-1.2)/25mA=152
152 pin
pin
220
device interface
device 220v 0v / 5v
interface 5v 220v
device 5v interface
0v 220v 5v . 220 v
56
AZ-EX Technical support Committee
2) Interface relay:
pin
magnetic
wave
contact
switch
relay switch closed v220 relay 30
12 6 34 22 12
relay 20 pin
NPN bc547 base
collector relay
. 1k
57
AZ-EX Technical support Committee
Chapter (4)
Projects
58
AZ-EX Technical support Committee
Small project
led .
hardware
pin1 10k VCC
. 4MHZ
: INPUT OUTPUT
: :
NEW PROJECT
59
AZ-EX Technical support Committee
60
AZ-EX Technical support Committee
}
FOR . MAIN
flashing
delay
function delay
.
simulation
.
61
AZ-EX Technical support Committee
Explain of proteus program
led pin 20mA high led
is on/ low led is off led data sheet led
voltage drop 1.2v 5
1.2 25 pin :
R= (5-1.2)/25mA=152
152 pin
pin
220
hex c
62
AZ-EX Technical support Committee
RUN .
PIC :
63
AZ-EX Technical support Committee
WINPIC
: SERIAL
PIC
_2 socket power .
_3 . winpic800
JDM :
* JDM programmer
* Com1 apply
64
AZ-EX Technical support Committee
65
AZ-EX Technical support Committee
* device detect device
unknown unknown
_ serial
_ serial kit
66
AZ-EX Technical support Committee
PROGRAM ALL
67
AZ-EX Technical support Committee
68
AZ-EX Technical support Committee
:
8 portb B0,B1,B5,B7
B2,B3,B4,B6 .
69
AZ-EX Technical support Committee
:
enter
.
8 .
70
AZ-EX Technical support Committee
.
flasher .
71
AZ-EX Technical support Committee
:
led b0 .
ACTIVE LOW
pin 0v . 5v
72
AZ-EX Technical support Committee
if == = zero
5 .
push button
push button push button
.
73
AZ-EX Technical support Committee
:
Push button
push button
74
AZ-EX Technical support Committee
:
PORTB C
push button
u sec
push button
delay user
loop check user
}{) While (RB0==0 push button
loop .
mechanical button
bounce bounce
press bounce 10m sec
delay button
bounce delay.
delay
. mechanical bouncing simulate
75
AZ-EX Technical support Committee
noisy environment noise
press noise key press noise
10m sec rb0==0 10m sec
noise press 10
high noise low press
76
AZ-EX Technical support Committee
:
IF
x=0
else x
if x=1
switch x zero if
x=0
switch x
x=1 x=1
.
77
AZ-EX Technical support Committee
:
binary ( 8 )
binary :
78
AZ-EX Technical support Committee
portb=0b00000001; portb=1; portb=0b00000000; portb=0
.
79
AZ-EX Technical support Committee
:
switch C0 B0
switch led 8
if switch
B0 switch ,
if
switch :
B0
SWITCH
B1
SWITCH ...
loop switch
;}{)While (rc0_bit==1
80
AZ-EX Technical support Committee
switch loop
81
AZ-EX Technical support Committee
if
switch
????
82
AZ-EX Technical support Committee
loop
led.
83
AZ-EX Technical support Committee
84
AZ-EX Technical support Committee
:
85
AZ-EX Technical support Committee
:
x zero switch
x x
switch x=1 if
b0 switch x 2 if
b0, b1 x=8
switch x=9 x=0 if
.
86
AZ-EX Technical support Committee
:
main
; portb=0b00000001 bo for
8 8 shift
portb=portb<<1; bit
portb port
portb 8 bit
87
AZ-EX Technical support Committee
bit 1 bit bit
shift:
00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000
<< >>
.
c0 C1
88
AZ-EX Technical support Committee
PORTB=0B00000001;
; PORTB=0B00000000
; portb=0b100000000 ;portb=0b00000000
; PORTB=0B00000001 c1
;portb=0b100000000 portb=0b100000000;
C0 ;PORTB=0B00000001
.......
89
AZ-EX Technical support Committee
portb portb=0b00000001;
if if (portb=0b10000000) if
if
;}{) while (portb.f0==1 :
90
AZ-EX Technical support Committee
; portb=0b00000001
if co c1
C1 ; portb=0b10000000 c1
c0 co ; portb=0b00000001
c1
91
AZ-EX Technical support Committee
:
portb=00000001; ; portb=00000001
portb=10000000; ; portb=0b00000001
c0
; portb=0b00000001 c1 portb=0b01000000;
.
92
AZ-EX Technical support Committee
:
93
AZ-EX Technical support Committee
Generating sound
PIC buzzer
buzzer
94
AZ-EX Technical support Committee
buzzer
95
AZ-EX Technical support Committee
:
operating buzzer
voltage=5v
Load resistance=120
12v 9v buzzer
96
AZ-EX Technical support Committee
buzzer 25 pin
15 9 buzzer 12
buzzer pin NPN
bc547 base
collector buzzer
. 1k
( )speaker/buzzer/piezo
.
97
AZ-EX Technical support Committee
98
AZ-EX Technical support Committee
99
AZ-EX Technical support Committee
100
AZ-EX Technical support Committee
DC coupling .
101
AZ-EX Technical support Committee
Tones
102
AZ-EX Technical support Committee
.
103
AZ-EX Technical support Committee
104
AZ-EX Technical support Committee
Chapter (5)
7-Segment
105
AZ-EX Technical support Committee
Seven segment
106
AZ-EX Technical support Committee
107
AZ-EX Technical support Committee
common cathode
7 segment common
7 segment 7
segment a , b,.
:
108
AZ-EX Technical support Committee
:
109
AZ-EX Technical support Committee
:
up counter
delay
110
AZ-EX Technical support Committee
111
AZ-EX Technical support Committee
x x
:
8 delay
counter
112
AZ-EX Technical support Committee
)switch (case
113
AZ-EX Technical support Committee
:
. down counter
up 10 1 up
0 10 up
function call
zero segment 1
up up 9 zero
.
114
AZ-EX Technical support Committee
.
even counter
115
AZ-EX Technical support Committee
up counter 2 up++
; up=up+2
seven segment
116
AZ-EX Technical support Committee
:
117
AZ-EX Technical support Committee
call function 9
up signed 1-
char 255
. 9
4
.
118
AZ-EX Technical support Committee
:
119
AZ-EX Technical support Committee
for 4 up=0
up*2 0 up=1 2
up=3 6 up=4 8
(UP*2)+1 UP=0 1 .
...
( )
)74LS48(
)(BCD to 7 segment Decoder
120
AZ-EX Technical support Committee
4 8..
.... b :
;portb =3
;Portb = 0b00000011
....
.. ( )7448 3
(
)a,b,c,d,g
3 ..
()7448
( )A,B,C,D
()a,b,c,d,e,f,g
121
AZ-EX Technical support Committee
122
AZ-EX Technical support Committee
7 segment
123
AZ-EX Technical support Committee
124
AZ-EX Technical support Committee
125
AZ-EX Technical support Committee
126
AZ-EX Technical support Committee
127
AZ-EX Technical support Committee
Chapter (6)
LCD
128
AZ-EX Technical support Committee
LCD
LCD
LCD
..
.
LCD ( Liquid Crystal
)Display (
)
.
.
.
..
( )
129
AZ-EX Technical support Committee
.
.
.
.
.
90
130
AZ-EX Technical support Committee
LCD
LCD :
CHARACTER LCD
Character
16 16
16 16 ,
GRAPHICAL LCD
Color LCD
Color LCD
131
AZ-EX Technical support Committee
COLOR LCD
character LCD
5*8 5*11
()5*8
132
AZ-EX Technical support Committee
16*2
16 32
32 .
..
ICs
.. (
) IC
" " A
IC .
. IC
IC
133
AZ-EX Technical support Committee
:
Lcd_Init
Lcd_Out
Lcd_Out_Cp
Lcd_Chr
Lcd_Chr_Cp
Lcd_Cmd
;)(Lcd_Init
.
Lcd_Out
.
" " ( )double quotations
Hello
;)Lcd_Out(1, 7, Hello
134
AZ-EX Technical support Committee
1 7
" " H e
Lcd_Out_Cp
Go
G O
Mohamed
;)"Lcd_Out_Cp("Mohamed
.. M
GoMohamed
Mohamed " " Mohamed
Lcd_Chr
'
' ( )single quotation
R
;)Lcd_Chr(1, 5, R
' 1 5 '
135
AZ-EX Technical support Committee
:
Lcd_Chr_Cp
' '
W
;)'Lcd_Chr_Cp('W
Lcd_Cmd
..
136
AZ-EX Technical support Committee
;)Lcd_Cmd(_LCD_CLEAR
;)Lcd_Cmd(_LCD_CURSOR_OFF
:
LCD int string LCD
string
;int temp //1
;]char temp_txt[7 //2
;)inttostring(temp,temp_txt //3
;)lcd_out(1,1,temp_txt //4
integer .temp .1
( C )string 7 .2
(temp_txt int
7 float 16
floattostr .)inttostr
temp .temp_txt .3
temp_txt LCD .4
.
LCD
7( )
:
temp
137
AZ-EX Technical support Committee
int temp, ons, tens, hun; //1
;ons=temp%10 //2
;temp=temp/10 //3
;tens=temp%10 //4
;hun=temp/10 //5
;)lcd_chr(1,1,hun+48 //6
lcd_chr_cp(tens+48); //7
;)lcd_chr_cp(ons+48 //8
7 .
138
AZ-EX Technical support Committee
:
16 pin
1 16
61
:
8 3
5 power data control
16
)P( power )D( data )C( control
139
AZ-EX Technical support Committee
P ( 1
)
P ( 5 2
)
P * 3
( )
C 4
( )high volt (])low volt
B4
C ( )low volt 5
(( )high volt )
C ] 6
B5
D ( 7 7
] )14 [
D ] [ 8
D ] [ 9
D ] [ 10
D ] B0 [ 11
D ] B1 [ 12
D ] B2 [ 13
D ] B3 [ 14
P ( 5) 15
P 16
15
16
* contrast
.
.
:
:
3 5
10 3
pin3float
.
140
AZ-EX Technical support Committee
:
7,8,9,10 4 bit mode 4 bit 4 bit
char 4 bit
8 bit mode data bus
4 bit mode pin 7,8,9,10 leave open pin 11,12,13,14. in use
( ) 4
8.
LCD_RS at RB4_bit
LCD_RS RB4 4 B
RB4 RA4
)(void main
.
141
AZ-EX Technical support Committee
lcd LM016L display
(( )).
i for loop 16
.
computer c i
1 computer computer
i=1 c computer i=2
c computer i=3
ccccccccomputer .
(( )) .
142
AZ-EX Technical support Committee
:
0 8
lcd_out_cp =
inttostr = .
(( ))
(( ))
143
AZ-EX Technical support Committee
Chapter (7)
DC Motor
144
AZ-EX Technical support Committee
.....
DC Motors
.
:
-1 .
-2 .
-3 .
-4 .
-5 .H-Bridge
-6 IC.
-7 .PWM
* : :
:
-1 .
-2.
-3 .
* : :
() ( google
145
AZ-EX Technical support Committee
).
.
:
.
)Speed=Kv*V..(1
Kv:::
V ::::: ( 5 ).
R
) (I*R
)Speed=Kv(V-I*R)..(1
Rated 12 V
Rated 120 Rpm
12 120
.
)( (Torque )
)Torque=Kt*I .(2
Kt:::
I :::
Io
.
)Torque=Kt(I-Io) .(2
.
* : :
" "Data sheet
. .
:
Speed=Kv(V-I*R)..(1
Torque=Kt(I-Io) .(2
146
AZ-EX Technical support Committee
Kv,Kt,R,Io
:
-1 : R
.
- ( )
.
- rated voltage
() .
.R
-2 Io :
- .
- Rated
.
.
.
-3 Kv :
Rated
.
+
-1 photo interrupter sensor
photo sensor
147
AZ-EX Technical support Committee
.
148
AZ-EX Technical support Committee
Vo 5 0
( )
16 16 .
16
.
:
( )Motor speed test
-4 Kt
1352
:
Kt=Kv/1352
* : :
.
.
.
149
AZ-EX Technical support Committee
( 0 )
.
:
:
Hfe(min)>(5*I)/25
I :::: mA
Ic (max)>I
.
NPN.
).RB=(V*hfe)/(5*I
* I ::: mA
V ::::: ( 5).
RB :::: .
150
AZ-EX Technical support Committee
:
-1 .
-2 .
PWM
:
-3fast recovery Diode
trr<200nsec
* : :
:One direction
PORTB.B0
:
;PORTB.B0=1
:
;PORTB.B0=0
Relay
151
AZ-EX Technical support Committee
.
:
.
bi-direction :H-Bridge
.
.
152
AZ-EX Technical support Committee
3 1
153
AZ-EX Technical support Committee
4 , 2
1 PORTB.B1 2 PORTB.B2
154
AZ-EX Technical support Committee
:
;PORTB.B1=1
;PORTB.B2=0
:
;PORTB.B1=0
;PORTB.B2=1
:
;PORTB.B1=0
;PORTB.F2=0
:
.Short
H-Bridge:
( 2 ) -
155
AZ-EX Technical support Committee
* : IC:
IC
IC . L298D L293D
: L293D :
156
AZ-EX Technical support Committee
Pin Position
ic l293d
input low0volt hi 5volt
157
AZ-EX Technical support Committee
: L298D :
l293d
pin position
158
AZ-EX Technical support Committee
:
159
AZ-EX Technical support Committee
Button RB0 RB1
F 1 0
R 0 1
STOP 0 0
: relay device
SPDT relay :
160
AZ-EX Technical support Committee
contact NO
NC ON /OFF NC . float
relay
pin NPN 12 RELAY
base
relay contact NO 12
DPDT :
161
AZ-EX Technical support Committee
contact
NC
FORWARD forward
pin
contact NO
reverse
direction on /off
162
AZ-EX Technical support Committee
:
port b 3pin RB3/RB4
RB3==0
stop
forward reverse
reverse or forward stop
163
AZ-EX Technical support Committee
:
164
AZ-EX Technical support Committee
* : :PWM
PWM dc motor
.
: hi , low
.
pic :
;portb.f0=1
;)delay_ms(500
;portb.f0=0
;)delay_ms(500
hi ,low
B0
.
( 500 )
. duty cycle
duty cycle
PWM .
duty cycle %50
2.5 . duty cycle
%25 1.25 ...
. duty cycle
: pwm
duty cycle . pic
165
AZ-EX Technical support Committee
ccp1 ccp2 .
.
pwm
pwm
pic16f628a
pic16f877a
PWM
:
.... :-
166
AZ-EX Technical support Committee
5
( )
.
duty cycle
Description
Sets PWM duty ratio. Parameter duty takes values from 0 to 255, where 0 is 0%,
127 is 50%, and 255 is 100% duty ratio. Other specific values for duty ratio can be
calculated as (Percent*255)/100.
;)PWM1_Set_Duty(172
duty cycle % 75
172/255 = 75 %
.75 ... 3.75 = 5.
;)PWM1_Start(void
167
AZ-EX Technical support Committee
:
: ccp1
:
;)(PWM1_Stop
: ( ) PWM
pic16f877a .
ccp1
ccp2
.
CCP1 ccp2
.
168
AZ-EX Technical support Committee
(
reed relay
BJT MOSFET .
pulses
169
AZ-EX Technical support Committee
:
170
AZ-EX Technical support Committee
current_duty1 duty cycle ratio 0_255
current_duty<250
current_duty>250
up
current_duty>30
current_duty<30
.
171
AZ-EX Technical support Committee
:
172
AZ-EX Technical support Committee
:
173
AZ-EX Technical support Committee
174
AZ-EX Technical support Committee
main increase duty cycle i
pin pwm I 255 for
loop led 5
. i=255
175
AZ-EX Technical support Committee
Chapter (8)
ADC
176
AZ-EX Technical support Committee
.....
Analog Digital
.
:
-1 ADC
-2 .ADC
-3 ADC.Pic16F877A
-4 MicroC .ADC
-5 .ADC
* : ( )Analog ( )Digital
..
()
..
( )
(
) ADC ( )
.
.
* : .ADC
ADC :
-1 ..
-2 ..
-3 .
-4 .ADC
177
AZ-EX Technical support Committee
ADC (
..)
:
-1 ) : (Sampling
) (Samples ... :
178
AZ-EX Technical support Committee
)..(Sampling Frequency
.
-2 ( : )Quantization
:
-3 16 ) 15 0 (
.. ) (A
13 ) (B 9 ) ( C 2 ) (D
.6
-4 .
: ADC 16
... ADC
() ADC
. ADC 16
ADC
179
AZ-EX Technical support Committee
2 ... n ... ADC 16
16
..
ADC
n=4 ADC
ADC (
).
: ( ADC )
.
* : ADC .Pic16F877A
: ADC
180
AZ-EX Technical support Committee
* : MicroC : ADC
AN 0 Digital
.
5 1023 :
1023 Quantization
5 AN 0 * 5 \
1023
volt
* : .ADC
181
AZ-EX Technical support Committee
Chapter (9)
Keypad
182
AZ-EX Technical support Committee
183
AZ-EX Technical support Committee
184
AZ-EX Technical support Committee
A/B/C/D OUTPUTS 1
A D
1 4
1 .
185
AZ-EX Technical support Committee
:
1 OUTPUTS
OUT IN IN
.
4 4 16 4*4
4*4
Keypad_Init
Keypad_Key_Press
Keypad_Key_Click
Keypad_Init
)(void main
;char keypadPort at PORTD
portd
portd port .
186
AZ-EX Technical support Committee
void main()
Keypad_Key_Press
. 16
Keypad_Key_Click
187
AZ-EX Technical support Committee
lcd
188
AZ-EX Technical support Committee
:
portd
char keypadPort at PORTD
kp
main :
initialization lcd pressed
.
:
{)while(1
;kp=0
};)(while(!kp){kp = Keypad_Key_Click
infinite loop kp 0
kp=0
kp 0 while kp
1 16 .
:
)(kp = Keypad_Key_Click
189
AZ-EX Technical support Committee
1
kp=49 1 49 case1 kp
49 break loop kp lcd
;) lcd _char (1,7,kp KP
49 1 . 1
ascii code :
kp
.
190
AZ-EX Technical support Committee
:
191
AZ-EX Technical support Committee
:
192
AZ-EX Technical support Committee
:
cnt oldstate
kp 0 cnt=1
cnt
193
AZ-EX Technical support Committee
kp old state
1 kp=old state
else
cnt 2 ......
2 kp old state if
.
cnt=255
over flow unsigned cnt=0
0 .
.......
: keypad
1 7 7 1 .
194
AZ-EX Technical support Committee
cases .
195
AZ-EX Technical support Committee
Chapter (10)
Stepper
Motor
196
AZ-EX Technical support Committee
) (Stepper motor
. 0001: 1
1000
8
1.8
:
.)1000 0100 - 0010 - 0001(:
Unipolar
Bipolar
)1001-0011-0110-1100(
197
AZ-EX Technical support Committee
: Bipolar stepper motor
.
, ,
.
. 2
.
198
AZ-EX Technical support Committee
-1 Bipolar motors
.
. .
-2 Unipolar motors
. center-tap .
.
. 1
199
AZ-EX Technical support Committee
.
.2
3 .
.
( ) .
.
200
AZ-EX Technical support Committee
( )
S , N
201
AZ-EX Technical support Committee
===================================================
-:
202
AZ-EX Technical support Committee
===================================================
90
45 90
.
203
AZ-EX Technical support Committee
( 90 )
( ) 1.8 !
http://upload.wikimedia.org/wikipedia/commons/6/67/StepperMotor.gif
204
AZ-EX Technical support Committee
6
.
-:
-1 1 .
-2 2 .
-3 4 3
90 .
-----------------------
-1 1 .
205
AZ-EX Technical support Committee
-2 2
45
.
-3 1
45
.
-4 4
45 4
2
2
45 .
206
AZ-EX Technical support Committee
void main)(
portb = 0;
trisb = 0;
trisc =11111111;
while(1)
if(portc.f0==1)
207
AZ-EX Technical support Committee
portb = 0b00000011;
delay_ms(150);
portb = 0b00000001;
delay_ms(150);
portb = 0b00001001;
delay_ms(150);
portb = 0b00001000;
delay_ms(150);
portb = 0b00001100;
delay_ms(150);
portb = 0b00000100;
delay_ms(150);
portb = 0b00000110;
delay_ms(150);
portb = 0b00000010;
delay_ms(150);
if(portc.f1==1)
portb = 0b00000011;
delay_ms(200);
portb = 0b00000110;
delay_ms(200);
portb = 0b00001100;
delay_ms(200);
208
AZ-EX Technical support Committee
;portb = 0b00001001
;)delay_ms(200
right .
lift
(
)
1
0011 1001
45
!
209
AZ-EX Technical support Committee
:
1 35
: 35
1 35
35
for loop
:
;portb=0b10001000
1
1
:
;)portb=(portb<<1)|(portb>>7
portb<<1
portb=0b0001000
portb>>7 7
portb=0b00000001
( )OR
portb=0b00010001
1 ( )
(
( >> <<
for loop
210
AZ-EX Technical support Committee
211
AZ-EX Technical support Committee
:
)stepper motor (
IC ULN2803
FREEWHEELING DIODES
pin
212
AZ-EX Technical support Committee
500 50
500
1.5 3
500
:
IC ULN2803 Not gate 1 0
0 1 ( )
.
213
AZ-EX Technical support Committee
Chapter (11)
Serial
Communication
214
AZ-EX Technical support Committee
Serial Port
2 devices
......
:
_1 serial .
low level 3 4 . 25
2 devices :
215
AZ-EX Technical support Committee
directional full-duplex
. half-duplex
Pin assignment
216
AZ-EX Technical support Committee
Synchronous and asynchronous communication
Synchronous communication:
0 9
clock
Asynchronous communication:
PIN 1
0 0 .
217
AZ-EX Technical support Committee
Serial data format
asynchronous format
: other bits
1_Start bit
2_data bits
3_parity bit
4_ Stop bits
parity bit
noise stop bit
pin .
lcd
.
1 49
49 48
.
218
AZ-EX Technical support Committee
logic high pin idle
stop high start bit low
. bit
219
AZ-EX Technical support Committee
USART
)(IC
: Bit Rate
bps .
: Baud Rate
220
AZ-EX Technical support Committee
4 1000
221
AZ-EX Technical support Committee
pin 10 T2IN
transmit pin RC6 max232 pin 9 T2OUT
receive pin RC7
222
AZ-EX Technical support Committee
PINS
.
: mikro C
9600
8bit start bit stop bit 10 bit
960=10/9600 960 9600 default
.
X UART UART
PIC16F877A UART UART1 1
. COMPILING
;)(UARTx _Data_Ready
wire start bit
.
{)While (1
}.
223
AZ-EX Technical support Committee
{)If (UARTx _ Data _Ready()==1
;)(UARTx _ Read
UARTX _ Data_ Ready .
receive char
;)( uartx_read . receive
a b
LCD . bit by bit
error :
)"UART1_ Write("aaa
224
AZ-EX Technical support Committee
text engineer
;)"UART1_Write_Text("engineer
) uart1_read_text(output,"ok",10 output
text ok ok .
;)UART1_Write_Text(output
output
engineer .
write char
read 50 .
225
AZ-EX Technical support Committee
226
AZ-EX Technical support Committee
LCD
lcd main lcd initialize
virtual terminal
hardware logic level max232
virtual instruments mode
RXD RC6 TXD
RC7 .
227
AZ-EX Technical support Committee
:
azex 2013
azex 2013
azex 2013
228
AZ-EX Technical support Committee
tool tool UART terminal
:
229
AZ-EX Technical support Committee
start
;)"UART1_Write_Text("Start
;)UART1_Write(10
;)UART1_Write(13
\n .
RS232
virtual terminal
RS232
230
AZ-EX Technical support Committee
COMPIM
RS232
:
231
AZ-EX Technical support Committee
com2 . com1
Tools>>USART Terminal
RS232
add pair
232
AZ-EX Technical support Committee
click
my computer properties device
manger :
233
AZ-EX Technical support Committee
ports :
port com1
run
run connect
234
AZ-EX Technical support Committee
:
235
AZ-EX Technical support Committee
:
user az_ex
user yes welcome azex orgnizer
. wrong enter right name
x 5 az_ex
y 5 y==5
az_ex yes .. yes
user az_ex
236
AZ-EX Technical support Committee
else wrong.
; y=0 y=5
.
237
AZ-EX Technical support Committee
,
RX TX .
transmitter 17 receive
2 baud rate
transmit receive . baud rate
serial . 9600
(( serial communication ((
238
AZ-EX Technical support Committee