|
可以参考的一个程序
- /***************************************************************************
- 本实验例程是用NEC红外线接收解码程序(红外线接收部分为板子配的林洋电子程序)
- 程序功能:
- 1、运行程序,按遥控器按键,在数码管上显示相应的控制码(以16进制显示);
- 2、对特别的几个键,有相应的现象出现:
- (1)电源键,使继电器工作或断开;
- (2)静音键,使蜂鸣器响或不响;
- (3)快进键让LED灯向右出现一次走马灯现象;
- (4)快退键让LED灯向左出现一次走马灯现象;
- (5)按0~9,数码管显示所按的键号;
- (6)按其它键,不会改变已经按的数字键的显示,表示看电视台开关电源或静音、快进快退,都不会
- 改变台号。
- (7)其它键没想好怎么以现有板产生相应功能,所以按下后,没有特别现象,只有显示其控制码。
- ******************************************************************************/
- #include "reg51.h"//头文件:
- #define LED8 P2//红外遥控功能之一是让LED灯亮,所以要将P2口改名
- sbit hwx=P3^3; //红外接收数据引脚,也是外部中断1的I/O口
- sbit SMG_q = P1^0; //定义数码管阳级控制脚(千位)
- sbit SMG_b = P1^1; //定义数码管阳级控制脚(百位)
- sbit SMG_s = P1^2; //定义数码管阳级控制脚(十位)
- sbit SMG_g = P1^3; //定义数码管阳级控制脚(个位)
- sbit JDQ=P1^4; //继电器
- sbit Beep = P1^5 ; //蜂鸣器
- code unsigned char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
- 0x88,0x8c,0xc6,0xa1,0x86,0x8e}; //共阳数码管段值表 0-9 a-f
- unsigned char ly_disdate[4]={0,0,0,0};
- unsigned char ly_lhj[4],i;
- bit ly_flag=1;
- void display();
- void delay(void);
- void Delay10ms(unsigned int c)
- {
- unsigned char a,b;
- for(c;c>0;c--)
- for(b=38;b>0;b--)
- for(a=130;a>0;a--);
- }
- void main(void)//主函数
- {
- EA=1;
- EX1=1;
- IT1=1;
- TMOD=0X10;
- JDQ=1;
- ly_flag=0;
- while(1){
- if(ly_flag){
- ly_flag=0;
- if ((ly_lhj[2]==0x45))
- {
- JDQ=~JDQ;
- }
- if ((ly_lhj[2]==0x47))
- {
- Beep=~Beep;
- }
- if ((ly_lhj[2]==0x40))
- {
- LED8=0xfe;
- for(i=0;i<8;i++)
- {
- Delay10ms(10);
- LED8=LED8<<1;
- }
- LED8=0xff;
- }
- if ((ly_lhj[2]==0x43))
- {
- LED8=0x7f;
- for(i=0;i<8;i++)
- {
- Delay10ms(10);
- LED8=LED8>>1;
- }
- LED8=0xff;
- }
- if ((ly_lhj[2]==0x16))
- {
- ly_disdate[0]=0;
- }
- if ((ly_lhj[2]==0x0c))
- {
- ly_disdate[0]=1;
- }
- if ((ly_lhj[2]==0x18))
- {
- ly_disdate[0]=2;
- }
- if ((ly_lhj[2]==0x5e))
- {
- ly_disdate[0]=3;
- }
- if ((ly_lhj[2]==0x08))
- {
- ly_disdate[0]=4;
- }
- if ((ly_lhj[2]==0x1c))
- {
- ly_disdate[0]=5;
- }
- if ((ly_lhj[2]==0x5a))
- {
- ly_disdate[0]=6;
- }
- if ((ly_lhj[2]==0x42))
- {
- ly_disdate[0]=7;
- }
- if ((ly_lhj[2]==0x52))
- {
- ly_disdate[0]=8;
- }
- if ((ly_lhj[2]==0x4a))
- {
- ly_disdate[0]=9;
- }
- ly_disdate[2]=ly_lhj[2]/16;
- ly_disdate[3]=ly_lhj[2]%16;
- }
- display();
- }
- }
- void hongwai(void) interrupt 2
- {
- unsigned char i,ia;
- TL1=0;
- TH1=0;
- TR1=1;
- while(!hwx);
- TR1=0;
- if(TH1<30||TH1>40)
- {
- return;
- }
- TH1=0;
- TR1=1;
- while(hwx) //
- {
- delay();
- if(TH1>22)
- return;
- }
- TR1=0;
- if(TH1<12)
- return;
- for(i=0;i<4;i++)
- {
- for(ia=0;ia<8;ia++)
- {
- while(!hwx);
-
- TH1=0;
- TR1=1;
- while(hwx)
- {
- delay();
- if(TH1>15)
- return;
- }
- TR1=0;
- ly_lhj[i]>>=1;
- if(TH1>4)
- ly_lhj[i]|=0x80;
- }
- }
- ly_flag=1;
- TF1=0;
- }
- void display()
- {
- SMG_q=0; //选择千位数码管(亮)
- P0=table[ly_disdate[0]]; //
- delay(); //
- P0=0XFF; //
- SMG_q=1; //(灭)
- SMG_s=0; //选择十位数码管
- P0=table[ly_disdate[2]]; //
- delay(); //
- P0=0XFF; //
- SMG_s=1; //
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
下载:
hwx.rar
(1.54 KB, 下载次数: 30)
|
|