- #include
- #include "delay.h"
- static unsigned short addr = 0x00;
- static unsigned char ir_rx_buf[256];
- static unsigned char ir_rx_w_offset = 0;
- static unsigned char ir_rx_r_offset = 0;
- void ir_tx_open(){
- P2DIR |= BIT2 | BIT3; //P2.2, P2.3 output
- P2SEL |= BIT3; //P2.2:IO P2.3:TA0
- P2SEL &= ~BIT2; //
- P2OUT &= ~(BIT2 | BIT3);
- //38K->P2.3
- CCR0 = (int)(26.3*8 + 0.5);
- CCTL1 = OUTMOD_6;
- CCR1 = (int)(13.15*8 + 0.5);
- TACTL = TASSEL_2 + MC_1;
- }
- void ir_set_addr(unsigned char addr){
- addr = (unsigned char)(0xff&addr);
- }
- static void ir_start(){
- P2OUT |= BIT2;
- delay_us(9000);
- P2OUT &= ~BIT2;
- delay_us(4500);
- }
- static void ir_next(){
- P2OUT |= BIT2;
- delay_us(9000);
- P2OUT &= ~BIT2;
- delay_us(2250);
- }
- static void ir_send_byte(unsigned char c){
- unsigned char i;
- for(i = 0; i != 8; ++i){
- P2OUT |= BIT2;
- delay_us(560);
- P2OUT &= ~BIT2;
- if(c&0x01){
- delay_us(1685);
- }
- else{
- delay_us(565);
- }
- c >>= 1;
- }
- }
- static void ir_end(){
- P2OUT |= BIT2;
- delay_us(300);
- P2OUT &= ~BIT2;
- }
- void ir_put_char(unsigned char c){
- ir_start();
- ir_send_byte(addr);
- ir_send_byte(~addr);
- ir_send_byte(c);
- ir_send_byte(~c);
- ir_end();
- }
- void ir_put_string(char* str){
- if(*str != '')
- ir_start();
- else
- return;
- while(1){
- ir_send_byte(addr);
- ir_send_byte(~addr);
- ir_send_byte(*str);
- ir_send_byte(~(*str));
- ++str;
- if(*str != ''){
- ir_next();
- }
- else{
- ir_end();
- }
- }
- }
- void ir_put_array(unsigned char* array, unsigned int length){
- unsigned int i;
- ir_start();
- for(i = 0; i != length; ++i){
- ir_send_byte(addr);
- ir_send_byte(~addr);
- ir_send_byte(array[i]);
- ir_send_byte(array[i]);
- if(i < length-1){
- ir_next();
- }
- else{
- ir_end();
- }
- }
- }
- void ir_tx_close(){
- P2SEL &- ~BIT3;
- P2DIR |= BIT3;
- P2OUT &= ~BIT3;
- TACTL = TACLR;
- }
- void ir_rx_open(){
- P2SEL &= ~BIT0; //I/O
- P2DIR &= ~BIT0; //Input
- P2IES |= BIT0; //High->Low
- P2IE |= BIT0; //Enable interrupt
- }
- void ir_rx_close(){
- P2IE &= ~BIT0; //Disable interrupt
- }
- unsigned char ir_get(){
- while(ir_rx_r_offset == ir_rx_w_offset);
- return ir_rx_buf[ir_rx_r_offset++];
- }
- #pragma vector=PORT2_VECTOR
- __interrupt void port2_handler(){
- static unsigned char ir_code[4];
- unsigned char i, j;
- unsigned short time;
- if(P2IFG&BIT0){
- P2IE &= ~BIT0;
- P2IFG &= ~BIT0;
- _UNITE();
- time_start(9500);
- while(!time_out() && !(P2IN&BIT0));
- time = time_end();
- if(!time_out() && time > 8500){
- time_start(5000);
- while(!time_out() && (P2IN&BIT0));
- time = time_end();
- if(!time_out() && time > 4000){
- for(i = 0; i != 4; ++i){
- for(j = 0; j != 8; ++j){
- while(!(P2IN&BIT0));//Wait for high level
- time_start(2000); //timing high level
- while(!time_out() && (P2IN&BIT0));
- time = time_end();
- ir_code[i] >>= 1;
- if(!time_out() && time > 1500){
- //uart_put(0x03);
- ir_code[i] |= 0x80;
- }
- else{
- //uart_put(0x04);
- ir_code[i] &= 0x7f;
- }
- }
- }
- if(ir_code[0] == addr && (0xff == ir_code[0] + ir_code[1])){
- if(0xff == ir_code[2] + ir_code[3]){
- ir_rx_buf[ir_rx_w_offset++] = ir_code[2];
- }
- }
- }
- }
- P2IE |= BIT0;;
- }
- }
Previous article:12864 LCD circular display of Chinese characters on three screens
Next article:MSP430 (f149) study notes - infrared remote control transmitter
- 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?
- USB Type-C® and USB Power Delivery: Designed for extended power range and battery-powered systems
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- RAQ #223: How to measure and determine soft-start timing without a soft-start equation?
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- GigaDevice's full range of automotive-grade SPI NOR Flash GD25/55 wins ISO 26262 ASIL D functional safety certification
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- New IsoVu™ Isolated Current Probes: Bringing a New Dimension to Current Measurements
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- Infineon Technologies Launches ModusToolbox™ Motor Kit to Simplify Motor Control Development
- STMicroelectronics IO-Link Actuator Board Brings Turnkey Reference Design to Industrial Monitoring and Equipment Manufacturers
- Some Experiences in Reducing Noise and Electromagnetic Interference
- New breakthrough: Domestic chip BAC201 challenges small size, low power consumption, low cost and high integration
- CC2530 key flow
- (Repost) Introduction to MOS tubes - only talk about applications, not principles
- stm32g474 realizes 5 independent ADC synchronous sampling
- Classification and characteristics of power modules
- Simple application example of PIC16F877 peripheral function module (1)
- How to use the ratiometric characteristics of sensors and ADCs to improve accuracy
- Read and write SD card in Uboot with SIN-IMX6UL development board
- P89LPC932 Chinese Device Manual