You are on page 1of 110

87

.
.

.
.
. .

.

.
.

.



JFOTUHI@GMAIL.COM

MHOOMAN@GMAIL.COM

- - - www.RoboCenter.ir

87

4 ........................................................................................................................................................
6 ....................................................................................................
13 .......................................................................................................................
32 ...................................................................................................................
85 ..........................................................................................................

- - - www.RoboCenter.ir

87

... AC 220

...

) (...

...

...

...


:
.1
.2
.3
.4
.5
:

.
:

.
:

.

- - - www.RoboCenter.ir

87

:
.
:
...
.
:
. )
( ... .
.
.
.
.

:
-1
-2
-3

- - - www.RoboCenter.ir

87



.
.
:

.
.

.
2050 .

.

.
IranOpen
. IranOpen

6 .
.
:
.1

HumanOid

.2

Small Size

.3

Middle Size

.4

Rescue Real

.5

@Home

.6

Demo

.7

Deminer

.8 1 1

Junior Soccer 1 on 1

.9 2 Junior Soccer 1 on 1 2
.10
.11

- - - www.RoboCenter.ir

87

. 1 Line Follower , Path Finder , Tracer



.
:
. 1.8 .
.

.

110

20cm

- - - www.RoboCenter.ir

87

:

. 50HZ 2.5mm
. .
.
25cm
180 .

- - - www.RoboCenter.ir

87

:

. . 50
5 . 3 .

200-160 . 100-80
60-40 100-80
. .

30 50
.

- - - www.RoboCenter.ir

87

:
6 7 .
3*3 5*5 ,
50 .
50 .
50
.
.
.
2mm 15mm .

.
.

:
15-5
. 20 30
. .
6 8 35
75 75 . 15
.

- - - www.RoboCenter.ir

10

87

:

.
5 1.6 .
16*16 18*18 .
.
10
. 10
.
.

- - - www.RoboCenter.ir

11

87

:

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

.

- - - www.RoboCenter.ir

12

87



.
, , , .. .
.
.
)(:
,
. , , ...

.
.
:
.
.
.
.
:
.
.
:

24 12 6 ... .
.
.
) (Plexiglass .
.
.
5 .

. )(Implex
. .
.

- - - www.RoboCenter.ir

13

87

"
" . " " Lexan .
.
.
.
.

.

.
.
.
.
.

:
.
-
.
. .
.
.
:
. .
. .

- - - www.RoboCenter.ir

14

87

:
. ..
. , ) (SMA .. .
.
.
. .
.
.
)( . )( :
. ) (
.

.
.

.
DC AC ...

.
DC .
) (
.
W=f.d .
.
.
:
-

-9

-2

-10

-3

-11 )

-4

-5

