MCU infrared decoding, short press to turn on and off the light, long press to dim, digital tube to display key value

Publisher:创意驿站Latest update time:2020-09-04 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//Infrared decoding, the experimental board tested normal, the 8-bit digital tube displays the remote control code (user code, user inverse code, the 3-digit digital tube on the right displays the PWM value),
//Two 74hc573 drives the 8-bit common cathode digital tube
//CH- key short press to turn on and off the light, + key long press to dim, the digital tube displays the key value; the decoding program for long press dimming is currently difficult to find on the Internet, I pondered for a long time before I adjusted the program//The compressed package contains the complete program code and the waveform of the burst code tested by the logic analyzer
 

The microcontroller source program is as follows:

#include "INCSTC89C52RC.H"

#include "INCMY_SET.H"

#include "INCIR_NEC.H" //Call NEC decoding header file



#define DIGI_PORT P0 // Macro definition of digital tube port. If the port changes, just modify this sentence

#define DIGI_NUM 8 // Macro definition of the number of digital tubes

unsigned char digiBuf[DIGI_NUM]; //Digital tube buffer

sfr SE = 0x80; //Digital tube segment selection P0: 0x80 P1: 0x90

sbit wela = P2^7; //bit selection

sbit dula = P2^6; //segment selection



sbit led = P1^2;


uint8 PWM_Val=200; //Duty cycle variable

uint8 flag; //Switch light flag

uint8 flag1; //dimming direction flag

uint8 count;

uint8 flag2; //

uint8 num,pwm;

                                // 0 1 2 3 4 5 6 7 8 9 A B C D E F not displayed -

uint8 code d[]={ 0x3F,0x06,0x5B,0x4F,0x66, 0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00,0x40}; //Digital tube segment code Common cathode without decimal point segment code


void KZ0(); //Short press processing

//void KZ1(); //Long press processing



/***************** Main function************************/

void main(void)

