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; } } }
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Why does the newly soldered STM32 main control board run about 10 times slower than normal after programming?
- [Discussion] There is no place to make money during the seven days of National Day holiday
- Linux-3.14.52 Compiler Reference Manual v2.0
- ESP32 firmware is divided into two versions: ESP-IDF v3.x/4.x
- Two methods of programming TMS320C6748
- Enabling higher-performance front-end radar to make Vision Zero a reality
- Power supply control principle of three-phase fuel pump used in Mercedes-Benz passenger cars
- Review summary: Free review of Fudan Micro FM33LG0 series, Winsilver chip
- ESP32-S2-Saola-1 calculates pi
- DCDC H-bridge circuit, what is the principle of boost and buck?