TA的每日心情 | 难过 2019-11-20 15:02 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
提取单片机遥控器的控制码,但无论按那个键,控制码始终是0x00
/ S( Y- N& I+ Y, }( M7 o+ |
7 |8 A" o: s, |) [$ k E#include "reg52.h"
! i6 n, l! C0 ~typedef unsigned char u8;
+ ^3 `, l; K; O3 ]7 ^; m- Ctypedef unsigned int u16;, [# L7 U: b% [! f( @- v5 ?, Y
9 y R+ {- w0 }: V; y, | m ]sbit LSA=P2^2;
& B- J& |1 z$ l4 ]8 hsbit LSB=P2^3;; ]9 K. E) w/ I
sbit LSC=P2^4;
. G' d: T0 W0 Isbit IRIN=P3^2; //这是红外线接收口* A( |! M& |5 E3 @& k
: v2 p/ e5 R4 o. ^! x
u8 IrValue[6]; //这里存储的是遥控器发过来的数码
. [1 c$ z4 Q1 R# iu8 time; V& N# _1 J9 z4 \! g J
u8 displayData[8];! X9 g4 Q" k* Y/ e5 I
u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x76};
. Y, `* ^7 V4 `2 }$ v K6 r5 q. j; ^; i2 F9 h
delay(u16 i)1 M) ]! ~- {; B1 p% y
{
( @/ T; y# P; H while(i--);
) H4 ^' o9 t, z$ |) \* k( p( f}- p: o# O; L2 T/ o# R+ d+ O/ c
" s, j- V$ k9 b6 N4 v! \void DigDisplay()
0 g1 m- U; m5 o& i6 Q1 \{
$ G& Z: S0 H$ {. [ u8 i;
3 J: q" w4 g+ _0 |( ` for(i=0;i<3;i++)8 s Q* T6 j, p1 N( d0 E8 I7 s
{7 e" {9 m9 }, M# y5 `# ^
switch(i)
$ z$ U5 M+ r4 J* F% o; D {! o( Y+ O3 \* b6 O
case(0): LSA=1;LSB=1;LSC=1;break;
j0 w1 T2 W) b' W: J( x$ S0 t case(1): LSA=0;LSB=1;LSC=1;break;+ V: e# K( E/ o
case(2): LSA=1;LSB=0;LSC=1;break; ^- ^" Y% H4 p$ u
}) c" l1 A$ |8 v0 x; @+ }
P0=DisplayData;
0 r5 g, c+ K- `1 e- C5 J# ? delay(100);( h7 _; O6 H) ~
P0=0x00;
2 a. D2 s, H1 g- _ }
1 v/ H) N2 m9 h0 J}0 _$ Z+ O1 v; P
" K' q7 A: s0 R+ B. N; wvoid IrInit()' u% j3 _' U- a) Y
{" a4 D6 M7 W( O: z4 k: R/ m
IT0=1;
0 j D+ N' ]& K. x, J6 R- d/ V EX0=1;
/ I7 ?3 @3 i& G. l+ I EA=1;3 ]! R8 m! x, w# T4 i; Z
IRIN=1;
; z2 [( C+ W& G3 j7 O& p8 v}3 t, G: }. K" V1 P
/ E3 `( a% b% y; U/ q7 c- \
void main()
8 C# @ ~. i4 F{
: g; p7 y( G8 `' {3 }( } IrInit();( Z! u2 }0 a* A6 n4 w$ O M
while(1)
1 O% f6 L- _9 ^+ w: z {
2 `0 Q; R% y- u3 s; N DisplayData[0]=smgduan[IrValue[2]/16] ;
( r2 E# `. ?' `5 k( @& n7 Q" j DisplayData[1]=smgduan[IrValue[2]%16] ;
' v( R' V3 ]" q: \4 Z" V" Q- j DisplayData[2]=smgduan[16] ;
4 F: F4 d: U# W' B: L0 N DigDisplay();/ W, s7 E2 X, o% K; V- S T1 S, N
}
2 z4 ^* I- H6 u6 c}
2 W" \ _: @! M
! \0 h+ S- i Q. evoid ReadIr() interrupt 0
& \2 ?8 q! `: Y7 y{0 k! @1 o3 x" h
u8 j,k;4 O5 \" [8 n2 Z+ y% w U1 e$ T! C
u16 err;
! J5 Z: `) F: n9 S1 c Time=0;
+ L# E j* ]1 [" o+ s9 f; P/ } delay(700);+ Y6 \2 v7 x' n" C4 s, y
if(IRIN==0)8 v. e! q) D& r
{
8 a; v) f& i. S; s err=1000;- ^1 @" z+ p2 Y, N# Q5 j
while((IRIN==0)&&(err>0))
. N3 d- D4 H. X6 P {; X u5 V7 Z! `( B- ]- k' p
delay(1);/ q9 E3 N$ t6 E" j. K1 e6 V7 ^+ U7 f
err--;
/ \0 Y0 [8 j1 @& h }4 g. T5 s# N9 t% t6 o
if(IRIN==1)) ]( F) y) i: s% y8 j9 }
{9 N& I: f' E3 \) M2 b% q9 Z1 w
err=500;
0 n# o" X1 s N6 f/ c5 U; b while((IRIN==1)&&(err>0))
5 y6 X1 g- ^2 l# h {
) l4 p% x) n1 e: t delay(1);. i' Q/ |# H% Z
err--;) `' z. L! v8 ?5 @5 H3 ]4 v
}1 t' f0 u3 |$ M% N. b
for(k=0;k<4;k++)
, r3 F: v6 H9 E( s! W {
5 ?' I# f" N( ` U9 R for(j=0;j<8;j++)6 m2 \1 D7 Y, j0 G2 ?! K
{- H: E% \. A6 I# N
err=60;
2 O+ E2 U' L# u/ y5 m4 B while((IRIN==0)&&(err>0)). I) B. d# }' m( o( l/ {; F, M& O- b
{ G. T* B- e1 I3 d1 X
delay(1);
; }# _9 s- P$ z$ N; |8 m, x err--;: J9 i7 Z& v" K
}
, o+ J+ t9 G7 I7 h- d6 b( x err=500;
1 Z6 \' V* n4 E0 i+ `9 @: D) v+ c while((IRIN==0)&&(err>0))6 S$ ^" c% e0 L9 f$ b
{
- \2 f& a/ _: o1 J A delay(10); W1 M ]/ [0 L' ~9 l- x6 W
Time++;" W* w# q' A( l' w. |& {
err--;0 G, b1 o( }4 e* ]$ u/ M6 B
if(Time>30)
9 H* m2 {# W$ N6 w( I {
' p# l6 g. ^$ _ d. D return;: l+ A$ b) Y+ i. Y
}$ [- X4 i1 r, }. ]/ a! T3 m @" E
}
0 T2 ~0 _$ \% ~" a$ y% Y# f IrValue[k]>>=1;
# e F2 E6 V, \" P if(Time>=8)
/ F. X! |6 S! B4 w6 b. t# ]- j {
, _2 f* C* L5 W6 D IrValue[k]|=0x80;* O: E/ T. P' b0 i8 E2 W
}4 Z) a7 @8 y' F; c
Time=0;% B: L8 |9 t$ t0 T3 ^
}
$ H1 d0 p/ r- m; w2 O3 A6 h! c }
) W- ]! b4 t1 C/ ` }+ b4 m& _+ V- G. j) K" i0 c' e
if(IrValue[2]!=~IrValue[3])
+ V. e7 a( ~7 Y2 `0 m$ f8 z {5 B# G# B; n1 a4 ^/ E: v
return;
0 }) Q$ ]2 F# e8 p v7 f% Z ^) h } 3 X& H' x- z8 p1 `. B- t, w
}! T7 e, \' t4 w" ?0 z0 k' q% r$ k
} 9 {8 d: x9 z( s4 z; D% l! G9 r2 E# K
|
|