|
给你一个C51代码,WORD说明有图,发不上来,就算了,如果需要可与我联系.
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- sbit sm1623_dout=P1^0;
- sbit sm1623_din=P1^1;
- sbit sm1623_clk=P1^2;
- sbit sm1623_stb=P1^3;
- sbit hw_send=P1^4;
- sbit sound=P1^5;
- sbit P3_2=P3^2;
- void delay(uchar delay_temp);//长延时
- void delaym(uchar delaym_temp);//短延时
- void disp(uchar dis);
- void display();
- uchar key(void);
- uchar key_deal(void);
- uchar i,j,k;
- uchar temp_1,temp_2;
- uchar code_dis[6];
- uchar pulse;
- uchar hw[34];
- const uchar code hw_t[13]={3,2,3,2,6,2,3,2,3,2,3,2,3};
- const uchar code hw_1[12]={2,3,2,3,2,3,2,3,2,3,5,3};
- const uchar code hw_2[12]={2,3,2,3,2,3,2,3,5,6,0,0};
- const uchar code hw_3[12]={2,3,2,3,2,3,2,3,5,3,2,3};
- const uchar code hw_4[12]={2,3,2,3,2,3,5,6,2,3,0,0};
- const uchar code hw_5[12]={2,3,2,3,2,3,5,6,5,3,0,0};
- const uchar code hw_6[12]={2,3,2,3,2,3,5,3,2,6,0,0};
- const uchar code hw_7[12]={2,3,2,3,2,3,5,3,2,3,2,3};
- const uchar code hw_8[12]={2,3,2,3,5,6,2,3,2,3,0,0};
- const uchar code hw_9[12]={2,3,2,3,5,6,2,3,5,3,0,0};
- const uchar code hw_0[12]={2,3,2,3,2,3,2,3,2,3,2,3};
- //红外测试程序
- exint0() interrupt 0
- {
- TR0=0;TR1=0;//关闭定时器0、1
- if(pulse>15)
- {
- TR0=0;TR1=0;
- TL0=0;TH0=0;TL1=0;TH1=0;
- pulse=0;
- return;
- }
-
- hw[pulse*2]=TH1-TH0;//低电平宽度
- hw[pulse*2+1]=TH0;//高电平宽度
- TL0=0;TH0=0;TL1=0;TH1=0;//定时器赋初值
- TR0=1;TR1=1;//打开定时器0、1
- delaym(10);//延时判断是否是干扰脉冲(干扰脉冲比较窄)
- P3_2=1;//判断INT0输入端是否为高电平,如是高电平说明是干扰脉冲
- if(P3_2==1)
- {
- TR0=0;TR1=0;
- TL0=0;TH0=0;TL1=0;TH1=0;
- pulse=0;
- return;
- }
- pulse++;
- }
- timer0() interrupt 1
- {
- uchar i;
- if(temp_2==0)//红外接收
- {
- TR0=0;TR1=0;//关定时器
- TL0=0;TH0=0;TL1=0;TH1=0;//定时器赋初值
- pulse=0;
- for(i=0;i<16;i++)
- {
- hw[2*i]=0;
- hw[2*i+1]=0;
- }
- hw[20]=0;
- }
- else//红外发送
- {
- if(pulse==26)
- {
- EA=0;
- TR0=0;//关闭定时器0
- hw_send=1;
- return;
- }
- if(hw[pulse]!=0)
- {
- TH0=0xff-hw[pulse];
- TL0=0xe0;
- pulse++;
- hw_send=!hw_send;
- }
- else//遇到最后一个脉冲
- {
- EA=0;
- TR0=0;//关闭定时器0
- hw_send=1;
- pulse=26;
- }
- }
- }
- timer1() interrupt 3
- {
- uchar i;
- EA=0;
- TR0=0;TR1=0;
- hw[2*pulse]=256-TH0;//可以计算最后一个低电平宽度
- TL0=0;TH0=0;TL1=0;TH1=0;
-
- //获得遥控按键键值并显示
- if(memcmp(hw+15,hw_1,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=1;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_2,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=2;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_3,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=3;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_4,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=4;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_5,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=5;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_6,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=6;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_7,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=7;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_8,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=8;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_9,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=9;
- display();
- goto hw_ok;
- }
- if(memcmp(hw+15,hw_0,12)==0)
- {
- sound=0;//鸣响
- code_dis[5]=0;
- display();
- }
- hw_ok: pulse=0;
- for(i=0;i<16;i++)
- {
- hw[2*i]=0;
- hw[2*i+1]=0;
- }
- hw[20]=0;
- EA=1;
- }
- main(void)
- {
- start:
- hw_send=1;
- temp_2=0;
- //---------------------------------------红外接收测试
- pulse=0;
- EA=0;
- TL0=0;
- TH0=0;
- TL1=0;
- TH1=0;
- TMOD=0x19;//T0受INT0控制、T0、T1为定时,工作方式1
- IT0=1;//外部中断0为边沿触发方式
- EX1=0;//不允许INT1中断
- EX0=1;//允许INT0中断
- ET1=1;//允许T1中断
- ET0=1;//允许T0中断
- EA=1;//允许中断
-
- for(i=0;i<5;i++)code_dis[i]=13;
- code_dis[5]=10;
- display();//最后一位显示黑
- while(key_deal()!=8)
- {
- delay(0xff);
- if(code_dis[5]!=10)
- {
- sound=1;//关鸣响
- code_dis[5]=10;
- display();//最后一位显示黑
- }
- }
-
- //---------------------------------------红外发送测试
- EA=0;//关中断
- temp_2=0xff;//表示定时器0中断中执行红外发送程序
- pulse=26;
- TL0=0;
- TH0=0;
- TL1=0;
- TH1=0;
- EX1=0;//不允许INT1中断
- EX0=0;//不允许INT0中断
- ET1=0;//不允许T1中断
- ET0=1;//允许T0中断
- code_dis[5]=10;
- display();
- sound=0;
- delay(0xff);
- sound=1;
- memcpy(hw,hw_t,15);
- for(i=0;i<5;i++)code_dis[i]=14;
- code_dis[5]=10;
- display();
-
复制代码 |
|