IR receiver for TG-LPC11U35-501

Dependencies:   AQM0802 IR mbed

Committer:
yasuyuki
Date:
Mon Sep 28 04:47:25 2015 +0000
Revision:
4:4642c669045c
Parent:
3:7ecc01d39b46
to change P0_13 to P0_7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuyuki 0:8ae7470a57ef 1 //**********************
yasuyuki 3:7ecc01d39b46 2 // Infrared Rays receiver and transceiver sample for mbed
yasuyuki 0:8ae7470a57ef 3 //
yasuyuki 0:8ae7470a57ef 4 // LPC1768 flash=512KB, ADC=12bits
yasuyuki 0:8ae7470a57ef 5 // LPC11U35 flash=64KB, ADC=10bits
yasuyuki 0:8ae7470a57ef 6 // Nucleo F401RE flash=512KB, ADC=12bits
yasuyuki 0:8ae7470a57ef 7 //
yasuyuki 2:31c91b18bba9 8 // (C)Copyright 2014-2015 All rights reserved by Y.Onodera
yasuyuki 0:8ae7470a57ef 9 // http://einstlab.web.fc2.com
yasuyuki 0:8ae7470a57ef 10 //**********************
yasuyuki 0:8ae7470a57ef 11 #include "mbed.h"
yasuyuki 0:8ae7470a57ef 12 #include "AQM0802.h"
yasuyuki 0:8ae7470a57ef 13 #include "IR.h"
yasuyuki 0:8ae7470a57ef 14
yasuyuki 0:8ae7470a57ef 15 //#pragma O0
yasuyuki 0:8ae7470a57ef 16 //#pragma O1
yasuyuki 2:31c91b18bba9 17 //#pragma O2
yasuyuki 2:31c91b18bba9 18 //#pragma O3 // default
yasuyuki 2:31c91b18bba9 19 //#pragma Otime // default
yasuyuki 0:8ae7470a57ef 20 //#pragma Ospace
yasuyuki 0:8ae7470a57ef 21
yasuyuki 0:8ae7470a57ef 22
yasuyuki 0:8ae7470a57ef 23 #if defined(TARGET_LPC1768)
yasuyuki 0:8ae7470a57ef 24 DigitalOut led1(LED1);
yasuyuki 0:8ae7470a57ef 25 DigitalOut led2(LED2);
yasuyuki 0:8ae7470a57ef 26 I2C i2c(p28,p27);
yasuyuki 0:8ae7470a57ef 27 AnalogIn ain(p15);
yasuyuki 0:8ae7470a57ef 28 #endif
yasuyuki 0:8ae7470a57ef 29 // for TG-LPC11U35-501
yasuyuki 0:8ae7470a57ef 30 #if defined (TARGET_LPC11U35_501)
yasuyuki 0:8ae7470a57ef 31 DigitalOut led1(P0_20);
yasuyuki 0:8ae7470a57ef 32 DigitalOut led2(P0_21);
yasuyuki 0:8ae7470a57ef 33 I2C i2c(P0_5,P0_4);
yasuyuki 0:8ae7470a57ef 34 AnalogIn ain(P0_11);
yasuyuki 0:8ae7470a57ef 35 #endif
yasuyuki 0:8ae7470a57ef 36 // for Nucleo
yasuyuki 0:8ae7470a57ef 37 #if defined (TARGET_NUCLEO_F401RE)
yasuyuki 0:8ae7470a57ef 38 DigitalOut led1(D13);
yasuyuki 0:8ae7470a57ef 39 I2C i2c(D14,D15);
yasuyuki 0:8ae7470a57ef 40 AnalogIn ain(PA_0);
yasuyuki 0:8ae7470a57ef 41 #endif
yasuyuki 0:8ae7470a57ef 42
yasuyuki 0:8ae7470a57ef 43 AQM0802 lcd(i2c);
yasuyuki 4:4642c669045c 44 IR ir(P0_12,P0_7);
yasuyuki 0:8ae7470a57ef 45 InterruptIn button(P0_12);
yasuyuki 0:8ae7470a57ef 46
yasuyuki 2:31c91b18bba9 47 void irInterrupt()
yasuyuki 0:8ae7470a57ef 48 {
yasuyuki 0:8ae7470a57ef 49 led1=!led1;
yasuyuki 2:31c91b18bba9 50 button.disable_irq(); // !!! not work !!!
yasuyuki 2:31c91b18bba9 51 ir.getIR();
yasuyuki 0:8ae7470a57ef 52 button.enable_irq();
yasuyuki 0:8ae7470a57ef 53
yasuyuki 0:8ae7470a57ef 54 // To do something, code here
yasuyuki 0:8ae7470a57ef 55
yasuyuki 0:8ae7470a57ef 56 }
yasuyuki 0:8ae7470a57ef 57
yasuyuki 2:31c91b18bba9 58
yasuyuki 0:8ae7470a57ef 59 int main() {
yasuyuki 0:8ae7470a57ef 60
yasuyuki 0:8ae7470a57ef 61 char msg[10];
yasuyuki 3:7ecc01d39b46 62 char i,n;
yasuyuki 3:7ecc01d39b46 63 char name[][5]={"none","NEC ","AEHA","SONY"};
yasuyuki 0:8ae7470a57ef 64
yasuyuki 2:31c91b18bba9 65 button.fall(&irInterrupt);
yasuyuki 0:8ae7470a57ef 66 button.mode(PullUp);
yasuyuki 0:8ae7470a57ef 67
yasuyuki 0:8ae7470a57ef 68 sprintf(msg, "%d", SystemCoreClock );
yasuyuki 0:8ae7470a57ef 69 lcd.locate(0,0);
yasuyuki 0:8ae7470a57ef 70 lcd.print(msg);
yasuyuki 0:8ae7470a57ef 71 wait(1);
yasuyuki 0:8ae7470a57ef 72
yasuyuki 0:8ae7470a57ef 73 while(1) {
yasuyuki 0:8ae7470a57ef 74
yasuyuki 0:8ae7470a57ef 75 lcd.locate(0,0);
yasuyuki 3:7ecc01d39b46 76 sprintf(msg,"%s",name[ir.mode]); // 1:NEC, 2:AEHA, 3:SONY
yasuyuki 0:8ae7470a57ef 77 lcd.print(msg);
yasuyuki 3:7ecc01d39b46 78 sprintf(msg,"%4d",ir.bits); // bits
yasuyuki 0:8ae7470a57ef 79 lcd.print(msg);
yasuyuki 0:8ae7470a57ef 80
yasuyuki 3:7ecc01d39b46 81 // scroll
yasuyuki 3:7ecc01d39b46 82 n=(ir.bits+7)/8; // bits to n bytes
yasuyuki 3:7ecc01d39b46 83 for(i=0;i<n;i++){
yasuyuki 3:7ecc01d39b46 84 lcd.locate(0,1);
yasuyuki 3:7ecc01d39b46 85 sprintf(msg,"buf%02d=%02X",i,ir.buf[i]); // data
yasuyuki 3:7ecc01d39b46 86 lcd.print(msg);
yasuyuki 3:7ecc01d39b46 87 wait(1);
yasuyuki 0:8ae7470a57ef 88 }
yasuyuki 2:31c91b18bba9 89
yasuyuki 2:31c91b18bba9 90
yasuyuki 2:31c91b18bba9 91 // Echo back
yasuyuki 2:31c91b18bba9 92 button.fall(NULL); // disable Interrupt
yasuyuki 2:31c91b18bba9 93 // set parameter to send out
yasuyuki 2:31c91b18bba9 94 // ir.mode is 1:NEC, 2:AEHA or 3:SONY
yasuyuki 2:31c91b18bba9 95 // ir.bits is number to send out less than IR_LIMITS x8
yasuyuki 2:31c91b18bba9 96 // ir.buf[] are bytes buffer
yasuyuki 2:31c91b18bba9 97 ir.setIR();
yasuyuki 2:31c91b18bba9 98 button.fall(&irInterrupt); // enable Interrupt
yasuyuki 3:7ecc01d39b46 99 lcd.locate(0,1);
yasuyuki 3:7ecc01d39b46 100 sprintf(msg,"sent out");
yasuyuki 3:7ecc01d39b46 101 lcd.print(msg);
yasuyuki 2:31c91b18bba9 102 wait(1);
yasuyuki 2:31c91b18bba9 103
yasuyuki 0:8ae7470a57ef 104 }
yasuyuki 0:8ae7470a57ef 105
yasuyuki 0:8ae7470a57ef 106 }
yasuyuki 2:31c91b18bba9 107
yasuyuki 2:31c91b18bba9 108