-12 ) (

-6 ) (

-13

-7

-14

-8

-15 )(RPM

- - - www.RoboCenter.ir

15

87



DC
.
.

DC


2/5

.
.

DC



)(PWM

- - - www.RoboCenter.ir

16

87

: DC
DC .
.
DC .
. DC
90 .
40 70 . .
.
: DC
DC .
.
.
) (
.
. .
) (
. )
( .
. .
.

- - - www.RoboCenter.ir

17

87

.
.

. ) (
.
DC
DC 8000 20000RPM .
.
.
:
.
RPM .
.

. .
1 10000 RPM 4
2500 RPM 4 .
. .
.
.
.
.
.
. .
RPM
.

- - - www.RoboCenter.ir

18

87


.
.
. .
.
Airtronics Futaba Hitec .

DC ) 180:1
( .
.
. 60 .
90 . ) (

.

- - - www.RoboCenter.ir

19

87

DC
.
) (PPM .
. PWM .
PWM PPM .
) 2 ( .
PPM .


) - - (.
40

0.21
40 60

- ) 2.5 (

0.21 . 0.11-0.21 .
17 200 .
.

.

.
. 4/8 6 .
6 .
.
.

.

- - - www.RoboCenter.ir

20

87


.
Brushless .
.
. .
.

.

. 50-100RPM

.
DC .


.
.

.

. .

. ) A,B,C,D (.

.
.
.
. .
: ) (
) (
.
.
.
.

- - - www.RoboCenter.ir

21

87


. .
.

.
.
) (
.
) (
. H-bridge
.
.
.

- - - www.RoboCenter.ir

22

87

) (
.
) ( .

. ) (
.
. .
) (
) ( .
:
. 6
) . (
. 5
.

3/6 .
.
30 0/9 .
.
:
.


.
.
:
:
. .
)
( .
:
.
. .
) 6( .

- - - www.RoboCenter.ir

23

87

6 6
. 5 7805 6 .
:

.
.
: .
. )
( .
.
.
:
.
.
.
:
. )( ) (
.
.
: .
.
. 12 24
. .
.
.
: .
.

.

- - - www.RoboCenter.ir

24

87


) ( .
.
.
. .
1 ) 2/54 ( 100 - ) 7200- (
2) 5 ( 50 - ) 3600- (
. .
.
) (RPM .
. .
:
)(6-3

D = d

D ) (d .
D RPM) ( .
/ / .
.

- - - www.RoboCenter.ir

25

87

:
5 :

... . 5
2 . 4
8 .
.
10 :
.
10 4 .
4 8

.

) (
. ) (
.

.



:


3

.


.

.

- - - www.RoboCenter.ir

26

87

4 :


. .
.
.
:

:
.
.
.

.
:


,Dubro . .
Dubro
. Dave Brown
.

- - - www.RoboCenter.ir

27

87

:
.
3 .
.


. .
.
. .

.
.
.
... .

:
-1

,
.
-2 : ,
.
-3 :
.

- - - www.RoboCenter.ir

28

87

- - - www.RoboCenter.ir

29

- - - www.RoboCenter.ir

87

30

- - - www.RoboCenter.ir

87

31

87

.
, ,
, .

.
:
.

. .
.

.
.
.
.
.
) (A . ) 61018 (
1 ) (1A . .
:
) (DC
.
.
) (AC .
) (+
) (-
.
:

) ( F
) (HZ .
50Hz .

- - - www.RoboCenter.ir

32

87

:
V
. .
) (
.
:
.
) (SI . R
.
V=RI
OR
R=V/I
V I
. :

:

.
2

P = I R :
) ( ) .
(.
:
. 1 :

.
. :

A 10 B C %

) 5 6 ( A .
) 5 6 ( B . )
5 6 ( ) ( C .
.
. 2 :
3

. (1) R K ) (10
M ) (106 . .
J=5% K=10% M=20% .
5K6K 5.6K10% .

- - - www.RoboCenter.ir

33

- - - www.RoboCenter.ir

87

34

87

.
. E24
:
)E24 Standard Series Values (5%
)1.0M(1M0
)1.1M(1M1
)1.2M(1M2
)1.3M(1M3
)1.5M(1M5
)1.6M(1M6
)1.8M(1M8
)2.0M(2M0
)2.2M(2M2
)2.4M(2M4
)2.7M(2M7
)3.0M(3M0
)3.3M(3M3
)3.6M(3M6
)3.9M(3M9
)4.3M(4M0
)4.7M(4M7
)5.1M(5M1
)5.6M(5M6
)6.2M(6M2
)6.8M(6M8
)7.5M(7M5
)8.2M(8M2
)9.1M(9M1

10M
11M
12M
13M
15M
16M
18M
20M
22M

100K
110K
120K
130K
150K
160K
180K
200K
220K
240K
270K
300K
330K
360K
390K
430K
470K
510K
560K
620K
680K
750K
820K
910K

10K
11K
12K
13K
15K
16K
18K
20K
22K
24K
27K
30K
33K
36K
39K
43K
47K
51K
56K
62K
68K
75K
82K
91K

)(1K0
)(1K1
)(1K2
)(1K3
)(1K5
)(1K6
)(1K8
)(2K0
)(2K2
)(2K4
)(2K7
)(3K0
)(3K3
)(3K6
)(3K9
)(4K3
)(4K7
)(5K1
)(5K6
)(6K2
)(6K8
)(7K5
)(8K2
)(9K1

1.0K
1.1K
1.2K
1.3K
1.5K
1.6K
1.8K
2.0K
2.2K
2.4K
2.7K
3.0K
3.3K
3.6K
3.9K
4.3K
4.7K
5.1K
5.6K
6.2K
6.8K
7.5K
8.2K
9.1K

100
110
120
130
150
160
180
200
220
240
270
300
330
360
390
430
470
510
560
620
680
750
820
910

1.0
1.1
1.2
1.3
1.5
1.6
1.8
2.0
2.2
2.4
2.7
3.0
3.3
3.6
3.9
4.3
4.7
5.1
5.6
6.2
6.8
7.5
8.2
9.1

10
11
12
13
15
16
18
20
22
24
27
30
33
36
39
43
47
51
56
62
68
75
82
91

.
A B
C .
. .
2W .
) ( 2W
.
Multiturn .
.
. .

- - - www.RoboCenter.ir

35

87


. .
.
RS=R1+R2+R3
RS=3K+10 K+5 K
RS=18 K

.
:
1/RP=1/R1+1/R2+1/R3
1/RP=1/10+1/2+1/1
1/RP=16/10
RP=10/16


.
.
5
.

- - - www.RoboCenter.ir

36

87

:
.
. C Capacitor
.

:

) (
.
)
(
.
. 1 7.
7 .

- - - www.RoboCenter.ir

37

87

) (

) ( .
.
.
)(C


.
C = k0A/d
= C
= Q
= V
= 0 8.85 10 -12 :
) K ( = . K 1 .
= A m2
= D m
1 .
. F nF pF .
means 10 6 (millionth), so 1000000F = 1F
n means 10 9 (thousand-millionth), so 1000nF = 1F
p means 10 12 (million-millionth), so 1000pF = 1nF

- - - www.RoboCenter.ir

38

87

) (q
)(V q/v .

.
.

) (K .

.
) (+ ) (- .
.
.
.
. .
.

. .

. .
.
.

- - - www.RoboCenter.ir

39

87

.
. .
:

V = V1 = V2 = V3
C = C1 + C2 + C3


. .
.


:
V = V1 = V2 = V3

1
1
1
1
=
+
+
C C1 C 2 C 3

- - - www.RoboCenter.ir

40

87



.
.
. .
AC DC .
.
.
:

)(



:

.
. .

.

. ) (
) (Film .
.

. .

:
.
.
. )(
.
10 400 5 30 .
.

- - - www.RoboCenter.ir

41

87


. 100 500
.

.
1 100 .

- - - www.RoboCenter.ir

42

87

) (Ceramic capacitor
.

. 5 0/1 .
)( 100 .
.
.


. :


.
.

.

- - - www.RoboCenter.ir

43

87

.
)( .
.

.
)(
. .

) (
.
0.01 1 .
.

.
. .

.
. .
.
.

- - - www.RoboCenter.ir

44

87

.
"" .

.

.
.


( 3(
.
:
.1
.2
.3
:
.1 .
.2 .
.3 .
.4 ) 330 (

- - - www.RoboCenter.ir

45

87

.
) ( . -
- 10000 10 .
.
.
0 9 :

. 22 47
25 117 .

- - - www.RoboCenter.ir

46

87

)(:
.
.
:
.
DC AC . 240V AC
1.5A DC 20V 3A .
.


DC
AC AC .

- - - www.RoboCenter.ir

47

87

SPST

Single Pole, Single Throw = SPST



. .

.
SPST toggle switch
N.O


.
.

Normal Open Push Button

N.C

Normal Close Push Button

SPDT

Single Pole, Double Throw = SPDT



.
.
SPDT toggle switch

SPDT slide switch


)(PCB mounting

SPDT rocker switch

- - - www.RoboCenter.ir

48

87

DPST

Double Pole, Single Throw = DPST



.
.
DPST rocker switch
DPDT

Double Pole, Double Throw = DPDT


SPDT
.

DC .

DPDT slide switch

Wiring for Reversing


Switch
:

SPST .
.


SPDT


.
SPST .

- - - www.RoboCenter.ir

49

87

REED SWITCH



.


.

.

)DIP Switch (DIP = Dual In-line Parallel


SPST
.


. 4
.
Multi-way rotary switch

1-pole 4-way switch symbol

- - - www.RoboCenter.ir

50

87

:
P N .

.
p & n
.

.
0.2
0.6 .
.
p n
.

.
:

p n
.
:

n p
.


) + - ( .
) (forward voltage drop
06 07 . ) + - (

- - - www.RoboCenter.ir

51

87

A
.
.


.
.

)(Rectifiers

) (Zener . + -
.



LED
) (

.
.
.

- - - www.RoboCenter.ir

52

87

P & N .

.

: .
.
. )
(. E12
E24 ) 2.7 86 (
:
: Bzy88 500 ) 25 ( .
2.7 15 . 25
25 (.
: Bzx85 1.3) 25 ( .
2.7 6.8 .
: Bzx61 1.3 ) 25 ( .
7.5 72 .
: Bzy93 20 74
9.1 75 .
: n5333 5 . 3.3 24
.
: LED

P & N
.

.
.
.

- - - www.RoboCenter.ir

53

87

) (

1.7 3.3

10 150

) ( :
P & N .
.
:

P & N . P & N

.
.

- - - www.RoboCenter.ir

54

87

) (Transformer
. )
( ,

.
VS VP
:

,
.
:

, )(

,
.

.
.
) ( .

.

- - - www.RoboCenter.ir

55

87



.

:
Pincoming = IPVP = Poutgoing = ISVS
:

.

.

- - - www.RoboCenter.ir

56

87

:
.
DC .
.
.
DC AC
. DC
5A . DC
.
) 5 ( . 5
5 .
220 AC . 220
.
.
.
) . 24 (

AC
. AC DC .
AC DC
.
3 :
. 1 :
AC
.
.

- - - www.RoboCenter.ir

57

87

) (470uF 1000uF


.
.

.

:

.
.

.
D1 D3
) D3 ( . D2 D4
) D4 ( .

.
.
. .

- - - www.RoboCenter.ir

58

87

DC

.
2 1.4V
.
.
DC .
) 5 ( .
) ( . ) (
. DC
.
.
.
:
) (78XX ) (79XX
. .
7805 5 . 3
. 1 .
15
.
.
Output Regulator Output
5
7905
-5
6
7906
-6
8
7908
-8
9
7909
-9
12
7912
-12
15
7915
-15
18
7918
-18
24
7924
-24

Regulator
7805
7806
7808
7809
7812
7815
7818
7824

- - - www.RoboCenter.ir

59

87

:
.
LM317 . 1.25v ) 37V ( .
LM317 1 .

LM317 .
)V out = V Ref (1 + R2/R1
V Ref = 1.25 V

PNP .
) ( TIP2955 5A
.

- - - www.RoboCenter.ir

60

87

5 1

1
2

5V out

1
2

Variable Voltage

DS2

R6
220

DS3

R4
220
3

C4
0.1uF

R3
220

OUT
GND

IN

U1

LM7805

10k

R5

OUT
ADJ

LM317T

IN

PNP TIP2955

C3
10uf
D2

C2

Diode 1N4001

10

330uf
C1
2000uf
DS1

R1
220
D1

1
2

V-

V+

AC

AC

3
4

2
1
V in

- - - www.RoboCenter.ir

61

87

:
.
. .
.

.
.
.
.

.
.

.
.
P N . P N .
. P
N . PNP .
NPN . .


. ) ( Base ( Collector )
) ( Emitter .
Collector Emitter .
Collector Emitter
.
.

- - - www.RoboCenter.ir

62

87

NPN
PNP
. NPN .
npn ) PNP
( :
.1
.2 mV 700 .
100
200 . .
.

.
.

E C E B .
.
.
BE ) Bias
( PN )
0.6 0.7 ( E

- - - www.RoboCenter.ir

63

87

C . E C
BE
E C .
IB IC
. .
:

10
) (HFE 120
:

120 120 .
10
.
.
. IC .
IC 25 5
25 500 .
. IC
)
(
. IC 5

. R1
.
) ( R1 .

.

- - - www.RoboCenter.ir

64

87

3 .

) (

.
.
.
.
.


... .

:

.
.
1000 .
.

. .
) ( .
. ) (
PNP ) (
NPN . -
.

- - - www.RoboCenter.ir

65

87

.
.1

CE

.2

CE

.3

.4

.5

.
BC

.
EC

.

.

HFE


IC

40-250
40-250
40-250
10-50
15-75

1.5A
1.5A
1.5A
3A
6A

40-250
40-250
40-250
10-50
15-75

1.5A
1.5A
1.5A
3A
6A


V CE

45V
60V
80V
40V
40V

BD135
BD137
BD139
TIP31
TIP41

NPN

PNP
45V
60V
80V
40V
40V

BD136
BD138
BD140
TIP32
TIP42

DARLINGTON NPN
750
500
1000
1000

6A
1.25A
3A
5A

60/80/100V
60/80/100V
60/80/100V
60/80/100V

BD331/333/335
TIP110/111/112
TIP120/121/122
TIP140/141/142

DARLINGTON PNP
750
500
1000
1000

6A
1.25A
3A
5A

60/80/100V
60/80/100V
60/80/100V
60/80/100V

BD336/338/340
TIP115/116/117
TIP125/126/127
TIP145/146/147

- - - www.RoboCenter.ir

66

87

:
) (relay
.
N.O N.C COM . N.C COM .

COM N.C N.O .
:


.
.

6 5
12 18 . N.C-N.O COM 220
.

.
.

.
.
. .

- - - www.RoboCenter.ir

67

87

:
.
500 .
.

. .
.
. DC
.
3 DC :

FORWARD

BACKWARD

STOP

DC :
. 1 :
DC DC
. STOP
) FORWARD ( BACKWARD .

.
. .
SPST .... .

- - - www.RoboCenter.ir

68

87

:
. DC :

.
.

) . ( HFE
R1 .
R1
.
AVR
20mA .
:
I B = 20mA
VBE = 0.7v
4.3v
= 215
0.02 A

= 5 + I B RB + VBE = 0 RB MIN
RB MIN = 215 220


220 330 1 .
.
. DC :

- - - www.RoboCenter.ir

69

87

. DC :

DC .

. .
ULN2003A ULN2803 .
7 8 .
500mA .
.
: 1 ) ( Sink .

) ( Source .
: 2 ULN2003A TTL
ULN2803 CMOS .

. 2 :

DC
.
( H Bridge ) H . H .

- - - www.RoboCenter.ir

70

87

. H :

. 4 NPN 4
. Q1 Q3
. Q2 Q4 .

DC ) (
.
.
.
) (
. ) ( 20 ) (
) ( . ) (
CEMF
CEMF .
.
.
CEMF .
CEMF . .
CEMF .
CEMF . 0.6
. )( .
.

- - - www.RoboCenter.ir

71

87

.
" " " "
. PWM CEMF
. CEMF
. V+ .
. " "
. ) (
) H ( .
) ( ) V+ (
. 0.1uF 0.22uF .
.
VS .
.
. H
.
H .

: ) Q3 ( Q4
VS

.

- - - www.RoboCenter.ir

72

87

H :
:

.
.
: NOT

H NOT
.
.
.

NPN PNP
.
.
NPN PNP
. PNP . PNP
. 1N5817 .
.

- - - www.RoboCenter.ir

73

87

. H :

H SPDT . :
.1 .
.2 H .
.3 2 . H
.

. H

H
. L293D L298N
:

- - - www.RoboCenter.ir

74

87

: L293

H DC
1.2A . 1.2

. . Vss
7 VS
36 .
.
H 2 2 .

- - - www.RoboCenter.ir

75

87

: L298

L298 L293
L298 H 2 3 .
Vss 7 VS 50 . H
2 2 .

- - - www.RoboCenter.ir

76

87

L298 L293 :
L298 .1 .
.2 Current Sensing .
.
.
0.1
0.5 10W .
.
.

- - - www.RoboCenter.ir

77

87

:

. .

.
. .
. 1 :

. 3 .
. 1 . )(LDR

. .
.
.
:

R2
VCC
R1 + R2

= Vout

LDR 20k
100 . 1k
LDR :
1K
5 = 0.23V 0V
20 K + 1K
:

= Vout

1K
5 = 4.54V 5V
100 + 1K

= Vout

- - - www.RoboCenter.ir

78

87

. 1 . :

.
.
LED
.
.
) ( .
8 )
( . .
.
LED .

.1 : .2
:


. .

.
.
.
.

.


3.3V .

- - - www.RoboCenter.ir

79

87

0.2V .


.
.

) ( Base
. .


) ( .
.
.

- - - www.RoboCenter.ir

80

87

:
: GP2S04


. )
600 1000 ) . ((87
4 2 2 220
470 VCC .
0.2 0.7
3.3 3.4 .
4-6mm .

- - - www.RoboCenter.ir

81

87

: CNY70

CNY70
. .
.

.
.

.
10-22K .

ON2179 TCR5000 TCR1000


.

- - - www.RoboCenter.ir

82

87


.
.
.
.

. 3
3.5 0.5 1 .
.
.
.
.


.

.
.

.
noninverting inverting .
Op-Amp .
. .
Vss . .

- - - www.RoboCenter.ir

83

87

Comparator


V+ V- .

. V ref
..

. .

- - - www.RoboCenter.ir

84

87

:

-
:

Cpu
Alu
I /O
Ram
Rom
Timer ...
:
: Pic - AVR - 8051
.
Assemblybasic, c
programmer

Rom .
.


.
:

.
:
c basic
programmer
.
.

- - - www.RoboCenter.ir

85

87

8051

. keil franklin
pic AVR
89S51 89C52 .

: AVR
8051 ) ADC
( ( EEPROM(
Tiny Mega.

: pic
AVR .
:
.
.

.

.
:
.


:
-1-2
: 10 6 .
....
..
: " "
.




.

- - - www.RoboCenter.ir

86

87

.
:


lcd .

lcd .



lcd .
.
:
cpu
.
cpu cpu
cpu
. cpu



.
:





.

- - - www.RoboCenter.ir

87

87


....

.
:
. !


10 9

.

6 :
8051
Pic
Avr
6811
Z8
Arm
6811 z8
.
6 .
6
. 6
). ( .
6 .

. avr atmega8
avr
.
6
. avr 8051
pic .
.

- - - www.RoboCenter.ir

88

87

.
.
.

6811 z8 .
8051 .
intel . intel
ATMEL , PHILIPS ,
SIEMENS , DALLAS ...
ATMEL
.
8051

AT89S5X 8051 ATMEL
8051 . AVR PIC .
8051 ) ) 0.001 AVR
4 PIC 12 AVR .
.
.
AT89S5X 1000 .
C

. AVR PIC
.
PIC

AVR .
PIC .
PIC16XXX PIC12XXXX X C ,X,E,F
AVR
X .
AVR

- - - www.RoboCenter.ir

89

87

AVR

8051 12 PIC
4 AVR . AVR
(HIGH LEVEL LANGUAGE) HLL
8051 PIC
.
(ADC) , ... . AVR
SPI,UART,12C,JTAG

.
AVR 3 4 .



.

. .


,AVBR , PIC , 8051 .

..
AVR
AVR .
C Assembly
. AVR
AVR
16 8 .
: AVR
MCU ( ! (MCU: Master Control Unit

) CPU (

- - - www.RoboCenter.ir

90

87


JTAG IEEE 1149.1
)(IEEE: Institute of Electrical and Electronics Engineers


Upgrade
AVR )(

.
AVR ) RISC (
32 .
Flash AVR .
AVR 2.7 5.5
Program
AVR 1.8 5.5 (Low
(Power .
AVR :
AVR
. AVR


.
: AVR
: Tiny AVR
4 128
). SRAM EEPROM(.
... tiny .
MCU

EEPROM .
: Tiny

.
.
: Mega AVR

- - - www.RoboCenter.ir

91

87


K 256 K 4 .

AVR Mega

.
: Mega
( (Boot Block
-8 10
USART SPI TWI
JTAG IEEE 1149.1
TWI: Two Wire Interface is a byte oriented interface
USART: Universal Serial Asynchronous Receiver/Transmitter
SPI: Serial Peripheral Interface
JTAG available only on devices with 16KB Flash and up
JTAG 16 .
: LCD AVR
LCD
. .
:

AVR
.
1.8 .
Standby
!
AVR :
LCD

. 100 UART SPI
.
: LCD

: LCD

.

- - - www.RoboCenter.ir

92

87

:

128
( (Boot Block




:
: Parallel

)(programmers
:
TWI SPI

ISP:


: JTAG
IEEE 1149.1 NVM
. .

ATMEL AVR Studio 4 :
ATMEL
http://www.atmel.com .
AVR .
.
C Assembly .

AVR 8 100
. ATMEGA32

ATMEGA32

- - - www.RoboCenter.ir

93

87

ATMEGA32 PDIP 40 TQFP 44 MLF 44


PDIP .
ATMRGA32 8 ) 1 (
. PORTA ADC
) (
.
V 4.5 V 5.5 .
MHz 16 MHz 8
. .
CPU .

9
.
13 , 12 .
: ATMGA32
)
( ROM .
ATMEGA32 KB ( 32 32 ( .
RAM KB 2 .
RAM
. ATMEGA32
. EEPROM
KB 1 100,000 .

- - - www.RoboCenter.ir

94

- - - www.RoboCenter.ir

87

95

87

Codevision

. .
c c
.
CodeVision AVR C
.
:
C . #include
.
>#include <mega32.h
ATMega32
>#include <delay.h
)( delay_ms )( delay_us .
:
.
:
bit
1 0 1 .
char
) ( 8 -128 127.
unsigned char
) ( 8
0 255.
int
) ( 16 -32768 32767.
:
>#include <mega32.h
;int x,y=69
;unsigned char a
.
.
.
;x=0xf2
;a=0b10100110
.

- - - www.RoboCenter.ir

96

87

x y 16 y , 69 10
x . f0 16 .
a 10100110 2 .
:
& AND . :
;x=0b10101010&0b01010101
AND x 0b00000000 .
| OR . OR.
^ XOR .
:
&& AND || OR
.
: if-else
if if
. else else .
) )if ( (x>4) && (y<7
;statement1
else
;ststement2
if x 4 y 7 ).
(
)(: while
)while (expression
{
;Statement1
.
.
}
while , while .
)(for
)for (i=0 ; i<10 ; i++
{
.
.
}

- - - www.RoboCenter.ir

97

87

10 for ) 0 (9
:
;DDRA=0xFF
;DDRD.3=0
0 1 . 8) A
( A 3 D .
;PORTB=0b10101111
;PORTC.0=1
. 0 3 B 1 4 , 6
0 5 1 , 7 . 0 1 C .
;x=PIND
;m=PINA.7
D x
. 7 A m .
:
C .
CodeWizard .
New .
2 Source Project . CodeWizard
Project Ok .

Yes .

- - - www.RoboCenter.ir

98

87

: CodeWizard

. Chip
mega32 .

Ports
C 3 6 .

- - - www.RoboCenter.ir

99

87

:External IRQ
:

External IRQ
4
): (
: Low Leve 0
0 .
: Failling Edge .
: Rising Edge .
: Any Change ) (
.

- - - www.RoboCenter.ir

100

87

:Timer
: )( a b
b ,
b a .
Timer 3 Watchdog .
0 .
: Clock Source
T0 B0
T0 .
d- system clock
.
: Clock Value
)
( 15.625 kHz
.
: Mode
PWM .
: Output
pwm
.
: Overfelow Interrupt

).
(
0 8 0 255
255
.
255 .
Timer Value .
d-

- - - www.RoboCenter.ir

101

87

: LCD
LCD LCD
.
LCD LCD 2x16 2 16 .
.

: LCD Port LCD


.
LCD
.
: Chars/Line LCD
). (
: LCD
;)Void lcd_clear(void
) (0,0 .
;)Void lcd_putchar(char c
c .
;)Void lcd_puts(char *str
str ,
Ram .
;)Void lcd_putsf(flash char *str
str ,
.
:
;)"Lcd_putsf("MAYBOD ROBOTIC
Void lcd_gotoxy(unsigned char x, unsigned char
;)y
x y .

- - - www.RoboCenter.ir

102

87

: ADC
:
8
0 5 5 255 0 0
0 255 .
ADC ADC .
: ADC Enabled ) A
)( Mega32(16 ADC
. ADC A I/O
.
: Use 8 bits 10 ADC
8 2
.
: Interrupt ADC
ADC .
) ADC ADC
(
: Volt Ref
) .
AVCC pin (
: Clock
.
: ADC
;)val_adc=read_adc(x
x
)( val_adc ) .(
;unsigned char val_adc0
;int val_adc1
;val_adc0=read_adc(0)>>2
;)val_adc1=read_adc(1
1 2 8 val_adc0 16 val_adc1 .
3 ADC 0 10
8 val_adc0 .
4 10 ADC 1 16 .

- - - www.RoboCenter.ir

103

87

: USART
: .
RS232 .
: Receiver
.
Rx: Interrupt
Tx
.
Reciever : Buffer
Transmitter
.
: Baud Rate
.
Baud Rate
Error ) (
: Communication Parameter
, Data Bit
Stop Bit ) (Parity.
: Mode ,
Master/Slave .
: USART
;)Char getchar(void
.
;)Void putchar(char c
c .
;)Void puts(char *s
s RAM .
;)Void putsf(char flash *s
s flash .
;)]Void printf(flash char *fmt,[arg1,arg2,
.
;)Void *gets(char *str,unsigned char len
str .
;)]Signed char scanf(char flash *fmt,[arg1addr,arg2addr,
.
File Generate, Save and Exit 3

.

- - - www.RoboCenter.ir

104

87

) while(1 .
)( main
.
Make the project Error
,

.
):( STK200+/300
Setting->Programmer Programmer )Kanda Systems
(STK200+/300
Code wizard . wizard C
Crystal Clock, Timer Setting, Port Setting,
. File->Generate, Save and
Exit .
Code Vision C ) .
Code Vision (. Make the project
AVR .
. Chip Programmer
.
:
Programmer LPT Flat JP4
. Tools->Chip Programmer Programmer
. VCC GND .
Read->Chip Signature VCC GND
Programmer . :

.
. :
Program->Erase Chip
)Program->Blank Check (optional
Program->Flash

- - - www.RoboCenter.ir

105

87

Chip Programmer BootSZ0=0 Fuse Bit(s): BootSZ1=0


Program->Fuse(s) Bit Crystal .
.
:
3
) (
LCD
LED .
Mega32 3 B
LCD 2x16 A LED C.0 L298 D
.
:

- - - www.RoboCenter.ir

106

87

:
/*****************************************************
by mohammad javad fotuhi & morteza homanfard
*****************************************************/
#include <mega32.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
bit flag=0;
int cont=0;
flash char *clean="
";
flash char *l="LEFT
<---";
flash char *r="RIGHT
--->";
flash char *f="FORWARD <-->";
flash char *s="STOP
>--<";
// Timer 2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
// Reinitialize Timer 2 value
TCNT2=0x1F;
cont++;
if(cont>20)
{
flag=~flag;
PORTC.0=flag;
cont=0;
}
}
//function forward ***************************
void forward()
{
PORTD=0b00111001;
}
//function left ***************************
void left()
{
PORTD=0b00110101;
}
//function right ***************************
void right()
{
PORTD=0b00111010;
}

107

www.RoboCenter.ir - --

87
//function right ***************************
void stop()
{
PORTD=0b00111111;
}
//****************************
void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization


// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=0
PORTC=0x00;
DDRC=0x01;
// Port D initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out
Func0=Out
// State7=T State6=T State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
PORTD=0x00;
DDRD=0x3F;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization

108

www.RoboCenter.ir - --

87
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 15.625 kHz
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x04;
TCNT2=0x1F;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x40;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

109

www.RoboCenter.ir - --

87

// LCD module initialization


lcd_init(16);
// Global enable interrupts
#asm("sei")
lcd_clear();
lcd_putsf("Mechateronic-T&Z");
while (1)
{
if(PINB.0==1)
{
left();
lcd_gotoxy(0,1);
lcd_putsf(l);
}
else if(PINB.1==1)
{
forward();
lcd_gotoxy(0,1);
lcd_putsf(f);
}
else if(PINB.2==1)
{
right();
lcd_gotoxy(0,1);
lcd_putsf(r);
}
else
{
stop();
lcd_gotoxy(0,1);
lcd_putsf(s);
}
};
}

,
.
.

110

www.RoboCenter.ir - --

You might also like