|
EDA365欢迎您!
您需要 登录 才可以下载或查看,没有帐号?注册
x
烟雾报警器制作过程及相关程序
& F$ x+ N- D! s* `% I' t |/ ^- }//程序头函数* p5 q: J7 m, a5 l/ v
#include <reg52.h>
2 z4 L! Q# |( ]( C) q& a
& I% B6 C1 G6 R1 c8 Y
+ k8 o* z% k- q, o: \6 Z; k7 { p& V$ k2 A
//宏定义
0 H4 D9 L! w0 d7 j#define uint unsigned int
a+ S9 Y |$ s#define uchar unsigned char% c4 o+ Y" I; P7 x; [1 _- @3 }
#define Data_ADC0809 P1: [7 l% H ~2 W: r8 E
) j. l, `% m4 T Z
//管脚声明
- @9 w3 Q. p9 T2 _4 x# \sbit Feng = P3^0;
0 t1 N4 d9 o+ j& K4 ]//ADC0809
# H/ A& L" @( [# y, h1 nsbit ST=P3^3;
8 C N; c- X' Z0 l6 l$ P, Jsbit EOC=P3^4;
% d& L4 [. D& X$ s. t& t4 E! jsbit OE=P3^2;0 J6 z4 g ]: u) c; U2 O4 w5 l
//按键
. O8 j2 [+ F k$ l4 csbit Key1=P3^5;
3 S2 b4 |' ? f& Fsbit Key2=P3^6;7 I% y9 r" s% W4 L
sbit Key3=P3^7;$ k' m; v# m6 O
, i ^5 ^7 ^- i
//显示数组 0-9+F$ A; ~+ @1 H+ Z; r6 k
uchar Data_[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x71,0x3f};
: _' E3 T( P9 @$ j- Q# V4 s4 `% s2 Usbit Wei1 = P2^7;
0 w5 `2 w J: Y* Wsbit Wei2 = P2^6;
: l# y9 p, W8 G3 v- Nsbit Wei3 = P2^5;; k$ G' n3 o3 G1 |3 ~
sbit Wei4 = P2^4;
# C% y' B: v6 s( [//函数声明
6 ]6 V$ v- |) \4 u7 yextern uchar ADC0809();% e% x h5 v* n" Y7 s: K' A* h% @
void Display(uchar X,uchar Data);
6 N, `( p Z# v/ y4 d& E8 Z7 ivoid delay(uint t);
( r/ ]2 A; x3 X! Z7 ? T8 y! [( p( Z8 f$ P
//酒精含量变量
0 w2 k7 \9 P# g! K% ]# F) t# i7 Luchar temp=0;
9 ~ }/ O& Y P+ E- U- l//蜂鸣器变量7 C7 a" l$ N2 y, K
uchar FF=10; i2 [1 a. y; x6 I, A4 ?5 g0 \
//显示模式
& Z z7 Q/ l, e7 g% k2 tuchar Mode=0;3 ] p N( Q4 I) u4 ^' b
uchar p;
( W" ]2 ]+ }! g6 t/ |0 b; f! Y/ _5 g" t6 U6 ]/ N0 i+ [, Q
void main()
$ Y1 R5 K+ @* ?6 h0 y0 r4 z{
: Z+ S, ~8 K, U* `8 c1 ? ?9 P# R# M+ C j9 t- K
while(1)
5 ~0 e/ R" w; I2 g& B7 i{
" u* [4 n+ ?1 ~$ Q) i/ Z& F; G//正常模式( K4 m$ A5 T( A
if(Mode==0)$ ?* e- A1 v. D
{; `+ h7 E( j( Z; H$ b
//读取AD值
. b" r6 j) @8 R% f! xtemp=ADC0809();% r3 d* U9 a7 ?1 Y
for(p=0;p<30;p++)
8 \; x% F) h& S5 RDisplay(0,temp);
; I/ T$ g2 _- E" S$ o+ y- f8 N//判断是否报警
8 j* _1 m2 D& T# x9 f; @if(temp>FF)- |* {: M) T1 \5 m
{
* e% u+ G- g' `: ]0 Z- R' t* MFeng=0;/ {0 Y8 r0 W4 k' C/ W9 `8 [/ U+ q
}* y9 v8 t, Y% j3 n( @
else
8 D, S/ E& g* ~9 m) x! w/ S{
4 }' N# F& ^0 O. ?Feng=1;' n- M" g( y, {3 n i$ |& [' \
}
2 j0 ~4 P6 q% t6 p$ P7 w}2 V- j: K0 i! g0 U; u0 m' K* {
//调整模式 a8 Z7 [# o7 ~4 ]* ?5 l* J
else; @/ `! `7 z7 ?' _- k6 }
{, H! i3 F- W, ~; O) y& v6 m. c
Display(1,FF);( Q' l& n* }& }/ F' Z
}
! D1 J" `( A9 l. B' ^9 Y9 F//功能键
- I; h5 p* G- Gif(Key3==0). J/ X) `3 j* b" V" y* E& d
{% O1 U4 l. F& d. J1 `* h/ ]
Feng=0;
7 i% s. C& c' V2 idelay(100);
/ A0 Q! e8 z0 Uwhile(Key3==0)
9 f# n, A/ N8 |( L8 M/ `{; n \4 L1 b; U, @$ m% G1 R2 o
if(Mode==0)
/ C# T8 K5 @+ \5 b# n ?+ ]/ xDisplay(0,temp);
1 n$ g: }% b! m& r" s6 s$ f( ^5 kelse
3 W* N9 {7 r E7 z! U. z8 CDisplay(1,FF);
9 u7 }' D6 p, M% v9 b}
' G6 I9 k x+ T& dif(Mode==0)
* y1 t8 [9 e: C) _ G4 J' ?Mode=1;
# o& S7 f% w# Q' S+ _else$ Q L% W) T# z) } y( M, [
Mode=0;" `3 n: S. z. Z& K: V" K
Feng=1;
% t- l( p4 p, N+ k}7 ]3 x+ [" c1 b- ?" I
//增加3 u# g0 E# }' s# e1 ^% O
if(Key2==0&&Mode==1)
/ F; b* M2 [4 [{
! |8 \$ F9 f2 l7 J$ A% iFeng=0;
, B/ I' U& I% U+ i; I( D- }delay(100);
3 Y4 V: Y$ l& [4 u- T" qwhile(Key2==0)
; M3 Y P3 l7 V& d{/ p: j% X; A1 I6 ~8 P% a
Display(1,FF); * p9 W0 S/ o1 p0 {
}
, K2 G7 F# [1 E7 V. fFF++;
, W; O7 R+ ~8 i3 X5 n: x- |/ |/ wif(FF==251) ) J0 k! E% c' B
FF=250;
4 ^" d. O3 z( A1 d0 @Feng=1;
3 C$ b% P4 B, k7 w7 O}8 z9 W- b% B6 B/ j Y; M
//减少
( a, E d8 w, Y" H' ^* C# i: K/ Qif(Key1==0&&Mode==1)
- `' g- J2 H9 Q2 Z) |. t; P$ [{
# l/ \' g8 P0 Z! A; bFeng=0;% S1 Z, u5 ~% ]* h9 B: S& N1 O
delay(100);. p8 w5 [# D6 O
while(Key1==0)/ Z0 g/ G8 B9 d4 o: v& T
{; r# }3 M& J; E% C& B& {' z
Display(1,FF); ) ?" X. q' S9 ?
}0 i" e' U6 @, ^& U
FF--;! y6 x- @, R/ X( R% i8 O0 y
if(FF==0xff) ! o H/ s3 s; I2 ]! m! ~9 ]% M: U
FF=0; 7 n4 U$ D6 ~9 Z( n ]; g; ~3 O
Feng=1;
6 F& \1 V' A* X N$ z- x( ^# z7 q}& Y& |8 _( G# o+ B8 c" S j: v9 w
}+ }8 f' J( t( O$ |3 q
}
- L* `- G' W4 p; X- k N$ U' r$ \" S//ADC0809读取信息
: }: F) p" I3 J: o7 Tuchar ADC0809()
$ ~& b* [0 {4 @/ S7 H{0 ^, u8 H: p, z5 L4 Q9 ~- P
uchar temp_=0x00;/ L$ g4 ]6 J7 [6 o
//初始化高阻太
& ?, u# J0 L7 Q" k2 n2 c; ROE=0;
: [) p9 W" |9 Q/ z3 C; l//转化初始化
" T. @5 G. F; ^5 FST=0;
0 \5 N$ a7 [. L, z//开始转换
$ {; P t6 [# L" |# KST=1;
u O7 Z4 L5 t n9 }3 KST=0;, a& x i' y/ F6 P9 q s5 h8 p, Z
//外部中断等待AD转换结束+ X6 I L" f5 D+ ], V+ M4 E9 i* g7 {
while(EOC==0): ?# P' ?2 |& T8 p+ @
//读取转换的AD值
! W+ Q! A# ?- f' ]# X8 o3 B; nOE=1;
K3 f3 @# U) i, _/ M, J1 ?" gtemp_=Data_ADC0809;" W5 a: n, a( `
OE=0;
! e" x; X( o0 m3 c/ r+ u6 xreturn temp_;
9 v0 W0 q' _3 R7 U; v}' l M) Z6 g8 o& i( i5 o! v
//延时8 `- M0 c* l/ v' h& H
void delay(uint t)
) l7 O- m F7 K1 ?- g8 r1 ^$ T{
/ m$ O. N/ _" v( z$ h* Cuint i,j; D+ g1 d+ j; b* a+ d0 g4 G. }" }
for(i=0;i<t;i++)7 p' y O0 t9 C! z( L
for(j=0;j<10;j++);
7 Y) j0 q: E2 A, ^/ X* f/ U}) q' F$ `6 g( G5 v/ C3 T5 D
' H6 v0 C5 G# B- p, m% |
//显示 X表示状态 Data表示数据
# y5 S; y4 p. j8 O( ?- Nvoid Display(uchar X,uchar Data)( ~0 z' u" p( U0 G
{( H9 ]- F! n4 q: M6 `7 q C
Wei1=1;% Z5 C8 B. {! b0 U7 g
Wei2=1;# O* n" s8 ^1 a0 g0 E& k
Wei3=1;
8 n( T/ y4 Z% F: _Wei4=1;, T; S; Q" Q2 m8 Z1 A
P0=0xff;, M4 `, t8 h0 B8 A9 R
- F4 Y. ^ r4 c3 L$ @//正常模式
z. r5 N0 _& y4 `$ b) k9 q( C2 oif(X==0)( U; i6 T& B }5 m
{/ u: U: j3 C: ?. C7 Q9 D
P0=~Data_[11];
- {9 w* n3 } R" ^+ w& q' a}
: ?/ P6 X% \& u# L7 o& Q//非正常, S8 R$ U. c+ j7 g% `3 A4 n
else3 A& ~6 @! `7 O
{
7 s9 ~3 ^# W3 f C% ~2 WP0=~Data_[10];1 n' P0 i& T/ G, K7 m
}
' `/ t9 d2 r$ L& J' RWei1=0;
5 l# J4 p0 Y) [- x+ ^% L' t. FWei2=1;
2 m5 z8 |' {2 q0 bWei3=1;
. b- A9 N3 F2 GWei4=1;
& ?* T. r3 r* f: J* x7 H! J! ~: bdelay(10);+ w( [6 i8 O+ W) ?
Wei1=1;
- ^, r. ^! ]) ?* o3 t: QWei2=1;
: f f/ s& p) [% n! kWei3=1;
; ?5 p+ H) }# ]* y, K8 @9 j9 |, OWei4=1;4 p- y' O6 x+ d0 S
% Z0 l1 A: K5 ~+ _9 _P0=~Data_[Data/100];
& Y) e) A |0 U/ D$ o4 q$ oWei1=1;
1 u8 A3 h6 i SWei2=0;3 _# P/ n; v& G6 l$ w( F8 p
Wei3=1;" `; P" u$ j- T2 H6 B
Wei4=1;
# a" g* h% J* ?: a8 _! `3 Pdelay(10);
( p* C4 }5 B8 k( y; s+ NWei1=1;
9 ~# D5 g" B, T" @Wei2=1;
- O) ~4 y& ~: QWei3=1;
, f- A8 U: ^0 ?) {8 X$ _Wei4=1;
- s* s$ {! }& i6 y# m: ^# x. M; o- C& U% s+ _" Y# A. @
. k* e4 g: ~+ {6 S3 `P0=~Data_[Data/10%10];4 ]' a% L, N: U( T [. \7 b
Wei1=1;5 j4 U, ?* d8 U
Wei2=1;" H+ T6 m1 d3 P! h. ^
Wei3=0;
' [0 g5 _5 d2 H( M+ Z. B$ w7 a; ^Wei4=1;1 r ]1 t9 e" d: j8 t. P7 A6 s! q5 |
delay(10);
/ h! z z. p" l! KWei1=1;/ f. t- R$ R2 P, a; V
Wei2=1;
/ y, Y0 B6 G6 GWei3=1; i4 @. P, h% P6 T
Wei4=1;
$ S6 E6 t$ a2 w) e0 z, X- ]; B3 a7 |# q
P0=~Data_[Data%10];
* p, H5 G3 _, m2 e/ p8 O: fWei1=1;
( s/ t) C4 M( j3 F$ OWei2=1;( Y" o4 E3 R/ o( `6 u) J: w6 x
Wei3=1;
' x1 E( {: B1 k' v- JWei4=0;
$ a( T4 R( Z1 A# I* z' Gdelay(10);
$ J- j0 r! G% U2 U7 r7 tWei1=1;4 Q4 B" J3 q& j
Wei2=1;
G/ S4 c" n" D% J; t' ?Wei3=1;
( S3 j+ v7 M# K( ~Wei4=1;; ^0 y% k# B! ?; P/ _/ x
5 K% i, v6 @8 U+ p8 L! Q}
' `4 _# s; x/ P1 a! }3 m0 [; ~2 ]1 ]$ O
|
|