M16 MCU l infrared decoding program + led digital tube display

Publisher:学海飘香Latest update time:2019-11-07 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I wrote a LED display + infrared decoding program using icc+M16


A special function is also their commonly used function key processing program. Press it to change a number. 

Press and hold for about 1s (set by yourself) to quickly change. Further functions are under development. 

The next step is the 3771+39610 stepper motor driver. I hope you will support me!

Oh, by the way, the pictures inside are made with flash8, and the schematic diagram is drawn with protues6.9. There are some problems in the simulation, but it is normal in the actual circuit.


MCU source code:

/*

01-05 22:30       2007-1-6 23:04

infrared

//ICC-AVR application builder : 2006-12-16 0:17:05         2006-12-18 20:04       IR_CDOE

// Target : M16

// Crystal: 16.000Mhz //Register uppercase and lowercase recognition. Must start with letters infrared

*/

#include

#include

#include "led.h"

#include "IR_DATA.H"

#define IR       6

//#include "delay.h"

//User code

#define          CUSTOMCODE          9

//Key code

#define          POWER_ON            221

#define          STAND_BY            220

#define          DMX                 216

#define          AUTO                212

#define          AUDIO               208

#define        FADETIME_UP           217

#define        FADETIME_DOWN         209

#define        PATTERN_UP            218

#define        PATTERN_DOWN          210


// value 0 1 10 11 12 13 14 15

//                         0         1         2         3         4          5        6         7         8        9          d          f            

char LED_DATA[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0Xa1,0X0e,0x00,0xff,0xef,0x3f}; //11 FOR "d"

char iPos,iPreBit,iNowBit,iHight,iLow,iIrMode,iBitCount,bIrCmdOk,bCmdOk,iCmd,iIrData[6];

char JS_001=0,JS_002=0;

long       JS_003=0;

char JS_004=0;

char JS_005=0;

char JS_006=0;

char JS_007=0;

char JS_008=0;

long       TIMER1_ICP_T,TIMER1_ICP_T1,TIMER1_ICP_T2;

char LED_DISPLAY_V1=10; // Initial value displayed is d001

char       LED_DISPLAY_V2=0;

char       LED_DISPLAY_V3=0;

char       LED_DISPLAY_V4=1;

char       LED_DISPLAY_V5=14;

long        JS_PRESS_ON_UP=0;

long        JS_PRESS_ON_DOWN=0;

char        JS_TIMER1_ICP_INPUT=0;

char        OUT_22_LOW;

char       JS_PRESS_ON_UP_1=0;

char       JS_PRESS_ON_UP_10000=0;

char       JS_PRESS_DWON_ON_1=0;

char       JS_PRESS_ON_DOWN_10000=0;

int         JS_PRESS_ON_UP_FAST=0;

int         JS_PRESS_OFF_UP=0;

char       JS_MODE_MODE=0;

char       JS_MENU_MODE=0;

char       JS_UP_MODE=0;

char       JS_DOWN_MODE=0;

int         JS_PRESS_OFF_DOWN;

int         JS_PRESS_ON_DOWN_FAST;

char       JS_PRESS_DOWN_ON_1;

char       ICP_TIME=0,ICP_TIME_T1=0;

char START_ICP_JS_TLOW=0;

char ICP_INT_SN=0; //ICP generates interrupt flag

char KEY_BANK=0;

char KEY_PAN_MODE_1=0;

char KEY_PAN_MODE_2=0;

char KEY_PAN_MODE_3=0;

char KEY_PAN_3=0;

char KEY_PAN_4=0;

char KEY_PAN_5=0;

char KEY_PAN_6=0;

char KEY_PAN_7=0;

char KEY_PAN_8=0;

char PAN_ICP_INPUT_CHECK=0,JS_ICP_INT=0;

char N_001=1,SUM=0;

char IR_CUSTOM_CODE=0;IR_DATA_CODE=0;

// Common anode 

void port_init(void)

{

PORT = 0xFF;

DDRA       = 0xFF;

PORTB = 0x1F;

DDRB       = 0x1F;

PORTC = 0x1F; //m103 output only

DDRC       = 0x10;

PORTD = 0x00;

DDRD       = 0x00;

}

//Watchdog initialize

// prescale: 16K 

//void watchdog_init(void)

//{

//WDR(); //this prevents a timout on enabling

//WDTCR = 0x08; //WATCHDOG ENABLED - dont forget to issue WDRs

//}       

//Watchdog initialize

// prescale: 2048K

void watchdog_init(void)

{

WDR(); //this prevents a timout on enabling

WDTCR = 0x0F; //WATCHDOG ENABLED - dont forget to issue WDRs

}

#pragma interrupt_handler eeprom_ready_isr:16

void eeprom_ready_isr(void)

{

//eeprom ready event

}

/////////////////////////TIMER0/////////////////////////////////////////////////////////////

//TIMER0 initialize - prescale:8

// WGM: Normal

// desired value: 100uSec

// actual value: 100.000uSec (0.0%)

void timer0_init(void)

{

TCCR0 = 0x00; //stop

TCNT0 = 0xCE; //set count

OCR0       = 0x32;       //set compare

TCCR0 = 0x02; //start timer

}

#pragma interrupt_handler timer0_ovf_isr:10

void timer0_ovf_isr(void)

