MCU:STC8单片机
解码协议:EV1527
显示:LCD1602
单片机源程序如下:
- #include "time.h"
- #include "uart.h"
- #include "delay.h"
- #include "task.h"
- ////////////////////////////////
- unsigned char decode_ok;
- unsigned int hh_w,ll_w;
- unsigned char ma_x;
- unsigned char bma1,bma2,bma3,bma4;
- unsigned char mma1,mma2,mma3,mma4;
- unsigned char mmb1,mmb2,mmb3,mmb4;
- //extern uint8_t mmb1,mmb2,mmb3,mmb4;
- unsigned char rf_ok1,rf_ok2,rf_ok;
- unsigned char old_rc5;
- unsigned char tb_ok;
- unsigned char D0,D1,D2,D3 ;
- unsigned int s ,s1;
- unsigned char bt_auto;
- unsigned char rf_data[4];
- void rexode_433M(void);
- //bit open_led_flag=0;
- unsigned char count_5ms=0;
-
- extern unsigned char code out[];//LED数组
- extern u8 add1,spacing,mode;//地址,间隔时间,模式
- //////////////////////////////////////////
- void Timer0Init(void)
- {
- TMOD|=0x00;
- TL0=65536-10; //定时10ms
- TH0=(65536-10)>>8;
- /////////////////////以下STC12/////////////////////
- // TL0=65536-46; //定时10ms,系统时钟12分频后,定时1的时钟为2.25M,
- // TH0=(65536-46)>>8;
- TR0=1;ET0=1; //定时器0 ,定时16位模式
- EA=1;
- }
- //////////////////////////////////////////
- void timer0_interrupt(void) interrupt 1
- {
- TL0=(65535-50)%256; //定时50us,
- TH0=(65535-50)/256;
- count_5ms++;
- TX_433M_pin=~TX_433M_pin;
- rexode_433M();
- }
- //////////////////////////////////////////////
- void rexode_433M(void)
- {
- if (!RF)
- {
- ll_w++;
- old_rc5=0;
- }
- else
- {
- hh_w++;
- if (!old_rc5)
- { // 2/5 100/130
- if (((hh_w>=2)&&(hh_w<=15))&&((ll_w>=160)&&(ll_w<=320)))
- {
- tb_ok = 1 ;
- ma_x = 0;
- bma1=0; bma2=0; bma3=0; bma4=0;
- }
- else if ((tb_ok)&&((ll_w>=19)&&(ll_w<=33))) //8/13
- {
- ma_x++;
- if(ma_x>23)
- {
- if(!rf_ok1)
- {
- mma1=bma1;
- mma2=bma2;
- mma3=bma3;
- mma4=bma4;
-
- rf_ok1=1;
- tb_ok=0;
- s=10000;
- }
- else
- {
- mmb1=bma1;
- mmb2=bma2;
- mmb3=bma3;
- mmb4=bma4;
-
- rf_ok2=1;
- tb_ok=0;
- }
- }
- }
- else if ((tb_ok)&&((ll_w>=2)&&(ll_w<=14))) // 2/7
- {
- switch (ma_x)
- {
- case 0 : { bma1=bma1 | 0x01; break; }
- case 1 : { bma1=bma1 | 0x02; break; }
- case 2 : { bma1=bma1 | 0x04; break; }
- case 3 : { bma1=bma1 | 0x08; break; }
- case 4 : { bma1=bma1 | 0x10; break; }
- case 5 : { bma1=bma1 | 0x20; break; }
- case 6 : { bma1=bma1 | 0x40; break; }
- case 7 : { bma1=bma1 | 0x80; break; }
- case 8 : { bma2=bma2 | 0x01; break; }
- case 9 : { bma2=bma2 | 0x02; break; }
- case 10: { bma2=bma2 | 0x04; break; }
- case 11: { bma2=bma2 | 0x08; break; }
- case 12: { bma2=bma2 | 0x10; break; }
- case 13: { bma2=bma2 | 0x20; break; }
- case 14: { bma2=bma2 | 0x40; break; }
- case 15: { bma2=bma2 | 0x80; break; }
- case 16: { bma3=bma3 | 0x01; break; }
- case 17: { bma3=bma3 | 0x02; break; }
- case 18: { bma3=bma3 | 0x04; break; }
- case 19: { bma3=bma3 | 0x08; break; }
- case 20: { bma3=bma3 | 0x10; break; }// ?????1?
- case 21: { bma3=bma3 | 0x20; break; }
- case 22: { bma3=bma3 | 0x40; break; }
- case 23: { bma3=bma3 | 0x80;
- if(!rf_ok1)
- {
- mma1=bma1;
- mma2=bma2;
- mma3=bma3;
- // mma4=bma4;
- rf_ok1=1;
- tb_ok=0;
- // bt_auto=0;
- s=10000;
- break;
- }
- else
- {
- mmb1=bma1;
- mmb2=bma2;
- mmb3=bma3;
- //mmb4=bma4;
- rf_ok2=1;
- tb_ok=0;
- break;
- }
- }
- }
- ma_x++;
- }
- else
- {ma_x=0; tb_ok=0;bt_auto=0;bma1=0;bma2=0; bma3=0; hh_w=1;ll_w=0;}
- ll_w=0;hh_w=1;
- }
- old_rc5=1;
- }
- if(rf_ok1)
- {
- s--;
- if(!s) rf_ok1=0;
- if(rf_ok2)
- {
- if((mma1==mmb1)&&(mma2==mmb2)&&(mma3==mmb3))
- {
- rf_ok=1;
- rf_ok1=0;
- rf_ok2=0;
- }
- else
- {
- rf_ok=0;
- rf_ok1=0;
- rf_ok2=0;
- }
- }
- }
- if((rf_ok))
- {
- TR0=0;
- rf_ok=0;
- rf_data[0]=mma1;
- rf_data[1]=mma2;
- rf_data[2]=mma3;
- SendOneByte(rf_data[0]);
- SendOneByte(rf_data[1]);
- SendOneByte(rf_data[2]);
- decode_ok=1;
- TR0=1;
- }
- }
- ////////////////////////////////////////////
- void EV1527_decoding()
- {
- char i=0;
- /////////////////解码值////////////////////////////////
- if(decode_ok)
- {
- decode_ok=0;
- switch(rf_data[2])
- {
- case 0x19: OUT1=~OUT1;rf_data[2]=0;break;//1号键
- case 0x29: OUT2=~OUT2;rf_data[2]=0;break;
- case 0x49: OUT3=~OUT3;rf_data[2]=0;break;
- case 0x89: OUT4=~OUT4;rf_data[2]=0;break;
- case 0x39: OUT5=~OUT5;rf_data[2]=0;break;
- case 0x59: OUT6=~OUT6;rf_data[2]=0;break;
- case 0xa9: OUT7=~OUT7;rf_data[2]=0;break;
- case 0x69: OUT8=~OUT8;rf_data[2]=0;break;
- case 0x79: OUT9=~OUT9;rf_data[2]=0;break;
- case 0xe9: OUT10=~OUT10;rf_data[2]=0;break;//10号键
- /////////////11键亮(流水)/////////12键灭(流水)////////////////////////////////////////////
- case 0X99: //解码 遥控器11键
- {
- delay_ms(1);
- led=out[i];//led灯开始往后面亮delay_ms(2);//led灯开始往后面亮
- i++;
- delay_ms(spacing*100);
- if(i>8)//如果led灯亮完了
- {
-
- i=8;
- led=0xff;rf_data[2]=0;
- }
- }break;
- case 0Xd9: //解码 遥控器12键
- {
- delay_ms(1);
- led=out[i];//灭-》灭
- i--;
- delay_ms(spacing*100);
- if(i<0)
- {
-
- i=0;led=0x00; //p35=1;
- rf_data[2]=0;
- }
- }break;
- }
-
- }
-
-
- }
复制代码
#include "time.h"
#include "uart.h"
#include "LCD1602.h"
#include "delay.h"
#include "key.h"
#include "task.h"
///////////////////////////////////////////////////////
extern u8 xdata U1RxBuf[];
extern u8 add;
extern bit flag;
extern unsigned char Uartflag ; //UART判断标志位
extern char Recive_state ; //接收完成标志
/********************************************************************
主函数
*********************************************************************/
void main()
{
InitUART();
Timer0Init();
///////////////配置端口为双向口////////////////////////
P1M0=0X00;
P1M1=0X00;
P2M0=0X00;
P2M1=0X00;
P3M0=0X00;
P3M1=0X00;
Init_LCD1602();;//lcd初始化
delay_ms(10);
LCD_Clear(); //清屏
//////////////////////LOGO///////////////////////////
LCD1602_write_com(0x80); //指针指向第1行第0个位置
LCD1602_write_word(" BLD ");//宝蕾德电子产品
LCD1602_write_com(0x80+0x40); //指针指向第2行第0个位置
LCD1602_write_word("0~10s APPLE:S118");
delay_ms(100);
LCD_Clear();//清屏
LCD1602_write_com(0x80); //指针指向第1行第0个位置
LCD1602_write_word(" ");
LCD1602_write_com(0x80+0x40); //指针指向第2行第0个位置
LCD1602_write_word("spacing: s~ "); //
// spacing=IapRead(0x0000); //EEPROM 读0x0000到hc[0]
// add1=IapRead(0x0002); //EEPROM 读0x0002到hc[1]
// mode=IapRead(0x0004); //EEPROM 读0x0002到hc[2]
delay_ms(2);
spacing_data();
P2=0x00;
while(1) //无限循环
{
EV1527_decoding();//解码
display_zhu();
}
}
原理图: 无
仿真: 无
代码:
STC8-解码433M EV1527 串口发送OK版.rar
(84.37 KB, 下载次数: 68)
|