Sei sulla pagina 1di 22

Digital Clock & Termometer

PIC 16F876

meisamfanoody3319@gmail.com
Tel: 09151495755

meisamfanoody3319@gmail.com
09151495755

PIC16F876

:
,
.
,
.

, PIC ,

.
.
.

.
WDT.

PWM.

DTMF .

Digital Clock & Termometer

PIC ,
, , , .... .

PICBASIC ,

PIC BASIC PRO ) ICPROG


( .

) ( PIC
.

LCD

LCDOUT LCD .

ADCIN .

) (High level Language .

: LCD
meisamfanoody3319@gmail.com
09151495755

PIC16F876

DTMF I 2C
... Basic C

. PIC IC
.

PIC16F876 .

Flash Rom Memory 8K*14bit


) (Data Memory 368*8 Bytes

) (Eeprom Memory 256*8 Bytes


)(A,B,C

PDIP, SOIC
.
:PIC16F876

Digital Clock & Termometer

: PIC16F876

( PIC16F876

meisamfanoody3319@gmail.com
09151495755

PIC16F876

Digital Clock & Termometer

PIC16F876 (

meisamfanoody3319@gmail.com
09151495755

PIC16F876

PIC16F876

Digital Clock & Termometer

( PIC16F876

meisamfanoody3319@gmail.com
09151495755

PIC16F876

:
.
.

Digital Clock & Termometer

meisamfanoody3319@gmail.com
09151495755

PIC16F876

C B .
16F876 .
Connect to

Pin

Clock button
)RC0(11
RC1(12) Set Clock mm (SCM) Button
RC2(13) Set Clock HH(SCH) Button
RC3(14) Set Alarm HH (SAH) Button
RC4(15) Set Alarm mm (SAM) Button
Start Button
)RC5(16
)RC6(17
No Connected
)RC7(18
No Connected

PORT B
pin
)RA0(2
)RA1(3
)RA2(4
)RA3(5
)RA4(6
)RA5(7

Connect
Analoge Input From Temp
Sensor (Lm35) CH0
No Connected
No Connected
No Connected
No Connected
No Connected

Buzzer - LED2
Pin 4 (RS) LCD
Pin 5 (R/W) LCD
Pin 6 (E) LCD
Pin 11 (D4) LCD
Pin 12 (D5) LCD
Pin 13 (D6) LCD
Pin 14 (D7) LCD

PORT C
pin

Connect

Reset

8
9
10
19
20

GND
OSC1
OSC2
GND
VCC

LM35

Digital Clock & Termometer

)RB0(21
)RB1(22
)RB2(23
)RB3(24
)RB4(25
)RB5(26
)RB6(27
)RB7(28

Pin

Connect to

. .

.
. .

LM35 LM34 . LM35



meisamfanoody3319@gmail.com
09151495755

PIC16F876

)( LM35 . . 10mv
.

LM35 .

+5v +Vs

GND .

A 0 16F876

Digital Clock & Termometer

. ADC

0 +5v . 4.9mv .
4.882mv +5v.

10mv LM35 .
* 10mv = LM35

.
) (
) (
.

PIC .
(

( MCRL
( WDT

( SLEEP

( WDT SLEEP

MCLR .
D2 .

meisamfanoody3319@gmail.com
09151495755

PIC16F876

. PIC
RC

. .

Digital Clock & Termometer

1) Lp: Low Power Crystal (32KHz-200KHz Frequency Crystal)


2) XT: Normal Crystal/Resonator (1Mhz,2Mhz,4Mhz Frequency Crystal)
3) HS: High Speed Crystal (8Mhz,10Mhz,20Mhz Frequency Crystal)
4) RC: Resistor/Capacitor (f=1/(RC)
5) Clock from externd System
27pF 20MHz
().

LCD

* LCD
. .
(

Pin No.
1
2

Symbol
VSS
VDD

Name
Power supply
Power supply
LCD Supply
Voltage

VEE

RS

Register select

When RS= High, data register is selected.


When RS= Low, instruction register is selected.
Read/Write selection input.

RW

Read/Write

6
7
8
9
10
11
12
13
14
15
16

E
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
A
K

Read Write enable


Data bus 0-7

When RW= High, read operation.


When RW= Low, write operation.
Start enable signal to read or write the data

meisamfanoody3319@gmail.com
09151495755

Description
0V (GND)
Power supply for logic circuit and LCD (+4.5V~+5.5V)
Bias voltage level for LCD driving
Register select input.

DB0-DB3, in 8-bit bus mode, used as low order bidirectional data bus.
During 4-bit bus mode, open these pins
DB4-DB7, in 8-bit bus mode, used as high order bidirectional data bus. In case of 4-bit bus mode, used as both
high and low order.
back-light anode
back-light cathode

PIC16F876

LCD .

Vss Vdd LCD .

Digital Clock & Termometer

Vo -
) (.

) Rs ( ) E , RC1 ( RC3 R/W

) ( LCD RC2 LCD


. PIC

PIC
.

PIC LCD .

. LCD

RC6, RC5 , RC4 RC7 .

LCD LCD LCD

Define Lcd_ bits 4


, .
Define lcd_dreg portC

Rs LCD

Define lcd_rsreg portC


meisamfanoody3319@gmail.com
09151495755

PIC16F876

Define lcd_rsbit 1
E LCD
.

Define lcd_ereg portC

Define lcd_ebit 3
R/W LCD
.

Digital Clock & Termometer

LCD .

Define lcd_rwreg portC


Define lcd_rwbit 2

Define lcd_lines 2
LCD LCDOUT .
).

LCD (.
(

meisamfanoody3319@gmail.com
09151495755

PIC16F876

Digital Clock & Termometer

Define LCD_DREG PORTC


Define LCD_DBIT 4
Define LCD_RSREG PORTC
Define LCD_RSBIT 1
Define LCD_EREG PORTC
Define LCD_EBIT 3
Define LCD_BITS 4
Define LCD_RWREG PORTC
Define LCD_RWBIT 2
Define LCD_LINES 2
LCD ) LCD(

20MHz

. 4Mhz .

Define OSC 20
. PIC

.
Define . PIC16F876

DEFINE ADC_BITS 10

DEFINE ADC_SAMPLEUS 50
DEFINE ADC_CLOCK 3
RC .

PIC
.

0 .

1 .

Tris . A B C
. .

trisb=$ff
trisc=$00
trisa=255

meisamfanoody3319@gmail.com
09151495755

PIC16F876


.
.

0 1 .

8 255 .

16 65535 .
.

b5 :

b5 :
b5 :
:
.
. b0=10

2 % . b0=%10

$ . b0=$10

Digital Clock & Termometer

Variables Var . b5

bit

b5 var

byte

b5 var

word

b5 var

b1 c0 b6 c1 W0
.

b1
b2
b3
b4
b5
b6

clock
Clock

c0
c1


LCD

Clock
Alarm
Alarm

w0

b1 var byte
b2 var byte
b3 var byte
b4 var byte
b5 var byte
b6 var byte
C1 Var Byte
C0 var byte
W0 VAR WORD

meisamfanoody3319@gmail.com
09151495755

PIC16F876

C LED .
b2 b5 .

portc.0=0
b5=0
b4=0
b3=0
b2=0

LCD .

. :

Digital Clock & Termometer

lcdout $fe,1
Sound .

]Sound pin,[note,Duration,
Note

. 78.74Hz
10Khz .

Duration
.

c0 .

sound
]portc.0,[130,5,50,30,128,5,100,5,10,30,70,5,90,40,230,50,240,100,250,200

PIC
. PIC16F876 .

) (ADCON1
). (

ADCON1 A

)/( .

A
.

. 0 A

Vcc Vss

0000 .

meisamfanoody3319@gmail.com
09151495755

PIC16F876

Digital Clock & Termometer

.
.
.
ADCON1.7=1

Or

ADCON1=%10000000

Logo1
.

LCD

( C1=143 . C0

LCDOUT C1
.

Logo1:
C1=143
for C0=0 to 15
C1=C1-1
meisamfanoody3319@gmail.com
09151495755

PIC16F876

" Lcdout $fe,C1," DIGITAL ClOCK


pause 500
next C0
LCDOUT .

" lcdout $fe,1," DIGITAL ClOCK


PAUSE .
100ms .

Digital Clock & Termometer

SOUND .

pause 100

]sound portc.0,[100,10,50,10,70,10,60,10,30,10
Logo2

. C1 LCD

.
.

Logo2:
c1=207
for c0=0 to 15
c1=c1-1
" lcdout $fe,c1,"With Thermometre
pause 500
next c0
" Lcdout $fe,$c0,"With Thermometre
pause 1000

Logo3 Logo5

DTMFOUT .
:

]}DTFMOUT pin,{onms,offms,}[tone{,tone.
Onms offms

onms offms
.

tone .
. )*(

) (# A D.

meisamfanoody3319@gmail.com
09151495755

PIC16F876

]DTMFOUT portc.0,[9,8,7,6,5,4,3,2,1,0
Scan1 .

Digital Clock & Termometer

. .

b5 b4 .
.

scan1:
lcdout $fe,1,"Set Alarm HH=",dec b5
lcdout $fe,$c0,"Set Alarm MM=",dec b4
dec b4 dec b5 .

If ) ( B SAH .

SAH ) (Then b5
) ( .

If portb.3=1 then b5=b5+1


If b5 24

If b5=24 then b5=0


LCDOUT b5 ). (.

lcdout $fe,1,"Set Alarm HH=",dec b5


) ( B SAM .

b4 b4
60 0 .

If portb.4=1 then b4=b4+1


If b4=60 then b4=0

lcdout $fe,$c0,"Set Alarm MM=",dec b4


B ) -
(Clock .

Scan1
SAM SAH .

meisamfanoody3319@gmail.com
09151495755

PIC16F876

Clock Scan .

b3 b2 .

LCD .

scan:
lcdout $fe,1,"Set Clock HH=",dec b3
lcdout $fe,$c0,"Set Clock MM=",dec b2
B SCH

Digital Clock & Termometer

SCM ) - (

LCDOUT LCD .

if portb.2=1 then b3=b3+1


if b3=24 then b3=0
lcdout $fe,1,"Set Clock HH=",dec b3
if portb.1=1 then b2=b2+1
if b2=60 then b2=0
lcdout $fe,$c0,"Set Clock MM=",dec b2
IF B Start


. SCM SCH .

START b5 ) b3 (

b2 ) b4 (
). (timer

start:
if b3=b5 and b4=b2 then timer
Toggel .

LED .

Toggle portc.0
b1 .
) ( .

LCD Refresh.

for b1=0 to 59
lcdout $fe,1
ADCIN A ADC

W0 .

meisamfanoody3319@gmail.com
09151495755

PIC16F876

10mv LM35 .
* 10mv = LM35 .

) ( = LM35 ( *

) ( +5v

+ 5v
= 4.8828e 3 :
1024

0.33

Digital Clock & Termometer

. .

) W0 (
. 0.5 .

Vout = 0.33v
0.33
= 67.58; A/ DConvert
= W0
4.8828m
67.58 * 0.5 = 33.79

) ( .
. ADC W0

W0 . 0.5 W0 . W0

LCDOUT .

ADCIN 0,W0
W0=(W0*5)/10
"LCDOUT $fe,1,"TEMP= ",DEC W0," C

** ) ** 22:15:56(

"** "lcdout $fe,$c0," ** ",dec b3,":",dec b2,":",dec b1,


) 1000ms ( 992ms

B SAH SSS

KKK

meisamfanoody3319@gmail.com
09151495755

PIC16F876

SSS .

Clock ) (KKK

Digital Clock & Termometer

if portb.3=1 then
sss:
lcdout $fe,1,"Set Alarm HH=",dec b5
lcdout $fe,$c0,"Set Alarm MM=",dec b4
if portb.3=1 then b5=b5+1
if b5=24 then b5=0
lcdout $fe,1,"Set Alarm HH=",dec b5
if portb.4=1 then b4=b4+1
if b4=60 then b4=0
lcdout $fe,$c0,"Set Alarm MM=",dec b4
if portb.0=1 then kkk
pause 150
goto sss
Endif
KKK ) b1 ( For

59 for .

) b2( ) ( ) (b2 If

) ( ) b3(
.

kkk:
next b1
b2=b2+1
if b2=60 then
b2=0
b3=b3+1
Endif
b3 .

Start .

Start .

Alarm Enable . For


0 c 110ms

1000ms . b1
. Start .

meisamfanoody3319@gmail.com
09151495755

PIC16F876

LCD :

Set Alarm HH=00


Set Alarm MM=00

SAH SAM .

Clock

Digital Clock & Termometer

SCH SCM .

Set Clock HH=00


Set Clock MM=00

Start .

SAH

Clock .

meisamfanoody3319@gmail.com
09151495755

U1

78L05
V
OUT
GND

VCC
3

VCC=+5V DC

SW SPST

V
IN

R1
680
+

C1

LCD1 2*16

100n

VCC

S3
Start

S4
SAM

D2
1N4148

C3
27p

R2

20.000MHZ

27p

10k

U2
9
10
1

R3
100ohm

2
3
4
5
6
7

VCC

U3
LM35
1
2

IN+ OUT
IN-

S2
Restart

S5
SAH

S6
SCH

S7
SCM

R4
100ohm

VCC

Y1
C4

21
22
23
24
25
26
27
28

S8
Clock

OSC1/CLKIN
OSC2/CLKOUT
MCLR/VPP
RA0/AN0
RA1/AN1
RA2/AN2/VrefRA3/AN3/Vref+
RA4/T0CKI
RA5/AN4/SS

11
12
13
14
15
16
17
18

RC0/T1OSO/T1CKI
RC1/T1OSI
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6
RC7

RB0/INT
RB1
RB2
RB3/PGM
RB4
RB5
RB6/PGC
RB7/PGD

VCC

20

VCC

VCC

19
8

VSS
VSS

U?

R5
10k

PIC16F 876A

R7
4.7k

R8
330ohm

BUZZER

Q1
BC548A

D3
LED

R6
100k

RP1
4.7k
9
10
11
12
13
14
15
16

VCC
VCC

8
7
6
5
4
3
2
1

D1
LED

Temp= 33 C
** 16:56:32 **

C2

1000u-16v

Vee
VCC
VSS

A
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
E
R/W
RS

S1
VDD=6-8V

Digital Clock & Termometer

A
Title
Size

Number

Revision

B
Date:
File:
1

meisamfanoody3319@gmail.com
09151495755

PDF created with pdfFactory Pro trial version www.pdffactory.com

23-Jul-2007
E:\Project\Sa@t 876\876.Ddb

Sheet of
Drawn By:
6

Potrebbero piacerti anche