{

       TCNT0 = 0xCE; //reload counter value       100us

       LED_SCAN(); 

       KEY_CHK(); 

       CheckIR();  

        JS_003=++JS_003;                     //KEY_CHECK 

        TEST();

        //display_times();              //TEST USE

  

  

   

}

/////////////////test/////////////////////////////////////

void       TEST()

{

       //LED_DISPLAY_V4=8;               //TEST

       if (JS_003==10000)

                {

                LED_DISPLAY_V5=14;

             

                }  

         else if (JS_003==20000)  

              {

              JS_003=0;  

              LED_DISPLAY_V5=13;

              } 

}

///////////////////////hour2/////////////////////// ///////////////////////////////////////////

//TIMER2 initialize - prescale:32

// WGM: Normal

// desired value: 10uSec

// actual value: 10.000uSec (0.0%)

void timer2_init(void)

{

TCCR2 = 0x00; //stop

ASSR       = 0x00; //set async mode

TCNT2 = 0xFB; //setup

OCR2       = 0x05;

TCCR2 = 0x03; //start

}

#pragma interrupt_handler timer2_ovf_isr:5

void timer2_ovf_isr(void)        //10us

{

TCNT2 = 0xFB; //reload counter value

//ICP_INT_JS();

//ICP_INT_CLR_JS();


}

/////////////////////////KEY_CHK/////////////////////////////////////////////////////////////

void KEY_CHK()

{

    

KEY_CHK_MODE(); // Call KEY_CHK_MODE

KEY_CHK_MENU(); // Call KEY_CHK_MENU

KEY_CHK_UP(); // Call KEY_CHK_UP

KEY_CHK_DOWN(); // Call KEY_CHK_DOWN  

}

//////////////////////////MODE///////////////////////////////////////////////////////////

void KEY_CHK_MODE()                        //100us /times

{

         KEY_BANK=KEY_INPUT; // Get PINC value

         KEY_BANK&=0X01; // Get the mode value 

if (KEY_BANK==0) //press to execute   

        {           //TEST--------OK------------->>>>  

            KEY_BANK=1;               

            JS_004=++JS_004;

            if (JS_004==1)

                             {

              //LED_DISPLAY_V1=11;

             LED_DISPLAY_V2=0;

             LED_DISPLAY_V3=0;

             LED_DISPLAY_V4=1;        

                             }

            else if (JS_004==2)

                              {

                                       JS_004&=0;

                                //LED_DISPLAY_V1=10;

                 LED_DISPLAY_V2=0;

              LED_DISPLAY_V3=0;

              LED_DISPLAY_V4=1;

                              }

        }

        else

           KEY_BANK=0;

    

}

void KEY_PRESS_CHECK_OFF()

{

            KEY_BANK=KEY_INPUT; // Get PINC value

            KEY_BANK&=0X01;    

          if (KEY_BANK==0) // V1 is pressed

              KEY_PAN_MODE_3=1;

          else // V1 is not pressed  

              KEY_PAN_MODE_3=0;

}

///////////////////////////////MENU/////////////////////////////////////////////////////////////////

void KEY_CHK_MENU() 

{

}

///////////////////////////////UP///////////////////////////////////////////////////////////////////////

void KEY_CHK_UP() 

{

         KEY_BANK=KEY_INPUT; // Get PINC value

         KEY_BANK=KEY_BANK>>2;

         KEY_BANK&=0X01; // Get DOWN value

       if (KEY_BANK==0)                   //press on       do it

           {    

           

                JS_PRESS_OFF_UP==0;  

           

            if (JS_PRESS_ON_UP_1==0)                 //press on       yes        first times

                {

                JS_PRESS_ON_UP_1=1;

                JS_PRESS_ON_UP=0;

                JS_PRESS_ON_UP_FAST=0;      

                JS_PRESS_ON_UP_10000=0;

                LED_DISPLAY_UP_DMX512();

           

                   // JS_UP_MODE=++JS_UP_MODE;

                   //        if (JS_UP_MODE==4)

                   //        JS_UP_MODE=0;

                }  

             else

             {

                    if (JS_PRESS_ON_UP_10000==1)

                        {

                                           if (JS_PRESS_ON_UP_FAST==2000)

                                             {

                            JS_PRESS_ON_UP_FAST=0;          

                            LED_DISPLAY_UP_DMX512();

                            }

                            else

                           JS_PRESS_ON_UP_FAST=++JS_PRESS_ON_UP_FAST;    

                        }

                   

                    if (JS_PRESS_ON_UP==30000)

                         {

                         JS_PRESS_ON_UP=0;          

                         JS_PRESS_ON_UP_10000=1; 

                         }

                    else

                        JS_PRESS_ON_UP=++JS_PRESS_ON_UP;                   

              }       

          }

       else             //unpress     

                {

                    JS_PRESS_ON_UP=0;

                    JS_PRESS_ON_UP_10000=0; 

                    JS_PRESS_ON_UP_FAST=0;     

                    JS_PRESS_OFF_UP=++JS_PRESS_OFF_UP; 

                  if (JS_PRESS_OFF_UP==2000)

                               { 

                                JS_PRESS_ON_UP_1=0;

                                JS_PRESS_OFF_UP=0;          

                               } 

          }     

                        

}


Reference address:M16 MCU l infrared decoding program + led digital tube display

Previous article:M8 MCU serial port communication monitoring (using PROTEUS serial port to simulate GSM module AT command communication)
Next article:TWI interrupt mode of AVR microcontroller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号