#include
#define uchar unsigned char
#define ulong unsigned long
/*------------------------------Display-----------------------------------*/
#define LED _DATA PORTB
const uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
/*
0 1 2 3 4 5 6 7 8 9 A B C D E F
*/
void delay(void){
uint i;
for(i=0;i<2000;i++);
}
void dis_int(uint dis_data)
{ //Four-digit common cathode digital tube , hexadecimal display
LED_DATA=tab[(uchar)((dis_data&0xf000)>>12)]; //Display thousands digit
PORTD=0xf7;
delay(); //Delay
LED_DATA=tab[(uchar)((dis_data&0x0f00)>>8)]; //Display hundreds digit
PORTD=0xfb;
delay(); //Delay
LED_DATA=tab[(uchar)(dis_data&0x00f0)>>4]; //Display tens digit
PORTD=0xfd;
delay(); //Delay
LED_DATA=tab[(uchar)dis_data&0x000f]; //Display ones digit
PORTD=0xfe;
delay(); //Delay
}
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0x00;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0x0F;
}
void timer1_init(void)
{
T CC R1B = 0x00; //stop
TCNT1H = 0x00; //setup
TCNT1L = 0x00;
IC R1H = 0x00;
ICR1L = 0x08;
TCCR1A = 0x00;
/*Connect the DATA pin of the integrated receiver to the PD6 (ICP1) pin of ATmega16, and decode by rising edge capture*/
/* The crystal oscillator is 6M, without frequency division , and 8M is too large (the frequency division is too small)*/
TCCR1B = 0x41; //start Timer
}
uint arr[16];//Save the capture value
uchar times;//Record the number of captures
uchar index;//Array index
uchar ir_code;//Infrared remote control key code
uchar OK_flag;//Decoding completed flag
/*------------------------------------------------------------------------------
Module Name: PD6 (ICP1) pin rising edge capture interrupt program
impact: Store captured value in arr[16]
___ ___
| | | |
___| |_________| |__________
|
//------------------------------------------------
Use M64, T3, crystal 7.3728, GCC 20040214
1
void timer1_init(void)
{
TCCR3B = 0x00; //stop
TCNT3H = 0x00; //setup
TCNT3L = 0x00;
ICR3H = 0x00;
ICR3L = 0x08;
TCCR3A = 0x00;
/*Connect the DATA pin of the integrated receiver to the PE7 (ICP3) pin of ATmega64, and use the rising edge capture method to decode*/
/*The crystal oscillator is 7.3728M, divided by 8*/
TCCR1B = 0xC2; //start Timer @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@change
}
2
SING(XXXXXXXXXXXXXXX)
{
uint value;
value=ICR3L;
value|=(uint)(ICR3H << 8);
TCNT3H = 0x00;
TCNT3L = 0x00;
times++;
if(times>18)&&(times<35){
//Save from the 19th rising edge to the 34th, there are 36 rising edges when short pressing
arr[index]=value;
index++;
}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@changeelse
if(times>35)@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@change
//else if(times>=35) //When this statement is used, the first bit of the second key value is reused by the 36th pulse of the previous key value,
{
//When the 35th rising edge arrives, decoding is completed
times=0;
index=0;
OK_flag=1;
}
}
Previous article:AVR dual CPU communication program (asynchronous mode) UART
Next article:ATMEGA88 analog serial port program
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Disassemble the Xiyangyang Bluetooth speaker into eight pieces
- I have a basic question about const in C. Can you please answer it?
- Sensirion SEK-SVM40 Review Summary
- [Pingtou Ge RVB2601 creative application development] Weather broadcaster based on Pingtou Ge RVB2601
- How to replace STM32 with GD32?
- [Homemade] DS-T10 Portable Smart Soldering Iron
- Frequently Asked Questions about Lingdongwei MM32F103 MCU
- The problem of increasing the driving capability of the oscillation circuit
- Antenna Design Solutions for Next Generation Mobile Devices
- Chapter 3 Using external interrupt EXTI to read keystrokes