You are on page 1of 238

1

AZ-EX Technical support Committee






.



.

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:

Chapter (1) Introduction ----------------------------- Page 6


Chapter (2)Mikro C ------------------------------------ Page 25
Chapter (3) Input & output devices --------------- Page 50
Chapter (4) Projects ----------------------------------- Page 58
Chapter (5) 7-Segment ------------------------------- Page 105
Chapter (6) LCD ----------------------------------------- Page 128
Chapter (7)DC motor ---------------------------------- Page 144
Chapter (8) ADC ---------------------------------------- Page 176
Chapter (9) Keypad ------------------------------------ Page 182
Chapter (10) Stepper ---------------------------------- Page 196
Chapter (11) Serial communication ---------------- Page 214

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

) 3_CU (control unit

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 (read only memory) _B

ROM MP
firmware ROM
.

: o/p ports _3

processor interface
. outputs

: timers _4

. processor

communication interface _5

: buses _6

buses micro computer

Example:
:

1_ read set point (user desired temperature)

2_ read room temperature with sensor

3_ if room temp. > Set point Turn compressor on

4_ if room temp. < Set point Turn compressor off

8
AZ-EX Technical support Committee
set point ram X

room temp. ROM T

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

_4 internal memory hard disk


. RAM

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

8 bit 16 bit 32 bit

11
AZ-EX Technical support Committee
8 bit

register 8 register

2^8 -1 =255 bit 8


bit 16 3 . Carry

8 byte
3/2 3/1
bits .

Types of microcontroller

.

8 bite semiconductor :

ATMEL
INTEL MICRO CHIP RENESAS
EL

8051 AVR


PIC

PIC AVR

temp. PIC polarity


power . AVR

PIC stability .

12
AZ-EX Technical support Committee

plc !!!!!!!!!!!!!!

plc hardware
power plc
power plc power
power .

controller
.

PIC microcontroller

Base line Mid range High end

PIC 10 PIC 12 PIC 18

PIC 16

I/O

1K BIT I/O

PIC 16F877A PIC 16

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

Rom masked FLASH


PROM EPROM E2PROM
ROM E2PROM

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 :

: clock operating speed


. 0 _20 MHZ

: memory
268
.

: 40 pin 44
pic16f877a
. pin 40

interfaces
:

:
1_ 3 timers

2_ serial port for connection with computer

3_ADC with 8 channels

15
AZ-EX Technical support Committee
:

100

VDD (positive voltage)>>>>>>>>>>>>-0.3_7.5

range .

VSS (negative voltage)>>>>>>>>>>>>>zero

sunk sourced . 25mA

16
AZ-EX Technical support Committee
PIC

PDIP

20 20

Through hole mount

IC hole

TQFP
Thin quad flat package

Surface mount
PCB

4
package standard NC

17
AZ-EX Technical support Committee
. pin 44

PIC

Specifications of microcontroller data sheet

1_How to read micro pins.

IC notch IC _ 1
. pin1 hole notch 1 pin

18
AZ-EX Technical support Committee
2_Oscillator 20MHZ

_2 counters & registers


clock clock digital signal
20MHZ pic16f877a clock pulses
20MHZ . 4MHZ & 8MHZ

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

push button reset


pin1
button float pin
noise high low VCC
VCC pin
drop zero pin 1
VCC pull up resistance float
. high

19
AZ-EX Technical support Committee
push button
reset power
. VCC pin 1

33 I/O PINS

1_PORT A 6 PINS from RA0:RA5

2_PORT B 8 PINS from RB0:RB7

3_PORT C 8 PINS from RC0:RC7

4_PORT D 8 PINS from RD0:RD7

5_PORT E 3 PINS from RE0:RE2

Individual PIN
......... A

digital (RAO) Analog (ANO) PIN


.

PINS 7 PORTS
. (1/32/11/12/31/14/13)

. PORTB

analog & digital PORTA & PORTE

. digital (PORTD,PORTC,PORTB)

out in pin programmer


. digital analog

RX RC6/TX PIN25 RC7/RX Pin26


PIN TX
SERIAL PORT SERIAL PORT
PIN PIN 26 TX/RX receive transmit
. digital out digital in 25

PIN32/PIN 11

5V +POWER SUPPLY VDD

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

power supply of computer component




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

1_NUMBER OF I/O PIN

outputs sensors SWITCHES inputs


. seven segment relay LEDS

2_ ANALOG INPUT

. analog channels analog

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
:

NEW PROJECT PROJECT _ 1

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
:

_1 messages decimal decimal


binary hex decimal

_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

1_ variable name consists of (letter, number or underscore)

2_ variable name must begin with a letter or underscore

3_ variable name cannot be a reserved word such as (void, main, while... for)

4_ c is sensitive for small or capital- -

5_ semi Column ;

:(int)

int x=10;

: (float )

float y;

: (char)

char eng ='a';

: (string )

char eng []=''engineer'';

: 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 .

function hello main

function bye hello

sequence :

main hello(); hello


;)( bye bye hello . main

function function limit

function function stack


8 level 8 level stack over flow
.

, 8 listed call function


function function function 8
.

Variable scope:

1) Local