{

        IR_Init(); //Initialize infrared decoding

        while(1)

        {

          //Remote control detection

                   if(IR_BT==2)

                {

                         KZ0(); //Short press processing

                        IR_BT =0; // Clear valid flag

                //Update the display

                        digiBuf[0] = NEC[0]/16; //User code               

                        digiBuf[1] = NEC[0]%16;   

                        digiBuf[2] = NEC[1]/16; //User inverse code

                        digiBuf[3] = NEC[1]%16;

        // digiBuf[4] = NEC[2]/16; //data code

        // digiBuf[5] = NEC[2]%16;

        // digiBuf[6] = NEC[3]/16; //Data inverse

        // digiBuf[7] = NEC[3]%16;

                }

                digiBuf[4] = 16; //not displayed

                digiBuf[5] = PWM_Val/100; //Display pwm value

                digiBuf[6] = PWM_Val%100/10;   

                digiBuf[7] = PWM_Val%10;


        

                if(IR_BT==3 && KeyUpDownFlag==0 ) //Long press to dim, release to stop dimming

                {        

                        

                        switch(NEC[2])

                        { //Long press to receive the burst code, 97.11ms high level, 10.15ms low level

                                case 0x15: if(IR==1) //if(IR==0)

                                                        {

                                                                KeyUpDownFlag = 1; //If the key is lifted, the release flag is set to 1

                                                        }         

                                

                                                        if(flag1==1 && flag==0) // Light on + long press to increase brightness

                                                        {

                                                                if(PWM_Val<200)

                                                                {

                                                                        

                                                                        PWM_Val++; // if(IR==1) use this sentence

                                                                // PWM_Val += 5; //if(IR==0) use this sentence to add 5 so that the light brightness changes significantly

                                                                        if(PWM_Val==200)

                                                                                

                                                                                flag1=0;

                                                                        

                                                                }

                                                        }         

                                                

                                                        if(flag1==0 && flag==0) //light on status + long press to reduce brightness

                                                        {

                                                                if(PWM_Val>0)

                                                                {

                                                                //PWM_Val -= 5;

                                                                        PWM_Val--;

                                                                        if(PWM_Val==0)

                                                                           

                                                                                flag1=1;

                                                               

                                                                }

                                                        } break;  

                        

                                                        

                                        case 0x07:break;

                                        default:break;

                        }        

               

                }        

               



///////////////////////////////////////////               

               

                if(flag==0) //Turn on the light

                {        

                        for(pwm=200;pwm>0;pwm--)

                        {

                                if(PWM_Val                                {

                                        led=1;

                        

                                }

                                else

                                {

                                        led=0;

                        

                                }

                        }

                }

                else

                {

                        led=1; //Turn off the light

                }


         

        }


}


Keywords:MCU Reference address:MCU infrared decoding, short press to turn on and off the light, long press to dim, digital tube to display key value

Previous article:Temperature alarm based on 51 single chip microcomputer
Next article:51 single chip temperature + pwm controls the fan speed, and the temperature is displayed on LCD1602

Recommended ReadingLatest update time:2024-11-23 12:37

Minimum MCU System
  The MCS-51 series is an 8-bit microcontroller series developed by INTEL in 1980. The initial products were 8051 with internal ROM and 8031 ​​without internal ROM. With the increase in the number of users of MCS-51 series microcontrollers, INTEL launched 8751 with internal EPROM and 8032, 8052, and 8752 with extended
[Microcontroller]
Minimum MCU System
Design of solar photovoltaic DC controller using AVR microcontroller control
Energy shortage and environmental pollution are becoming increasingly serious in the world today, forcing people to find and use new alternative energy sources. With the improvement of electronic technology and solar panel production technology, the use of solar energy is becoming more and more common. Solar energy ha
[Microcontroller]
Design of solar photovoltaic DC controller using AVR microcontroller control
51 MCU bus and non-bus program comparison
#include #include intrins.h #define uchar unsigned char #define uint unsigned int uchar code table ="The distance is "; uchar code table1 =" 00.0cm "; sbit shuru=P1^0; sbit yidianling=P1^0; sbit yidianyi=P1^3; //delay void delay(uint z) { uint x,y; for(x=z;x 0;x--) for(y=110;y 0;y--); } //1602 write addre
[Microcontroller]
Introduction to LCD driver MAX7232BF and hardware connection with microcontroller
MAX7232BF has 4-bit serial input, 2 decimal points and 4-bit address; the output is 10-bit data plus 20 independent decimal points, the data output code is BCD code, and the 2 decimal points of each bit are on COM3. It can be directly connected to the microprocessor. 1 Pin structure and description MAX7232
[Microcontroller]
Introduction to LCD driver MAX7232BF and hardware connection with microcontroller
51 single chip microcomputer LED water lamp
type of data Before writing the running light program, let's understand the data types. When using corresponding data, you should pay attention to overflow problems. If there is overflow, the compiler may compile it through, but the execution result will be wrong. Flowing lights Before operating the LED, you must
[Microcontroller]
51 single chip microcomputer LED water lamp
51 MCU C programming (fifteen 74HC595 control four-digit digital tube)
#include reg51.h #include intrins.h #define uchar unsigned char #define uint unsigned int uchar code DAT ={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x02,0xf8,0x00,0x10}; sbit SDATA_595=P1^0;   //Serial data input sbit SCLK_595=P1^1;     //Shift clock pulse sbit RCK_595=P1^2;       //Output latch control pulse sbit
[Microcontroller]
Wu Jianhong's microcontroller sharing diary (1)
  Wu Jianhong said that he would try to share his daily life with MCU. Because he is busy, he will only post his sharing in the post " Wu Jianhong talks about whether learning MCU or embedded system has a future ", so the editor will organize and post his sharing to the blog~~       Maybe I am ignorant, but accordi
[Microcontroller]
Wu Jianhong's microcontroller sharing diary (1)
PIC microcontroller floating point number and its conversion to decimal number
Abstract This paper focuses on the format of floating point numbers, the conversion between decimal numbers and floating points, and program design. In the instrument we designed, we used PIC series microcontrollers and encountered the problem of floating point operation. After consulting its relevant information,
[Microcontroller]
PIC microcontroller floating point number and its conversion to decimal number
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号