1. Schematic diagram
315/433 MHz super regenerative module used in the experiment
Transmitter schematic diagram
Schematic diagram of receiving end
2. Transmitter Code
Send data using NEC protocol
#include #include #define FOSC 6000000L //IRC frequency sfr P3M1 = 0xB1; sfr P3M0 = 0xB2; sbit SEND = P3 ^ 4; //data sending pin sbit btn = P3 ^ 2; //Send key #ifndef fly #define uchar unsigned char #endif #ifndef uint #define uint unsigned int #endif uchar tx_buff[4]; //send buffer void Delay9ms() //@6.000MHz { unsigned char i, j; i = 53; j = 132; do { while(--j); } while(--i); } void Delay4ms() //@6.000MHz { unsigned char i, j; i = 24; j = 85; do { while(--j); } while(--i); } void Delay560us() //@6.000MHz { unsigned char i, j; i = 4; j = 65; do { while(--j); } while(--i); } void Delay20us() //@6.000MHz { unsigned char i; _nop_(); _nop_(); i = 27; while(--i); } //Send logic 1, logic 1 is 2.25ms, pulse time is 560us void send_logic_1() { SEND = 1; Delay560us(); SEND = 0; Delay560us(); Delay560us(); Delay560us(); } //Send logic 0, logic 0 is 1.12ms, pulse time is 560us void send_logic_0() { SEND = 1; Delay560us(); SEND = 0; Delay560us(); } //Send data of specified length void send(uchar *dat, uint len) { fly i, j, temp; //Boot code SEND = 1; Delay9ms(); //9ms high level SEND = 0; Delay4ms(); //4ms low level //Data code for(j = 0; j < len; j++){ temp = *that; for(i = 0; i < 8; i++) { if((temp & 0x01) == 0x01) { send_logic_1(); } else { send_logic_0(); } temp = temp >> 1; } that++; } //End code SEND = 1; Delay4ms(); //4ms high level SEND = 0; } void main() { INT0 = 1; IT0 = 1; //Set the interrupt type of INT0 (1: falling edge only 0: rising edge and falling edge) EX0 = 1; // Enable INT0 interrupt EA = 1; P3M1 &= 0xEF; //P3.4 push-pull output P3M0 &= 0xFF; tx_buff[0] = 0x40; tx_buff[1] = ~tx_buff[0]; //取反 tx_buff[2] = 0x56; tx_buff[3] = ~tx_buff[2]; //取反 while(1) { } } //Interrupt service routine void ex_int0() interrupt 0 //INT0 interrupt entry { if(btn == 0) { Delay20us(); if(btn == 0) { Delay20us(); send(tx_buff, 4); } while(!btn); //wait for button to be pressed } } 3. Receiver Code Receive data using NEC protocol #include #include #ifndef DARK #define FOSC 6000000L //IRC frequency #endif #ifndef fly #define uchar unsigned char #endif #ifndef uint #define uint unsigned int #endif sfr P3M1 = 0xB1; sfr P3M0 = 0xB2; sbit RECEIVE = P3 ^ 2; //Data receiving pin, INT0 bit exint0; bit flag = 0; //receive flag sbit LED = P3 ^ 3; //LED uchar recv[4]; //Receive buffer void Delay2ms() //@6.000MHz { unsigned char i, j; i = 12; j = 169; do { while(--j); } while(--i); } void Delay200us() //@6.000MHz { unsigned char i, j; i = 2; j = 39; do { while(--j); } while(--i); } void Init_Int0(void) { INT0 = 1; IT0 = 0; //Set the interrupt type of INT0 (1: falling edge only 0: rising edge and falling edge) EX0 = 1; // Enable INT0 interrupt } void main() { Heat_Int0(); EA = 1; P3M1 &= 0xF7; //P3.3 push-pull output P3M0 &= 0xFF; flag = 0; while(1) { if(flag) { flag = 0; LED = !LED; //Receive data and invert IO output } } } //Interrupt service routine void External_INT0() interrupt 0 //INT0 interrupt entry { flying i, j, N; uint k; exint0 = INT0; //Save the status of INT0 port, INT0=0 (falling edge); INT0=1 (rising edge) EX0 = 0; //Disable interrupt flag = 0; Delay2ms(); if(RECEIVE == 0) { EX0 = 1; flag = 0; return; } k = 100; //Confirm that the RECEIVE signal appears while(RECEIVE && k) { //Wait for RECEIVE to become a low level and skip the 9ms leading high level signal. Delay200us(); k--; } k = 100; while(!RECEIVE && k) { //Wait for RECEIVE to become high level and skip the 4ms leading low level signal. Delay200us(); k--; } for(i = 0; i < 4; i++) { //4 groups of data for(j = 0; j < 8; j++) { //Each set of data has 8 bits k = 100; while(RECEIVE && k) { //Wait for RECEIVE to become low level Delay200us(); k--; } k = 100; N = 0; while(!RECEIVE && k) { //Calculate the RECEIVE low level duration Delay200us(); N++; k--; if(N >= 30) { EX0 = 1; flag = 0; return; //0.14ms count is too long and automatically exits. } } //Low level counting completed recv[i] = recv[i] >> 1; //Fill the highest bit of data with "0" if(N >= 8) { recv[i] = recv[i] | 0x80; //Fill the highest bit of data with "1" } N = 0; } } if((recv[0] == ~recv[1]) && (recv[2] == ~recv[3])){ //Data verification successful flag = 1; } else{ flag = 0; } EX0 = 1; //Open interrupt } 4. Receive output waveform
Previous article:STC15 series MCU SPI usage tutorial (I)
Next article:STC15F104W PWM dimming
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Nand flash driver working principle
- Several questions in the chip manual
- Southchip SC8905 EVM evaluation report summary
- There is a new board~~ Take a look~~
- LSM6DSOX First Experience
- About CC2640 power consumption test problem
- An experienced person tells you how to choose a common mode noise filter
- stm32 and AD7732 help
- TI Audio Pre-Processing System Reference Design for Speech-Based Applications
- Playing with Zynq Serial 14 - Using GIT for Project Backup and Version Management 6