function function .

2) Global

outside function . functions

37
AZ-EX Technical support Committee
global

function local variable


variable

variable global
RAM local

Operators:

1) Arithmetic

Unsigned char x=5, y= 2,q;

q=x/y;

X/Y assignment operator


fraction unsigned q=2 q included
.

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

y =0000000010000000 8bit . x=0

LCD 8
bit .

2) Relational :

w=4 e=2 q=w>e


q=1 .

One mean true zero mean false

q=x==y

assignment operator relational operator


.

. Z=0

39
AZ-EX Technical support Committee
3) Logic operators

. bit variable bit wise

Ex:

Unsigned char x=7, y=27, q;

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

One shift left as u multiply by 2

Y=4*2*2=16

Statements
IF FOR WHILE
If:

If (expression) {

..

zero curl brackets 1 expression


. {}

41
AZ-EX Technical support Committee
If (expression) {

..

Else {

curl false if curl brackets true


else brackets

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:

{)for(Initialization; condition; increment

}..

;Unsigned char I

{ )For (i=0; I<10; I++

}.

sequence I=0
loop condition 0<10 {}
1<10 increment {}
condition loop .

{);;( For

infinite loop

);;( for main restart

43
AZ-EX Technical support Committee
infinite loop main system
.

infinite loop

While:

{ )while (exp

expression is true false


while for

}For (; exp ;){.

) While (1 );;( for loop .

Do while:

{ Do

}.

)While (condition

true or false
false true do statement

Body of the program


:

: MAIN

: input
. output

: .

infinite loop :

44
AZ-EX Technical support Committee
. power

I/O ports

Data direction

. output input pin

0 ____________ output

1 _____________ input

: C code

TRISX=Value;

X: - is the port name we want to control its pins [A, B, C, D, and E]

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=0b10110101; //Binary so we use 0b

input PORTB pin0

......output PORTB 1Pin

: PORT PORT PIN

TRISX.fN = 0 or 1;

OUT PORTB PIN3 PORT PIN N


:

TRISB.f3 = 0;

.SMALL OR CAPITAL LETTER PORT TRIS

45
AZ-EX Technical support Committee
input pin input pin default
input high impedance float

random 0 or 1 OUT pin


. system default

PIN OUTPUT

. 5V 0V PIN

PORTX = Value;

46
AZ-EX Technical support Committee
PIN PINS PORT 5V / 0V :

;PORTX .fN =0 or 1

INPUT :

)If (PORTB = 0b11111111 Receive values from microcontroller pins :


{
; PORTC = 0b00000000 :
}
else INPUT
{
; PORTC = 0b11111111 0b11111111
0b00000000
}
PORTC 0b11111111
.

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:

1) Digital input devices

A) Push buttons

: push button

: (active high switch)

If pin is high button is pressed else button is released

51
AZ-EX Technical support Committee
):(active low switch

If pin is low button is pressed else button is released

VCC
low high pin
. reset

2) Limit switch


switch

switch
switch .

Push button

limit switch push button


3) Proximity switch

sensor
.

) First type (inductive

metal

52
AZ-EX Technical support Committee
) Second type (capacitive

metal& nonmetal

high 24v DC

low 0V

5 24 24 clamping
:

zero sensor D1& D2


Is off O.C zero volt pin

sensor 24v

D1 is on

D2 is off 5 pin
S.C VCC PIN
19=5-24 .

D2

clamping
24 5

1mA switch 20mA

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

Passive infra red


PIR

sensor 5
.

54
AZ-EX Technical support Committee
PIR




. sensor

Input devices

Active
Dry contact

_ Push button Max. Output >5v

_ Limit switch _ Proximity switch

_ Switch _ Photocell

Output<=5v

(Low=o, high=5)

_PIR

55
AZ-EX Technical support Committee
Digital Output devices

delay 5 pin 5v pin


.

1) Led:

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

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

