You are on page 1of 201

:

Facebook: https://www.facebook.com/H.Hedait

Twitter: https://twitter.com/Hossam_Hedait

Linkedin: https://www.linkedin.com/in/hossamhedait/

Blogger: http://hossamhedait.blogspot.com.eg/

Instagram: https://www.instagram.com/hossamhedait/
-:
.1 :.
1.1 ( (inputs- outputs .
1.2 ( ).
1.3 .
1.4 .
1.5 .Dec-Bin-Oct, and Hex
1.6 .
1.7 .
1.8 Duty .PW
1.9 .Interfaces
1.10 .
1.11 .

.2 : .
2.1 .
2.2 .PIC
2.3 .PIC
2.4 PICS ().
2.5 .Data sheet analysis

.3 : .
3.1 .
-1 .
-2 .
PICPgm -3.
.4 : .
. 4.1
-1 .Algorithm
-2 .Pseudocode
-3 .flowchart
+ .
4.2 ().
.
4.3

.5 : .
:







.

1969
BUSICOM INTEL
, Marcian Hoff
.

.
Marcian Hoff .
Frederico Faggin Intel
1971
BUSICOM .

Frederico Faggin

1

,
,




IC

,



PLC


.

.
IC Chip



.

2
() 30

30 .
.



,
, ,
.

()

3





()
.

Fuzzy PID PLC


PICS

ATMEL

Arduino


()

bits
.

4


( [)]Basics
Chapter 1

:
basics
.
1.1 ( (inputs- outputs



switch

.
sensor



.


input pins

output pins
.


() . -
switch -
() . -
.keypad -
) LDR ). -
-

keypad

5

( LED ). -
( Relay or transistor ). -
7-segment. -
LCD. -
Relay
.Motor -
. -

LCD
7-segment Motor

((Input-output



:
,

switch
,

25 2.5 (
) Inputs
(---)

.

6
: output
( )

.
1.2 ( )

( : )

0-1 0 0
0 1
5 1 5 .
( : )
.

0 0 volt 1 5 volts

0s 1s logic logic 1 = 5 volts

7

zeros ones logic 0 5

9 8.5
8 .
1.3
0 1


.
8 16 byte
bit-byte ,
, bit
.

1 or 0 bit
8 byte

.

Bit, nibble, byte, word 8




.
-1 bit .
-2 nibble 4 .
-3 byte 8 .
-4 word 16 .
Long word -5 32.
Very long word -6 64.
(
).

9
1.4

( )
,

( = 1000)
1000
.
1000 (1 = 0.001)

.

.

10
SI Prefix
Prefix Symbol ...10n Decimal Multiplier


yotta Y 1024 1000000000000000000000000
zetta Z 1021 1000000000000000000000
exa E 1018 1000000000000000000
peta P 1015 1000000000000000
tera T 1012 1000000000000
giga G 109 1000000000
mega M 106 1000000
kilo K 103 1000
hecto H 102 100
deca Da 101 10

deci D 10-1 0.1


centi C 10-2 0.01
milli M 10-3 0.001
micro 10-6 0.000 001

nano N 10-9 0.000 000 001


pico P 10-12 0.000 000 000 001
femto F 10-15 0.000 000 000 000 001
atto A 10-18 0.000 000 000 000 000 001
zepto Z 10-21 0.000 000 000 000 000 000 001
yocto Y 10-24 0.000 000 000 000 000 000 000 001
( )
11
1.5 Dec-Bin-Oct, and Hex


Decimal.-1 4-3-2-1
Binary. -2 .
Octal.-3 8
Hexadecimal. -4 16

3-2-1


00 01 10 11
00 0
01 1 10 2 11 3
00 0
2

2 ... 2x 2

:
20 ( ) (
)

25 24 23 2 2 21 20
= 20 1 32 16 8 4 2 1
4 16 1 0 1 0 1 0 0
20 = 16+4

12

35 ( ).
25 24 2 3 22 21 20
= 20 1 32 16 8 4 2 1
1 322 1 35 1 0 0 0 1 1
35 100011
.

010101
0 1 0 1 0 1
25 24 23 22 21 20
32 16 8 4 2 1
- - -
21 = 16 + 4 + 1
101010 21
.

13



011100



011100

0 1 1 1 0 0
22 21 20 22 21 20

3 4

011100 = @ 34
@
...

14



011100
0 0 0 1 1 1 0 0
23 22 21 20 23 22 21 20

1 C
4

0001 = 1 1

0010 = 2 2

0011 = 3 3

0100 = 4 4

0101 = 5 5

0110 = 6 6

0111 = 7 7

1000 = 8 8

1001 = 9 9

1010 = 10 A

1011 = 11 B

1100 = 12 C

1101 = 13 D

1110 = 14 E

1111 = 15 F


15
12
12 C



https://www.mathsisfun.com/binary-decimal-hexadecimal-
converter.html

/http://www.miniwebtool.com/binary-converter

--------------------------------------------------------------------------

16
1.6



-1 ....

.
-2 ....
C E
.Base and emitter

-3 .... relay







.


.

17

3
c e b
b e
b c
e b
c , e

C-E
B
.

5
c NC-NO
: NC NO

C
NC

C NO
C NO

NC
( )
( ).

18
-4 ... LEDS


Forward reverse









.
Red LED: 2V 15mA
Green LED: 2.1V 20mA
Blue LED: 3.2V 25mA
White LED: 3.2V 25mA
R=(Vs-VL) / IL
Vs .
VL .
IL .
R .



http://led.linear1.org/1led.wiz :
http://led.linear1.org/led.wiz :

19

20
7 -5 .... 7 Segment

7


7







.

21
-6 ....
, ,

( )

AC DC
DC


.DC
: DC
AC ( ).
.

DC AC

22
23
IC -7 .... Regulator

, PIC
5 9 12
5
9 12 5
5
5 5

. 7805
IC 7805 .

7805 IC Pins

() .

24
-8 .... LCD




LCD 20 4
20 4
.

LCD

-9 .... Switches



.

25
Single Pole Single Throw Switch (SPST) :


closed loop
. open loop

Single Pole Single Throw Switch

Single Pole Double Throw Switch (SPDT) :








.

Single Pole Double Throw Switch


)(SPDT
26
Push Button Switch :


closed loop

open loop
.

Push Button Switch


Limit Switch :






( )
.

27
Double Pole Single Throw Switch (DPST) :

Double Pole Double Throw Switch (DPDT) :

Toggle Switch :

Float Switches :

Float Switches :

28
-10 .....


.

....Pin header -11


.

29

diagram

Pull down resistor - Pull up resistor -1
0-1
1
0

vcc 5= vcc
S1
0 = GROUND.
.
pull up resistor
pull down resistor
.
)(COM )(COM

)R1(1 )R1(1

R1 R1
4.7k 4.7k

+5.00 0.00 0.00 +5.00


Volts Volts Volts Volts
R2 R2
4.7k 4.7k

pull up resistor pull down resistor pull up resistor pull down resistor

30
-2 .


0.00001
.

clock 8


1 8
1
= 1.25 107
8106

.










.

31
1.7 .





.
-1



.
-2
.
-3
.

-4


.
: .

32
1.8 Duty .PW


.



(
1 0 )



1
= 6
1
6 1 .
Duty

.

33
duty cycle
pulse width modulation

.
duty


12
12 rated speed
11 10 9
11 12
10 9

: PWM
.
DC
6 .

3 , PWM
%50
%50
6 ( 3)
%33.3
% 33.3 6
(2) .

.
34
1.9 .Interfaces





usb
usb .

0 1 0 5

24

5
,
rs232
usb
usb vcc 5
.




.
( )18-17

35
()

...
1.10 .




ROM-EEPROM EPROM








( )

( )
.



.

36
1.11 .
: .
( )
30
35
LCD
.

10

.
.

.
2


10

80 ( )
10 ( )
.

37
: .
. -1
. -2
. -3
. -4
: 3 .
: .

:
DC AC .
.PWM
.
.
Duty time
.
.

38
:
132 = ......................
132=.......................
132=.......................
10=........................
12=........................
20=......................
20=.....................
:
50 = ..................
22 = .................
33 = ...............
80 = ..............
= ..................
2 = ...............
2 =................
2 =................ .
: .
16
17
46
19
12
55
95
66
39


(
[)]PICS
Chapter 2

:c
pic
.
2.1 .




.

PIC ATmega-AVR 8051

)(Microchip )(ATMEL )(Intel


, PICS



PIC



( )

.
40

PIC
((PIC
.
2.2 .PIC
: microprocessor




.
:
RAM
.

.

.
: pic 5 25 .
:
.
:

.

41
2.3 .PIC

PWM

Pulse width modulation

.
The Clock
" " clock
.
" " crystal 2
, 30 " "
resonator " -" .
.

.
Timers
" ." ""
" "
.
8 16 .
.
(
) .
.

42
Watchdog
" " " "
"" , " "
" " reset .
" " " " .
" "
.
" " real-time
Reset Input
" ." reset
" " " "0
. " " push-
button . ""
.29
Brown-out Detector
( )
rest "" ,
( )
. EEPROM
Analog-to-Digital Converter
" A/D" , ,
.
. A/D A/D
. A/D bit-8
bit-10 "" quantization 256 1024 .
A/D
. PIC18F452 8
A/D . bit-10

43
Serial Input-Output


. PIC16F
Interrupts
"" ,
( ) .
"" ""
" " , ISR
()
"" .
"
" . " "
" " "
" . nested
,
.
PIC18F "
" " " .
PWM
Pulse width modulation
duty
5

.

44
2.4 PICS ().


.
PIC12F675 -1
- .
- .
- 1.
- 64.
- 20.
PIC 16F877A -2
- .
- .
- .8 k 14
- 368.
- 20.
PIC 18F452 -3
- .
- .
- 16.
- 1536.
- 40.
- .USB interface

.
PIC 12, 16, 17, 18 and 32 families

45
2.5 .Data sheet analysis




PIC 16F877A
.


http://pdf1.alldatasheet.com/datasheet-pdf/view/115035/MICROCHIP/PIC16F87XA.html

PIC16F87XA
x 1-5

.




46
.
47
1

,
20
200


20.
2.46

1.46
100000.
3.46


2.46
2
5.5


.

3.46

48
1.47

1.47

1


2


3 .
4 pwm .
5 usart
yes .
6 ( ).
7
2 .

49
3
1.48


.

1.48

2.48

50
2.48 1.47
1 2
pic16f877a
20
3
4
8
5
15 ( )
6
A
RA0-A-RA1-RA2-RA3-
RA0 A
A

5
7

3 3
8 2 PWM 2
10- 9

UART
11 8


12 13
.
51
7
.

1.50

1.50 10 pin description


A 3
B

PDIP

c
D .

52
1 13
OSC1/CLKI

( )/ 13
OSC1 CLK /

OSC1
13
1.51 13
CLKI


1.51

14
2 14 OSC2/CLKO
13 14

.
3 1 MCLR/VPP
MCLR 29

0
5 0
VPP .

53
4 ( ( A
: A 2 RA0/AN0
RA0 A
.
AN0 A

.
: A 3 RA1/AN1

RA1 A
.
AN1 A
.
: A 4 RA2/AN2/VREF-
/CVREF :
RA2 A
.
AN2 A
.
VREF- (
) LOW
CVREF .
: A 5 RA3/AN3/VREF+
:
RA3 A
.

54
AN3 A
.
VREF+ (
) .HIGH
: A 6 RA4/T0CKI/C1OUT
:
RA4 A
.
T0CKI
.
C1OUT .
: A 7
RA5/AN4/SS/C2OUT :
RA5 A
.
AN4 A
.
SS .slave select input
C2OUT .

55
1.54
1.54 11

5 B
: B 33 RB0/INT
:
RB0 B
.
INT
interrupt
.
56
: B 34 RB1
:
RB1 B
.
: B 35 RB2
:
RB2 B
.
: B 36 RB3/PGM
:
RB3 B
.
PGM programming enable pin
LOW VOLTAGE 0.
: B 37 RB4
:
RB4 B
.
: B 38 RB5
:
RB5 B
.
: B 39 RB6/PGC
:
RB6 B
.
PGC
. programming clock
57
: B 40 RB7/PGD
:
RB7 B
.
PGD
programming data .

1.56

1.56 12

6 C

58
: C 15
RC0/T1OSO/T1CKI :
RC0 C
.
T1OSO .
T1CKI
.
: C 16 RC1/T1OSI/CCP2
:
RC1 C
.
T1OSI .
CCP2
Capture2 input, Compare2 output, PWM2 output.

.
: C 17 RC2/CCP1
:
RC2 C
.
CCP1
Capture1 input, Compare1 output, PWM1 output
+ .
: C 18 RC3/SCK/SCL
:
RC3 C
.

59
SCK
serial . SPI
SCL
serial . I2C
: C 23 RC4/SDI/SDA
:
RC4 C
.
SDI . SPI
SDA
. I2C
: C 24 RC5/SDO
:
RC5 C
.
SDO . SPI
: C 25 RC6/TX/CK
:
RC6 C
.
TX


.USART
CK
. USART1

60
: C 26 RC7/RX/DT
:
RC7 C
.
RX


.USART
CK .USART1

1.59

61
1.59 13

7 D
: D 19 RD0/PSP0
:
RD0 D
.
PSP0 Parallel Slave Port
.data
: D 20 RD1/PSP1
:
RD1 D
.
PSP1 Parallel Slave Port
.data
: D 21 RD2/PSP2
:
RD2 D
.
PSP2 Parallel Slave Port
.data
: D 22 RD3/PSP3
:
RD3 D
.
PSP3 Parallel Slave Port
.data
62
: D 27 RD4/PSP4
:
RD4 D
.
PSP4 Parallel Slave Port
.data
: D 28 RD5/PSP5
:
RD5 D
.
PSP5 Parallel Slave Port
.data
: D 29 RD6/PSP6
:
RD6 D
.
PSP6 Parallel Slave Port
.data
: D 30 RD7/PSP7
:
RD7 D
.
PSP7 Parallel Slave Port
.data
8 E

63
: E 8 RE0/RD/AN5
:
RE0 E
.
RD
0 5
Parallel Slave Port .
AN5 E
.
: E 9 RE1/WR/AN6
:
RE1 E
.
WR
0 5
Parallel Slave Port .
AN6 E
.
: E 10 RE2/CS/AN7
:
RE2 E
.
CS select control Parallel
. Slave Port.
AN7 E
.

64
9 31-12
ground 0 .
10 32-11
5 .
11 .

PIC16F877A .

.

65

PIC16F877A 30

14-13 16-15 14-13
.

1.63

.
TABLE14-2

146



.

66
1.65

1.65 1

2
3

4
vss-vdd
.

67
1.66

1.66 ic

PCB

.

68


( )
Chapter 3

:

.


%90




.
3.1 .
-1 . PROTUES

( )ISIS ARIS ISIS






( )
ISIS

ARIS PCB
. 1.67
ISIS

( ).

1.67 69
-2 . Micro C
( (compiler








:
Build
.HEX

(
).
-3 PICPgm . winpic




1.68
2.68
( ).

1.68 2.68 70


-1 :

.

isis
.
1


2 1
isis-aris
.
71
3
4 overview .
5
.
6 p
.

p
1 .
2
3
.
4
.
5 . PCB

72
7 .
8
.



1 Selection mode
( ).
2 Component mode
(
).
3 junction dot mode

( ) .
4 wire label mode
.
5 terminal mode .
6 generator mode .
7 probe mode
.
8 instruments
.
9
.
9
.

.
73
-2 .Micro C
Micro C Pro for PIC

( ) HEX.
( ) 1.72
.

1.72

2.72 .

2.72
74
1 ( ).
file
new .
Open .
Save .
Save as .
Print .
Exit .
Edit
Undo .
Redo ().
cut .
copy .
paste .
delete .
find .
go to line .
project

new project .
Open project .
Edit project

.

75
build


build


().

build
.

Help



( ).


f1
help . f1

76
2

1
.
2 .
3 .
4 .
5 hex.
6 7 segment .uart
3
4 .
:

77
:

78
:

79
.

80
-3 .PICPgm

()
.
( ).

.

RS-232 .

81
( )
() .

82

JDM .OK

Browse .

83
.



PIC16F877A
.

84

PIC16F877A .


()
.



PICPmg
winpic IC Prog

usb

.
85


( )
Chapter 4

:




.PICS











()
4.1 .

.
Flowchart Pseudo code Algorithm





Algorithm



.
. .

86

-1 .Algorithm




.


10
.
-1 .
-2 .
-3 1 .
-4 .
-5 .
-6 2 .
-7 .
-8 .
-9 .
-10 .

87
-2 .Pseudocode





: pseudocode



b<a b a
b>a b a
b=a b a
b*a ab
b+a ab
b-a ab
b/a b a
1-2-3-4-5-etc.
Begin or start
End , finish or
stop
While
end while while
if () ..
then if true
else if false

88
-3 .flowchart



.
.

89
pseudocode . flowchart

90
91
92
93
94
()


4.2 ().


} {

( )


.
; .

/
} ()void main
{ }
{ ().
;tris*=0*--------
*
A B.
Port*= ---- ; or
; Port*.*0= - 0 0 1 5 * .
;)Delay_ms(----
.
A-E ;ADCON1 = 0x06
{ ) (While } {
} ( )
{ ) For (A;B;C
} A,B,C
95
{ ) ( IF ( )
} } { if
{ else ( )
} } { else
if .else
; Int x
.
; float x
.
; char x .
;)UART*_init(---
* .
;)UART*_write(---
( )
* .
;)UART*_read(--- ( )
( ) * .
) )(if (UART*_Data_Ready
{ *
.
}

;)"UART*_write_text("-
* .
;)UART*_write(13
* .

96
;)(Lcd_Init LCD .
// Lcd pinout settings
;sbit LCD_RS at RB*_bit
;sbit LCD_EN at RB*_bit
;sbit LCD_D* at RB*_bit LCD
;sbit LCD_D* at RB*_bit
;sbit LCD_D* at RB*_bit
;sbit LCD_D* at RB*_bit

// Pin direction LCD
sbit LCD_RS_Direction at ;TRISB*_bit
sbit LCD_EN_Direction at ;TRISB*_bit * LCD
sbit LCD_D*_Direction at ;TRISB*_bit
sbit LCD_D*_Direction
sbit LCD_D*_Direction
at
at
;TRISB*_bit
;TRISB*_bit
.
sbit LCD_D*_Direction at ;TRISB*_bit

;)"Lcd_Out(*, *, "---------- LCD


* .
;)"Lcd_Out_Cp("-------- LCD
( )
;)'Lcd_Chr(*, *, '--
;)Lcd_Cmd(-------- LCD .

( ) .
_LCD_FIRST_ROW (.
_LCD_SECOND_ROW first second
_LCD_THIRD_ROW ).

_LCD_CLEAR LCD
_LCD_CURSOR_OFF .
_LCD_MOVE_CURSOR_RIGHT
_LCD_MOVE_CURSOR_LEFT

97
;)(Keypad_Init Keypad

;*char keypadPort at PORT
* ( .) main
;)(Keypad_Key_Click
.
;)(Keypad_Key_Press
( ).
;)****(PWM#_Init pwm
#
**** .
;)***(PWM#_Set_Duty
high ( )
;)(PWM*_Start pwm * .
;)(PWM*_Stop pwm *,.

;)* Sound_Init(&PORT#,
# *
;) * Sound_Play( # , # *.

;)(ADC_Init ADC .

;)*(ADC_Read *.

.

98

( )...
//-----------------------


.
+ .
- .
* .
++ 1
-- 1 .
== .
=! .
> .
< .
=> .
=< .

& ( ).

| ( ).
^ (
).
/*--------------*/

* / */
.
, .
: .

99
} ()void main 1



{
} {
( ) ( )
( )
{ }


.

;Tris#=0*-------- 2
;Tris#.b*=--------


,
TRIS


( )0 (( 1
;TRISB.B0=0 RB0
B
;TRIS B. B 0 =0
.

100
: 4 C
;TRISC.B3=1
: 6 D
; TRISD.B5=0
( )
( ) ():

B ;TRISB=0B00000000

;TRIS B = 0B 00000000


C :

;TRISC=0B00000000

RC0
RC3 RC1 RC6
RC7
RC6 RC6
RC6 RC5 RC7

RC6
RC7 RC2 RC7
RC7
RC7
RC4

RC6

RC7
RC6 RC7

4 C
;TRISC=0B11110000
101



8
( ) ( ):
B
;TRISB=0X00

TRIS B = 0X ;00

HEXADEC

00 ; 00000000
4 0 0000

Quick converter .

102
;Port#=0*-------- 3 1
;Port#.b*=-------- 0


high 1 5
25
0 0 .


:
0 B ;PortB.B0=0
0 B ;PortB=0B00000000
0 B ;PortB=0X00

;)Delay_ms (---- 4


3
( )----
5 ;)Delay_ms(5000

103
{ ) * ( While

5
} ()---

} {-------
30
30
30 ,

2
} {-----
1
{ )While (1 .
}

{ ) For (A; B; C 6

}

10
A,B,C
A ( ) B, .
{ )For (X=0; X<6; X++ C .
,
} X
6 1
1 X=1 6
X 6 ( .)X

104
{ ) ( IF
}
7
{ else , If
} Else else
if ()---
} {-- if
} {-- else
30
else
30
.

; Int x 8
; float x
6 ( )X
; char x
, x
x
void main
x 3-2-1 ; Int x .
x 2.3 ; float x .
x H ; char x .

.

105
;)UART*_init(--- UART
9
;)UART*_write(---

;)UART*_read(---
) )(if (UART*_Data_Ready
{ ;) UART*_init(---

}
.
;)"UART*_write_text("-
;)UART*_write(---
;)UART*_write(13

WELCOME .

;) UART*_read(---
.

;)" UART*_write_text("-
.

;) UART*_write(13
.

106
;)(Lcd_Init UART
10

;)( Lcd_Init Initiolization
. LCD
;sbit LCD_RS at R#*_bit
;sbit LCD_EN at R#*_bit 11
;sbit LCD_D* at R#*_bit LCD #
;sbit LCD_D* at R#*_bit *
;sbit LCD_D* at R#*_bit
;sbit LCD_D* at R#*_bit
;sbit LCD_RS_Direction at TRIS#*_bit .
;sbit LCD_EN_Direction at TRIS#*_bit

;sbit LCD_D*_Direction at TRIS#*_bit

;sbit LCD_D*_Direction at TRIS#*_bit

;sbit LCD_D*_Direction at TRIS#*_bit

sbit LCD_D*_Direction at TRIS#*_bit


D4 RB2
RS B

4
RS-E
6
6 .
107
;)"Lcd_Out(*, *, "---------- LCD
12
;)"Lcd_Out_Cp("--------
;)" Lcd_Out(*, #, "---------- LCD
;)'Lcd_Chr(*, *, '-- -------
* # .
LCD
.
.

;)Lcd_Cmd(-------- 13
LCD
LCD ---------
LCD
_LCD_CLEAR

;)Lcd_Cmd(_LCD_CLEAR
_LCD_CURSOR_OFF :
;)Lcd_Cmd(_LCD_CURSOR_OFF
.

.

108
;)****(PWM#_Init
14
;)***(PWM#_Set_Duty
PWM

;)****( PWM#_Init
#
PWM
1 CCP1 2
;)***( PWM#_Set_Duty DUTY

8
1 255
27 26 25 24 23 22 21 2 0
128 64 32 16 8 4 2 1
255 % 100
DUTY %75
75
255 = 191.25 192
100

75 .
;)PWM1_Set_Duty(192
% 50
50
255 = 127.5 128
100

;)PWM1_Set_Duty(192

109



HELP
Help

LCD library
LCD .

110
4.3 .




.
-1 .
-2 ( ) .
-3 .
-4 .
-5 Flowchart .
-6 } {
.
-7 i
.
-8 ; .
-9 build .
:



;


.

.
111
; .
; ; expected

.

{expected {
}expected }
expected, ,
) Expected ( - expected )> - <-(-
> expected < - expected
Expression syntax
Undefined symbol
' ' Unable to open include file ()
Bad file name format in include
directive
Array size too large

112


()
Chapter 5

:
()


.


5 .

Void main
while
( )1 b
1 5 .
113



.

114


.

115

5

.

116


while
( )1
for
h
h 2 h h++
h 1
1
h 2
h
.

117

2 2

2 .

118

,




2
if
.

.



2

.

119

5
5
5 .

120
:


7
void main
while
) while(1 ()
} for(;;){ program
loop
goto loop
, tris
port
1 ,0 delay
for
if
.

121

24 3

.

122



terminal input
terminal output

.

123

124


4 1
.0

125

( ).

126


.0

127

7
1.2.3.4
. ic4511

128
7
ic4511
7
.

129

( )
ic4511 .

130
ic 4511

7
.


1
2
.

131

7
.

132

10
7
.

133

. LCD

134
LCD .

135


uart
. uart

136
UART
() .

137



lcd .

138

139



1 7
.

140

//Hossam Hedait (password machine using keyboard and LCD)
char keypadPort at PORTC;
sbit LCD_RS at RB0_bit; sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN at RB1_bit; sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4 at RB2_bit; sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5 at RB3_bit; sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6 at RB4_bit; sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7 at RB5_bit; sbit LCD_D7_Direction at TRISB5_bit;
int i;
char password[4]; //4 because i will make 3 numbers as a password.
char get_password()
{
loop:
lcd_cmd(_lcd_clear;)
lcd_out(1,1,"enter password");
for(i=0;i<3;i{)++
while (password[i] ==0)
{
password[i]=keypad_key_click();
}
if (password[i]==1) password[i]= '7;'
if (password[i]==2) password[i]= '8;'
if (password[i]==3) password[i]= '9;'
if (password[i]==5) password[i]= '4;'
if (password[i]==6) password[i]= '5;'
if (password[i]==7) password[i]= '6;'
if (password[i]==9) password[i]= '1;'
if (password[i]==10) password[i]= '2;'
if (password[i]==11) password[i]= '3;'
lcd_chr(2,i+1;)'*',

}
if (strcmp(password,"123")==0) { return 1; }
else{
password[0] = 0; password[1] = 0; password[2] = 0; password[3] = 0;
goto loop;
} }
void main{ )(
trisd.b0=0; portd.B0=0; Lcd_Init(); Keypad_Init;)(
get_password;)(
lcd_cmd(_lcd_clear;)
lcd_out(1,1,"WELCOME HOSSAM;)"
while(1{)
portd.B0=1;
delay_ms(500;)
portd.B0=0;
delay_ms(500;)
}}
141


UART
.

142

a
7 b
.

143
( ) .uart

144

pwm
.

145
100/50

a uart ( ccp1
) pwm 1
. 0

100/75

b
0.75
0.25

146
ccp1 . 75/100

147

148

2 ((push button 7
7

.
f
;if (PORTd.F0==0) PORTB.F0=1

149
150

DC
.


( )
5 25


6 24


( ) () .
151

152
153

dc 5
.pwm

154
pwm
ccp1
5
4 4 .
.

155




.

156

157
158
159

pwm .
A
B
C .
1 .
2 .
3 .
4 .

160


5
5 5.59.





{)'if (y=='5

.

161


5 5
5 .

162

LCD
LCD
. LCD

163

LCD




LCD

.

164
LCD
.
1

165

Paste void main

;)CustomChar(1,1





;)CustomChar1(1,2
;)CustomChar3(1,1
;) CustomChar4(1,1

.
.

166


.

.
.

167

( )

().

:


:
5 25 ()

10
25 20
()

330 1
.

=

20
2 10

= 300 = 523
1010
300 330 .

168
:






( )



.

You might also like