|
include <reg51.h>
2 P/ G% v8 k1 Z; e#define uchar unsigned char
% y# y- @1 I- p#define uint unsigned int
& \3 k3 P5 ?( b* M, l4 X
, q. U, d) d }) k& c: \sbit INT1=P3^1;中断0 6 c+ Y8 G: B' S
sbit FEN=P3^6; 蜂鸣器
4 l {0 x8 ^9 T3 s0 p6 M0 T6 {( K/ \) N1 i5 J: i$ N* h; o
void delay(uint x); F, v5 q N$ }# |, }+ ~* f4 D
{% P1 j0 g- T' W4 F# @* ^, R* w7 P
uint a,b;
3 z+ L2 i J2 E/ M5 X for(a=x;a>0;a--)
( p2 g) W5 D4 K for(b=10;b>0;b--);
8 Q; P$ s5 s& W8 t0 f: K; k}
. H) P { ], q r8 |% ^; L) l$ U2 x" }" m$ V: J( O
main()
8 C. o8 @, t. T* [0 \{
2 H& I/ \& ]2 g) b d5 l# i EA=1;//开总中断8 o) ?2 A. j/ i% f
EX0=1;//开外部中断0
. A* L! X2 n, E& V% r$ W+ C; D4 U% N$ d4 k3 s+ @# E
while(1);0 `' y m$ V3 n" U! L" E' o
}- ]' A4 j# I" m- T* k* ], a
void exter0() interrupt 0* H m7 I. _/ q X+ Q, s* P0 D/ c1 @
{- E- u9 P8 d" y8 k8 ]. P
FEN =0;
3 s. v% X5 ~+ f( ?5 U. K delay(1000);2 l& a, N, J- a- ?% ?! s! w9 w
FEN=0;
$ k. P! s9 L: Y; |9 j; }; H}5 m8 _+ l2 u8 `
9 D- l( l1 R% U1 i6 y4 q
1 K- s' {, w4 w. {" Z& ~
- C& w# |9 E- \- W/ Q0 |+ x我忘了外部中断0的引脚了,记得好像是3.1,你回去查查,如果是就不用改了,不是就把这个引脚改过来,这个引脚接红外传感器的输出。 |
|