pin high saturation


emitter collector short circuit
relay contact 12 relay
, low
cutoff emitter collector High impedanceOpen
circuit .

relay 1N4007 energy off


Reverse current
on
0ff .

. 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 .

Explain of winpic program


: PIC

PIC :

63
AZ-EX Technical support Committee
WINPIC
: SERIAL

PIC

_1 programmer kit . burn mode

_2 socket power .

_3 . winpic800

programmer settings hardware

JDM :

* JDM programmer

* Com1 apply

* pic 16 device hardware test

64
AZ-EX Technical support Committee
65
AZ-EX Technical support Committee
* device detect device
unknown unknown

_ burn mode run burn mode

_ serial

_ serial kit

file open pic .hex

setting osc XT LVP WDTEN


UNCHECKED

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

:

PIR PIR HIGH


SWITCH
SWITCH

register unsigned char x=0


2 PIR sensor switch .

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
:

PIR simulate switch


SW-SPDT VCC GROUND .

binary ( 8 )

8 255_0 11111111 255


. decimal

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

;}{ ) while (portc.f0==1 && portc.f1==1 c1


; portb=0b10000000 c0 portb=0b00000010;

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

pin high saturation


emitter collector short circuit
buzzer , low
cutoff emitter collector open circuit
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

If (x=0; x<100; x++) {delay _ ms(x) ;}

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

function input output count


up zero 1
function count binary
up=0 count
0 b00111111 portb zero

switch ..case up=2 4


.

up=0 function count count


num =up=0 ) switch (0 case 0
; ob00111111 portb zero up
1 up=1 up==10
count case1 1 up=10
up=0 .

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
:

call function main up


signed
up up
up 10 10 call
function
up up=10 up=0
call function
up -1 up<0 up=9

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..

BCD binary coded decimal


(.. )0,1

.... 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 ,

SEGMENT TYPE LCD



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

hun tens ons .1


.
temp 10 ons ons .2
int temp
ons
452 temp 10
45 2 .452
temp 10 temp temp .3
int 452 temp.45
.4
temp .tens
temp .hun .5
. .6
48 lcd_chr
48 0 48
.
. .7
. .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.

sbit ;LCD_RS at RB4_bit


sbit ;LCD_EN at RB5_bit
sbit ;LCD_D7 at RB3_bit
sbit ;LCD_D6 at RB2_bit
sbit ;LCD_D5 at RB1_bit
sbit ;LCD_D4 at RB0_bit

sbit ;LCD_RS_Direction at TRISB4_bit


sbit ;LCD_EN_Direction at TRISB5_bit
sbit ;LCD_D7_Direction at TRISB3_bit
sbit ;LCD_D6_Direction at TRISB2_bit
sbit ;LCD_D5_Direction at TRISB1_bit
sbit ;LCD_D4_Direction at TRISB0_bit

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 .

(( )) .

lcd char string char


16 ;] char txt [16 i int
string ;) IntToStr(i, txt string .

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

:

Pin RB1&RB0 output 5v 0v forward


reverse

159
AZ-EX Technical support Committee
Button RB0 RB1
F 1 0
R 0 1
STOP 0 0


: relay device

SPDT relay :

NC switch common single pole dual throw


normal closed/ normal open NO

160
AZ-EX Technical support Committee
contact NO
NC ON /OFF NC . float

relay
pin NPN 12 RELAY
base
relay contact NO 12

DPDT :

Dual pole dual throw2 common 2 switches

direction forward or reverse relay 8 pin

161
AZ-EX Technical support Committee
contact
NC
FORWARD forward
pin


contact NO

reverse

direction on /off

relay 5 pin on/off pin RB3 relay


on off

Button RB3 RB4


F 1 0
R 1 1
STOP 0 Dont care
3 Push buttons stop F R

RB2 RB1 RB0


STOP R F
PORTB OUT IN PIN OUT IN 0
1 default input pins

162
AZ-EX Technical support Committee
:
port b 3pin RB3/RB4

RB3==0
stop

forward reverse

reverse or forward stop

button stop power


off RB4 .

163
AZ-EX Technical support Committee
:

164
AZ-EX Technical support Committee
* : :PWM

PWM dc motor
.

:: PWM Pulse Width Modulation .


square wave . low hi

: 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
:

;)PWM1_Init(const long freq


.... :-

166
AZ-EX Technical support Committee
5
( )
.

;)PWM1_Set_Duty(unsigned short duty_ratio

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

pwm duty cycle


.

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
:

not_rbpu_bit=0 portb pull up resistor


,
current_duty current_duty1
current_duty duty cycle
current_duty
duty cycle

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
:

PWM ;)( pwm1_stop


pin=0
pwm_stop pin =0

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
.

;)( adc_read samples


Quantization num


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

1 kp=49 old state


kp 1

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 .

line D 4 line (+/_///=/0/on)


(. )

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(

: Unipolar stepper motor


(
"" ) .
.
.

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 .

_2 logic level high level 3-


4- 25-

low level 3 4 . 25

2 devices :

serial bit by bit


line 2 lines

215
AZ-EX Technical support Committee
directional full-duplex
. half-duplex

male female . COM ports

Pin assignment

3 pins pin3 pin2pin5

male female male


. female

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

start bit start


bit zero start bit data
bits ASCII Code 8 . data 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

Bytes versus values


byte stop bit parity bit data bits start bit
byte 8 bits byte 11 bits

. data bits byte

219
AZ-EX Technical support Committee
USART
)(IC

5V/0V LOGIC LEVEL logic


level hardware logic level
logic level .

: Bit Rate & Baud Rate


: Bit Rate

bps .

: Baud Rate

Baud Rate Bit Rate


220
AZ-EX Technical support Committee
4 1000

221
AZ-EX Technical support Committee

max232 pin 15 pin 16 GND pin 14/13/12/11 VCC


pin 10 T2IN
transmit pin RC6 max232 pin 9 T2OUT
receive pin RC7

MAX232 PIN7 T2OUT MAX


PIN 2 PIN8
MAX IN PIN3
.

222
AZ-EX Technical support Committee
PINS
.

: mikro C

;)UARTX _Init (const unsigned long baud _rate

UART baud rate

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

{))(If (UARTx _ Data_ Ready

}.

223
AZ-EX Technical support Committee
{)If (UARTx _ Data _Ready()==1

{))(If (UARTx _ Data _Ready

;)(UARTx _ Read


UARTX _ Data_ Ready .

receive char
;)( uartx_read . receive

a b
LCD . bit by bit

;)_UARTx _Write(char data


error :

)"UART1_ Write("aaa

224
AZ-EX Technical support Committee

;)UARTx _Write_Text(char * UART_text

text engineer

;)"UART1_Write_Text("engineer

;"!char output[]="Hi World

) 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

uart initialize eng lcd


eng
engineer 2012 write text
eng lcd engineer 2012
while while
{))( if (UART_DATA_READY
uart_rd char
write
lcd engineer 2012 eng

lcd i
lcd ......

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

graphical user interface


notepad

228
AZ-EX Technical support Committee
tool tool UART terminal
:

com port com 1 band rate


9600 max
max connect
send send
. receive

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

COM1 & COM2 RS232


Virtual Serial Ports Driver 6.9

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
:

pin RC0 PIN RC7


TRIS 1 .

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

You might also like